[vim/vim] runtime(vim): Improve Vim9 and legacy-script comment highlighting (PR #13104)

34 views
Skip to first unread message

dkearns

unread,
Sep 16, 2023, 10:42:46 AM9/16/23
to vim/vim, Subscribed

This is a simple attempt to only highlight Vim9 and legacy script
comments in the appropriate syntactic contexts.

Vim9 comments are highlighted at top level in a Vim9 script file, in all
:def functions, and in all :au and :com command blocks. Legacy script
comments are highlighted at top level in a legacy script file and in all
:func functions.

It attempts to fix #13047 and #11307 with minimal disruption to the
existing syntax definition as there is currently no maintainer
oversight.

I ran some comparison tests across runtime/*.vim and it doesn't appear
to break anything.

I am aware that the Vim9 comment matching, in particular, could be
greatly simplified but duplicating it for the moment seems like the
easiest strategy. Syntax files can be extremely fragile.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/13104

Commit Summary

  • 552a79d runtime(vim): Improve Vim9 and legacy-script comment highlighting

File Changes

(4 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104@github.com>

codecov[bot]

unread,
Sep 16, 2023, 10:57:01 AM9/16/23
to vim/vim, Subscribed

Codecov Report

Merging #13104 (552a79d) into master (ad29f6a) will increase coverage by 0.50%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #13104      +/-   ##
==========================================
+ Coverage   76.67%   77.18%   +0.50%     
==========================================
  Files         150      150              
  Lines      152416   152381      -35     
  Branches    39282    39256      -26     
==========================================
+ Hits       116872   117609     +737     
+ Misses      23519    22583     -936     
- Partials    12025    12189     +164     
Flag Coverage Δ
mingw-x64-HUGE ?
mingw-x86-HUGE 77.18% <ø> (?)
windows 77.18% <ø> (+0.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 101 files with indirect coverage changes


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c1722247241@github.com>

dkearns

unread,
Feb 25, 2024, 7:49:43 AM2/25/24
to vim/vim, Push

@dkearns pushed 1 commit.

  • 7fd5a46 runtime(vim): Improve Vim9 and legacy-script comment highlighting


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/push/17255809995@github.com>

dkearns

unread,
Feb 25, 2024, 10:42:22 AM2/25/24
to vim/vim, Push

@dkearns pushed 1 commit.

  • c3af787 runtime(vim): Improve Vim9 and legacy-script comment highlighting


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/push/17257189705@github.com>

dkearns

unread,
Apr 7, 2024, 11:38:38 AM4/7/24
to vim/vim, Push

@dkearns pushed 1 commit.

  • 7512b4c runtime(vim): Improve Vim9 and legacy-script comment highlighting


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/push/17887632465@github.com>

dkearns

unread,
Apr 9, 2024, 11:15:00 AM4/9/24
to vim/vim, Push

@dkearns pushed 1 commit.

  • 5350008 runtime(vim): Improve Vim9 and legacy-script comment highlighting


View it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/push/17920452094@github.com>

Christian Brabandt

unread,
Apr 9, 2024, 3:21:14 PM4/9/24
to vim/vim, Subscribed

Thanks. Can you please rebase and resolve the existing conflicts?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2045905665@github.com>

Christian Brabandt

unread,
Apr 10, 2024, 4:17:26 PM4/10/24
to vim/vim, Subscribed

thanks.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2048365040@github.com>

Christian Brabandt

unread,
Apr 10, 2024, 4:18:39 PM4/10/24
to vim/vim, Subscribed

@chrisbra approved this pull request.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/review/1992601644@github.com>

Christian Brabandt

unread,
Apr 10, 2024, 4:19:32 PM4/10/24
to vim/vim, Subscribed

Merged #13104 into master.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/issue_event/12427683462@github.com>

Maxim Kim

unread,
Apr 10, 2024, 8:17:52 PM4/10/24
to vim/vim, Subscribed

Hi @zeertzjq, before this improvement I was able to "lower" vimscript syntax noise by substituting vimCommand syntax group with minimum set of keywords:

syn clear vimCommand
syn keyword vimCommand contained vim9cmd vim9script import autoload export def enddef call function endfunction defer defcompile delfunction return
syn keyword vimCommand contained if else elseif endif
syn keyword vimCommand contained for endfor while endwhile continue break
syn keyword vimCommand contained class endclass interface endinterface enum endenum
syn keyword vimCommand contained throw try endtry catch finally
syn keyword vimCommand contained silent unsilent
syn keyword vimCommand contained public static final const var let unlet
syn keyword vimCommand contained highlight runtime source eval finish verbose command delcommand

However now it somehow influences comment highlighting:

image.png (view on web)

Before the patch:

image.png (view on web)

Could you suggest how can I set my own keywords for vimCommand?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2048635933@github.com>

Maxim Kim

unread,
Apr 10, 2024, 8:33:48 PM4/10/24
to vim/vim, Subscribed

oops, sorry @zeertzjq, I meant to ping @dkearns


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2048647769@github.com>

Maxim Kim

unread,
Apr 10, 2024, 9:06:37 PM4/10/24
to vim/vim, Subscribed

If I change vimPreVim9script to:

syn region vimPreVim9script start="\%^" end="^\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment keepend

adding keepend and removing \zs -- my changes to vimCommand work how it was before:

asciicast


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2048717706@github.com>

dkearns

unread,
Apr 12, 2024, 9:27:38 AM4/12/24
to vim/vim, Subscribed

@habamax, do you do that because of all the false positive matches for commands? I have a fix for that if I can catch enough edge cases not to annoy everyone in the short term.

Could you please try this patch with your additions and check folding works for a legacy header section before vim9script?

diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index c016703b6..1562476f1 100644
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -872,10 +872,11 @@ syn region        vimGlobal       matchgroup=Statement start='\<v\%[global]!\=/' skip='\\.' e
 
 if s:vim9script
   syn cluster vimLegacyTop contains=TOP,vimPreVim9script,vim9Comment,vim9LineComment
-  syn region vimPreVim9script start="\%^" end="^\ze\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment
+  syn region vimPreVim9script  start="\%^" end="^\ze\s*vim9s\%[cript]\>" contains=@vimLegacyTop,vimComment,vimLineComment fold
 
-  syn keyword vim9ScriptArg noclear
-  syn keyword vimCommand vim9s[cript] nextgroup=vim9ScriptArg skipwhite
+  syn keyword vim9ScriptArg    noclear
+  syn keyword vim9Script       vim9s[cript] nextgroup=vim9ScriptArg skipwhite
+  hi def link vim9Script vimCommand
 endif
 
 " Embedded Scripts:  {{{2


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2051761642@github.com>

Maxim Kim

unread,
Apr 12, 2024, 9:36:48 AM4/12/24
to vim/vim, Subscribed

do you do that because of all the false positive matches for commands?

Yes, short abbreviated commands especially.

I have a fix for that if I can catch enough edge cases not to annoy everyone in the short term

Would be glad to check it out once it is available.

Could you please try this patch with your additions and check folding works for a legacy header section before vim9script?

Looks like it works:

image.png (view on web)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13104/c2051777590@github.com>

Reply all
Reply to author
Forward
0 new messages