aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-04-25 23:09:53 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-04-25 23:09:53 +1200
commit02814702ca4d5a70d91df13404b07581203b892a (patch)
tree184a9a3194947bf288f3bab96934e3b4911c3428
parentMerge branch 'hotfix/v8.20.1' into develop (diff)
parentBump VERSION (diff)
downloaddotfiles-02814702ca4d5a70d91df13404b07581203b892a.tar.gz
dotfiles-02814702ca4d5a70d91df13404b07581203b892a.zip
Merge branch 'hotfix/v8.20.2' into develop
* hotfix/v8.20.2: Refactor adjusted XDG handling Improve compliance/sanity of XDG implementation Handle invalid XDG cache home Correct absolute test
-rw-r--r--VERSION4
-rw-r--r--vim/autoload/xdg.vim45
-rw-r--r--vim/vimrc93
3 files changed, 82 insertions, 60 deletions
diff --git a/VERSION b/VERSION
index e57e820b..f68eb207 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v8.20.1
-Sat, 25 Apr 2020 08:46:20 +0000
+tejr dotfiles v8.20.2
+Sat, 25 Apr 2020 11:03:00 +0000
diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim
index 9e6d6553..14aa3055 100644
--- a/vim/autoload/xdg.vim
+++ b/vim/autoload/xdg.vim
@@ -7,6 +7,8 @@ let s:defaults = {
\ 'XDG_DATA_DIRS': '/usr/local/share/:/usr/share/',
\}
+let s:subdir = 'vim'
+
function! s:Get(name) abort
let name = a:name
let env = environ()
@@ -20,34 +22,35 @@ function! s:Get(name) abort
endfunction
function! s:Absolute(path) abort
- return a:path !=# '^[/~]'
+ return a:path =~# '^[/~]'
endfunction
-function! xdg#CacheDir(name) abort
- let name = a:name
- let home = s:Get('XDG_CACHE_HOME')
+function! s:Home(name) abort
+ let home = s:Get(a:name)
if !s:Absolute(home)
- return
+ return ''
endif
- return join([home, name], '/')
+ return join([home, s:subdir], '/')
endfunction
-function! xdg#ConfigDirs(name) abort
- let name = a:name
- let home = s:Get('XDG_CONFIG_HOME')
- let dirs = split(s:Get('XDG_CONFIG_DIRS'), ':')
+function! s:Dirs(name) abort
+ let dirs = split(s:Get(a:name), ':')
return map(
- \ filter(insert(dirs, home), 's:Absolute(v:val)')
- \,'join([v:val, name], "/")'
+ \ filter(dirs, 's:Absolute(v:val)')
+ \,'join([v:val, s:subdir], "/")'
\)
endfunction
-function! xdg#DataDirs(name) abort
- let name = a:name
- let home = s:Get('XDG_DATA_HOME')
- let dirs = split(s:Get('XDG_DATA_DIRS'), ':')
- return map(
- \ filter(insert(dirs, home), 's:Absolute(v:val)')
- \,'join([v:val, name], "/")'
- \)
-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'),
+ \ },
+ \}
diff --git a/vim/vimrc b/vim/vimrc
index 27a79a6f..abbdda4b 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -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