" 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('<afile>')[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('<afile>')[7:]
if has('win32') || !&undofile || !filereadable(p)
return
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
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!')