diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-10-03 20:44:40 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-10-03 20:44:40 +1300 |
commit | 6d28b9fca6aa5aa16c35615ed48b0b61572ee975 (patch) | |
tree | 8d8f1d280aab82ffbd8e8d6641f8889fe0fcae29 | |
parent | Update put_date.vim to v0.2.0 (diff) | |
download | dotfiles-6d28b9fca6aa5aa16c35615ed48b0b61572ee975.tar.gz dotfiles-6d28b9fca6aa5aa16c35615ed48b0b61572ee975.zip |
Refactor patch testing into new patch#() wrapper
This is a little more efficient, and perhaps a bit clearer, too.
-rw-r--r-- | vim/autoload/has.vim | 34 | ||||
-rw-r--r-- | vim/autoload/indent.vim | 2 | ||||
-rw-r--r-- | vim/autoload/patch.vim | 27 | ||||
-rw-r--r-- | vim/vimrc | 26 |
4 files changed, 41 insertions, 48 deletions
diff --git a/vim/autoload/has.vim b/vim/autoload/has.vim deleted file mode 100644 index 162e4929..00000000 --- a/vim/autoload/has.vim +++ /dev/null @@ -1,34 +0,0 @@ -" Wrapper to backport the nicer has() syntax for simultaneous version and -" patch level checking that was introduced in v7.4.236 and fixed in v7.4.237. -" -" * <https://github.com/vim/vim/releases/tag/v7.4.236> -" * <https://github.com/vim/vim/releases/tag/v7.4.237> -" -function! has#(feature) abort - - " If we're new enough, we can just run the native has() - if has('patch-7.4.237') - return has(a:feature) - endif - - " Otherwise, we have to break down the pattern and do manual version and - " patch level checks; if it doesn't match the patch syntax, just return what - " the native has() does - " - let feature = a:feature - let pattern = '^patch-\(\d\+\)\.\(\d\+\)\.\(\d\+\)$' - let matchlist = matchlist(feature, pattern) - if empty(matchlist) - return has(a:feature) - endif - let [major, minor, patch] = matchlist[1:3] - - " The v:version variable looks like e.g. 801 for v8.1 - let l:version = major * 100 + minor - - " Compare the version numbers, and then the patch level if they're the same - return v:version != l:version - \ ? v:version > l:version - \ : has('patch-'.patch) - -endfunction diff --git a/vim/autoload/indent.vim b/vim/autoload/indent.vim index d597653f..5f62fb0b 100644 --- a/vim/autoload/indent.vim +++ b/vim/autoload/indent.vim @@ -10,7 +10,7 @@ function! indent#Spaces(...) abort " If we have the patch that supports it, set 'softtabstop' to dynamically " mirror the value of 'shiftwidth'; failing that, just copy it - let &l:softtabstop = has#('patch-7.3.693') + let &l:softtabstop = patch#('7.3.693') \ ? -1 \ : &l:shiftwidth diff --git a/vim/autoload/patch.vim b/vim/autoload/patch.vim new file mode 100644 index 00000000..54637e09 --- /dev/null +++ b/vim/autoload/patch.vim @@ -0,0 +1,27 @@ +" Wrapper to emulate the nicer has() syntax for simultaneous version and patch +" level checking that was introduced in v7.4.236 and fixed in v7.4.237. +" +" * <https://github.com/vim/vim/releases/tag/v7.4.236> +" * <https://github.com/vim/vim/releases/tag/v7.4.237> +" +function! patch#(feature) abort + + " If we're new enough, we can just run the native has() + if has('patch-7.4.237') + return has(a:feature) + endif + + " Otherwise, we need to start splitting and comparing numbers + let [major, minor, patch] = split(a:feature, '\.') + + " The v:version variable looks like e.g. 801 for v8.1 + let l:version = major * 100 + minor + + " If the version numbers are the same, return whether we have the patch; + " otherwise, return whether the version + " + return v:version == l:version + \ ? has('patch-'.patch) + \ : v:version > l:version + +endfunction @@ -2,7 +2,7 @@ " Tom Ryder (tejr)’s Literate Vimrc " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " -" Last updated: Sat, 19 Sep 2020 08:36:41 UTC +" Last updated: Sat, 03 Oct 2020 07:24:40 UTC " " │ And I was lifted up in heart, and thought " │ Of all my late-shown prowess in the lists, @@ -72,7 +72,7 @@ " " <https://github.com/vim/vim/releases/tag/v8.1.0733> " -if has#('multi_byte') +if has('multi_byte') if &encoding ==# 'latin1' && !exists('$LANG') set encoding=utf-8 endif @@ -238,7 +238,7 @@ if s:xdgcachehome !=# '' call mkdir(s:xdgcachehome.'/backup', 'p', 0700) endif execute 'set backupdir^='.option#Escape(option#item#Escape( - \ s:xdgcachehome.'/backup'.(has#('patch-8.1.251') ? '//' : '') + \ s:xdgcachehome.'/backup'.(patch#('8.1.251') ? '//' : '') \)) endif @@ -248,7 +248,7 @@ endif " default value of 'backupskip' here, in order to prevent the creation of such " undesired backup files. " -if has#('unix') +if has('unix') " Prior to v8.1.1519, Vim didn’t check patterns added to 'backupskip' for " uniqueness, so adding the same path repeatedly resulted in duplicate strings @@ -260,7 +260,7 @@ if has#('unix') " " <https://github.com/vim/vim/releases/tag/v8.1.1519> " - if !has#('patch-8.1.1519') + if !patch#('8.1.1519') set backupskip& endif @@ -316,7 +316,7 @@ endif " Support for these persistent undo file caches was not released until v7.3.0, " so we need to check for the feature’s presence before we enable it. " -if s:xdgcachehome !=# '' && has#('persistent_undo') +if s:xdgcachehome !=# '' && has('persistent_undo') set undofile if !isdirectory(s:xdgcachehome.'/undo') call mkdir(s:xdgcachehome.'/undo', 'p', 0700) @@ -331,7 +331,7 @@ endif " directories of this type. This isn't a comma-separated list like the others " ('backupdir', 'directory', 'spell', 'undodir') " -if s:xdgcachehome !=# '' && has#('mksession') +if s:xdgcachehome !=# '' && has('mksession') if !isdirectory(s:xdgcachehome.'/view') call mkdir(s:xdgcachehome.'/view', 'p', 0700) endif @@ -526,7 +526,7 @@ set linebreak " Checking that ‘&encoding ==# 'utf-8'’ is not quite the same thing, though " it’s unlikely I’ll ever use a different Unicode encoding by choice. " -if has#('multi_byte_encoding') +if has('multi_byte_encoding') set showbreak=… else set showbreak=... @@ -610,7 +610,7 @@ set formatoptions+=1 " " <https://github.com/vim/vim/releases/tag/v7.3.541> " -if has#('patch-7.3.541') +if patch#('7.3.541') set formatoptions+=j endif @@ -650,7 +650,7 @@ set cpoptions+=J " " <https://github.com/vim/vim/releases/tag/v8.1.1523> " -if has#('patch-8.1.728') +if patch#('8.1.728') set formatoptions+=p endif @@ -662,7 +662,7 @@ endif " flag should be set here, rather that in the GUI-specific gvimrc file, as one " might otherwise think. " -if has#('gui_running') +if has('gui_running') set guioptions+=M endif @@ -733,7 +733,7 @@ set listchars+=nbsp:+ " Non-breaking spaces " " Failing that, ‘<’ and ‘>’ will do the trick. " -if has#('multi_byte_encoding') +if has('multi_byte_encoding') set listchars+=extends:»,precedes:« else set listchars+=extends:>,precedes:< @@ -977,7 +977,7 @@ endif " it. " if &background ==# 'dark' - \ && (has#('gui_running') || &t_Co >= 256) + \ && (has('gui_running') || &t_Co >= 256) \ && globpath(&runtimepath, 'colors/sahara.vim') !=# '' colorscheme sahara endif |