From d0e9d6b498a7a98951e6ad7717ea77d749e30f7c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 May 2020 22:06:46 +1200 Subject: First version, spun out from tejr dotfiles v8.29.1 --- README.md | 14 ++++++++++++++ VERSION | 1 + autoload/undoskip.vim | 20 ++++++++++++++++++++ doc/undoskip.vim | 42 ++++++++++++++++++++++++++++++++++++++++++ plugin/undoskip.vim | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 README.md create mode 100644 VERSION create mode 100644 autoload/undoskip.vim create mode 100644 doc/undoskip.vim create mode 100644 plugin/undoskip.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..f574b05 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +undoskip.vim +============ + +This plugin emulates the `'backupskip'` option's functionality for the +`+persistent_undo` feature, checking buffer file paths against a list of globs, +and switching the `'undofile'` option off locally if any of them match. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/autoload/undoskip.vim b/autoload/undoskip.vim new file mode 100644 index 0000000..8813ff1 --- /dev/null +++ b/autoload/undoskip.vim @@ -0,0 +1,20 @@ +" Internal function returns a local value for 'undofile' +function! undoskip#Check(path) 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 + for glob in g:undoskip + if a:path =~# glob2regpat(glob) + return 0 + endif + endfor + + " Otherwise, we'll use whatever the global setting is + return &g:undofile + +endfunction diff --git a/doc/undoskip.vim b/doc/undoskip.vim new file mode 100644 index 0000000..c0dbbe5 --- /dev/null +++ b/doc/undoskip.vim @@ -0,0 +1,42 @@ +*undoskip.txt* For Vim version 8.0 Last change: 2020 May 5 + +DESCRIPTION *undoskip* + +This plugin emulates the `'backupskip'` option's functionality for the +|+persistent_undo| feature, checking buffer file paths against a list of +globs, and switching the `'undofile'` option off locally if any of them match. + +REQUIREMENTS *undoskip-requirements* + +This plugin only loads if 'compatible' is not set. If requires both the +|+persistent_undo| feature and the |glob2regpat()| function. The earliest +full release of Vim with both of these was v8.0. + +OPTIONS *undoskip-options* + + *g:undoskip* +Set `g:undoskip` to a list of globs to match against file buffer paths and +switch 'undofile' on or off accordingly. Defaults to the same values as +'backupskip' (or tries to). + +Some possibly useful values: +> + let g:undoskip = [ + \ '/tmp/*', + \ '/dev/shm/*', + \ '/usr/tmp/*', + \ '/var/tmp/*', + \ '*.git/*_EDITMSG', + \ '*.git/ADD_EDIT.patch', + \ '*.git/rebase-merge/git-rebase-todo', + \] +< +AUTHOR *undoskip-author* + +Written and maintained by Tom Ryder . + +LICENSE *undoskip-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/undoskip.vim b/plugin/undoskip.vim new file mode 100644 index 0000000..047d9e1 --- /dev/null +++ b/plugin/undoskip.vim @@ -0,0 +1,35 @@ +" +" undoskip.vim: Don't save undo history for temporary or secure files. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('loaded_undoskip') || &compatible + finish +endif +if !has('persistent_undo') || !exists('*glob2regpat') + finish +endif +let loaded_undoskip = 1 + +" Set default list of patterns to exclude; mirror documented 'backupskip' +" behavior +if !exists('g:undoskip') + let g:undoskip = [] + if has('mac') + call add(g:undoskip, '/private/tmp/*') + elseif has('unix') + call add(g:undoskip, '/tmp/*') + endif + call extend(g:undoskip, map( + \ filter([$TMPDIR, $TMP, $TEMP], 'v:val !=# '''''), + \ 'v:val.''/*''' + \)) +endif + +" Check the path on every buffer rename, create, or read +augroup undoskip + autocmd! + autocmd BufAdd,BufNewFile,BufRead * + \ let &l:undofile = undoskip#Check(expand('')) +augroup END -- cgit v1.2.3