+" re-enable backup, swap, undo for suda buffers that we can read
+" https://github.com/lambdalisue/vim-suda/issues/25
+function s:SudaSettingsSave()
+ let l:f = expand('<afile>')
+ if stridx(l:f, 'suda://') == 0
+ let g:sev_suda_file = expand('<afile>')
+ let g:sev_suda_backup = &backup
+ let g:sev_suda_swapfile = &swapfile
+ let g:sev_suda_undofile = &undofile
+ endif
+endfunction
+function s:SudaSettingsRestore()
+ if exists('g:sev_suda_file') && filereadable(g:sev_suda_file)
+ if exists('g:sev_suda_backup') && g:sev_suda_backup
+ " XXX: suda.vim uses setlocal for this, even though it's global...
+ setlocal backup
+ endif
+ if exists('g:sev_suda_swapfile') && g:sev_suda_swapfile
+ setlocal swapfile
+ endif
+ if exists('g:sev_suda_undofile') && g:sev_suda_undofile
+ setlocal undofile
+ endif
+ endif
+endfunction
+autocmd BufReadPre * call s:SudaSettingsSave()
+autocmd BufReadPost suda://* call s:SudaSettingsRestore()