diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-04 10:51:26 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-04 10:51:26 +1200 |
commit | 6f4a8288d4c5950ae4423dd1403e8536a447fafc (patch) | |
tree | b43e717dac36d91ad9b3b28a863dc3f9afb021a9 /vim | |
parent | Working on rewording vimrc (diff) | |
parent | Merge branch 'hotfix/v8.28.2' into develop (diff) | |
download | dotfiles-6f4a8288d4c5950ae4423dd1403e8536a447fafc.tar.gz dotfiles-6f4a8288d4c5950ae4423dd1403e8536a447fafc.zip |
Merge branch 'develop' into feature/vimrc-edit
* develop:
Use global variable not autoload for undoskip.vim
Test for correct feature for undoskip.vim plugin
Flesh out new undoskip.vim plugin a lot
Add plugin undoskip.vim; switch 'undofile' on path
Update dotfiles(7) manual page
Reflow features list
Remove spaces around em-dashes
Many README.md improvements in phrasing or grammar
Order sub-targets of `install` correctly
Update PGP key
Update dotfiles(7) manual page
Reformat paragraphs in README.md
Remove outdated description of GnuPG config gen
Update documentation of personal mail paths
Add comment to installation dry run command
Suggest creation of recommended path in docs
Update recommended path in documentation
Copy, don't reference XDG basedir lists
Write v:null back out of XDG routines
Remove trailing slashes from default XDG basedir
Update PGP key fingerprint
Use a dash rather than a three-period ellipsis
Tighten :try block around 'dictionary'/'thesaurus'
Factor out iteration variables with some maps
Test dir lists for emptiness to avoid force :unlet
Use v:null in XDG-related contexts
Add handling of "after" subdirs in Vim XDG config
Separate cache runtime behaviour from config
Tolerate unset iteration variables
Improve "absolute path" check for XDG base dirs
Tidy and correct XDG var getenv() fallback
Force unwanted --quoting-style option to ls(1) off
Bump updated date for vimrc
Diffstat (limited to 'vim')
-rw-r--r-- | vim/autoload/getenv.vim | 17 | ||||
-rw-r--r-- | vim/autoload/xdg.vim | 23 | ||||
-rw-r--r-- | vim/plugin/undoskip.vim | 46 | ||||
-rw-r--r-- | vim/vimrc | 70 |
4 files changed, 114 insertions, 42 deletions
diff --git a/vim/autoload/getenv.vim b/vim/autoload/getenv.vim new file mode 100644 index 00000000..3b5f4c1b --- /dev/null +++ b/vim/autoload/getenv.vim @@ -0,0 +1,17 @@ +" Backport getenv() from v8.1.1305, except return an empty string rather than +" v:null +" +" <https://github.com/vim/vim/releases/tag/v8.1.1305> +" +function! getenv#(name) abort + + if a:name !~# '^[A-Z][A-Z0-9_]*$' + throw 'Illegal env var name' + endif + let value = '' + 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..dd9a129b 100644 --- a/vim/autoload/xdg.vim +++ b/vim/autoload/xdg.vim @@ -4,29 +4,26 @@ let s:defaults = { \ 'XDG_CONFIG_HOME': '~/.config', \ 'XDG_CONFIG_DIRS': '/etc/xdg', \ 'XDG_DATA_HOME': '~/.local/share', - \ 'XDG_DATA_DIRS': '/usr/local/share/:/usr/share/', + \ 'XDG_DATA_DIRS': '/usr/local/share:/usr/share', \} 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 !=# '' + \ ? value + \ : s:defaults[name] endfunction function! s:Absolute(path) abort - return a:path =~# '^[/~]' + return a:path =~# '^/' + \ || a:path =~# '^\~/' + \ || a:path ==# '~' endfunction function! s:Home(name) abort diff --git a/vim/plugin/undoskip.vim b/vim/plugin/undoskip.vim new file mode 100644 index 00000000..ffbabf86 --- /dev/null +++ b/vim/plugin/undoskip.vim @@ -0,0 +1,46 @@ +" +" undoskip.vim: Don't save undo history for temporary or secure files. +" +" Author: Tom Ryder <tom@sanctum.geek.nz> +" License: Same as Vim itself +" +if exists('loaded_undoskip') || &compatible || !has('persistent_undo') + finish +endif +let loaded_undoskip = 1 + +" Set the paths to test; can be changed by the user +let g:undoskip_patterns = ['^/dev/shm/.', '^/tmp/.', '^/var/tmp/.'] + +" Internal function returns a local value for 'undofile' +function s:CheckUndoSkip() abort + + " If this isn't a normal buffer, don't save undo data + if &buftype !=# '' + return 0 + endif + + " Get the path from the buffer name; if that path matches any of the + " patterns, don't save undo data + let path = bufname('%') + for pattern in g:undoskip_patterns + if path =~# pattern + return 0 + endif + endfor + + " Otherwise, we'll use whatever the global setting is + return &g:undofile + +endfunction + +" Command interface into the private function's value, does the actual set +command -nargs=0 CheckUndoSkip + \ let &l:undofile = s:CheckUndoSkip() + +" Check the path on every buffer rename, create, or read +augroup undoskip + autocmd! + autocmd BufAdd,BufNewFile,BufRead * + \ CheckUndoSkip +augroup END @@ -2,7 +2,7 @@ " Tom Ryder (tejr)’s Literate Vimrc " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ " -" Last updated: Wed, 29 Apr 2020 23:52:08 UTC +" Last updated: Sun, 03 May 2020 22:50:34 UTC " " │ And I was lifted up in heart, and thought " │ Of all my late-shown prowess in the lists, @@ -108,22 +108,32 @@ endif " " <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables> " -" 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', including "after" +" directories to the end of it, in reverse order, forming the desired layers +" of configuration. " -let s:xdgruntimepaths = xdg#['config']['dirs'] +let s:xdgconfigpaths = copy(xdg#['config']['dirs']) if xdg#['config']['home'] !=# '' - call insert(s:xdgruntimepaths, xdg#['config']['home']) + call insert(s:xdgconfigpaths, xdg#['config']['home']) endif +if !empty(s:xdgconfigpaths) + execute 'set runtimepath^='.option#Escape(join(map( + \ s:xdgconfigpaths, 'option#item#Escape(v:val)' + \), ',')) + execute 'set runtimepath+='.option#Escape(join(map( + \ reverse(s:xdgconfigpaths), 'option#item#Escape(v:val."/after")' + \), ',')) +endif +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'] !=# '' - call insert(s:xdgruntimepaths, xdg#['cache']['home']) + execute 'set runtimepath^='.option#Escape( + \ option#item#Escape(xdg#['cache']['home']) + \) endif -for s:xdgruntimepath in reverse(s:xdgruntimepaths) - execute 'set runtimepath^=' - \.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 @@ -405,20 +415,22 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) " 'isfname'; the blacklist is hard-coded. " set dictionary^=/usr/share/dict/words -try - 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 - unlet s:refdirs s:refdir -catch /^Vim\%((\a\+)\)\=:E474:/ -endtry +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( + \ s:refdirs, 'option#item#Escape(v:val."/dictionary.txt")' + \), ',')) + execute 'set thesaurus^='.option#Escape(join(map( + \ s:refdirs, 'option#item#Escape(v:val."/thesaurus.txt")' + \), ',')) + catch /^Vim\%((\a\+)\)\=:E474:/ + endtry +endif +unlet s:refdirs " Next, we’ll modernize a little in adjusting some options with old " language-specific defaults. @@ -917,9 +929,9 @@ endif " almost always stands out too much for my liking. " " You’d think the pattern here could be used to match the color scheme name, -" and it can be...after patch v7.4.108, when Christian Brabandt fixed it. -" Until that version, it matched against the current buffer name, so we’re -" forced to have an explicit test in the command instead. +" and it can be—after patch v7.4.108, when Christian Brabandt fixed it. Until +" that version, it matched against the current buffer name, so we’re forced to +" have an explicit test in the command instead. " " <https://github.com/vim/vim/releases/tag/v7.4.108> " |