aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-04 14:52:07 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-04 15:14:46 +1300
commitc88cb8805f683eb6d886743f3e147a3ab0fbee91 (patch)
tree94039bcd2ee0c15efd14f52951f4d1ecf9c6b623
parentSpecify an install-vim-autoload target (diff)
downloaddotfiles-c88cb8805f683eb6d886743f3e147a3ab0fbee91.tar.gz
dotfiles-c88cb8805f683eb6d886743f3e147a3ab0fbee91.zip
Move Vim background detection logic into plugin
-rw-r--r--vim/autoload/detect_background.vim18
-rw-r--r--vim/config/syntax.vim27
2 files changed, 20 insertions, 25 deletions
diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim
new file mode 100644
index 00000000..a1a2c208
--- /dev/null
+++ b/vim/autoload/detect_background.vim
@@ -0,0 +1,18 @@
+" Invert Vim's built-in logic for choosing dark or light backgrounds; we'll
+" default to choosing a dark background unless we find some reason *not* to.
+function! detect_background#DetectBackground()
+
+ " Split up the value of $COLORFGBG (if any) by semicolons
+ let l:colorfgbg = split($COLORFGBG, ';')
+
+ " Get the background color value, or an empty string if none
+ let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : ''
+
+ " Choose the background setting based on this value
+ if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15'
+ set background=light
+ else
+ set background=dark
+ endif
+
+endfunction
diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim
index e7d94b1b..dfa7b784 100644
--- a/vim/config/syntax.vim
+++ b/vim/config/syntax.vim
@@ -5,32 +5,9 @@ if has('syntax')
silent! syntax enable
silent! syntax sync minlines=100
- " Invert Vim's built-in logic for choosing dark or light backgrounds; we'll
- " default to choosing a dark background unless we find some reason *not* to.
+ " If we can, detect a light background, but default to a dark one
if has('eval') && v:version >= 701
-
- " Wrap all this logic in a function
- function! s:DetectBackground()
-
- " Split up the value of $COLORFGBG (if any) by semicolons
- let l:colorfgbg = split($COLORFGBG, ';')
-
- " Get the background color value, or an empty string if none
- let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : ''
-
- " Choose the background setting based on this value
- if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15'
- set background=light
- else
- set background=dark
- endif
-
- endfunction
-
- " Call the function just defined directly
- call s:DetectBackground()
-
- " Ancient or cut-down Vim? Just go dark
+ call detect_background#DetectBackground()
else
set background=dark
endif