[llvm] [vim] Fix command already exists on opening multiple mir buffers (PR #82410)

Joe Nash via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 11:53:34 PST 2024


https://github.com/Sisyph created https://github.com/llvm/llvm-project/pull/82410

When using the vim syntax for mir, an error occurs in nvim (unknown if it affects the original vim) when opening multiple .mir buffers. Add '!' when defining HiLink to redefine the command instead of giving an error. Only the changes to mir.vim and llvm.vim are required to fix the error, but from similarity making the change in all the syntax files seems prudent.

To reproduce:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Open an .mir file, for example llvm/test/Codegen/X86/expand-post-ra-pseudo.mir                                                                                                                                                   
Open another mir file from within nvim, for example peephole.mir
                                                                                                                                                                 
```
Error detected while processing function 335[30]..<SNR>43_callback[25]..function 335[30]..<SNR>43_callback:                                                                                                                      
line   23:                                                                                                                                                                                                                       
Vim(command):E174: Command already exists: add ! to replace it: HiLink hi def link <args>   
```

>From 133d8082973429de25f72c59bee932a6fc67ccee Mon Sep 17 00:00:00 2001
From: Joe Nash <joseph.nash at amd.com>
Date: Mon, 18 Dec 2023 16:47:34 -0500
Subject: [PATCH] [vim] Fix command already exists on opening multiple mir
 buffers

When using the vim syntax for mir, an error occurs in nvim (unknown if it
affects the original vim) when opening multiple .mir buffers. Add '!' when
defining HiLink to redefine the command instead of giving an error. Only the
changes to mir.vim and llvm.vim are required to fix the error, but from
similarity making the change in all the syntax files seems prudent.
---
 llvm/utils/vim/syntax/llvm.vim       | 4 ++--
 llvm/utils/vim/syntax/machine-ir.vim | 4 ++--
 llvm/utils/vim/syntax/mir.vim        | 4 ++--
 llvm/utils/vim/syntax/tablegen.vim   | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/llvm/utils/vim/syntax/llvm.vim b/llvm/utils/vim/syntax/llvm.vim
index d86e3d1ddbc27f..a0acc58236939a 100644
--- a/llvm/utils/vim/syntax/llvm.vim
+++ b/llvm/utils/vim/syntax/llvm.vim
@@ -246,9 +246,9 @@ syn match  llvmSpecialComment /;\s*XFAIL:.*$/
 if version >= 508 || !exists("did_c_syn_inits")
   if version < 508
     let did_c_syn_inits = 1
-    command -nargs=+ HiLink hi link <args>
+    command! -nargs=+ HiLink hi link <args>
   else
-    command -nargs=+ HiLink hi def link <args>
+    command! -nargs=+ HiLink hi def link <args>
   endif
 
   HiLink llvmType Type
diff --git a/llvm/utils/vim/syntax/machine-ir.vim b/llvm/utils/vim/syntax/machine-ir.vim
index 814b31b4671e10..2f03de63acf439 100644
--- a/llvm/utils/vim/syntax/machine-ir.vim
+++ b/llvm/utils/vim/syntax/machine-ir.vim
@@ -23,9 +23,9 @@ syn match   mirPReg /$[-a-zA-Z$._][-a-zA-Z$._0-9]*/
 if version >= 508 || !exists("did_c_syn_inits")
   if version < 508
     let did_c_syn_inits = 1
-    command -nargs=+ HiLink hi link <args>
+    command! -nargs=+ HiLink hi link <args>
   else
-    command -nargs=+ HiLink hi def link <args>
+    command! -nargs=+ HiLink hi def link <args>
   endif
 
   HiLink mirType Type
diff --git a/llvm/utils/vim/syntax/mir.vim b/llvm/utils/vim/syntax/mir.vim
index 51ac4982b7c95e..126ccb9c43dfc4 100644
--- a/llvm/utils/vim/syntax/mir.vim
+++ b/llvm/utils/vim/syntax/mir.vim
@@ -37,9 +37,9 @@ syn match  mirSpecialComment /#\s*XFAIL:.*$/
 if version >= 508 || !exists("did_c_syn_inits")
   if version < 508
     let did_c_syn_inits = 1
-    command -nargs=+ HiLink hi link <args>
+    command! -nargs=+ HiLink hi link <args>
   else
-    command -nargs=+ HiLink hi def link <args>
+    command! -nargs=+ HiLink hi def link <args>
   endif
 
   HiLink mirSpecialComment SpecialComment
diff --git a/llvm/utils/vim/syntax/tablegen.vim b/llvm/utils/vim/syntax/tablegen.vim
index c2a22306636047..c84594513e3e06 100644
--- a/llvm/utils/vim/syntax/tablegen.vim
+++ b/llvm/utils/vim/syntax/tablegen.vim
@@ -33,9 +33,9 @@ syn region  tgComment2 matchgroup=tgComment2  start=+/\*+ end=+\*/+ contains=tgT
 if version >= 508 || !exists("did_c_syn_inits")
   if version < 508
     let did_c_syn_inits = 1
-    command -nargs=+ HiLink hi link <args>
+    command! -nargs=+ HiLink hi link <args>
   else
-    command -nargs=+ HiLink hi def link <args>
+    command! -nargs=+ HiLink hi def link <args>
   endif
 
   HiLink tgKeyword Statement



More information about the llvm-commits mailing list