From 1b8859a9d0bf1da2d8a9320a78862e2c8a7ef41a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 15 May 2020 10:26:46 +1200 Subject: Add an issue --- ISSUES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ISSUES.md b/ISSUES.md index 692bdb55..53237bcb 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -31,3 +31,7 @@ Known issues * The `_text_filenames` completion handler for Bash won't work on files with newlines in their names. Can it be made to? * Typing the normal mode mapping for `paste_open.vim` *twice* causes an error. +* The `xdg#` dictionary doesn't really work as an idea because it relies on the + user to make a copy of the structure or lists to avoid changing it in-place. + There would be a little more overhead to change this into a function call, + but it'd be somewhat safer. -- cgit v1.2.3 From 2a20c61eaeee75a72c71fdc2abca7a0c6815d11a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 15 May 2020 21:45:06 +1200 Subject: Add an issue with syntax highlighting --- ISSUES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ISSUES.md b/ISSUES.md index 53237bcb..3b0b2316 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -35,3 +35,5 @@ Known issues user to make a copy of the structure or lists to avoid changing it in-place. There would be a little more overhead to change this into a function call, but it'd be somewhat safer. +* Highlighting the variable name in e.g. `unset -v VARNAME` works with `bash` + highlighting, but not with `sh` highlighting -- cgit v1.2.3 From 8e55b0ef8f9d76565f115498ca1c226b2d676b68 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:15:56 +1200 Subject: Use $HOME not tildes for XDG basedir defaults This is both closer to the spec, and also takes some of the pain out of expanding paths for use in options. --- vim/autoload/xdg.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index 5cef0f98..9c6e018f 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -1,9 +1,9 @@ " let s:defaults = { - \ 'XDG_CACHE_HOME': '~/.cache', - \ 'XDG_CONFIG_HOME': '~/.config', + \ 'XDG_CACHE_HOME': $HOME.'/.cache', + \ 'XDG_CONFIG_HOME': $HOME.'/.config', \ 'XDG_CONFIG_DIRS': '/etc/xdg', - \ 'XDG_DATA_HOME': '~/.local/share', + \ 'XDG_DATA_HOME': $HOME.'/.local/share', \ 'XDG_DATA_DIRS': '/usr/local/share:/usr/share', \} -- cgit v1.2.3 From f20c0f17ad13ccdb99bc6dfa776d96d9959219f9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:16:48 +1200 Subject: Simplify Vim XDG subdir definition YAGNI --- vim/autoload/xdg.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index 9c6e018f..e0230b60 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -7,8 +7,6 @@ let s:defaults = { \ 'XDG_DATA_DIRS': '/usr/local/share:/usr/share', \} -let s:subdir = 'vim' - function! s:Get(name) abort let name = a:name if !has_key(s:defaults, name) @@ -31,14 +29,14 @@ function! s:Home(name) abort if !s:Absolute(home) return '' endif - return join([home, s:subdir], '/') + return home.'/vim' endfunction function! s:Dirs(name) abort let dirs = split(s:Get(a:name), ':') return map( \ filter(copy(dirs), 's:Absolute(v:val)') - \,'join([v:val, s:subdir], "/")' + \,'v:val.''/vim''' \) endfunction -- cgit v1.2.3 From 516eea5f36f9d565014c23d8e0b10b43191aedce Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:22:22 +1200 Subject: Switch XDG semantics to functions not global var --- ISSUES.md | 4 -- vim/after/plugin/spellfile_local.vim | 8 +-- vim/autoload/xdg.vim | 32 ++++++---- vim/vimrc | 120 ++++++++++++++++------------------- 4 files changed, 79 insertions(+), 85 deletions(-) diff --git a/ISSUES.md b/ISSUES.md index 3b0b2316..6fd39517 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -31,9 +31,5 @@ Known issues * The `_text_filenames` completion handler for Bash won't work on files with newlines in their names. Can it be made to? * Typing the normal mode mapping for `paste_open.vim` *twice* causes an error. -* The `xdg#` dictionary doesn't really work as an idea because it relies on the - user to make a copy of the structure or lists to avoid changing it in-place. - There would be a little more overhead to change this into a function call, - but it'd be somewhat safer. * Highlighting the variable name in e.g. `unset -v VARNAME` works with `bash` highlighting, but not with `sh` highlighting diff --git a/vim/after/plugin/spellfile_local.vim b/vim/after/plugin/spellfile_local.vim index 9d89852e..1655e78c 100644 --- a/vim/after/plugin/spellfile_local.vim +++ b/vim/after/plugin/spellfile_local.vim @@ -1,8 +1,8 @@ -" Use XDG dirs for 'spellfile' -if xdg#['data']['home'] !=# '' - let g:spellfile_local_dirs = [ xdg#['data']['home'] ] +" Use XDG dirs for 'spellfile' if XDG_DATA_HOME is useable +if xdg#DataHome() !=# '' + let g:spellfile_local_dirs = [ xdg#DataHome() ] call extend( \ g:spellfile_local_dirs, - \ copy(xdg#['data']['dirs']) + \ xdg#DataDirs(), \) endif diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim index e0230b60..c5737506 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -40,16 +40,22 @@ function! s:Dirs(name) abort \) 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'), - \ }, - \} +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! xdg#ConfigDirs() abort + return s:Dirs('XDG_CONFIG_DIRS') +endfunction + +function! xdg#DataDirs() abort + return s:Dirs('XDG_DATA_DIRS') +endfunction diff --git a/vim/vimrc b/vim/vimrc index ebd9de3d..13987c10 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -130,9 +130,7 @@ endif " We'll start by retrieving the list of valid paths for configuration from " both the XDG_CONFIG_HOME and XDG_CONFIG_DIRS variables, or from their -" defaults, using the autoloaded xdg#() function. We need to copy() it -" because of Vim's implicit semantics for map() and reverse(), otherwise we'll -" edit the values in-place. Man, my kingdom for Perl… +" defaults, using autoloaded xdg# functions. " " We put XDG_CONFIG_HOME at the front of the list with insert(), provided it " isn't empty, which is what the function returns when the configured path @@ -147,23 +145,22 @@ endif " " Ours not to reason why… " -let s:xdgconfigpaths = copy(xdg#['config']['dirs']) -if xdg#['config']['home'] !=# '' - call insert(s:xdgconfigpaths, xdg#['config']['home']) -endif -if !empty(s:xdgconfigpaths) +if xdg#ConfigHome() !=# '' || !empty(xdg#ConfigDirs()) execute 'set runtimepath^='.option#Escape(join(map( - \ copy(s:xdgconfigpaths), + \ extend( + \ xdg#ConfigHome() !=# '' ? [xdg#ConfigHome()] : [], + \ xdg#ConfigDirs() + \), \ 'option#item#Escape(v:val)' \), ',')) -endif -if !empty(s:xdgconfigpaths) execute 'set runtimepath+='.option#Escape(join(map( - \ reverse(copy(s:xdgconfigpaths)), + \ reverse(extend( + \ xdg#ConfigHome() !=# '' ? [xdg#ConfigHome()] : [], + \ xdg#ConfigDirs() + \)), \ 'option#item#Escape(v:val.''/after'')' \), ',')) endif -unlet s:xdgconfigpaths " 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 @@ -190,9 +187,12 @@ 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#CacheHome() !=# '' + if !isdirectory(xdg#CacheHome()) + call mkdir(xdg#CacheHome(), 'p', 0700) + endif execute 'set viminfo+='.option#Escape( - \ 'n'.xdg#['cache']['home'].'/viminfo' + \ 'n'.xdg#CacheHome().'/viminfo' \) endif @@ -239,14 +239,13 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -if xdg#['cache']['home'] !=# '' - let s:backupdir = xdg#['cache']['home'].'/backup' - if path#Create(s:backupdir) - execute 'set backupdir^='.option#Escape(option#item#Escape( - \ s:backupdir.(has#('patch-8.1.251') ? '//' : ''), - \)) +if xdg#CacheHome() !=# '' + if !isdirectory(xdg#CacheHome().'/backup') + call mkdir(xdg#CacheHome().'/backup', 'p', 0700) endif - unlet s:backupdir + execute 'set backupdir^='.option#Escape(option#item#Escape( + \ xdg#CacheHome().'/backup'.(has#('patch-8.1.251') ? '//' : '') + \)) endif " Files in certain directories on Unix-compatible filesystems should not be @@ -280,17 +279,15 @@ endif " default of writing them to the same directory as the buffer file. Add two " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions, since the 'directory' -" 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'] !=# '' - let s:directory = xdg#['cache']['home'].'/swap' - if path#Create(s:directory) - execute 'set directory^='.option#Escape(option#item#Escape( - \ s:directory.'//' - \)) +" option has supported that hint for much longer than 'backupdir' has. +" +if xdg#CacheHome() !=# '' + if !isdirectory(xdg#CacheHome().'/swap') + call mkdir(xdg#CacheHome().'/swap', 'p', 0700) endif - unlet s:directory + execute 'set directory^='.option#Escape(option#item#Escape( + \ xdg#CacheHome().'/swap//' + \)) endif " Keep tracked undo history for files permanently, in a dedicated cache @@ -306,17 +303,14 @@ endif " Support for these persistent undo file caches was not released until v7.3.0, " so we need to check for the feature’s presence before we enable it. " -if has#('persistent_undo') +if xdg#CacheHome() !=# '' && has#('persistent_undo') set undofile - if xdg#['cache']['home'] !=# '' - let s:undodir = xdg#['cache']['home'].'/undo' - if path#Create(s:undodir) - execute 'set undodir^='.option#Escape(option#item#Escape( - \ s:undodir.'//' - \)) - endif - unlet s:undodir + if !isdirectory(xdg#CacheHome().'/undo') + call mkdir(xdg#CacheHome().'/undo', 'p', 0700) endif + execute 'set undodir^='.option#Escape(option#item#Escape( + \ xdg#CacheHome().'/undo//' + \)) endif " Set up a directory for files generated by :mkview. To date, I think I have @@ -324,13 +318,13 @@ endif " directories of this type. This isn't a comma-separated list like the others " ('backupdir', 'directory', 'spell', 'undodir') " -if has#('mksession') && xdg#['cache']['home'] - let s:viewdir = xdg#['cache']['home'].'/view' - if path#Create(s:viewdir) - execute 'set viewdir=' - \.option#Escape(option#item#Escape(s:viewdir)) +if xdg#CacheHome() !=# '' && has#('mksession') + if !isdirectory(xdg#CacheHome().'/view') + call mkdir(xdg#CacheHome().'/view', 'p', 0700) endif - unlet s:viewdir + execute 'set viewdir='.option#Escape(option#item#Escape( + \ xdg#CacheHome().'/view' + \)) endif " Now that we have a bit more confidence in our runtime environment, set up @@ -450,24 +444,22 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) " 'isfname'; the blacklist is hard-coded. " set dictionary^=/usr/share/dict/words -let s:refdirs = copy(xdg#['data']['dirs']) -if xdg#['data']['home'] !=# '' - call insert(s:refdirs, xdg#['data']['home']) -endif -if !empty(s:refdirs) - try - execute 'set dictionary^='.option#Escape(join(map( - \ copy(s:refdirs), - \ 'option#item#Escape(v:val.''/dictionary.txt'')' - \), ',')) - execute 'set thesaurus^='.option#Escape(join(map( - \ copy(s:refdirs), - \ 'option#item#Escape(v:val.''/thesaurus.txt'')' - \), ',')) - catch /^Vim\%((\a\+)\)\=:E474:/ - endtry +if xdg#DataHome() !=# '' || !empty(xdg#DataDirs()) + execute 'set dictionary^='.option#Escape(join(map( + \ extend( + \ xdg#DataHome() !=# '' ? [xdg#DataHome()] : [], + \ xdg#DataDirs() + \), + \ 'option#item#Escape(v:val.''/dictionary.txt'')' + \), ',')) + execute 'set thesaurus^='.option#Escape(join(map( + \ reverse(extend( + \ xdg#DataHome() !=# '' ? [xdg#DataHome()] : [], + \ xdg#DataDirs() + \)), + \ 'option#item#Escape(v:val.''/thesaurus.txt'')' + \), ',')) endif -unlet s:refdirs " Next, we’ll modernize a little in adjusting some options with old " language-specific defaults. -- cgit v1.2.3 From 3f52145bbedc8d291567d41e29805c6bd5d3a467 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:22:54 +1200 Subject: Write out over-engineered path creation function --- vim/autoload/path.vim | 14 -------------- vim/vimrc | 20 ++------------------ 2 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 vim/autoload/path.vim diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim deleted file mode 100644 index 54aacbc2..00000000 --- a/vim/autoload/path.vim +++ /dev/null @@ -1,14 +0,0 @@ -" Create all the directories needed for a path, with optional flag for -" owner-only permissions -function! path#Create(name, ...) abort - if a:0 > 2 - echoerr 'Too many arguments' - endif - let name = fnamemodify(a:name, ':p') - if isdirectory(name) - return 1 - endif - let path = 'p' - let prot = a:0 == 1 && a:1 ? 0700 : 0755 - return mkdir(name, path, prot) -endfunction diff --git a/vim/vimrc b/vim/vimrc index 13987c10..dc1183f6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -162,21 +162,6 @@ if xdg#ConfigHome() !=# '' || !empty(xdg#ConfigDirs()) \), ',')) 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 -" path#Create() with similar calling conventions to mkdir(), but with the ‘p’ -" value for the second parameter {prot} forced on. Calling it with a bang -" like :CreatePath! creates a private directory (permissions 0700). -" -command! -bang -bar -complete=dir -nargs=1 CreatePath - \ call path#Create(expand(), ==# '!') - -" Now that we have a way to create directories if they don’t already exist, -" let’s apply it for the first time to the user runtime directory. Note that -" we aren’t checking whether this actually succeeded. We do want errors -" raised if there were problems with the creation, but we’ll barrel on ahead -" regardless after warning the user about our failure. -" " Using a logical but non-default location for viminfo has the nice benefit of " preventing command and search history from getting clobbered when something " runs Vim without using this vimrc, because such an instance will safely @@ -1373,8 +1358,7 @@ nnoremap D \ :PutDate! " This group contains mappings that are to do with file and path management -" relative to the current buffer. The Leader,P mapping that creates -" directory hierarchies uses the :CreatePath command created earlier. +" relative to the current buffer. "" Leader,g shows the current file’s fully expanded path nnoremap g @@ -1384,7 +1368,7 @@ nnoremap G \ :cd %:hpwd "" Leader,P creates the path to the current file if it doesn’t exist nnoremap P - \ :CreatePath %:h + \ :call mkdir(expand('%:h'), 'p') " This group contains mappings that show information about Vim’s internals: " marks, registers, variables, and the like. -- cgit v1.2.3 From ac26a33542925fe5fa458572e2a0161f3d9c5beb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:25:11 +1200 Subject: Bail from Vim if &runtimepath is empty Really shouldn't happen, but probably worth catching. --- vim/vimrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index dc1183f6..0d9c7b39 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -113,9 +113,10 @@ endif " first value from the 'runtimepath'. We'll use this later on in the file to " comprehensively match expected paths for vimrc files. " -if &runtimepath !=# '' - let $MYVIM = option#Split(&runtimepath)[0] +if &runtimepath ==# '' + throw 'Empty ''runtimepath''' endif +let $MYVIM = option#Split(&runtimepath)[0] " The next components of the runtime directory that we'll set up here will " make use of the user’s configured XDG base directories: -- cgit v1.2.3 From cc89a0f03c56cd20a01d2762904ea115bbdbb156 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:27:07 +1200 Subject: Correct some poor writing --- vim/vimrc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 0d9c7b39..bdd1532d 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -281,10 +281,9 @@ endif " Vim invocations. " " The 'undodir' option has the same structure as 'backupdir' and 'directory'; -" if we have a user runtime directory, create a sub-subdirectory within it -" dedicated to the undo files cache. Note also the trailing double-slash as -" a signal to Vim to use the full path of the original file in its undo file -" cache’s name. +" if we have a user cache directory, create a subdirectory within it dedicated +" to the undo files cache. Note also the trailing double-slash as a signal to +" Vim to use the full path of the original file in its undo file cache’s name. " " Support for these persistent undo file caches was not released until v7.3.0, " so we need to check for the feature’s presence before we enable it. -- cgit v1.2.3 From 4cee96177814f39631b9c8d4875bc6f52678547a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 01:27:33 +1200 Subject: Update updated date in vimrc --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index bdd1532d..6cde7036 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -2,7 +2,7 @@ " Tom Ryder (tejr)’s Literate Vimrc " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " -" Last updated: Thu, 14 May 2020 08:24:17 UTC +" Last updated: Fri, 15 May 2020 13:24:13 UTC " " │ And I was lifted up in heart, and thought " │ Of all my late-shown prowess in the lists, -- cgit v1.2.3 From 0c8aed845e4a43975974c730d9ecffe60ef8702f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 16 May 2020 03:43:40 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 663cdde8..6fa19988 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v8.37.2 -Fri, 15 May 2020 04:33:46 +0000 +tejr dotfiles v8.38.0 +Fri, 15 May 2020 15:43:40 +0000 -- cgit v1.2.3