vim icon indicating copy to clipboard operation
vim copied to clipboard

runtime(vim): correctly handle ! attribute for augroup/doautocmd/doautoall

Open chrisbra opened this issue 1 year ago • 4 comments

I noticed that

:autocmd! FooBar
:augroup! FooBar

looks slightly different to how the ! is drawn. While the ! for the autocmd case is shown in the same color as autocmd, for :augroup is is shown as VimEventList

In addition, the vim syntax seems to accept doautocmd! and doautoall! (with bang attribute) even so this is not valid.

So let's fix all of those and mark the ! as an error for the the :doautocmd/doautoall case.

cc @dkearns

chrisbra avatar Jun 03 '24 19:06 chrisbra

Thanks. We need to match vimAutoEventList after a ! so I'd add a dedicated bang group for autocmds like the following.

--- vim.vim     2024-06-04 13:18:27.530178121 +1000
+++ /tmp/vim2.vim       2024-06-04 20:20:11.472645559 +1000
@@ -565,8 +565,9 @@
 if !exists("g:vimsyn_noerror")
  syn match     vimAutoBangError        contained       "!"     skipwhite nextgroup=vimAutoEventList
 endif
-syn keyword    vimAutoCmd      au[tocmd]       skipwhite       nextgroup=vimAugroupBang,vimAutoEventList
+syn keyword    vimAutoCmd      au[tocmd]       skipwhite       nextgroup=vimAutoCmdBang,vimAutoEventList
 syn keyword    vimAutoCmd      do[autocmd] doautoa[ll] skipwhite nextgroup=vimAutoBangError,vimAutoEventList
+syn match      vimAutoCmdBang  contained       "\a\@1<=!"      skipwhite nextgroup=vimAutoEventList
 syn match      vimAutoCmdMod   "\(++\)\=\(once\|nested\)"      skipwhite nextgroup=vimAutoCmdBlock
 syn region     vimAutoCmdBlock contained       matchgroup=vimSep start="{" end="}" contains=@vimDefBodyList
 
@@ -1106,6 +1107,7 @@
  hi def link vimAugroupError   vimError
  hi def link vimAugroupKey     vimCommand
  hi def link vimAutoCmd        vimCommand
+ hi def link vimAutoCmdBang    vimBang
  hi def link vimAutoEvent      Type
  hi def link vimAutoCmdMod     Special
  hi def link vimBang   vimOper

Patch on top of your changes.

dkearns avatar Jun 04 '24 10:06 dkearns

I also found a stash attempting to fix a number of issues with :au. I'll see what I can salvage...

dkearns avatar Jun 04 '24 11:06 dkearns

do you want to take over this one then? Or shall I squash your patch on top of mine and go ahead merging?

chrisbra avatar Jun 05 '24 11:06 chrisbra

I can take it if you're not in a hurry for the intermediate fix.

dkearns avatar Jun 10 '24 19:06 dkearns