diff options
Diffstat (limited to 'vim/vimrc')
-rw-r--r-- | vim/vimrc | 93 |
1 files changed, 56 insertions, 37 deletions
@@ -103,17 +103,22 @@ endif " We'll use the XDG directories as machine-local configuration and storage. " <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables> " -"" Config -for s:configdir in reverse(xdg#ConfigDirs('vim')) +" Add all the configuration directories to 'runtimepath', and then put the +" cache home at the very front, so that e.g. 'spellfile' gets created in there +" rather than in the configuration directories. +" +let s:xdgruntimepaths = xdg#['config']['dirs'] +if xdg#['config']['home'] !=# '' + call insert(s:xdgruntimepaths, xdg#['config']['home']) +endif +if xdg#['cache']['home'] !=# '' + call insert(s:xdgruntimepaths, xdg#['config']['home']) +endif +for s:xdgruntimepath in reverse(s:xdgruntimepaths) execute 'set runtimepath^=' - \.option#Escape(option#item#Escape(s:configdir)) + \.option#Escape(option#item#Escape(s:xdgruntimepath)) 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)) -"" Data -let s:datadir = xdg#DataDirs('vim')[0] +unlet s:xdgruntimepaths s:xdgruntimepath " We need a command to reliably establish a full path, whether or not the " directories already exist. We create a wrapper for the autoloaded function @@ -144,8 +149,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 xdg#['cache']['home'] !=# '' + execute 'set viminfo+='.option#Escape('n'.xdg#['cache']['home'].'/viminfo') + call path#Create(xdg#['cache']['home']) +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 +197,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 xdg#['cache']['home'] !=# '' + execute 'set backupdir^='.option#Escape(option#item#Escape( + \ xdg#['cache']['home'].'/backup'.(has#('patch-8.1.251') ? '//' : ''), + \)) + call path#Create(xdg#['cache']['home'].'/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 +238,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 xdg#['cache']['home'] !=# '' + let s:directory = xdg#['cache']['home'].'/swap' + execute 'set directory^=' + \.option#Escape(option#item#Escape(s:directory.'//')) + call path#Create(s:directory) +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 +260,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 xdg#['cache']['home'] !=# '' + let s:undodir = xdg#['cache']['home'].'/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,8 +273,8 @@ endif " directories of this type. This isn't a comma-separated list like the others " ('backupdir', 'directory', 'spell', 'undodir') " -if has#('mksession') - let s:viewdir = s:cachedir.'/view' +if has#('mksession') && xdg#['cache']['home'] + let s:viewdir = xdg#['cache']['home'].'/view' execute 'set viewdir=' \.option#Escape(option#item#Escape(s:viewdir)) call path#Create(s:viewdir) @@ -369,21 +382,27 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) " first two metadata lines from thesaurus.txt, as Vim appeared to interpret " them as part of the body data. " -" Extra checks for appending the 'dictionary' and 'thesaurus' paths in MYVIM -" need to be made, because the P_NDNAME property is assigned to them, which -" enforces a character blacklist in the option value. We check for the -" expected Vim error code here, and if the MYVIM path offends, we just skip -" the setting entirely, rather than throwing cryptic errors at the user. None -" of the blacklisted characters are particularly wise characters to have in -" paths, anyway, legal though they may be on Unix filesystems. We can’t work -" around this one with 'isfname'; the blacklist is hard-coded. +" Extra checks for appending the 'dictionary' and 'thesaurus' paths need to be +" made, because the P_NDNAME property is assigned to them, which enforces +" a character blacklist in the option value. We check for the expected Vim +" error code here, and if the path offends, we just skip the setting entirely, +" rather than throwing cryptic errors at the user. None of the blacklisted +" characters are particularly wise characters to have in paths, anyway, legal +" though they may be on Unix filesystems. We can’t work around this one with +" 'isfname'; the blacklist is hard-coded. " set dictionary^=/usr/share/dict/words try - execute 'set dictionary^=' - \.option#Escape(option#item#Escape(s:datadir.'/dictionary.txt')) - execute 'set thesaurus^=' - \.option#Escape(option#item#Escape(s:datadir.'/thesaurus.txt')) + let s:refdirs = xdg#['data']['dirs'] + if xdg#['data']['home'] !=# '' + call insert(s:refdirs, xdg#['data']['home']) + endif + for s:refdir in reverse(s:refdirs) + execute 'set dictionary^=' + \.option#Escape(option#item#Escape(s:refdir.'/dictionary.txt')) + execute 'set thesaurus^=' + \.option#Escape(option#item#Escape(s:refdir.'/thesaurus.txt')) + endfor catch /^Vim\%((\a\+)\)\=:E474:/ endtry |