Hi, Nikolay
Thanks for your answer. Its a little bit strange how my brain works. I saw you
version of the 'match' and I saw the solution right there. I didn't really
need a transparent region. I just wanted that the highlighted area not leak to
the start and end patterns. For that, Vim has 'hs' and 'he' pattern options.
So I rewrote the region, got rid of the match and everything worked fine. I
also included matches for bold, italic and code highlight in markdown style.
Here they are:
syn region doxygenUnderlined contained start="[\\@]uf{"hs=s+4 end="}"he=e-1 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn match doxygenMarkdownCode contained /\W\@<=`[^`']*`/ms=s+1,me=e-1 contains=doxygenContinueComment containedin=doxygenBrief*,doxygenLine,doxygenBody,doxygen.*Desc
syn region doxygenMarkdownBold contained start="\(\w\|_\)\@<!__[^[:space:]_]"hs=s+2 end="[^[:space:]_]__[^[:alnum:]]"he=e-3 end="[^[:space:]_]__$"he=e-2 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn region doxygenMarkdownBold contained start="\(\w\|\*\)\@<!\*\*[^[:space:]*]"hs=s+2 end="[^[:space:]*]\*\*[^[:alnum:]]"he=e-3 end="[^[:space:]*]\*\*$"he=e-2 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn region doxygenMarkdownEmph contained start="\(\w\|_\)\@<!_[^[:space:]_]"hs=s+1 end="[^[:space:]_]_[^[:alnum:]]"he=e-2 end="[^[:space:]_]_$"he=e-1 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn region doxygenMarkdownEmph contained start="\(\w\|\*\)\@<!\*[^[:space:]*]"hs=s+1 end="[^[:space:]*]\*[^[:alnum:]]"he=e-2 end="[^[:space:]*]\*$"he=e-1 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
And the test:
/**
* Brief description \uf{underlined}.
* With body @uf{underlined too}. This is _italic_ and this is __bold__.
* Both *italic* and **bold** works as of `monospaced font`.
*
* And with numbers: \uf{1.4}, _1.4_ and __1.4__.
* Every thing seams to be perfect. Separated \uf{dd
* ddd} in lines. We can have __bold separated
* into multiple lines__. Starred version of **bold
* can work** on separated lines. The *starred
* italic* also works on multiple lines.
* Bold __()__, **{}**, __[]__ __and,__ finally **.a.**.
* Italic _()_, *{}*, _[]_ _and,_ finally *.a.*.
*/
Only the backtick style code highlight doesn't work on multiple lines. Is very
late and I need to sleep a little.
Thanks for your help.
Thanks for your answer. Its a little bit strange how my brain works. I saw you
version of the 'match' and I saw the solution right there. I didn't really
need a transparent region. I just wanted that the highlighted area not leak to
the start and end patterns. For that, Vim has 'hs' and 'he' pattern options.
So I rewrote the region, got rid of the match and everything worked fine. I
also included matches for bold, italic and code highlight in markdown style.
Here they are:
syn region doxygenUnderlined contained start="[\\@]uf{"hs=s+4 end="}"he=e-1 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn match doxygenMarkdownCode contained /\W\@<=`[^`']*`/ms=s+1,me=e-1 contains=doxygenContinueComment containedin=doxygenBrief*,doxygenLine,doxygenBody,doxygen.*Desc
syn region doxygenMarkdownBold contained start="\(\w\|_\)\@<!__[^[:space:]_]"hs=s+2 end="[^[:space:]_]__[^[:alnum:]]"he=e-3 end="[^[:space:]_]__$"he=e-2 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn region doxygenMarkdownBold contained start="\(\w\|\*\)\@<!\*\*[^[:space:]*]"hs=s+2 end="[^[:space:]*]\*\*[^[:alnum:]]"he=e-3 end="[^[:space:]*]\*\*$"he=e-2 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn region doxygenMarkdownEmph contained start="\(\w\|_\)\@<!_[^[:space:]_]"hs=s+1 end="[^[:space:]_]_[^[:alnum:]]"he=e-2 end="[^[:space:]_]_$"he=e-1 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
syn region doxygenMarkdownEmph contained start="\(\w\|\*\)\@<!\*[^[:space:]*]"hs=s+1 end="[^[:space:]*]\*[^[:alnum:]]"he=e-2 end="[^[:space:]*]\*$"he=e-1 contains=doxygenContinueComment containedin=doxygenBrief,doxygenBody
And the test:
/**
* Brief description \uf{underlined}.
* With body @uf{underlined too}. This is _italic_ and this is __bold__.
* Both *italic* and **bold** works as of `monospaced font`.
*
* And with numbers: \uf{1.4}, _1.4_ and __1.4__.
* Every thing seams to be perfect. Separated \uf{dd
* ddd} in lines. We can have __bold separated
* into multiple lines__. Starred version of **bold
* can work** on separated lines. The *starred
* italic* also works on multiple lines.
* Bold __()__, **{}**, __[]__ __and,__ finally **.a.**.
* Italic _()_, *{}*, _[]_ _and,_ finally *.a.*.
*/
Only the backtick style code highlight doesn't work on multiple lines. Is very
late and I need to sleep a little.
Thanks for your help.
2015-04-07 13:18 GMT-03:00 Nikolay Pavlov <zyx.vim@gmail.com>:
2015-04-07 17:51 GMT+03:00 Alessandro Antonello <antonello.ale@gmail.com>:
> Hi everyone.
>
> I think I'm a little bit rusty using regular expressions in syntax
> highlight.
> I was trying to add a custom highlight to a Doxygen comment body and, for
> some
> reason, it is leaking to outside the comment limits.
>
> In the file 'after/syntax/doxygen.vim' I did the following:
>
> syn match doxygenCustomUnderline contained /[^}]*/
> \ containedin=doxygenUnderlineMatch
> syn region doxygenUnderlineMatch transparent contained
> \ start=/\%(\%(\\\|@\)uf\){/ms=s+4 end=/}/ keepend
> \ contains=doxygenCustomUnderline containedin=doxygenBody,doxygenBrief
>
> hi def link doxygenCustomUnderline Underlined
Your regex is rather strange:
1. You don't need outer \%(\) at all.
2. You don't need inner \%(\) as well because what you have there is
naturally expressed as the collection.
In any case, with
hi def link doxygenCustomUnderline Underlined
set ft=cpp.doxygen
syn match doxygenCustomUnderline contained /[^}]*/
containedin=doxygenUnderlineMatch
syn region doxygenUnderlineMatch transparent contained
start=/[@\\]uf{/ms=s+4 end=/}/ keepend
containedin=doxygenBody,doxygenBrief contains=doxygenCustomUnderline
I don't have the behaviour you observe. Vim version is 7.4.683.
Specifically I have `\uf{underlined}` underlined where expected, but
not `@uf{underlined too}`. `(int argc… {<Space>` *are* underlined.
My special ShowSyntax command (shows synstack output at cursor
position) shows that if there is `containedin=doxygenUnderlineMatch`
there is no doxygenUnderlineMatch at that position, but there is
doxygenCustomUnderline.
Worse, it seems to depend on some state: I see this behaviour *only in
first attempt in the first unnamed buffer that is there when Vim
starts*.
If I do <C-w>v:enew<CR> (including without `<C-w>v`) and repeat those
commands `(int…` is not underlined.
If I do `set ft=cpp.doxygen` in the very same buffer `(int…` is no
longer highlighted.
Also note that `(int` is highlighted immediately I define `syn
match…`. It is also highlighted if I rename groups to `dcu` and `dum`.
Not sure what is this exactly, but this is definitely some strange bug.
>
> NOTE: In the original file there are no continuation lines. Each group is
> wrote in a single line. I use continuation line here to ease reading.
>
> The I made the test in a 'syntest.cpp' file:
>
> /**
> * Brief description \uf{underlined}.
> * With body @uf{underlined too}.
> */
> int main(int argc, char** argv) { }
> --------------------------
>
> Surprisingly the underlined text is marked with '--' in addition to both
> regions in the doxygen comment. What could cause this kind of leak? I can't
> understand since the group 'doxygenCustomUnderline' is specifically set as
> contained in the group 'doxygenUnderlineMatch'.
>
> --
> --
> 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.
--
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:
Post a Comment