From 291e05d96f7b938ab975e19205a42f6b41a35900 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Sat, 16 Apr 2022 09:53:54 +0200 Subject: [PATCH] Refactor theme configuration conditions (#295) The conditions and default values of the theme configurations were quite verbose so this commit improves them by... - ...using inline ternary operators instead of if/else blocks to reduce the code overhead and make it way more readable. - ...using Vim builtin `get` function [1] instead of if/else blocks. - ...inlining the script-scoped `logWarning` function since it was only used once. - ...grouping some blocks where it made sense. [1]: https://vimhelp.org/builtin.txt.html#builtin.txt#get%28%29 GH-295 Co-authored-by: Sven Greb --- colors/nord.vim | 64 +++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/colors/nord.vim b/colors/nord.vim index 87539895..6341b7bf 100755 --- a/colors/nord.vim +++ b/colors/nord.vim @@ -72,68 +72,36 @@ let s:nord3_gui_brightened = [ \ "#7b88a1", \ ] -if !exists("g:nord_bold") - let g:nord_bold = 1 -endif - -let s:bold = "bold," -if g:nord_bold == 0 - let s:bold = "" -endif - -if !exists("g:nord_italic") - if has("gui_running") || $TERM_ITALICS == "true" - let g:nord_italic = 1 - else - let g:nord_italic = 0 - endif -endif +let g:nord_bold = get(g:, "nord_bold", 1) +let s:bold = (g:nord_bold == 0) ? "" : "bold," -let s:italic = "italic," -if g:nord_italic == 0 - let s:italic = "" -endif +let g:nord_underline = get(g:, "nord_underline", 1) +let s:underline = (g:nord_underline == 0) ? "NONE," : "underline," -let s:underline = "underline," -if ! get(g:, "nord_underline", 1) - let s:underline = "NONE," -endif +let g:nord_italic = get(g:, "nord_italic", (has("gui_running") || $TERM_ITALICS == "true")) +let s:italic = (g:nord_italic == 0) ? "" : "italic," let s:italicize_comments = "" -if exists("g:nord_italic_comments") - if g:nord_italic_comments == 1 - let s:italicize_comments = s:italic - endif +if get(g:, "nord_italic_comments", 0) + let s:italicize_comments = s:italic endif -if !exists('g:nord_uniform_status_lines') - let g:nord_uniform_status_lines = 0 -endif - -function! s:logWarning(msg) - echohl WarningMsg - echomsg 'nord: warning: ' . a:msg - echohl None -endfunction +let g:nord_uniform_status_lines = get(g:, "nord_uniform_status_lines", 0) if exists("g:nord_comment_brightness") - call s:logWarning('Variable g:nord_comment_brightness has been deprecated and will be removed in version 1.0.0!' . + echohl WarningMsg + echomsg 'nord: warning: Variable g:nord_comment_brightness has been deprecated and will be removed in version 1.0.0!' . \' The comment color brightness has been increased by 10% by default.' . - \' Please see https://github.com/arcticicestudio/nord-vim/issues/145 for more details.') + \' Please see https://github.com/arcticicestudio/nord-vim/issues/145 for more details.' + echohl None let g:nord_comment_brightness = 10 endif -if !exists("g:nord_uniform_diff_background") - let g:nord_uniform_diff_background = 0 -endif +let g:nord_uniform_diff_background = get(g:, "nord_uniform_diff_background", 0) -if !exists("g:nord_cursor_line_number_background") - let g:nord_cursor_line_number_background = 0 -endif +let g:nord_cursor_line_number_background = get(g:, "nord_cursor_line_number_background", 0) -if !exists("g:nord_bold_vertical_split_line") - let g:nord_bold_vertical_split_line = 0 -endif +let g:nord_bold_vertical_split_line = get(g:, "nord_bold_vertical_split_line", 0) function! s:hi(group, guifg, guibg, ctermfg, ctermbg, attr, guisp) if a:guifg != ""