aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-05-16 03:43:41 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-05-16 03:43:41 +1200
commitba9ea13e821538309c8979a1a322d97bfde45244 (patch)
treec39b07efc6e7893172d5c01d800468cc1c4d9269
parentMerge branch 'hotfix/v8.37.2' (diff)
parentBump VERSION (diff)
downloaddotfiles-ba9ea13e821538309c8979a1a322d97bfde45244.tar.gz
dotfiles-ba9ea13e821538309c8979a1a322d97bfde45244.zip
Merge branch 'release/v8.38.0'v8.38.0
* release/v8.38.0: Update updated date in vimrc Correct some poor writing Bail from Vim if &runtimepath is empty Write out over-engineered path creation function Switch XDG semantics to functions not global var Simplify Vim XDG subdir definition Use $HOME not tildes for XDG basedir defaults Add an issue with syntax highlighting Add an issue
-rw-r--r--ISSUES.md2
-rw-r--r--VERSION4
-rw-r--r--vim/after/plugin/spellfile_local.vim8
-rw-r--r--vim/autoload/path.vim14
-rw-r--r--vim/autoload/xdg.vim44
-rw-r--r--vim/vimrc154
6 files changed, 97 insertions, 129 deletions
diff --git a/ISSUES.md b/ISSUES.md
index 692bdb55..6fd39517 100644
--- a/ISSUES.md
+++ b/ISSUES.md
@@ -31,3 +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.
+* Highlighting the variable name in e.g. `unset -v VARNAME` works with `bash`
+ highlighting, but not with `sh` highlighting
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
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/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/autoload/xdg.vim b/vim/autoload/xdg.vim
index 5cef0f98..c5737506 100644
--- a/vim/autoload/xdg.vim
+++ b/vim/autoload/xdg.vim
@@ -1,14 +1,12 @@
" <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables>
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',
\}
-let s:subdir = 'vim'
-
function! s:Get(name) abort
let name = a:name
if !has_key(s:defaults, name)
@@ -31,27 +29,33 @@ 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
-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..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,
@@ -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:
@@ -130,9 +131,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,39 +146,23 @@ 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
-" 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(<q-args>), <q-bang> ==# '!')
-
-" 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
@@ -190,9 +173,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 +225,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 +265,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
@@ -298,25 +281,21 @@ 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.
"
-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 +303,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 +429,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.
@@ -1381,8 +1358,7 @@ nnoremap <Leader>D
\ :PutDate!<CR>
" 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 <Leader>g
@@ -1392,7 +1368,7 @@ nnoremap <Leader>G
\ :<C-U>cd %:h<Bar>pwd<CR>
"" Leader,P creates the path to the current file if it doesn’t exist
nnoremap <Leader>P
- \ :<C-U>CreatePath %:h<CR>
+ \ :<C-U>call mkdir(expand('%:h'), 'p')<CR>
" This group contains mappings that show information about Vim’s internals:
" marks, registers, variables, and the like.