Skip to content

Commit

Permalink
Refactor theme configuration conditions (nordtheme#295)
Browse files Browse the repository at this point in the history
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

nordthemeGH-295


Co-authored-by: Sven Greb <[email protected]>
  • Loading branch information
jvoisin and svengreb committed May 14, 2022
1 parent 085a184 commit bf09e50
Showing 1 changed file with 16 additions and 48 deletions.
64 changes: 16 additions & 48 deletions colors/nord.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ""
Expand Down

0 comments on commit bf09e50

Please sign in to comment.