Skip to content

Commit

Permalink
Only call execute function once per syntax group (#303)
Browse files Browse the repository at this point in the history
Before the custom `s:hi` function called Vim's `execute` function [1]
for each defined attribute which is quite expensive in terms of
performance. To improve this the attributes are now concatenate as
string and passed to `exec` at the end of the function instead.


Co-authored-by: Julien Voisin <jvoisin@google.com>
Co-authored-by: Sven Greb <development@svengreb.de>
Co-authored-by: Arctic Ice Sudio <development@arcticicestudio.com>

[1]: https://vimhelp.org/builtin.txt.html#builtin.txt#execute%28%29

GH-303
  • Loading branch information
jvoisin authored and svengreb committed May 14, 2022
1 parent dd7666d commit f3327db
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions colors/nord.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,27 @@ let g:nord_cursor_line_number_background = get(g:, "nord_cursor_line_number_back
let g:nord_uniform_diff_background = get(g:, "nord_uniform_diff_background", 0)

function! s:hi(group, guifg, guibg, ctermfg, ctermbg, attr, guisp)
let cmd = ""
if a:guifg != ""
exec "hi " . a:group . " guifg=" . a:guifg
let cmd = cmd . " guifg=" . a:guifg
endif
if a:guibg != ""
exec "hi " . a:group . " guibg=" . a:guibg
let cmd = cmd . " guibg=" . a:guibg
endif
if a:ctermfg != ""
exec "hi " . a:group . " ctermfg=" . a:ctermfg
let cmd = cmd . " ctermfg=" . a:ctermfg
endif
if a:ctermbg != ""
exec "hi " . a:group . " ctermbg=" . a:ctermbg
let cmd = cmd . " ctermbg=" . a:ctermbg
endif
if a:attr != ""
exec "hi " . a:group . " gui=" . a:attr . " cterm=" . substitute(a:attr, "undercurl", s:underline, "")
let cmd = cmd . " gui=" . a:attr . " cterm=" . substitute(a:attr, "undercurl", s:underline, "")
endif
if a:guisp != ""
exec "hi " . a:group . " guisp=" . a:guisp
let cmd = cmd . " guisp=" . a:guisp
endif
if cmd != ""
exec "hi " . a:group . cmd
endif
endfunction

Expand Down Expand Up @@ -188,12 +192,12 @@ if has('nvim')
call s:hi("DiagnosticUnderlineError" , s:nord11_gui, "", s:nord11_term, "", "undercurl", "")
call s:hi("DiagnosticUnderlineInfo" , s:nord8_gui, "", s:nord8_term, "", "undercurl", "")
call s:hi("DiagnosticUnderlineHint" , s:nord10_gui, "", s:nord10_term, "", "undercurl", "")

"+- Neovim DocumentHighlight -+
call s:hi("LspReferenceText", "", s:nord3_gui, "", s:nord3_term, "", "")
call s:hi("LspReferenceRead", "", s:nord3_gui, "", s:nord3_term, "", "")
call s:hi("LspReferenceWrite", "", s:nord3_gui, "", s:nord3_term, "", "")

"+- Neovim LspSignatureHelp -+
call s:hi("LspSignatureActiveParameter", s:nord8_gui, "", s:nord8_term, "", s:underline, "")
endif
Expand Down Expand Up @@ -805,12 +809,12 @@ else
for s:i in range(1,6)
call s:hi("VimwikiHeader".s:i, s:vimwiki_hcolor_guifg[s:i-1] , "", s:vimwiki_hcolor_ctermfg[s:i-1], "", s:bold, "")
endfor
endif
endif
call s:hi("VimwikiLink", s:nord8_gui, "", s:nord8_term, "", s:underline, "")
hi! link VimwikiHeaderChar markdownHeadingDelimiter
hi! link VimwikiHR Keyword
hi! link VimwikiList markdownListMarker

" YAML
" > stephpy/vim-yaml
call s:hi("yamlKey", s:nord7_gui, "", s:nord7_term, "", "", "")
Expand Down

0 comments on commit f3327db

Please sign in to comment.