From 2582628f1b95eb98159e77e8359dea6c1b3e005f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 01:32:13 +1200 Subject: Tidy and correct XDG var getenv() fallback It's more correct for this function to get upset it's been passed a variable name outside the XDG basedirs spec; a more general function, in this case a backporting of getenv() from v8.1.1305. --- vim/autoload/getenv.vim | 22 ++++++++++++++++++++++ vim/autoload/xdg.vim | 17 ++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 vim/autoload/getenv.vim diff --git a/vim/autoload/getenv.vim b/vim/autoload/getenv.vim new file mode 100644 index 00000000..2b8fef1b --- /dev/null +++ b/vim/autoload/getenv.vim @@ -0,0 +1,22 @@ +" Backport getenv() from v8.1.1305 +" +" +" +function! getenv#(name) abort + + " Use native if available + if exists('*getenv') + return getenv(a:name) + endif + + " Backport + if a:name !~# '^[A-Z][A-Z0-9_]*$' + throw 'Illegal env var name' + endif + let value = v:null + if exists('$'.a:name) + execute 'let value = $'.a:name + endif + return value + +endfunction diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index 2b1e7c56..a0b88f82 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -11,18 +11,13 @@ let s:subdir = 'vim' function! s:Get(name) abort let name = a:name - if name !~# '^[A-Z][A-Z0-9_]*$' - throw 'Illegal env var name' - endif - let value = '' - execute 'let value = $'.name - if value !=# '' - return value - elseif has_key(s:defaults, name) - return s:defaults[name] - else - return '' + if !has_key(s:defaults, name) + throw 'Illegal XDG basedirs env var name' endif + let value = getenv#(name) + return value !=# v:null + \ ? value + \ : s:defaults[name] endfunction function! s:Absolute(path) abort -- cgit v1.2.3 From 31d93c78f7bf50c21e1bc924bf759814a82ee6cf Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 01:49:42 +1200 Subject: Improve "absolute path" check for XDG base dirs * /foo/bar -- absolute * ~/foo -- absolute * / -- Weird, but absolute * ~ -- Weird, but absolute * foo -- Not absolute * foo/bar -- Not absolute * ~foo -- Not absolute --- vim/autoload/xdg.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index a0b88f82..9003b076 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -21,7 +21,9 @@ function! s:Get(name) abort endfunction function! s:Absolute(path) abort - return a:path =~# '^[/~]' + return a:path =~# '^/' + \ || a:path =~# '^\~/' + \ || a:path ==# '~' endfunction function! s:Home(name) abort -- cgit v1.2.3 From fc7fb091736f97fe0cea18562d94454b3a865380 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 01:51:47 +1200 Subject: Tolerate unset iteration variables --- vim/vimrc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index d34ce24d..3d5aef3a 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -118,7 +118,8 @@ for s:xdgruntimepath in reverse(s:xdgruntimepaths) execute 'set runtimepath^=' \.option#Escape(option#item#Escape(s:xdgruntimepath)) endfor -unlet s:xdgruntimepaths s:xdgruntimepath +unlet! s:xdgruntimepath +unlet s:xdgruntimepaths " 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 @@ -411,7 +412,8 @@ try execute 'set thesaurus^=' \.option#Escape(option#item#Escape(s:refdir.'/thesaurus.txt')) endfor - unlet s:refdirs s:refdir + unlet! s:refdir + unlet s:refdirs catch /^Vim\%((\a\+)\)\=:E474:/ endtry -- cgit v1.2.3 From 6ceccd1ef32997625eecb6fd92ab77a8f4546cae Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 02:00:23 +1200 Subject: Separate cache runtime behaviour from config It's a little awkward to conflate them. --- vim/vimrc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 3d5aef3a..04aebfd6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -2,7 +2,7 @@ " Tom Ryder (tejr)’s Literate Vimrc " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " -" Last updated: Wed, 29 Apr 2020 02:53:22 UTC +" Last updated: Sat, 02 May 2020 13:59:44 UTC " " │ And I was lifted up in heart, and thought " │ Of all my late-shown prowess in the lists, @@ -103,23 +103,26 @@ endif " We'll use the XDG directories as machine-local configuration and storage. " " -" 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. +" Add all the configuration directories to 'runtimepath'. " -let s:xdgruntimepaths = xdg#['config']['dirs'] +let s:xdgconfigpaths = xdg#['config']['dirs'] if xdg#['config']['home'] !=# '' - call insert(s:xdgruntimepaths, xdg#['config']['home']) + call insert(s:xdgconfigpaths, xdg#['config']['home']) endif -if xdg#['cache']['home'] !=# '' - call insert(s:xdgruntimepaths, xdg#['cache']['home']) -endif -for s:xdgruntimepath in reverse(s:xdgruntimepaths) +for s:xdgconfigpath in reverse(s:xdgconfigpaths) execute 'set runtimepath^=' - \.option#Escape(option#item#Escape(s:xdgruntimepath)) + \.option#Escape(option#item#Escape(s:xdgconfigpath)) endfor -unlet! s:xdgruntimepath -unlet s:xdgruntimepaths +unlet! s:xdgconfigpath +unlet s:xdgconfigpaths + +" Now put the XDG cache home at the very front, so that e.g. 'spellfile' gets +" created in there rather than in the configuration directories. +" +if xdg#['cache']['home'] !=# '' + execute 'set runtimepath^=' + \.option#Escape(option#item#Escape(xdg#['cache']['home'])) +endif " 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 -- cgit v1.2.3 From f8db34968d3cdcc0b171d2a45cf6060ce7b7e752 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 02:01:45 +1200 Subject: Add handling of "after" subdirs in Vim XDG config --- vim/vimrc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 04aebfd6..0e50fbea 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -2,7 +2,7 @@ " Tom Ryder (tejr)’s Literate Vimrc " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " -" Last updated: Sat, 02 May 2020 13:59:44 UTC +" Last updated: Sat, 02 May 2020 14:01:35 UTC " " │ And I was lifted up in heart, and thought " │ Of all my late-shown prowess in the lists, @@ -103,7 +103,9 @@ endif " We'll use the XDG directories as machine-local configuration and storage. " " -" Add all the configuration directories to 'runtimepath'. +" Add all the configuration directories to 'runtimepath', including "after" +" directories to the end of it, in reverse order, forming the desired layers +" of configuration. " let s:xdgconfigpaths = xdg#['config']['dirs'] if xdg#['config']['home'] !=# '' @@ -112,6 +114,8 @@ endif for s:xdgconfigpath in reverse(s:xdgconfigpaths) execute 'set runtimepath^=' \.option#Escape(option#item#Escape(s:xdgconfigpath)) + execute 'set runtimepath+=' + \.option#Escape(option#item#Escape(s:xdgconfigpath.'/after')) endfor unlet! s:xdgconfigpath unlet s:xdgconfigpaths -- cgit v1.2.3 From 145998c8b71198c0d60685cda424a52478c6c9a9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 02:07:06 +1200 Subject: Use v:null in XDG-related contexts I hadn't realised it was supported in Vim v7.0. --- vim/autoload/xdg.vim | 2 +- vim/vimrc | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index 9003b076..2b90f5f1 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -29,7 +29,7 @@ endfunction function! s:Home(name) abort let home = s:Get(a:name) if !s:Absolute(home) - return '' + return v:null endif return join([home, s:subdir], '/') endfunction diff --git a/vim/vimrc b/vim/vimrc index 0e50fbea..a5814aa7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -2,7 +2,7 @@ " Tom Ryder (tejr)’s Literate Vimrc " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " -" Last updated: Sat, 02 May 2020 14:01:35 UTC +" Last updated: Sat, 02 May 2020 14:04:10 UTC " " │ And I was lifted up in heart, and thought " │ Of all my late-shown prowess in the lists, @@ -108,7 +108,7 @@ endif " of configuration. " let s:xdgconfigpaths = xdg#['config']['dirs'] -if xdg#['config']['home'] !=# '' +if xdg#['config']['home'] !=# v:null call insert(s:xdgconfigpaths, xdg#['config']['home']) endif for s:xdgconfigpath in reverse(s:xdgconfigpaths) @@ -123,7 +123,7 @@ unlet s:xdgconfigpaths " Now put the XDG cache home at the very front, so that e.g. 'spellfile' gets " created in there rather than in the configuration directories. " -if xdg#['cache']['home'] !=# '' +if xdg#['cache']['home'] !=# v:null execute 'set runtimepath^=' \.option#Escape(option#item#Escape(xdg#['cache']['home'])) endif @@ -153,7 +153,7 @@ command! -bang -bar -complete=dir -nargs=1 CreatePath " v8.1.716 introduced a way to set this with an option named 'viminfofile', " but I don't see a reason to use that. " -if xdg#['cache']['home'] !=# '' && path#Create(xdg#['cache']['home']) +if xdg#['cache']['home'] !=# v:null && path#Create(xdg#['cache']['home']) execute 'set viminfo+='.option#Escape( \ 'n'.xdg#['cache']['home'].'/viminfo' \) @@ -202,7 +202,7 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -if xdg#['cache']['home'] !=# '' +if xdg#['cache']['home'] !=# v:null let s:backupdir = xdg#['cache']['home'].'/backup' if path#Create(s:backupdir) execute 'set backupdir^='.option#Escape(option#item#Escape( @@ -246,7 +246,7 @@ 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 xdg#['cache']['home'] !=# '' +if xdg#['cache']['home'] !=# v:null let s:directory = xdg#['cache']['home'].'/swap' if path#Create(s:directory) execute 'set directory^='.option#Escape(option#item#Escape( @@ -271,7 +271,7 @@ endif " if has#('persistent_undo') set undofile - if xdg#['cache']['home'] !=# '' + if xdg#['cache']['home'] !=# v:null let s:undodir = xdg#['cache']['home'].'/undo' if path#Create(s:undodir) execute 'set undodir^='.option#Escape(option#item#Escape( @@ -410,7 +410,7 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) set dictionary^=/usr/share/dict/words try let s:refdirs = xdg#['data']['dirs'] - if xdg#['data']['home'] !=# '' + if xdg#['data']['home'] !=# v:null call insert(s:refdirs, xdg#['data']['home']) endif for s:refdir in reverse(s:refdirs) -- cgit v1.2.3 From c3c08a79bc42ec6abf2b4359254541c057b82c52 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 May 2020 02:16:31 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index b9757eea..c7443ec1 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v8.23.0 -Sat, 02 May 2020 11:39:33 +0000 +tejr dotfiles v8.24.0 +Sat, 02 May 2020 14:16:31 +0000 -- cgit v1.2.3