From 7428a166af15972ebaeeb3a8bc08c7c79ba3a93c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 11:36:21 +1200 Subject: Add an issue --- ISSUES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ISSUES.md b/ISSUES.md index 103c3a98..cd6228ea 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -30,3 +30,4 @@ Known issues pushed upstream. * The `_text_filenames` completion handler for Bash won't work on files with newlines in their names. Can it be made to? +* A paste operation, maybe TextChanged, should probably end a pending paste -- cgit v1.2.3 From e618c4580973c13baaa9f9ea70494c717d1cc9b2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 11:36:41 +1200 Subject: Remove an implemented idea --- IDEAS.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/IDEAS.md b/IDEAS.md index 88361aaa..8f6f68c7 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -31,5 +31,3 @@ Ideas some point * I'd like a Git hook that pre-fills out "Version X.Y.Z" if making an annotated tag named `vX.Y.Z`. -* Per-filetype spelling dictionaries might be a good idea, e.g. writing all the - valid :commands and 'options' for Vim script into a file for ft=vim. -- cgit v1.2.3 From 1c26be4a302b185bb287b188652e462efdd1d637 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 11:44:39 +1200 Subject: Add an idea --- IDEAS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/IDEAS.md b/IDEAS.md index 8f6f68c7..2e03cef5 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -31,3 +31,4 @@ Ideas some point * I'd like a Git hook that pre-fills out "Version X.Y.Z" if making an annotated tag named `vX.Y.Z`. +* There's no reason to limit `digraph_search.vim` to insert mode only -- cgit v1.2.3 From 71608a51af125ceab602832a5b976fb94c0c0c9d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 22:51:09 +1200 Subject: Factor out functions from vimrc --- vim/autoload/escape.vim | 13 ++++++ vim/autoload/map.vim | 5 ++ vim/autoload/path.vim | 10 ++++ vim/autoload/plugin.vim | 5 ++ vim/autoload/reload.vim | 12 +++++ vim/autoload/split.vim | 8 ++++ vim/autoload/unescape.vim | 3 ++ vim/vimrc | 115 +++++++++++----------------------------------- 8 files changed, 84 insertions(+), 87 deletions(-) create mode 100644 vim/autoload/escape.vim create mode 100644 vim/autoload/map.vim create mode 100644 vim/autoload/path.vim create mode 100644 vim/autoload/plugin.vim create mode 100644 vim/autoload/reload.vim create mode 100644 vim/autoload/split.vim create mode 100644 vim/autoload/unescape.vim diff --git a/vim/autoload/escape.vim b/vim/autoload/escape.vim new file mode 100644 index 00000000..0fdfba99 --- /dev/null +++ b/vim/autoload/escape.vim @@ -0,0 +1,13 @@ +function! escape#Arg(arg) abort + return exists('*fnameescape') + \ ? fnameescape(a:arg) + \ : escape(a:arg, "\n\r\t".' *?[{`$\%#''"|!<') +endfunction + +function! escape#Item(item) abort + return escape(a:item, ',') +endfunction + +function! escape#Wild(string) abort + return escape(a:string, '\*?[{`''$~') +endfunction diff --git a/vim/autoload/map.vim b/vim/autoload/map.vim new file mode 100644 index 00000000..2630bcd3 --- /dev/null +++ b/vim/autoload/map.vim @@ -0,0 +1,5 @@ +function! map#(list, Func) abort + return has('patch-7.4.1989') + \ ? map(a:list, a:Func) + \ : map(a:list, string(a:Func).'(0, v:val)') +endfunction diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim new file mode 100644 index 00000000..2506ad53 --- /dev/null +++ b/vim/autoload/path.vim @@ -0,0 +1,10 @@ +function! path#Create(name, ...) abort + if a:0 > 2 + echoerr 'Too many arguments' + endif + if isdirectory(a:name) + return 1 + endif + let prot = a:0 >= 1 ? a:1 : 0755 + return mkdir(a:name, 'p', prot) +endfunction diff --git a/vim/autoload/plugin.vim b/vim/autoload/plugin.vim new file mode 100644 index 00000000..b6f3d974 --- /dev/null +++ b/vim/autoload/plugin.vim @@ -0,0 +1,5 @@ +function! plugin#Ready(name) abort + return &loadplugins + \ && globpath(&runtimepath, 'plugin/'.a:name.'.vim') != '' +endfunction + diff --git a/vim/autoload/reload.vim b/vim/autoload/reload.vim new file mode 100644 index 00000000..558f24d6 --- /dev/null +++ b/vim/autoload/reload.vim @@ -0,0 +1,12 @@ +function! reload#FileType() abort + if exists('g:did_load_filetypes') + doautocmd filetypedetect BufRead + endif +endfunction + +function! reload#Vimrc() abort + noautocmd source $MYVIMRC + call reload#FileType() + redraw + echomsg fnamemodify($MYVIMRC, ':p:~').' reloaded' +endfunction diff --git a/vim/autoload/split.vim b/vim/autoload/split.vim new file mode 100644 index 00000000..92d7a133 --- /dev/null +++ b/vim/autoload/split.vim @@ -0,0 +1,8 @@ +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, '\\\@ " -function! s:Map(list, Func) abort - return has('patch-7.4.1989') - \ ? map(a:list, a:Func) - \ : map(a:list, string(a:Func).'(0, v:val)') -endfunction - -" We will need to be able to escape and unescape commas within separated list -" items. As noted above, we do this by adding and removing a backslash before -" each comma. -" -function! s:EscItem(item) abort - return escape(a:item, ',') -endfunction -function! s:UnEscItem(key, val) abort - return substitute(a:val, '\\,', ',', 'g') -endfunction " We will need a way to escape a string for general use in an :execute wrapper " to prevent it being interpreted as anything but a string. The fnameescape() @@ -134,19 +113,10 @@ endfunction " " " -function! s:EscArg(arg) abort - return exists('*fnameescape') - \ ? fnameescape(a:arg) - \ : escape(a:arg, "\n\r\t".' *?[{`$\%#''"|!<') -endfunction " For the particular case of 'runtimepath', we also need to escape glob " characters like * to prevent them from being expanded. " -function! s:EscWild(string) abort - let string = a:string - return escape(string, '\*?[{`''$~') -endfunction " If an environment variable MYVIM exists, and it isn’t blank, apply its value " as the first value of 'runtimepath', after escaping it appropriately. @@ -154,11 +124,11 @@ endfunction " list becomes MYVIM. " if exists('$MYVIM') && $MYVIM != '' - execute 'set runtimepath^='.s:EscArg(s:EscItem(s:EscWild( - \ $MYVIM - \))) + execute 'set runtimepath^='.escape#Arg( + \ escape#Item(escape#Wild($MYVIM)) + \) elseif &runtimepath != '' - let $MYVIM = s:SplitOption(&runtimepath)[0] + let $MYVIM = split#Option(&runtimepath)[0] endif " We need a function to reliably create a full path, whether or not the @@ -167,21 +137,14 @@ endif " {prot} forced on. You can still provide alternative permissions in the " second argument. " -function! s:CreatePath(name, ...) abort - if isdirectory(a:name) - return 1 - endif - let prot = a:0 >= 1 ? a:1 : 0755 - return mkdir(a:name, 'p', prot) -endfunction " That’s a useful function, too, so we make it available to the user with " a user command. We’ll generally use the function form, as it requires less " escaping. An optional second argument can be provided, corresponding to the " mkdir() permissions parameter. " -command! -bar -complete=dir -nargs=1 CreatePath - \ call s:CreatePath() +command! -bar -complete=dir -nargs=+ CreatePath + \ call path#Create() " Now that we have a clean means to create directories if they don’t already " exist, let’s apply it for the first time to the user runtime directory. @@ -189,7 +152,7 @@ command! -bar -complete=dir -nargs=1 CreatePath " errors raised if there were problems with the creation, but we’ll barrel on " ahead regardless after warning the user about our failure. " -call s:CreatePath($MYVIM) +CreatePath $MYVIM " Our next application of our new :CreatePath command is to configure the path " for the viminfo metadata file, putting it in a cache subdirectory of the @@ -209,8 +172,9 @@ call s:CreatePath($MYVIM) " " " -let s:viminfo = $MYVIM.'/viminfo' -execute 'set viminfo+='.s:EscArg('n'.s:viminfo) +execute 'set viminfo+='.escape#Arg( + \ 'n'.$MYVIM.'/viminfo' + \) " Speaking of recorded data in viminfo files, the default Vim limit of a mere " 50 entries for command and search history is pretty stingy. Because I don’t @@ -255,10 +219,9 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -let s:backupdir = $MYVIM.'/backup' -call s:CreatePath(s:backupdir, 0700) -execute 'set backupdir^='.s:EscArg(s:EscItem( - \ s:backupdir.(has('patch-8.1.251') ? '//' : ''), +CreatePath $MYVIM/backup 0700 +execute 'set backupdir^='.escape#Arg(escape#Item( + \ $MYVIM.'/backup'.(has('patch-8.1.251') ? '//' : ''), \)) " Files in certain directories on Unix-compatible filesystems should not be @@ -295,10 +258,9 @@ endif " option has supported that hint for much longer than 'backupdir' has. We " apply CreatePath() to attempt to create the path first, if needed. " -let s:directory = $MYVIM.'/swap' -call s:CreatePath(s:directory, 0700) -execute 'set directory^='.s:EscArg(s:EscItem( - \ s:directory.'//' +CreatePath $MYVIM/swap 0700 +execute 'set directory^='.escape#Arg(escape#Item( + \ $MYVIM.'/swap//' \)) " Keep tracked undo history for files permanently, in a dedicated cache @@ -316,10 +278,9 @@ execute 'set directory^='.s:EscArg(s:EscItem( " if has('persistent_undo') set undofile - let s:undodir = $MYVIM.'/undo' - call s:CreatePath(s:undodir, 0700) - execute 'set undodir^='.s:EscArg(s:EscItem( - \ s:undodir.'//' + CreatePath $MYVIM/undo 0700 + execute 'set undodir^='.escape#Arg(escape#Item( + \ $MYVIM.'/undo//' \)) endif @@ -333,13 +294,8 @@ filetype plugin indent on " We'll set up a user command named :ReloadFileType to do this, with " a script-local function backing it. " -function! s:ReloadFileType() abort - if exists('g:did_load_filetypes') - doautocmd filetypedetect BufRead - endif -endfunction command! -bar ReloadFileType - \ call s:ReloadFileType() + \ call reload#FileType() " We'll also define a :ReloadVimrc command. This may seem like overkill, at " first. Surely just `:source $MYVIMRC` would be good enough? @@ -364,13 +320,8 @@ command! -bar ReloadFileType " happened. The :redraw just before that message seems to be necessary for " this message to display correctly. I'm not sure why. " -function! s:ReloadVimrc() abort - ReloadFileType - redraw - echomsg fnamemodify($MYVIMRC, ':p:~').' reloaded' -endfunction command! -bar ReloadVimrc - \ noautocmd source $MYVIMRC | call s:ReloadVimrc() + \ call reload#Vimrc() " We'll now create or reset a group of automatic command hooks specific to " matters related to reloading the vimrc itself, or maintaining and managing @@ -413,9 +364,8 @@ endif " the path is valid. We put it back immediately afterwards. " set spelllang=en_nz -let s:spelldir = $MYVIM.'/spell' -call s:CreatePath(s:spelldir) -let s:spellfile = s:spelldir.'/'.join([ +CreatePath $MYVIM/spell +let s:spellfile = $MYVIM.'/spell/'.join([ \ split(&spelllang, '_')[0], \ &encoding, \ 'add', @@ -424,7 +374,7 @@ if has('unix') let s:isfname = &isfname set isfname=1-255 endif -execute 'set spellfile^='.s:EscArg(s:EscItem(s:spellfile)) +execute 'set spellfile^='.escape#Arg(escape#Item(s:spellfile)) let &isfname = s:isfname " Spell checking includes optional support for catching lower case letters at @@ -477,10 +427,10 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) set dictionary^=/usr/share/dict/words let s:ref = $MYVIM.'/ref' try - execute 'set dictionary^='.s:EscArg(s:EscItem( + execute 'set dictionary^='.escape#Arg(escape#Item( \ s:ref.'/dictionary.txt' \)) - execute 'set thesaurus^='.s:EscArg(s:EscItem( + execute 'set thesaurus^='.escape#Arg(escape#Item( \ s:ref.'/thesaurus.txt' \)) catch /^Vim\%((\a\+)\)\=:E474:/ @@ -838,21 +788,12 @@ set noshowcmd " set shortmess+=I -" We declare a function just to make a slightly more readable way to express -" a check that plugins are going to be loaded and that a plugin of a given -" name appears to be available somewhere in one of the runtime paths. -" -function! s:PluginReady(name) abort - return &loadplugins - \ && globpath(&runtimepath, 'plugin/'.a:name.'.vim') != '' -endfunction - " We’ll only use the old 'showmatch' method of a brief jump to the matching " bracket under the cursor if the much-preferred matchparen.vim standard " plugin doesn’t look like it’s going to load, whether because plugins have " been disabled, or it’s not in any of the plugin directories. " -if !s:PluginReady('matchparen') +if !plugin#Ready('matchparen') set showmatch matchtime=3 endif @@ -1201,7 +1142,7 @@ nnoremap " If the plugin isn’t available, I just abandon CTRL-C to continue its " uselessness. " -if s:PluginReady('insert_cancel') +if plugin#Ready('insert_cancel') imap (InsertCancel) endif -- cgit v1.2.3 From f0786745e4ebb57fc598c0796cdc7db89ae4c563 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 22:52:00 +1200 Subject: Refine NZ vs US Vim spelling setup --- vim/vimrc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index c65115ae..5109ce6c 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -363,10 +363,10 @@ endif " since Vim uses it internally for 'spellfile' assignment to decide whether " the path is valid. We put it back immediately afterwards. " -set spelllang=en_nz +set spelllang^=en_nz CreatePath $MYVIM/spell let s:spellfile = $MYVIM.'/spell/'.join([ - \ split(&spelllang, '_')[0], + \ split(split#Option(&spelllang)[0], '_')[0], \ &encoding, \ 'add', \], '.') @@ -1358,9 +1358,9 @@ nnoremap f " target audience. I generally use US English for international audiences. " nnoremap u - \ :set spelllang=en_us + \ :set spelllang-=en_nz spelllang^=en_us spelllang? nnoremap z - \ :set spelllang=en_nz + \ :set spelllang-=en_us spelllang^=en_nz spelllang? " The next mapping is also for toggling an option, but it’s more complicated; " it uses a simple plugin of mine called copy_linebreak.vim to manage several -- cgit v1.2.3 From 8863b60fdbfbec6b356da426b32e9461e17f7b25 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 22:52:24 +1200 Subject: Add case sensitivity flag to needed opers --- vim/autoload/plugin.vim | 3 +-- vim/vimrc | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/vim/autoload/plugin.vim b/vim/autoload/plugin.vim index b6f3d974..68e3d54b 100644 --- a/vim/autoload/plugin.vim +++ b/vim/autoload/plugin.vim @@ -1,5 +1,4 @@ function! plugin#Ready(name) abort return &loadplugins - \ && globpath(&runtimepath, 'plugin/'.a:name.'.vim') != '' + \ && globpath(&runtimepath, 'plugin/'.a:name.'.vim') !=# '' endfunction - diff --git a/vim/vimrc b/vim/vimrc index 5109ce6c..7e2eb099 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -123,11 +123,11 @@ scriptencoding utf-8 " Otherwise, do it the other way around: the first path in the 'runtimepath' " list becomes MYVIM. " -if exists('$MYVIM') && $MYVIM != '' +if exists('$MYVIM') && $MYVIM !=# '' execute 'set runtimepath^='.escape#Arg( \ escape#Item(escape#Wild($MYVIM)) \) -elseif &runtimepath != '' +elseif &runtimepath !=# '' let $MYVIM = split#Option(&runtimepath)[0] endif -- cgit v1.2.3 From a1a3038c30a37471a1b912df98a769c090b4f3a2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:23:01 +1200 Subject: Revert to simpler spelling approach --- vim/vimrc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 7e2eb099..f7d60f5e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -363,10 +363,11 @@ endif " since Vim uses it internally for 'spellfile' assignment to decide whether " the path is valid. We put it back immediately afterwards. " -set spelllang^=en_nz +set spelllang=en_nz CreatePath $MYVIM/spell +let s:spelllang = split#Option(&spelllang) let s:spellfile = $MYVIM.'/spell/'.join([ - \ split(split#Option(&spelllang)[0], '_')[0], + \ split(s:spelllang[0], '_')[0], \ &encoding, \ 'add', \], '.') @@ -376,6 +377,7 @@ if has('unix') endif execute 'set spellfile^='.escape#Arg(escape#Item(s:spellfile)) let &isfname = s:isfname +unlet s:isfname " Spell checking includes optional support for catching lower case letters at " the start of sentences, and defines a pattern in 'spellcapcheck' for the end @@ -1357,10 +1359,10 @@ nnoremap f " excluding or including the ‘u’ in words like 'favourite', depending on the " target audience. I generally use US English for international audiences. " -nnoremap u - \ :set spelllang-=en_nz spelllang^=en_us spelllang? nnoremap z - \ :set spelllang-=en_us spelllang^=en_nz spelllang? + \ :set spelllang=en_nz +nnoremap u + \ :set spelllang=en_us " The next mapping is also for toggling an option, but it’s more complicated; " it uses a simple plugin of mine called copy_linebreak.vim to manage several -- cgit v1.2.3 From bfe83f14560817e2ce2b08be17df7b7a7cca83e2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:23:11 +1200 Subject: More vimrc comment refactoring --- vim/vimrc | 77 ++++++++++++++++----------------------------------------------- 1 file changed, 19 insertions(+), 58 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index f7d60f5e..effa9de1 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -68,9 +68,9 @@ scriptencoding utf-8 " these variables. One of the first things we’ll need to be able to do is " split the value of 'runtimepath' into its constituent path parts. " -" Splitting the values of these comma-separated options correctly is -" surprisingly complicated. The list separator for such options is more -" accurately defined as follows: +" Splitting the values of comma-separated options correctly is surprisingly +" complicated. The list separator for such options is more accurately defined +" as follows: " " │ A comma not preceded by a backslash, and possibly followed by an arbitrary " │ number of spaces and commas. @@ -88,36 +88,11 @@ scriptencoding utf-8 " We don’t, however, have to deal with backslashes before other backslashes, " nor before any other character. You can read the source code for the ad-hoc " tokenizer in copy_option_part() in src/misc2.c in Vim’s source code, and -" test it with some values of your own, if you want to understand why. +" test it with some values of your own, if you want to understand why. Vim, +" I love you, but you are really weird sometimes. " -" Vim, I love you, but you are really weird. +" We do all this with an autoloaded function split#Option(). " -" Note that we’re calling a script-local wrapper around map() named Map(), and -" making a function reference to a script-local function UnEscItem(), both of -" which we’ll define shortly. -" - -" We declare a wrapper around map() to allow us always to call it with -" a Funcref as the second function parameter, which isn’t directly supported -" by map() until Vim v7.4.1989. If the running version is older than that, -" apply string() to the Funcref to use the older calling convention. -" -" -" - -" We will need a way to escape a string for general use in an :execute wrapper -" to prevent it being interpreted as anything but a string. The fnameescape() -" function, while somewhat misnamed, is the correct way to do this, but it -" wasn’t added until Vim v7.1.299, so we’ll have to do our best to backport it -" here. -" -" -" - -" For the particular case of 'runtimepath', we also need to escape glob -" characters like * to prevent them from being expanded. -" - " If an environment variable MYVIM exists, and it isn’t blank, apply its value " as the first value of 'runtimepath', after escaping it appropriately. " Otherwise, do it the other way around: the first path in the 'runtimepath' @@ -131,26 +106,20 @@ elseif &runtimepath !=# '' let $MYVIM = split#Option(&runtimepath)[0] endif -" We need a function to reliably create a full path, whether or not the -" directories already exist. We create a wrapper with similar calling -" conventions to mkdir(), but with the ‘p’ value for the second parameter -" {prot} forced on. You can still provide alternative permissions in the -" second argument. -" - -" That’s a useful function, too, so we make it available to the user with -" a user command. We’ll generally use the function form, as it requires less -" escaping. An optional second argument can be provided, corresponding to the -" mkdir() permissions parameter. +" We need a command to reliably establish a full path, whether or not the +" directories already exist. We create a wrapper for the autolated function +" path#Create() with similar calling conventions to mkdir(), but with the ‘p’ +" value for the second parameter {prot} forced on. You can still optionally +" provide alternative permissions in the second argument. " command! -bar -complete=dir -nargs=+ CreatePath \ call path#Create() -" Now that we have a clean means to create directories if they don’t already -" exist, let’s apply it for the first time to the user runtime directory. -" Note that we aren’t checking whether this actually succeeded. We do want -" errors raised if there were problems with the creation, but we’ll barrel on -" ahead regardless after warning the user about our failure. +" Now that we have a way to create directories if they don’t already exist, +" let’s apply it for the first time to the user runtime directory. Note that +" we aren’t checking whether this actually succeeded. We do want errors +" raised if there were problems with the creation, but we’ll barrel on ahead +" regardless after warning the user about our failure. " CreatePath $MYVIM @@ -304,22 +273,14 @@ command! -bar ReloadFileType " the vimrc is reloaded. The :set commands for options like 'expandtab' and " 'shiftwidth' may trample over different buffer-local settings that were " specified by filetype and indent plugins. To ensure these local values are -" reinstated, we'll define the new command wrapper to issue a :ReloadFileType -" command after the vimrc file is sourced. +" reinstated, we'll define the new command wrapper around an autoloaded +" function that itself issues a :ReloadFileType command after the vimrc file +" is sourced. " " We can't put the actual :source command into the script-local function we " define here, because Vim would get upset that we're trying to redefine " a function as it executes! " -" Just to be on the safe side, we also suppress any further ##SourceCmd hooks -" from running the :source command with a :noautocmd wrapper. This is -" a defensive measure to avoid infinite recursion. It may not actually be -" necessary. -" -" We emit a message afterwards, just to make it clear that something has -" happened. The :redraw just before that message seems to be necessary for -" this message to display correctly. I'm not sure why. -" command! -bar ReloadVimrc \ call reload#Vimrc() -- cgit v1.2.3 From c45715ca5c073536cd39e495cb495f756946d97d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:27:32 +1200 Subject: Remove excessive linebreaks --- vim/autoload/map.vim | 7 ++++ vim/vimrc | 98 +++++++--------------------------------------------- 2 files changed, 19 insertions(+), 86 deletions(-) diff --git a/vim/autoload/map.vim b/vim/autoload/map.vim index 2630bcd3..43cdf381 100644 --- a/vim/autoload/map.vim +++ b/vim/autoload/map.vim @@ -1,3 +1,10 @@ +" We declare a wrapper around map() to allow us always to call it with +" a Funcref as the second function parameter, which isn’t directly supported +" by map() until Vim v7.4.1989. If the running version is older than that, +" apply string() to the Funcref to use the older calling convention. +" +" +" function! map#(list, Func) abort return has('patch-7.4.1989') \ ? map(a:list, a:Func) diff --git a/vim/vimrc b/vim/vimrc index effa9de1..2937b8db 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -99,9 +99,7 @@ scriptencoding utf-8 " list becomes MYVIM. " if exists('$MYVIM') && $MYVIM !=# '' - execute 'set runtimepath^='.escape#Arg( - \ escape#Item(escape#Wild($MYVIM)) - \) + execute 'set runtimepath^='.escape#Arg(escape#Item(escape#Wild($MYVIM))) elseif &runtimepath !=# '' let $MYVIM = split#Option(&runtimepath)[0] endif @@ -228,9 +226,7 @@ endif " apply CreatePath() to attempt to create the path first, if needed. " CreatePath $MYVIM/swap 0700 -execute 'set directory^='.escape#Arg(escape#Item( - \ $MYVIM.'/swap//' - \)) +execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//')) " Keep tracked undo history for files permanently, in a dedicated cache " directory, so that the u/:undo and CTRL-R/:redo commands will work between @@ -328,9 +324,7 @@ set spelllang=en_nz CreatePath $MYVIM/spell let s:spelllang = split#Option(&spelllang) let s:spellfile = $MYVIM.'/spell/'.join([ - \ split(s:spelllang[0], '_')[0], - \ &encoding, - \ 'add', + \ split(s:spelllang[0], '_')[0], &encoding, 'add', \], '.') if has('unix') let s:isfname = &isfname @@ -390,12 +384,8 @@ 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^='.escape#Arg(escape#Item(s:ref.'/dictionary.txt')) + execute 'set thesaurus^='.escape#Arg(escape#Item(s:ref.'/thesaurus.txt')) catch /^Vim\%((\a\+)\)\=:E474:/ endtry @@ -865,77 +855,13 @@ set wildmode=list:longest,full " " " -set wildignore=*~,#*# - \,*.7z - \,.DS_Store - \,.git - \,.hg - \,.svn - \,*.a - \,*.adf - \,*.asc - \,*.au - \,*.aup - \,*.avi - \,*.bin - \,*.bmp - \,*.bz2 - \,*.class - \,*.db - \,*.dbm - \,*.djvu - \,*.docx - \,*.exe - \,*.filepart - \,*.flac - \,*.gd2 - \,*.gif - \,*.gifv - \,*.gmo - \,*.gpg - \,*.gz - \,*.hdf - \,*.ico - \,*.iso - \,*.jar - \,*.jpeg - \,*.jpg - \,*.m4a - \,*.mid - \,*.mp3 - \,*.mp4 - \,*.o - \,*.odp - \,*.ods - \,*.odt - \,*.ogg - \,*.ogv - \,*.opus - \,*.pbm - \,*.pdf - \,*.png - \,*.ppt - \,*.psd - \,*.pyc - \,*.rar - \,*.rm - \,*.s3m - \,*.sdbm - \,*.sqlite - \,*.swf - \,*.swp - \,*.tar - \,*.tga - \,*.ttf - \,*.wav - \,*.webm - \,*.xbm - \,*.xcf - \,*.xls - \,*.xlsx - \,*.xpm - \,*.xz - \,*.zip +set wildignore=*~,#*#,*.7z,.DS_Store,.git,.hg,.svn,*.a,*.adf,*.asc,*.au,*.aup + \,*.avi,*.bin,*.bmp,*.bz2,*.class,*.db,*.dbm,*.djvu,*.docx,*.exe + \,*.filepart,*.flac,*.gd2,*.gif,*.gifv,*.gmo,*.gpg,*.gz,*.hdf,*.ico + \,*.iso,*.jar,*.jpeg,*.jpg,*.m4a,*.mid,*.mp3,*.mp4,*.o,*.odp,*.ods,*.odt + \,*.ogg,*.ogv,*.opus,*.pbm,*.pdf,*.png,*.ppt,*.psd,*.pyc,*.rar,*.rm + \,*.s3m,*.sdbm,*.sqlite,*.swf,*.swp,*.tar,*.tga,*.ttf,*.wav,*.webm,*.xbm + \,*.xcf,*.xls,*.xlsx,*.xpm,*.xz,*.zip " Allow me to be lazy and type a path to complete on the Ex command line in " all-lowercase, and transform the consequent completion to match the -- cgit v1.2.3 From 3f7c5729f82633a15f9823d47de79e3b748af7c1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:39:30 +1200 Subject: Adjust order of directory reference and creation --- vim/vimrc | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 2937b8db..ddece845 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -119,18 +119,12 @@ command! -bar -complete=dir -nargs=+ CreatePath " raised if there were problems with the creation, but we’ll barrel on ahead " regardless after warning the user about our failure. " -CreatePath $MYVIM - -" Our next application of our new :CreatePath command is to configure the path -" for the viminfo metadata file, putting it in a cache subdirectory of the -" user runtime directory set in MYVIM. -" -" Using this non-default location for viminfo has the nice benefit of +" Using a logical but non-default location for viminfo has the nice benefit of " preventing command and search history from getting clobbered when something " runs Vim without using this vimrc, because such an instance will safely -" write its history to the default viminfo path instead. It also contributes -" to our aim of having everything related to the Vim runtime process in one -" dedicated directory tree. +" write its own history to the default viminfo path instead. It also +" contributes to our aim of having everything related to the Vim runtime +" process in one dedicated directory tree. " " The normal method of specifying the path to the viminfo file, as applied " here, is an addendum of the path to the 'viminfo' option with an "n" prefix. @@ -139,9 +133,8 @@ CreatePath $MYVIM " " " -execute 'set viminfo+='.escape#Arg( - \ 'n'.$MYVIM.'/viminfo' - \) +execute 'set viminfo+='.escape#Arg('n'.$MYVIM.'/viminfo') +CreatePath $MYVIM " Speaking of recorded data in viminfo files, the default Vim limit of a mere " 50 entries for command and search history is pretty stingy. Because I don’t @@ -186,10 +179,10 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -CreatePath $MYVIM/backup 0700 execute 'set backupdir^='.escape#Arg(escape#Item( \ $MYVIM.'/backup'.(has('patch-8.1.251') ? '//' : ''), \)) +CreatePath $MYVIM/backup 0700 " Files in certain directories on Unix-compatible filesystems should not be " backed up, for security reasons. This is particularly important if editing @@ -223,10 +216,10 @@ endif " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions, since the 'directory' " option has supported that hint for much longer than 'backupdir' has. We -" apply CreatePath() to attempt to create the path first, if needed. +" apply CreatePath() to attempt to create the path, if needed. " -CreatePath $MYVIM/swap 0700 execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//')) +CreatePath $MYVIM/swap 0700 " Keep tracked undo history for files permanently, in a dedicated cache " directory, so that the u/:undo and CTRL-R/:redo commands will work between @@ -243,10 +236,8 @@ execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//')) " if has('persistent_undo') set undofile + execute 'set undodir^='.escape#Arg(escape#Item($MYVIM.'/undo//')) CreatePath $MYVIM/undo 0700 - execute 'set undodir^='.escape#Arg(escape#Item( - \ $MYVIM.'/undo//' - \)) endif " Now that we have a bit more confidence in our runtime environment, set up @@ -321,7 +312,6 @@ endif " the path is valid. We put it back immediately afterwards. " set spelllang=en_nz -CreatePath $MYVIM/spell let s:spelllang = split#Option(&spelllang) let s:spellfile = $MYVIM.'/spell/'.join([ \ split(s:spelllang[0], '_')[0], &encoding, 'add', @@ -331,8 +321,11 @@ if has('unix') set isfname=1-255 endif execute 'set spellfile^='.escape#Arg(escape#Item(s:spellfile)) -let &isfname = s:isfname -unlet s:isfname +if exists('s:isfname') + let &isfname = s:isfname + unlet s:isfname +endif +CreatePath $MYVIM/spell " Spell checking includes optional support for catching lower case letters at " the start of sentences, and defines a pattern in 'spellcapcheck' for the end -- cgit v1.2.3 From 19b91a889f84ddb3204222f814cdbb08621ba012 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:46:48 +1200 Subject: Force load of Funcref autoload func on older Vim --- vim/autoload/split.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vim/autoload/split.vim b/vim/autoload/split.vim index 92d7a133..44065094 100644 --- a/vim/autoload/split.vim +++ b/vim/autoload/split.vim @@ -1,3 +1,7 @@ +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' -- cgit v1.2.3 From e980a90349e79973e944bedda1175eb82222d059 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:47:05 +1200 Subject: Expand arguments to :CreatePath --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index ddece845..aa08fcfd 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -111,7 +111,7 @@ endif " provide alternative permissions in the second argument. " command! -bar -complete=dir -nargs=+ CreatePath - \ call path#Create() + \ call path#Create(expand()) " Now that we have a way to create directories if they don’t already exist, " let’s apply it for the first time to the user runtime directory. Note that -- cgit v1.2.3 From 4620fc91ff048b4bb1b87980faff046ec5da6b38 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 6 Jul 2019 23:55:37 +1200 Subject: Handle path expansion in CreatePath --- vim/autoload/path.vim | 5 +++-- vim/vimrc | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim index 2506ad53..410cd294 100644 --- a/vim/autoload/path.vim +++ b/vim/autoload/path.vim @@ -2,9 +2,10 @@ function! path#Create(name, ...) abort if a:0 > 2 echoerr 'Too many arguments' endif - if isdirectory(a:name) + let name = expand(a:name) + if isdirectory(name) return 1 endif let prot = a:0 >= 1 ? a:1 : 0755 - return mkdir(a:name, 'p', prot) + return mkdir(name, 'p', prot) endfunction diff --git a/vim/vimrc b/vim/vimrc index aa08fcfd..ddece845 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -111,7 +111,7 @@ endif " provide alternative permissions in the second argument. " command! -bar -complete=dir -nargs=+ CreatePath - \ call path#Create(expand()) + \ call path#Create() " Now that we have a way to create directories if they don’t already exist, " let’s apply it for the first time to the user runtime directory. Note that -- cgit v1.2.3 From 651846f32dbcf16d326ac456a2a7579d20247625 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 7 Jul 2019 00:08:56 +1200 Subject: Rearrange command/function call semantics --- vim/autoload/path.vim | 9 +++++---- vim/vimrc | 15 +++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim index 410cd294..83102138 100644 --- a/vim/autoload/path.vim +++ b/vim/autoload/path.vim @@ -2,10 +2,11 @@ function! path#Create(name, ...) abort if a:0 > 2 echoerr 'Too many arguments' endif - let name = expand(a:name) - if isdirectory(name) + if isdirectory(a:name) return 1 endif - let prot = a:0 >= 1 ? a:1 : 0755 - return mkdir(name, 'p', prot) + let name = a:name + let path = 'p' + let prot = a:0 == 1 && a:1 ? 0700 : 0755 + return mkdir(name, path, prot) endfunction diff --git a/vim/vimrc b/vim/vimrc index ddece845..99afc22f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -107,11 +107,10 @@ endif " We need a command to reliably establish a full path, whether or not the " directories already exist. We create a wrapper for the autolated function " path#Create() with similar calling conventions to mkdir(), but with the ‘p’ -" value for the second parameter {prot} forced on. You can still optionally -" provide alternative permissions in the second argument. +" value for the second parameter {prot} forced on. " -command! -bar -complete=dir -nargs=+ CreatePath - \ call path#Create() +command! -bang -bar -complete=dir -nargs=1 CreatePath + \ call path#Create(expand(), ==# '!') " Now that we have a way to create directories if they don’t already exist, " let’s apply it for the first time to the user runtime directory. Note that @@ -182,7 +181,7 @@ set backup execute 'set backupdir^='.escape#Arg(escape#Item( \ $MYVIM.'/backup'.(has('patch-8.1.251') ? '//' : ''), \)) -CreatePath $MYVIM/backup 0700 +CreatePath! $MYVIM/backup " Files in certain directories on Unix-compatible filesystems should not be " backed up, for security reasons. This is particularly important if editing @@ -216,10 +215,10 @@ endif " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions, since the 'directory' " option has supported that hint for much longer than 'backupdir' has. We -" apply CreatePath() to attempt to create the path, if needed. +" apply path#Create() to attempt to create the path, if needed. " execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//')) -CreatePath $MYVIM/swap 0700 +CreatePath! $MYVIM/swap " Keep tracked undo history for files permanently, in a dedicated cache " directory, so that the u/:undo and CTRL-R/:redo commands will work between @@ -237,7 +236,7 @@ CreatePath $MYVIM/swap 0700 if has('persistent_undo') set undofile execute 'set undodir^='.escape#Arg(escape#Item($MYVIM.'/undo//')) - CreatePath $MYVIM/undo 0700 + CreatePath! $MYVIM/undo endif " Now that we have a bit more confidence in our runtime environment, set up -- cgit v1.2.3 From 15b0ed324d50e08ee5c046108387d0de0a057eac Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 7 Jul 2019 00:21:38 +1200 Subject: Remove multibyte character from autoload file --- vim/autoload/map.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/autoload/map.vim b/vim/autoload/map.vim index 43cdf381..d4bd90a2 100644 --- a/vim/autoload/map.vim +++ b/vim/autoload/map.vim @@ -1,5 +1,5 @@ " We declare a wrapper around map() to allow us always to call it with -" a Funcref as the second function parameter, which isn’t directly supported +" a Funcref as the second function parameter, which isn't directly supported " by map() until Vim v7.4.1989. If the running version is older than that, " apply string() to the Funcref to use the older calling convention. " -- cgit v1.2.3 From ca23de7b4fbc20a5c36fb7cd86796ead698c8905 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 7 Jul 2019 00:30:12 +1200 Subject: Set 'spellfile' back to default before prefixing --- vim/vimrc | 1 + 1 file changed, 1 insertion(+) diff --git a/vim/vimrc b/vim/vimrc index 99afc22f..cf0c4675 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -319,6 +319,7 @@ if has('unix') let s:isfname = &isfname set isfname=1-255 endif +set spellfile& execute 'set spellfile^='.escape#Arg(escape#Item(s:spellfile)) if exists('s:isfname') let &isfname = s:isfname -- cgit v1.2.3 From a456b8043a83a3eb07e9f592044483e6077c7605 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 7 Jul 2019 00:30:25 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index ffb23ce0..5a80561a 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v6.50.0 -Fri, 05 Jul 2019 22:57:15 +0000 +tejr dotfiles v6.51.0 +Sat, 06 Jul 2019 12:30:25 +0000 -- cgit v1.2.3