From df63dd10450ace5d638e9eaf0c30d516a06d095e Mon Sep 17 00:00:00 2001 From: David Perry Date: Wed, 14 Jun 2023 12:33:59 -0400 Subject: [PATCH] [#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 --- autoload/indent_guides.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/autoload/indent_guides.vim b/autoload/indent_guides.vim index a1aa032..d85d05c 100644 --- a/autoload/indent_guides.vim +++ b/autoload/indent_guides.vim @@ -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