automatic redraw for multi-line syntax highlighting patterns

25 views
Skip to first unread message

Tom M

unread,
Dec 27, 2019, 6:33:17 PM12/27/19
to vim...@googlegroups.com
Hi,

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 fromstart
hi link m Comment
syntax 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,

Tom

Tom M

unread,
Dec 27, 2019, 6:40:28 PM12/27/19
to vim...@googlegroups.com
On Sat, Dec 28, 2019 at 12:32 AM Tom M <7to...@gmail.com> wrote:
Hi,

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 fromstart
hi link m Comment
syntax 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?
)
 Typo here. This last screen looks, of course, like this:
( comment?
x
Sorry for the confusion.

Tom

Bram Moolenaar

unread,
Dec 28, 2019, 4:57:52 PM12/28/19
to vim...@googlegroups.com, Tom M

> 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 -- Br...@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 ///

Tom M

unread,
Dec 28, 2019, 5:32:01 PM12/28/19
to Bram Moolenaar, vim...@googlegroups.com
> 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".

My syn-sync setup does include "syn sync fromstart". Am I missing
something else in the syn-sync setup?

Thanks,

Tom

Tom M

unread,
Jan 13, 2020, 7:50:59 AM1/13/20
to Bram Moolenaar, vim...@googlegroups.com
As stated above, the syntax highlighting is not updated to reflect the
changed text even with "syn sync fromstart". So this definitely looks
like a bug. Should I open a ticket in the issue tracker?

Tom
Reply all
Reply to author
Forward
0 new messages