diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-06 23:53:12 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-06 23:53:45 +1200 |
commit | 2c94109ed4b6e16bbf1b07c1ab5538909e301dfa (patch) | |
tree | 94b0d0bf80652a0accf61a578261dcfd9f96e4a4 | |
parent | Let's give 'showmatch' another try (diff) | |
download | dotfiles-2c94109ed4b6e16bbf1b07c1ab5538909e301dfa.tar.gz dotfiles-2c94109ed4b6e16bbf1b07c1ab5538909e301dfa.zip |
Create cache directories as needed with function
-rw-r--r-- | vim/autoload/vimrc.vim | 9 | ||||
-rw-r--r-- | vim/vimrc | 3 |
2 files changed, 12 insertions, 0 deletions
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index 94922e93..2c9a9cd2 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -11,6 +11,15 @@ function! vimrc#EscapeSetPart(string) abort 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. +function! vimrc#Establish(string) abort + let part = vimrc#SplitOption(a:string)[0] + let dirname = expand(part) + return isdirectory(dirname) + \ || mkdir(dirname, 'p') +endfunction + " Check that we have a plugin available, and will be loading it function! vimrc#PluginReady(filename) abort return globpath(&runtimepath, 'plugin/'.a:filename.'.vim') !=# '' @@ -27,6 +27,7 @@ set backup execute 'set backupdir^='.vimrc#EscapeSetPart( \ $MYVIM.'/cache/backup'.(vimrc#Version('8.1.251') ? '//' : '') \ ) +call vimrc#Establish(&backupdir) " Add some *nix paths not to back up if has('unix') @@ -60,6 +61,7 @@ set dictionary^=/usr/share/dict/words " Keep swap files in dedicated directory, named with full path execute 'set directory^='.vimrc#EscapeSetPart($MYVIM.'/cache/swap//') +call vimrc#Establish(&directory) " If the environment didn't set an encoding, use UTF-8, not ASCII if !exists('$LANG') @@ -187,6 +189,7 @@ if has('persistent_undo') " v7.2.438 execute 'set undodir^='.vimrc#EscapeSetPart( \ $MYVIM.'/cache/undo//' \ ) + call vimrc#Establish(&undodir) endif " Keep the viminfo file in the home Vim directory, mostly to stop history |