aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-10-03 20:44:40 +1300
committerTom Ryder <tom@sanctum.geek.nz>2020-10-03 20:44:40 +1300
commit6d28b9fca6aa5aa16c35615ed48b0b61572ee975 (patch)
tree8d8f1d280aab82ffbd8e8d6641f8889fe0fcae29 /vim/autoload
parentUpdate put_date.vim to v0.2.0 (diff)
downloaddotfiles-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.
Diffstat (limited to 'vim/autoload')
-rw-r--r--vim/autoload/has.vim34
-rw-r--r--vim/autoload/indent.vim2
-rw-r--r--vim/autoload/patch.vim27
3 files changed, 28 insertions, 35 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