X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/8aac59d62a252503085ff488f59fe1090ad7b3d7..d2204ed1a0eb3ea915d866ba10b7e36481774f9f:/etc/vim/.vimrc?ds=sidebyside diff --git a/etc/vim/.vimrc b/etc/vim/.vimrc index 9e1a6cd..0b9bcd9 100644 --- a/etc/vim/.vimrc +++ b/etc/vim/.vimrc @@ -184,24 +184,87 @@ endif " re-enable backup, swap, undo for suda buffers that we can read " https://github.com/lambdalisue/vim-suda/issues/25 function s:SudaSettingsSave() - let g:sev_suda_backup = &backup - let g:sev_suda_swapfile = &swapfile - let g:sev_suda_undofile = &undofile + let b:sev_suda_swapfile = &swapfile + let b:sev_suda_undofile = &undofile + " fix https://github.com/lambdalisue/vim-suda/issues/87 + setlocal noswapfile endfunction function s:SudaSettingsRestore() if filereadable(expand('')[7:]) - if exists('g:sev_suda_backup') && g:sev_suda_backup - " XXX: suda.vim uses setlocal for this, even though it's global... - " https://github.com/lambdalisue/vim-suda/issues/85 - setlocal backup + if exists('b:sev_suda_swapfile') && b:sev_suda_swapfile + try + setlocal swapfile + catch + " ignore swapfile errors, they should have been shown already + echohl ErrorMsg + for line in split(v:exception, '\n') + echomsg printf('[suda] %s', line) + endfor + echohl None + endtry endif - if exists('g:sev_suda_swapfile') && g:sev_suda_swapfile - setlocal swapfile - endif - if exists('g:sev_suda_undofile') && g:sev_suda_undofile + if exists('b:sev_suda_undofile') && b:sev_suda_undofile setlocal undofile endif endif endfunction +function s:SudaProcessUndo(cmd) + let p = expand('')[7:] + if has('win32') || !&undofile || !filereadable(p) + return + endif + let p = resolve(p) + " XXX: comments are from :help backupdir to mark implementation details + let x = &undodir + " For backwards compatibility with Vim version 3.0 a '>' at the start + " of the option is removed. + if stridx(x, '>') == 0 + let x = x[1:] + endif + " To include a comma in a directory name precede it with a backslash. + for u in split(x, '\v\\@1