automatic redraw for multi-line syntax highlighting patterns

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

automatic redraw for multi-line syntax highlighting patterns

Tom M
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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAD_dSXiPJzHXRqpWgtKQPS0Y8UhBkk3Ns6iCtJW566jKgcJysw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: automatic redraw for multi-line syntax highlighting patterns

Tom M

On Sat, Dec 28, 2019 at 12:32 AM Tom M <[hidden email]> 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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAD_dSXjKeSDVXJ3XfHuLWHusKL0c5%3DmSLhDoe7LKbFs4DOaJ1g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: automatic redraw for multi-line syntax highlighting patterns

Bram Moolenaar
In reply to this post by 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 -- [hidden email] -- 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/201912282157.xBSLvhPG001161%40masaka.moolenaar.net.
Reply | Threaded
Open this post in threaded view
|

Re: automatic redraw for multi-line syntax highlighting patterns

Tom M
> 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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAD_dSXiY5R-OyrF8Q8FqXpSejgbrQjFOvvbEy_X7mkvPWzFqwg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: automatic redraw for multi-line syntax highlighting patterns

Tom M
> > 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?

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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAD_dSXgPBiuiP4W1aSitH91N3akMfQqmu_VJY3sPkgQe5RCqvA%40mail.gmail.com.