Skip to content

Commit

Permalink
[preservim#154] avoid execute() in capture_highlight
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Boolean263 committed Jun 14, 2023
1 parent a1e1390 commit df63dd1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions autoload/indent_guides.vim
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,13 @@ endfunction
" Captures and returns the output of highlight group definitions.
"
" Example: indent_guides#capture_highlight('normal')
" Returns: 'Normal xxx guifg=#323232 guibg=#ffffff'
" Returns: 'Normal fg=#323232 bg=#ffffff'
"
function! indent_guides#capture_highlight(group_name) abort
let l:output = execute('hi ' . a:group_name, 'silent')
let l:output = substitute(l:output, '\n', '', '')
let l:syn_id = synIDtrans(hlID(a:group_name))
let l:output = synIDattr(l:syn_id, 'name')
let l:output .= ' fg=' . synIDattr(l:syn_id, 'fg')
let l:output .= ' bg=' . synIDattr(l:syn_id, 'bg')
return l:output
endfunction

Expand Down

0 comments on commit df63dd1

Please sign in to comment.