diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-04-25 21:27:48 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-04-25 21:27:48 +1200 |
commit | 6dcd250f4fa39e3ac414338adbf6f95fc66fc04f (patch) | |
tree | 395727e885e8e6088ee70a5981d3b73de7d89e2c | |
parent | Correct absolute test (diff) | |
download | dotfiles-6dcd250f4fa39e3ac414338adbf6f95fc66fc04f.tar.gz dotfiles-6dcd250f4fa39e3ac414338adbf6f95fc66fc04f.zip |
Handle invalid XDG cache home
-rw-r--r-- | vim/autoload/xdg.vim | 2 | ||||
-rw-r--r-- | vim/vimrc | 46 |
2 files changed, 30 insertions, 18 deletions
diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index b1bc523a..675cf460 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -27,7 +27,7 @@ function! xdg#CacheDir(name) abort let name = a:name let home = s:Get('XDG_CACHE_HOME') if !s:Absolute(home) - return + return '' endif return join([home, name], '/') endfunction @@ -110,8 +110,12 @@ for s:configdir in reverse(xdg#ConfigDirs('vim')) endfor "" Cache; put this first so that e.g. spellfiles get created in it let s:cachedir = xdg#CacheDir('vim') -execute 'set runtimepath^=' - \.option#Escape(option#item#Escape(s:cachedir)) +if strlen(s:cachedir) + execute 'set runtimepath^=' + \.option#Escape(option#item#Escape(s:cachedir)) +else + unlet s:cachedir +endif "" Data let s:datadir = xdg#DataDirs('vim')[0] @@ -144,8 +148,10 @@ command! -bang -bar -complete=dir -nargs=1 CreatePath " " <https://github.com/vim/vim/releases/tag/v8.1.0716> " -execute 'set viminfo+='.option#Escape('n'.s:cachedir.'/viminfo') -call path#Create(s:cachedir) +if exists('s:cachedir') + execute 'set viminfo+='.option#Escape('n'.s:cachedir.'/viminfo') + call path#Create(s:cachedir) +endif " 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 @@ -190,10 +196,12 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -execute 'set backupdir^='.option#Escape(option#item#Escape( - \ s:cachedir.'/backup'.(has#('patch-8.1.251') ? '//' : ''), - \)) -call path#Create(s:cachedir.'/backup') +if exists('s:cachedir') + execute 'set backupdir^='.option#Escape(option#item#Escape( + \ s:cachedir.'/backup'.(has#('patch-8.1.251') ? '//' : ''), + \)) + call path#Create(s:cachedir.'/backup') +endif " Files in certain directories on Unix-compatible filesystems should not be " backed up, for security reasons. This is particularly important if editing @@ -229,10 +237,12 @@ endif " option has supported that hint for much longer than 'backupdir' has. We " apply path#Create() to attempt to create the path, if needed. " -let s:swap = s:cachedir.'/swap' -execute 'set directory^=' - \.option#Escape(option#item#Escape(s:swap.'//')) -call path#Create(s:swap) +if exists('s:cachedir') + let s:swap = s:cachedir.'/swap' + execute 'set directory^=' + \.option#Escape(option#item#Escape(s:swap.'//')) + call path#Create(s:swap) +endif " 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 @@ -249,10 +259,12 @@ call path#Create(s:swap) " if has#('persistent_undo') set undofile - let s:undodir = s:cachedir.'/undo' - execute 'set undodir^=' - \.option#Escape(option#item#Escape(s:undodir.'//')) - call path#Create(s:undodir) + if exists('s:cachedir') + let s:undodir = s:cachedir.'/undo' + execute 'set undodir^=' + \.option#Escape(option#item#Escape(s:undodir.'//')) + call path#Create(s:undodir) + endif endif " Set up a directory for files generated by :mkview. To date, I think I have @@ -260,7 +272,7 @@ endif " directories of this type. This isn't a comma-separated list like the others " ('backupdir', 'directory', 'spell', 'undodir') " -if has#('mksession') +if has#('mksession') && exists('s:cachedir') let s:viewdir = s:cachedir.'/view' execute 'set viewdir=' \.option#Escape(option#item#Escape(s:viewdir)) |