Monday, September 5, 2011

Re: nextgroup across line border

On Sep 5, 1:52 am, ZyX <zyx....@gmail.com> wrote:
> I want to create a syntax for filetype that looks like this:
>
>     item0onLine0 item1onLine1
>     item0onLine1 item1onLine1
>     separatorLine
>     item0onLine0 item1onLine0
>     item1onLine1 item1onLine1
>     ...
>
> In order to do this I try
>
>     syn match i0l0 /^item0onLine0/             nextgroup=i1l0
>     syn match i1l0 / item1onLine0\n/ contained nextgroup=i0l1
>     syn match i0l1 /item0onLine1/    contained nextgroup=i1l1
>     syn match i1l1 / item1onLIne1\n/ contained
>
> , but this works on first line only. How can I have next group located on the
> next line? `item0onLine1' cannot be matched reliably on its own. `item0onLine0'
> is always matched reliably.
>
>  signature.asc
> < 1KViewDownload

Don't know if I got you right but my personal experience is that too
many "nextgroup"s was no good, it's just a hint to Vim that certain
syntax groups should get a privilege next, it doesn't ensure anything.
If what you mean is that some text's syntax group can't be decided by
it's own signature but the context it resides, than I suggest you use
a structural approach:

AAA ... XXX
BBB ... XXX

Say, you want to color the second 'XXX' differently because it's in
the line begin with "BBB", then this should do:

" syntax container
syntax match Aline /^AAA\>.*/
hi link Aline Normal " no color, just for containing other groups

syntax match Bline /^BBB\>.*/
hi link Bline Normal " the same as above

" target syntax groups
syntax match Aword /\<XXX\>/ containedin=Aline contained
hi link Aword ColorA

syntax match Bword /\<XXX\>/ containedin=Bline contained
hi link Bword ColorB

If you can find the appropriate container group with its own signature
then things will get a lot easier, because with 'containedin'
and 'contained' together, Vim won't try to match 'XXX' anywhere else.

Just a wild guess, hope it helps.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: