Monday, June 29, 2015

Re: syntax region end when either pattern occurs?

2015-06-29 18:52 GMT+03:00 Rick Dooling <rpdooling@gmail.com>:
> I am trying to syntax highlight yaml blocks in Markdown files.
>
> Right now, I can get it so it handles either blocks that look like this:
>
> ---
> author: me
> document: Help
> ---
>
> or
>
> ---
> author: me
> document: Help
> ...
>
> But not both. Is there a way to do both?
>
> I tried end=\(/^---$/\|/^\.\.\.$\) but that didn't work

end=\(/^---$/\|/^\.\.\.$\)

Syntax for such items is end={separator}{regex}{separator}[offsets].
In your example separator is `\` which really results in something
weird because `\` is *always* an escape character. This has no chances
to work, you need to use `end=/\v^%(\.{3}|\-{3})$/`. (Note: in
very-magic mode (:h /\v) you *must* escape HYPHEN-MINUS because it is
an ASCII character that is not guaranteed not to have special meaning
according to help even though it currently means itself.)

>
> unlet b:current_syntax
>
> " Bring in YAML syntax for front matter
> syntax include @Yaml syntax/yaml.vim
>
> syntax region yamlFrontmatter start=/\%^---$/ end=/^---$/ keepend contains=@Yaml
> syntax region yamlFrontmatter start=/\%^---$/ end=/^\.\.\.$/ keepend contains=@Yaml

This variant has no chances to work AFAIK because which exactly region
is started is determined when `start` regexp is encountered from
whatever rule *first* happened to match. No global "backtracking" and
trying another region to see whether it fits better.

>
> let b:current_syntax='markdown'
>
> --
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: