diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-03 23:44:09 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-03 23:44:09 +1200 |
commit | 7e0e503fb431a90b61ff66b7b6cbd7a8d49a4e58 (patch) | |
tree | 4cfcb93db0769c6674882fb855e4ad0a58bc23c8 | |
parent | Add plugin undoskip.vim; switch 'undofile' on path (diff) | |
download | dotfiles-7e0e503fb431a90b61ff66b7b6cbd7a8d49a4e58.tar.gz dotfiles-7e0e503fb431a90b61ff66b7b6cbd7a8d49a4e58.zip |
Flesh out new undoskip.vim plugin a lot
-rw-r--r-- | vim/plugin/undoskip.vim | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/vim/plugin/undoskip.vim b/vim/plugin/undoskip.vim index d3ebcca2..80609433 100644 --- a/vim/plugin/undoskip.vim +++ b/vim/plugin/undoskip.vim @@ -1,10 +1,46 @@ -" Don't save undo history for temporary or secure files +" +" 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 - \ * - \ setlocal undofile< - autocmd BufAdd,BufNewFile,BufRead - \ /dev/shm/*,/tmp/*,/var/tmp/* - \ setlocal noundofile + autocmd BufAdd,BufNewFile,BufRead * + \ CheckUndoSkip augroup END |