From 3e400157a4049bd6409e775f1be814de6281e936 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 14:37:41 +1300 Subject: Reshape autoloads into noun#Verb() pattern --- Makefile | 7 ++++++- vim/autoload/argument.vim | 6 ++++++ vim/autoload/escape.vim | 18 ------------------ vim/autoload/option.vim | 8 ++++++++ vim/autoload/option/item.vim | 11 +++++++++++ vim/autoload/split.vim | 12 ------------ vim/autoload/unescape.vim | 5 ----- vim/vimrc | 22 +++++++++++++--------- 8 files changed, 44 insertions(+), 45 deletions(-) create mode 100644 vim/autoload/argument.vim delete mode 100644 vim/autoload/escape.vim create mode 100644 vim/autoload/option.vim create mode 100644 vim/autoload/option/item.vim delete mode 100644 vim/autoload/split.vim delete mode 100644 vim/autoload/unescape.vim 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, '\\\@ 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, '\\\@ " -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 -- cgit v1.2.3