From b758c1000aa81a146633112bdf8a54e8f5efbbc9 Mon Sep 17 00:00:00 2001 From: sev Date: Fri, 6 Dec 2024 16:49:39 -0600 Subject: [PATCH] vim: update vim-suda and supporting framework - vim-suda was updated to remove `setlocal backup`, so the rc no longer handles that option. (#85) - didn't notice at the time but even if undofile is set during :read or enabled after, the buffer's undo stack is not updated, so expand the undofile save to also read the undofile when loading suda:// buffers. --- etc/vim/.vimrc | 26 ++++++++++++++++---------- etc/vim/pack/vim-suda/start/vim-suda | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/etc/vim/.vimrc b/etc/vim/.vimrc index 5e027bd..0b9bcd9 100644 --- a/etc/vim/.vimrc +++ b/etc/vim/.vimrc @@ -184,26 +184,31 @@ 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 b:sev_suda_backup = &backup 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('b:sev_suda_backup') && b: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 - endif if exists('b:sev_suda_swapfile') && b:sev_suda_swapfile - setlocal 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('b:sev_suda_undofile') && b:sev_suda_undofile setlocal undofile endif endif endfunction -function s:SudaWriteUndo() +function s:SudaProcessUndo(cmd) let p = expand('')[7:] if has('win32') || !&undofile || !filereadable(p) return @@ -252,7 +257,7 @@ function s:SudaWriteUndo() continue endif try - execute printf('wundo! %s/%s', fnameescape(d), fnameescape(f)) + execute printf('%s %s/%s', a:cmd, fnameescape(d), fnameescape(f)) break catch continue @@ -261,4 +266,5 @@ function s:SudaWriteUndo() endfunction autocmd BufReadPre suda://* call s:SudaSettingsSave() autocmd BufReadPost suda://* call s:SudaSettingsRestore() -autocmd BufWritePost suda://* call s:SudaWriteUndo() +autocmd BufReadPost suda://* call s:SudaProcessUndo('silent! rundo') +autocmd BufWritePost suda://* call s:SudaProcessUndo('wundo!') diff --git a/etc/vim/pack/vim-suda/start/vim-suda b/etc/vim/pack/vim-suda/start/vim-suda index b97fab5..e333169 160000 --- a/etc/vim/pack/vim-suda/start/vim-suda +++ b/etc/vim/pack/vim-suda/start/vim-suda @@ -1 +1 @@ -Subproject commit b97fab52f9cdeabe2bbb5eb98d82356899f30829 +Subproject commit e333169211b84d6f4012ac9e40bcbbf370b74289 -- 2.48.1