aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-08 21:44:43 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-08 21:45:23 +1200
commit81c17d5551c399c9170ee06162aa0b4a7fbcde93 (patch)
treee42ff5d8809db7f9a3f72947a6852c27c2f37716
parentComplete documentation of 'formatoptions' choices (diff)
downloaddotfiles-81c17d5551c399c9170ee06162aa0b4a7fbcde93.tar.gz
dotfiles-81c17d5551c399c9170ee06162aa0b4a7fbcde93.zip
Drastically simplify $MYVIM handling
It was a fun exercise, but it's a pretty perverse situation to set up. People generally don't put commas in their runtime directory names, and it's not too out of order simply to tell them not to do that if they do. This removes the need for two small utility functions.
-rw-r--r--vim/autoload/vimrc.vim21
-rw-r--r--vim/vimrc73
2 files changed, 36 insertions, 58 deletions
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim
index f5cad283..b3a28062 100644
--- a/vim/autoload/vimrc.vim
+++ b/vim/autoload/vimrc.vim
@@ -1,26 +1,5 @@
" Utility functions for use in .vim/vimrc only
-" Escape a text value for :execute-based :set inclusion as an option value
-function! vimrc#EscapeSet(string) abort
-
- " Escape all the characters that `:help option-backslash` warns us about
- return escape(a:string, '\ |"')
-
-endfunction
-
-" Escape a text value for :execute-based :set inclusion as an element in
-" a comma-separated option value
-function! vimrc#EscapeSetPart(string) abort
-
- " Message to future Tom: yes, the comma being the sole inner escaped
- " character here is correct. No, we shouldn't escape backslash itself.
- " Yes, that means it's impossible to have the literal string '\,' in a part.
- " Yes, this reflects what Vim does internally. Read the source of
- " copy_option_part() in vim/src/misc2.c to confirm.
- return vimrc#EscapeSet(escape(a:string, ','))
-
-endfunction
-
" Expand the first path in an option string, check if it exists, and attempt
" to create it if it doesn't. Strip double-trailing-slash hints.
function! vimrc#Ensure(string) abort
diff --git a/vim/vimrc b/vim/vimrc
index 4edc1a96..f3f901e8 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -33,17 +33,29 @@
" variable for the first runtime directory? It's a mystery, and that's why so
" is mankind.
"
+" We'll use the first path specified in 'runtimepath', rather like Vim itself
+" does for spelling database files in the absence of a setting for
+" 'spellfile'. Splitting the values of an option like 'runtimepath' correctly
+" is a bit more complicated than it seems; we defer that to an autoloaded
+" utility function for clarity.
+"
if !exists('$MYVIM') && &runtimepath !=# ''
+ let $MYVIM = vimrc#SplitOption(&runtimepath)[0]
+endif
- " We'll use the first path specified in 'runtimepath', rather like Vim
- " itself does for spelling database files in the absence of a setting for
- " 'spellfile'. Splitting the values of an option like 'runtimepath' is
- " a bit more complicated than it looks; we defer it to an autoloaded utility
- " function for clarity.
- "
- let s:runtimepath_paths = vimrc#SplitOption(&runtimepath)
- let $MYVIM = s:runtimepath_paths[0]
-
+" The path named in the MYVIM environment variable can't contain a comma
+" anywhere, because its use in comma-separated option values will confuse Vim
+" into thinking more than one directory is being specified for the option
+" value, per normal :set semantics. If it does, we refuse to proceed.
+"
+" It's possible to work around this with some careful escaping, either at :set
+" time with an :execute abstraction or with a separate environment variable
+" for that particular context, but it's not really worth the extra complexity
+" for such a niche situation.
+"
+if stridx($MYVIM, ',') != -1
+ echoerr '$MYVIM contains a comma, refusing to proceed'
+ finish
endif
" Create a 'vimrc' automatic command hook group, if it already exists, and
@@ -121,11 +133,11 @@ set backup
" It's all so awkward. Surely options named something like 'backupfullpath',
" 'swapfilefullpath', and 'undofullpath' would have been clearer.
"
-let s:backupdir = $MYVIM.'/cache/backup'
if vimrc#Version('8.1.251')
- let s:backupdir .= '//'
+ set backupdir^=$MYVIM/cache/backup//
+else
+ set backupdir^=$MYVIM/cache/backup
endif
-execute 'set backupdir^='.vimrc#EscapeSetPart(s:backupdir)
" Create the first path in the 'backupdir' list, the one we just added, if it
" doesn't already exist. It isn't created automatically, which is by design.
@@ -140,30 +152,18 @@ call vimrc#Ensure(&backupdir)
"
if has('unix')
- " * /dev/shm: RAM disk, default path for password-store's temporary files
- " * /usr/tmp: Hard-coded path for sudoedit(8) [1/2]
- " * /var/tmp: Hard-coded path for sudoedit(8) [2/2]
- "
- let s:backupskip_patterns = [
- \ '/dev/shm/*'
- \,'/usr/tmp/*'
- \,'/var/tmp/*'
- \ ]
-
" Vim doesn't seem to check patterns added to 'backupskip' for uniqueness,
" so adding them repeatedly if this file is reloaded results in duplicates.
- " This might be a bug in Vim. To work around this, we attempt to remove
- " each pattern before we add it.
+ " This might be a bug in Vim. To work around this, we reset the path back
+ " to its default first.
+ set backupskip&
+
"
- " We sort and add them backwards only so that they're in alphabetical order
- " in the final option!
+ " * /dev/shm: RAM disk, default path for password-store's temporary files
+ " * /usr/tmp: Hard-coded path for sudoedit(8) [1/2]
+ " * /var/tmp: Hard-coded path for sudoedit(8) [2/2]
"
- for s:pattern in reverse(sort(s:backupskip_patterns))
- let s:pattern_escaped = vimrc#EscapeSetPart(s:pattern)
- execute 'set'
- \.' backupskip-='.s:pattern_escaped
- \.' backupskip^='.s:pattern_escaped
- endfor
+ set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/*
endif
@@ -243,8 +243,7 @@ set dictionary^=/usr/share/dict/words
" trailing slashes to the path to prompt Vim to use the full escaped path in
" its name, in order to avoid filename collisions.
"
-let s:directory = $MYVIM.'/cache/swap'.'//'
-execute 'set directory^='.vimrc#EscapeSetPart(s:directory)
+set directory^=$MYVIM/cache/swap
" Create the first path in the 'directory' swapfile path list, the one we just
" added, if it doesn't already exist. It isn't created automatically, which
@@ -434,7 +433,7 @@ set splitright " Right of the current window, not left
set synmaxcol=500
" Add thesaurus; install with `make install-vim-thesaurus`
-execute 'set thesaurus^='.vimrc#EscapeSetPart($MYVIM.'/ref/thesaurus.txt')
+set thesaurus^=$MYVIM/ref/thesaurus.txt
" PuTTY is a fast terminal, but Vim doesn't know that yet
if &term =~# '^putty'
@@ -450,7 +449,7 @@ endif
" Keep persistent undo files in dedicated directory, named with full path
if has('persistent_undo') " v7.2.438
set undofile
- execute 'set undodir^='.vimrc#EscapeSetPart($MYVIM.'/cache/undo//')
+ set undodir^=$MYVIM/cache/undo//
call vimrc#Ensure(&undodir)
endif
@@ -459,7 +458,7 @@ endif
if exists('+viminfofile') " Use new option method if we can (v8.1.716)
set viminfofile=$MYVIM/cache/viminfo
else " Resort to clunkier method with 'viminfo' option flag
- execute 'set viminfo+='.vimrc#EscapeSet('n'.$MYVIM.'/cache/viminfo')
+ set viminfo+=n$MYVIM/cache/viminfo
endif
" Let me move beyond buffer text in visual block mode