Saturday, December 28, 2019

Re: automatic redraw for multi-line syntax highlighting patterns

> the docs state (:help syn-multi-line) that syntax highlighting with
> multi-line patterns "mostly works as expected". I am not sure if this
> "mostly" includes automatic highlighting change of a multi-line syntax
> group when it's modified. Especially as soon as the pattern's end is
> destroyed. For example, take the commands of a session file ~/tmp/s.vim:
>
> call append(0, ['( comment?', ')'])syntax sync fromstarthi link m
> Commentsyntax match m /(.*\n)/
>
> They give us two lines highlighted as a comment (:hi Comment):
>
> ( comment?)
>
> Now, let's change the ')' into an 'x' via "2gg0rx". The test in the two
> lines does not match the defined syntax group anymore. But the display does
> not reflect this change right away. Instead I get something that's
> displayed partly as a comment (line 1) and partly as normal text (line 2):
>
> ( comment?)
>
> Note the different color of the two parentheses. I have to press CTRL-L to
> see the comment highlighting disappear completely. Having set syntax
> syncing to start from the very start of the file I would expect this to
> happen automatically. Is this imperfection the reason why the help says
> "mostly works" instead of "always works"? Or am I missing something?
>
> This is Vim 8.1.2337 (Huge version with GTK2 GUI) on Debian GNU/Linux,
> started with:
> vim --clean -S ~/tmp/s.vim
>
> Thanks in advance for all your insights,

When the text changes Vim by default assumes only that line needs to be
updated for syntax highlighting. In other words: the cached syntax
state at the start of the line is assumed to be valid.

If there are multi-line patterns, the sync mechanism needs to take care
of any syntax items where more state becomes invalid. The extreme
version is to use "syn sync fromstart". See ":help syn-sync".

--
ARTHUR: Be quiet!
DENNIS: --but by a two-thirds majority in the case of more--
ARTHUR: Be quiet! I order you to be quiet!
WOMAN: Order, eh -- who does he think he is?
ARTHUR: I am your king!
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/201912282157.xBSLvhPG001161%40masaka.moolenaar.net.

No comments: