Skip to content

Commit df63dd1

Browse files
committed
[preservim#154] avoid execute() in capture_highlight
Instead of using `execute()` to get the foreground and background colours of a colour scheme, use [`synIDattr()`][1] and related functions. This prevents an E12 error when using this plugin in neovim to edit a file which has a [modeline][2]. Tested in neovim 0.9.0 and vim 8.2. [1]: https://vimhelp.org/builtin.txt.html#synIDattr%28%29 [2]: https://vimhelp.org/options.txt.html#modeline
1 parent a1e1390 commit df63dd1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

autoload/indent_guides.vim

+5-3
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,13 @@ endfunction
250250
" Captures and returns the output of highlight group definitions.
251251
"
252252
" Example: indent_guides#capture_highlight('normal')
253-
" Returns: 'Normal xxx guifg=#323232 guibg=#ffffff'
253+
" Returns: 'Normal fg=#323232 bg=#ffffff'
254254
"
255255
function! indent_guides#capture_highlight(group_name) abort
256-
let l:output = execute('hi ' . a:group_name, 'silent')
257-
let l:output = substitute(l:output, '\n', '', '')
256+
let l:syn_id = synIDtrans(hlID(a:group_name))
257+
let l:output = synIDattr(l:syn_id, 'name')
258+
let l:output .= ' fg=' . synIDattr(l:syn_id, 'fg')
259+
let l:output .= ' bg=' . synIDattr(l:syn_id, 'bg')
258260
return l:output
259261
endfunction
260262

0 commit comments

Comments
 (0)