aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-12-21 14:37:41 +1300
committerTom Ryder <tom@sanctum.geek.nz>2019-12-21 14:38:56 +1300
commit3e400157a4049bd6409e775f1be814de6281e936 (patch)
treee747ff4e09c268079aec824a258b3426f2a37aac
parentFix up capitalization patterns for indent autoload (diff)
downloaddotfiles-3e400157a4049bd6409e775f1be814de6281e936.tar.gz
dotfiles-3e400157a4049bd6409e775f1be814de6281e936.zip
Reshape autoloads into noun#Verb() pattern
-rw-r--r--Makefile7
-rw-r--r--vim/autoload/argument.vim6
-rw-r--r--vim/autoload/escape.vim18
-rw-r--r--vim/autoload/option.vim8
-rw-r--r--vim/autoload/option/item.vim11
-rw-r--r--vim/autoload/split.vim12
-rw-r--r--vim/autoload/unescape.vim5
-rw-r--r--vim/vimrc22
8 files changed, 44 insertions, 45 deletions
diff --git a/Makefile b/Makefile
index 5eedfacf..8146f1cc 100644
--- a/Makefile
+++ b/Makefile
@@ -573,7 +573,12 @@ install-vim-after-syntax:
install-vim-autoload:
mkdir -p $(VIMDIR)/autoload
- cp -p -- vim/autoload/*.vim $(VIMDIR)/autoload
+ cd vim && find autoload \
+ -type d -exec sh -c \
+ 'mkdir -p -- $(VIMDIR)/"$$1"' _ {} \; \
+ -o \
+ -type f -exec sh -c \
+ 'cp -p -- "$$1" $(VIMDIR)/"$$1"' _ {} \;
install-vim-bundle: install-vim-config
cd vim/bundle && find */* \
diff --git a/vim/autoload/argument.vim b/vim/autoload/argument.vim
new file mode 100644
index 00000000..9e381000
--- /dev/null
+++ b/vim/autoload/argument.vim
@@ -0,0 +1,6 @@
+function! argument#Escape(argument) abort
+ return exists('*fnameescape')
+ \ ? fnameescape(a:argument)
+ \ : escape(a:argument, "\n\r\t".' *?[{`$\%#''"|!<')
+endfunction
+
diff --git a/vim/autoload/escape.vim b/vim/autoload/escape.vim
deleted file mode 100644
index 37ac3e8b..00000000
--- a/vim/autoload/escape.vim
+++ /dev/null
@@ -1,18 +0,0 @@
-" Escape text for use as an Ex command argument
-function! escape#Arg(arg) abort
- return exists('*fnameescape')
- \ ? fnameescape(a:arg)
- \ : escape(a:arg, "\n\r\t".' *?[{`$\%#''"|!<')
-endfunction
-
-" Escape text for use as a list item
-function! escape#Item(item) abort
- return escape(a:item, ',')
-endfunction
-
-" Escape wildcard characters in list items to prevent e.g. tilde or glob
-" expansion in the resulting item
-"
-function! escape#Wild(string) abort
- return escape(a:string, '\*?[{`''$~')
-endfunction
diff --git a/vim/autoload/option.vim b/vim/autoload/option.vim
new file mode 100644
index 00000000..d203dfe8
--- /dev/null
+++ b/vim/autoload/option.vim
@@ -0,0 +1,8 @@
+function! option#Split(expr, ...) abort
+ if a:0 > 1
+ echoerr 'Too many arguments'
+ endif
+ let keepempty = a:0 ? a:1 : 0
+ let parts = split(a:expr, '\\\@<!,[, ]*', keepempty)
+ return map#(parts, 'substitute(v:val, ''\\,'', '','', ''g'')')
+endfunction
diff --git a/vim/autoload/option/item.vim b/vim/autoload/option/item.vim
new file mode 100644
index 00000000..6081fa8b
--- /dev/null
+++ b/vim/autoload/option/item.vim
@@ -0,0 +1,11 @@
+function! option#item#Escape(item, ...) abort
+ if a:0 > 1
+ echoerr 'Too many arguments'
+ endif
+ let item = a:item
+ let wild = a:0 ? a:1 : 0
+ if wild
+ let item = substitute(item, '\\,', ',', 'g')
+ endif
+ return escape(item, ',')
+endfunction
diff --git a/vim/autoload/split.vim b/vim/autoload/split.vim
deleted file mode 100644
index 44065094..00000000
--- a/vim/autoload/split.vim
+++ /dev/null
@@ -1,12 +0,0 @@
-if v:version < 702 || v:version == 702 && !has('patch-61')
- runtime autoload/unescape.vim
-endif
-
-function! split#Option(expr, ...) abort
- if a:0 > 2
- echoerr 'Too many arguments'
- endif
- let keepempty = a:0 ? a:1 : 0
- let parts = split(a:expr, '\\\@<!,[, ]*', keepempty)
- return map#(parts, function('unescape#Item'))
-endfunction
diff --git a/vim/autoload/unescape.vim b/vim/autoload/unescape.vim
deleted file mode 100644
index d42403f8..00000000
--- a/vim/autoload/unescape.vim
+++ /dev/null
@@ -1,5 +0,0 @@
-" Unescape a list item escaped with escape#Item(), by replacing all escaped
-" commas with unescaped ones
-function! unescape#Item(key, val) abort
- return substitute(a:val, '\\,', ',', 'g')
-endfunction
diff --git a/vim/vimrc b/vim/vimrc
index 07f979b8..7daa54b6 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -91,7 +91,7 @@ scriptencoding utf-8
" test it with some values of your own, if you want to understand why. Vim,
" I love you, but you are really weird sometimes.
"
-" We do all this with an autoloaded function split#Option().
+" We do all this with an autoloaded function option#Split().
"
" If an environment variable MYVIM exists, and it isn’t blank, apply its value
" as the first value of 'runtimepath', after escaping it appropriately.
@@ -99,9 +99,9 @@ scriptencoding utf-8
" list becomes MYVIM.
"
if exists('$MYVIM') && $MYVIM !=# ''
- execute 'set runtimepath^='.escape#Arg(escape#Item(escape#Wild($MYVIM)))
+ execute 'set runtimepath^='.argument#Escape(option#item#Escape($MYVIM, 1))
elseif &runtimepath !=# ''
- let $MYVIM = split#Option(&runtimepath)[0]
+ let $MYVIM = option#Split(&runtimepath)[0]
endif
" We need a command to reliably establish a full path, whether or not the
@@ -133,7 +133,7 @@ command! -bang -bar -complete=dir -nargs=1 CreatePath
"
" <https://github.com/vim/vim/releases/tag/v8.1.0716>
"
-execute 'set viminfo+='.escape#Arg('n'.$MYVIM.'/viminfo')
+execute 'set viminfo+='.argument#Escape('n'.$MYVIM.'/viminfo')
CreatePath $MYVIM
" Speaking of recorded data in viminfo files, the default Vim limit of a mere
@@ -179,7 +179,7 @@ set history=10000
" 'backupfullname', 'swapfilefullname' would have been clearer.
"
set backup
-execute 'set backupdir^='.escape#Arg(escape#Item(
+execute 'set backupdir^='.argument#Escape(option#item#Escape(
\ $MYVIM.'/backup'.(has#('patch-8.1.251') ? '//' : ''),
\))
CreatePath! $MYVIM/backup
@@ -218,7 +218,8 @@ endif
" option has supported that hint for much longer than 'backupdir' has. We
" apply path#Create() to attempt to create the path, if needed.
"
-execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//'))
+execute 'set directory^='
+ \.argument#Escape(option#item#Escape($MYVIM.'/swap//'))
CreatePath! $MYVIM/swap
" Keep tracked undo history for files permanently, in a dedicated cache
@@ -236,7 +237,8 @@ CreatePath! $MYVIM/swap
"
if has#('persistent_undo')
set undofile
- execute 'set undodir^='.escape#Arg(escape#Item($MYVIM.'/undo//'))
+ execute 'set undodir^='
+ \.argument#Escape(option#item#Escape($MYVIM.'/undo//'))
CreatePath! $MYVIM/undo
endif
@@ -354,8 +356,10 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\)
set dictionary^=/usr/share/dict/words
let s:ref = $MYVIM.'/ref'
try
- execute 'set dictionary^='.escape#Arg(escape#Item(s:ref.'/dictionary.txt'))
- execute 'set thesaurus^='.escape#Arg(escape#Item(s:ref.'/thesaurus.txt'))
+ execute 'set dictionary^='
+ \.argument#Escape(option#item#Escape(s:ref.'/dictionary.txt'))
+ execute 'set thesaurus^='
+ \.argument#Escape(option#item#Escape(s:ref.'/thesaurus.txt'))
catch /^Vim\%((\a\+)\)\=:E474:/
endtry