Procházet zdrojové kódy

Use a separate `syntax/bufexplorer.vim` file for syntax highlighting.

This follows Vim's recommended syntax highlighting structure as
described in `:help syntax.txt`.

With this structure, changes to the buffer's filetype are handled
automatically.  This includes redundant changes such as the one done by
the `rainbow_csv` plugin's "ugly hacks" commit mentioned in BufExplorer
issue #82:
https://github.com/mechatroner/rainbow_csv/commit/dbc7be7dd419508c9a5a16d9cac57616135895c8

`rainbow_csv` executes the below command when entering a BufExplorer
buffer:

  set filetype=bufexplorer

Previously, this had the effect of disabling BufExplorer's syntax
highlighting; with the new `syntax/bufexplorer.vim` file in place,
syntax highlighting remains active.  This fixes #82.
Michael Henry před 9 měsíci
rodič
revize
949256b8fe
2 změnil soubory, kde provedl 54 přidání a 46 odebrání
  1. 0 46
      plugin/bufexplorer.vim
  2. 54 0
      syntax/bufexplorer.vim

+ 0 - 46
plugin/bufexplorer.vim

@@ -670,7 +670,6 @@ function! s:DisplayBufferList()
     setlocal nowrap
     setlocal bufhidden=wipe
 
-    call s:SetupSyntax()
     call s:MapKeys()
 
     " Wipe out any existing lines in case BufExplorer buffer exists and the
@@ -755,51 +754,6 @@ function! s:MapKeys()
     endfor
 endfunction
 
-" SetupSyntax {{{2
-function! s:SetupSyntax()
-    if has("syntax")
-        syn match bufExplorerHelp     "^\".*" contains=bufExplorerSortBy,bufExplorerMapping,bufExplorerTitle,bufExplorerSortType,bufExplorerToggleSplit,bufExplorerToggleOpen
-        syn match bufExplorerOpenIn   "Open in \w\+ window" contained
-        syn match bufExplorerSplit    "\w\+ split" contained
-        syn match bufExplorerSortBy   "Sorted by .*" contained contains=bufExplorerOpenIn,bufExplorerSplit
-        syn match bufExplorerMapping  "\" \zs.\+\ze :" contained
-        syn match bufExplorerTitle    "Buffer Explorer.*" contained
-        syn match bufExplorerSortType "'\w\{-}'" contained
-        syn match bufExplorerBufNbr   /^\s*\d\+/
-        syn match bufExplorerToggleSplit  "toggle split type" contained
-        syn match bufExplorerToggleOpen   "toggle open mode" contained
-
-        syn match bufExplorerModBuf    /^\s*\d\+.\{4}+.*/
-        syn match bufExplorerLockedBuf /^\s*\d\+.\{3}[\-=].*/
-        syn match bufExplorerHidBuf    /^\s*\d\+.\{2}h.*/
-        syn match bufExplorerActBuf    /^\s*\d\+.\{2}a.*/
-        syn match bufExplorerCurBuf    /^\s*\d\+.%.*/
-        syn match bufExplorerAltBuf    /^\s*\d\+.#.*/
-        syn match bufExplorerUnlBuf    /^\s*\d\+u.*/
-        syn match bufExplorerInactBuf  /^\s*\d\+ \{7}.*/
-
-        hi def link bufExplorerBufNbr Number
-        hi def link bufExplorerMapping NonText
-        hi def link bufExplorerHelp Special
-        hi def link bufExplorerOpenIn Identifier
-        hi def link bufExplorerSortBy String
-        hi def link bufExplorerSplit NonText
-        hi def link bufExplorerTitle NonText
-        hi def link bufExplorerSortType bufExplorerSortBy
-        hi def link bufExplorerToggleSplit bufExplorerSplit
-        hi def link bufExplorerToggleOpen bufExplorerOpenIn
-
-        hi def link bufExplorerActBuf Identifier
-        hi def link bufExplorerAltBuf String
-        hi def link bufExplorerCurBuf Type
-        hi def link bufExplorerHidBuf Constant
-        hi def link bufExplorerLockedBuf Special
-        hi def link bufExplorerModBuf Exception
-        hi def link bufExplorerUnlBuf Comment
-        hi def link bufExplorerInactBuf Comment
-    endif
-endfunction
-
 " ToggleHelp {{{2
 function! s:ToggleHelp()
     let g:bufExplorerDetailedHelp = !g:bufExplorerDetailedHelp

+ 54 - 0
syntax/bufexplorer.vim

@@ -0,0 +1,54 @@
+" Vim syntax file
+" Language: bufexplorer
+
+if exists("b:current_syntax")
+    finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+syn match bufExplorerHelp     "^\".*" contains=bufExplorerSortBy,bufExplorerMapping,bufExplorerTitle,bufExplorerSortType,bufExplorerToggleSplit,bufExplorerToggleOpen
+syn match bufExplorerOpenIn   "Open in \w\+ window" contained
+syn match bufExplorerSplit    "\w\+ split" contained
+syn match bufExplorerSortBy   "Sorted by .*" contained contains=bufExplorerOpenIn,bufExplorerSplit
+syn match bufExplorerMapping  "\" \zs.\+\ze :" contained
+syn match bufExplorerTitle    "Buffer Explorer.*" contained
+syn match bufExplorerSortType "'\w\{-}'" contained
+syn match bufExplorerBufNbr   /^\s*\d\+/
+syn match bufExplorerToggleSplit  "toggle split type" contained
+syn match bufExplorerToggleOpen   "toggle open mode" contained
+
+syn match bufExplorerModBuf    /^\s*\d\+.\{4}+.*/
+syn match bufExplorerLockedBuf /^\s*\d\+.\{3}[\-=].*/
+syn match bufExplorerHidBuf    /^\s*\d\+.\{2}h.*/
+syn match bufExplorerActBuf    /^\s*\d\+.\{2}a.*/
+syn match bufExplorerCurBuf    /^\s*\d\+.%.*/
+syn match bufExplorerAltBuf    /^\s*\d\+.#.*/
+syn match bufExplorerUnlBuf    /^\s*\d\+u.*/
+syn match bufExplorerInactBuf  /^\s*\d\+ \{7}.*/
+
+hi def link bufExplorerBufNbr Number
+hi def link bufExplorerMapping NonText
+hi def link bufExplorerHelp Special
+hi def link bufExplorerOpenIn Identifier
+hi def link bufExplorerSortBy String
+hi def link bufExplorerSplit NonText
+hi def link bufExplorerTitle NonText
+hi def link bufExplorerSortType bufExplorerSortBy
+hi def link bufExplorerToggleSplit bufExplorerSplit
+hi def link bufExplorerToggleOpen bufExplorerOpenIn
+
+hi def link bufExplorerActBuf Identifier
+hi def link bufExplorerAltBuf String
+hi def link bufExplorerCurBuf Type
+hi def link bufExplorerHidBuf Constant
+hi def link bufExplorerLockedBuf Special
+hi def link bufExplorerModBuf Exception
+hi def link bufExplorerUnlBuf Comment
+hi def link bufExplorerInactBuf Comment
+
+let b:current_syntax = "bufexplorer"
+
+let &cpo = s:cpo_save
+unlet! s:cpo_save