Den lör 23 nov. 2024 04:59Doug Kearns <dougkea...@gmail.com> skrev: > On Sat, 23 Nov 2024 at 04:28, BPJ <b...@melroch.se> wrote: > >> I have a syntax for a markup language where certain delimited constructs >> allow single newlines but not blank lines, i.e. this is OK >> >> ``` markup >> {_foo >> bar_} >> ``` >> >> but this is not OK >> >> ``` markup >> {_foo >> >> bar_} >> ``` >> >> is there any way to set up a region so that it behaves like this? I tried >> `oneline` plus a contained `syn match` which matches a newline not preceded >> or followed by a blank line but no luck! >> >> I get the behavior I want with a `syn match` with this pattern >> >> ``` pattern >> {_\%([^\n]\|\%(\_^\s*\)\@<!\n\%(\s*\_$\)\@!\)\{-}_} >> ``` >> > > Does something like this work? > > :syn region foobar start="{_" end="_}" end="$" skip="\n\s*\S" >
I already tried that. No lunch unfortunately. I'm going with the `syn match` version which incorporates the single newline pattern. It is probably less efficient but is also probably my only choice now as I found that I also need to exclude backslash from the "normal" subpattern and skip past backslash + char lest the closing delimiter is directly preceded by a backslash. BTW for reference the correct pattern, maybe inefficient but accurate, for a newline not preceded or followed by any blank line is ``````pattern \%(\_^\s*\)\@<!\n\%(\s*\_$\)@! `````` i.e. with negative lookbehind for optional horizontal whitespace and a start-of-line and the opposite negative lookahead for optional horizontal whitespace and an end-of-line. FWIW the backslash escape pattern I used is `\\\_.`, with later Special highlighting of backslashes followed by ASCII punctuation or space/newline/return. Who said it has to be easy! :-) > >> but then highlighting obviosly doesn't kick in until I type the closing >> delimiter so I would prefer a region. >> >> Also is there a better way to match the start or end of the file than >> `\_.\@<!` and `\_.\@!`? >> > > :help \%^ > Thanks. I still learn new things about Vim after having used it for ~20 years, which is both gratifying and frustrating! /bpj > Regards, > Doug > > -- > -- > 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 > > --- > You received this message because you are subscribed to the Google Groups > "vim_use" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to vim_use+unsubscr...@googlegroups.com. > To view this discussion visit > https://groups.google.com/d/msgid/vim_use/CAJ1uvoB5GPjE1RKY4wQkRW_zawUvFxnYWDHgOdOQ8tgkMdU%2Bpw%40mail.gmail.com > <https://groups.google.com/d/msgid/vim_use/CAJ1uvoB5GPjE1RKY4wQkRW_zawUvFxnYWDHgOdOQ8tgkMdU%2Bpw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- -- 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 --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_use/CADAJKhBE-Ffjycp9BWdayNi5No84nSq%2BNfNMn919OGsVh56CKw%40mail.gmail.com.