aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-05-03 23:44:46 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-05-03 23:44:46 +1200
commit2d777cc6902330b31e95955a011a1fd7066adc59 (patch)
treee4907a6a1da36d9d9ca0126a485efb677ac4703d
parentMerge branch 'release/v8.27.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-2d777cc6902330b31e95955a011a1fd7066adc59.tar.gz
dotfiles-2d777cc6902330b31e95955a011a1fd7066adc59.zip
Merge branch 'release/v8.28.0'v8.28.0
* release/v8.28.0: Flesh out new undoskip.vim plugin a lot Add plugin undoskip.vim; switch 'undofile' on path
-rw-r--r--VERSION4
-rw-r--r--vim/plugin/undoskip.vim46
2 files changed, 48 insertions, 2 deletions
diff --git a/VERSION b/VERSION
index 31dbc5f6..3ae41974 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v8.27.0
-Sun, 03 May 2020 10:39:52 +0000
+tejr dotfiles v8.28.0
+Sun, 03 May 2020 11:44:44 +0000
diff --git a/vim/plugin/undoskip.vim b/vim/plugin/undoskip.vim
new file mode 100644
index 00000000..80609433
--- /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 || v:version < 700
+ finish
+endif
+let loaded_undoskip = 1
+
+" Set the paths to test; can be changed by the user
+let 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