diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-04-25 23:02:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-04-25 23:02:40 +1200 |
commit | 5f3ebed25f6d997c8f7161b97476054c865c0807 (patch) | |
tree | c10eb2a6bc235c0dc0e9f89d9be4f2b348055060 | |
parent | Improve compliance/sanity of XDG implementation (diff) | |
download | dotfiles-5f3ebed25f6d997c8f7161b97476054c865c0807.tar.gz dotfiles-5f3ebed25f6d997c8f7161b97476054c865c0807.zip |
Refactor adjusted XDG handling
-rw-r--r-- | vim/autoload/xdg.vim | 32 | ||||
-rw-r--r-- | vim/vimrc | 69 |
2 files changed, 39 insertions, 62 deletions
diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index 62d515c1..14aa3055 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -33,18 +33,6 @@ function! s:Home(name) abort return join([home, s:subdir], '/') endfunction -function! xdg#CacheHome() abort - return s:Home('XDG_CACHE_HOME') -endfunction - -function! xdg#ConfigHome() abort - return s:Home('XDG_CONFIG_HOME') -endfunction - -function! xdg#DataHome() abort - return s:Home('XDG_DATA_HOME') -endfunction - function! s:Dirs(name) abort let dirs = split(s:Get(a:name), ':') return map( @@ -53,10 +41,16 @@ function! s:Dirs(name) abort \) endfunction -function! xdg#ConfigDirs() abort - return s:Dirs('XDG_CONFIG_DIRS') -endfunction - -function! xdg#DataDirs() abort - return s:Dirs('XDG_DATA_DIRS') -endfunction +let xdg# = { + \ 'cache': { + \ 'home': s:Home('XDG_CACHE_HOME'), + \ }, + \ 'config': { + \ 'home': s:Home('XDG_CONFIG_HOME'), + \ 'dirs': s:Dirs('XDG_CONFIG_DIRS'), + \ }, + \ 'data': { + \ 'home': s:Home('XDG_DATA_HOME'), + \ 'dirs': s:Dirs('XDG_DATA_DIRS'), + \ }, + \} @@ -103,39 +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> " -"" Cache -let s:cache_home = xdg#CacheHome() -if strlen(s:cache_home) == 0 - unlet s:cache_home -endif -"" Config -let s:config_home = xdg#ConfigHome() -if strlen(s:config_home) == 0 - unlet s:config_home -endif -let s:config_dirs = xdg#ConfigDirs() -"" Data -let s:data_home = xdg#DataHome() -if strlen(s:data_home) == 0 - unlet s:data_home -endif -let s:data_dirs = xdg#DataDirs() - " 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:runtime_dirs = s:config_dirs -if exists('s:config_home') - call insert(s:runtime_dirs, s:config_home) +let s:xdgruntimepaths = xdg#['config']['dirs'] +if xdg#['config']['home'] !=# '' + call insert(s:xdgruntimepaths, xdg#['config']['home']) endif -if exists('s:cache_home') - call insert(s:runtime_dirs, s:config_home) +if xdg#['cache']['home'] !=# '' + call insert(s:xdgruntimepaths, xdg#['config']['home']) endif -for s:runtime_dir in reverse(s:runtime_dirs) +for s:xdgruntimepath in reverse(s:xdgruntimepaths) execute 'set runtimepath^=' - \.option#Escape(option#item#Escape(s:runtime_dir)) + \.option#Escape(option#item#Escape(s:xdgruntimepath)) endfor +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 @@ -166,9 +149,9 @@ command! -bang -bar -complete=dir -nargs=1 CreatePath " " <https://github.com/vim/vim/releases/tag/v8.1.0716> " -if exists('s:cache_home') - execute 'set viminfo+='.option#Escape('n'.s:cache_home.'/viminfo') - call path#Create(s:cache_home) +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 @@ -214,11 +197,11 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -if exists('s:cache_home') +if xdg#['cache']['home'] !=# '' execute 'set backupdir^='.option#Escape(option#item#Escape( - \ s:cache_home.'/backup'.(has#('patch-8.1.251') ? '//' : ''), + \ xdg#['cache']['home'].'/backup'.(has#('patch-8.1.251') ? '//' : ''), \)) - call path#Create(s:cache_home.'/backup') + call path#Create(xdg#['cache']['home'].'/backup') endif " Files in certain directories on Unix-compatible filesystems should not be @@ -255,8 +238,8 @@ endif " option has supported that hint for much longer than 'backupdir' has. We " apply path#Create() to attempt to create the path, if needed. " -if exists('s:cache_home') - let s:directory = s:cache_home.'/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) @@ -277,8 +260,8 @@ endif " if has#('persistent_undo') set undofile - if exists('s:cache_home') - let s:undodir = s:cache_home.'/undo' + 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) @@ -290,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') && exists('s:cache_home') - let s:viewdir = s:cache_home.'/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) @@ -410,15 +393,15 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) " set dictionary^=/usr/share/dict/words try - let s:ref_dirs = s:data_dirs - if exists('s:data_home') - call insert(s:ref_dirs, s:data_home) + let s:refdirs = xdg#['data']['dirs'] + if xdg#['data']['home'] !=# '' + call insert(s:refdirs, xdg#['data']['home']) endif - for s:ref_dir in reverse(s:ref_dirs) + for s:refdir in reverse(s:refdirs) execute 'set dictionary^=' - \.option#Escape(option#item#Escape(s:ref_dir.'/dictionary.txt')) + \.option#Escape(option#item#Escape(s:refdir.'/dictionary.txt')) execute 'set thesaurus^=' - \.option#Escape(option#item#Escape(s:ref_dir.'/thesaurus.txt')) + \.option#Escape(option#item#Escape(s:refdir.'/thesaurus.txt')) endfor catch /^Vim\%((\a\+)\)\=:E474:/ endtry |