Commits

ZyX_I committed e4b59af

@%aurum/vimdiff: Switch to previous buffers before wiping vimdiff buffers out
@%aurum/status: Use only mrun(), not run()

Fixes #65 (it allows exiting vimdiff with X on aurum://file buffer with all
buffers switched back: by X mapping of aurum://file and by
aurum://file BufWipeOut event handler set by vimdiff.split)

Comments (0)

Files changed (2)

autoload/aurum/vimdiff.vim

 "▶1 diffrestore
 let s:F.diffrestore={}
 "▶2 diffrestore.onotherenter
-function s:F.diffrestore.onotherenter(buf, abuf, dbvar, ddbvars)
+function s:F.diffrestore.onotherenter(buf, abuf, dbvar, ddbvars, prevbuffers)
     if has_key(a:dbvar, 'bufnr')
         if bufexists(a:dbvar.bufnr)
             return
         else
-            call s:F.diffrestore.onwipe(a:buf, a:abuf, a:dbvar, a:ddbvars)
+            call s:F.diffrestore.onwipe(a:buf, a:abuf, a:dbvar, a:ddbvars,
+                        \               a:prevbuffers)
         endif
     endif
     let ddbvar=remove(a:ddbvars, a:abuf)
     return s:F.restore(a:ddbvars[a:abuf])
 endfunction
 "▶2 diffrestore.onenter
-function s:F.diffrestore.onenter(buf, abuf, dbvar, ddbvars)
+function s:F.diffrestore.onenter(buf, abuf, dbvar, ddbvars, prevbuffers)
     if !empty(filter(copy(a:dbvar.diffbufs), 'bufwinnr(v:val)!=-1'))
         return
     endif
     return s:F.restore(a:dbvar)
 endfunction
 "▶2 diffrestore.onotherwipe
-function s:F.diffrestore.onotherwipe(buf, abuf, dbvar, ddbvars)
+function s:F.diffrestore.onotherwipe(buf, abuf, dbvar, ddbvars, prevbuffers)
     call filter(a:dbvar.diffbufs, 'v:val isnot '.a:abuf)
     unlet a:ddbvars[a:abuf]
 endfunction
 "▶2 diffrestore.onwipe
-function s:F.diffrestore.onwipe(buf, abuf, dbvar, ddbvars)
+function s:F.diffrestore.onwipe(buf, abuf, dbvar, ddbvars, prevbuffers)
     call map(copy(a:ddbvars), 'remove(v:val, "srcbuf")')
     let toremove=keys(filter(copy(a:ddbvars),
                 \            '!v:val.existed && bufexists(v:val.bufnr)'))
     if !empty(toremove)
-        call feedkeys("\<C-\>\<C-n>:silent bwipeout ".join(toremove)."\n\<C-l>",
-                    \ 'n')
+        let cmd="\<C-\>\<C-n>:"
+        for buf in filter(toremove, 'bufwinnr(+v:val)!=-1 && '.
+                    \               'get(a:prevbuffers, v:val, 0)')
+            let cmd.=bufwinnr(+buf).'wincmd w|'.
+                        \'silent buffer '.a:prevbuffers[buf].'|'.
+                        \'wincmd p|'
+        endfor
+        let cmd.=    'try|'.
+                    \   'silent bwipeout '.join(toremove).'|'.
+                    \'catch /Vim(bwipeout):E517:/|'.
+                    \'endtry'.
+                    \"\n\<C-l>"
+        call feedkeys(cmd, 'n')
     endif
 endfunction
 "▶2 diffrestore.call
     endif
     let dbvar=t:auvimdiff_origbufvar
     let ddbvars=t:auvimdiff_diffbufvars
-    return s:F.diffrestore[a:func](a:buf, +expand('<abuf>'), dbvar, ddbvars)
+    let prevbuffers=t:auvimdiff_prevbuffers
+    return s:F.diffrestore[a:func](a:buf, +expand('<abuf>'), dbvar, ddbvars,
+                \                  prevbuffers)
 endfunction
 "▶1 findwindow
 function s:F.findwindow()

ftplugin/aurumstatus.vim

         endif
         if get(bvar.opts, 'record', 0)
             if exists('file2')
-                execute 'silent view' fnameescape(file2)
+                execute 'silent edit' fnameescape(file2)
             else
-                call call(s:_r.mrun, ['silent view']+fargs2, {})
+                call call(s:_r.mrun, ['silent edit']+fargs2, {})
             endif
             diffthis
             execute rwnr.'wincmd w'
-            call call(s:_r.mrun, ['silent view']+fargs1, {})
+            call call(s:_r.mrun, ['silent edit']+fargs1, {})
             diffthis
             wincmd p
         else
             if exists('file2')
                 execute 'silent edit' fnameescape(file2)
             else
-                call call(s:_r.run, ['silent view']+fargs2, {})
+                call call(s:_r.mrun, ['silent edit']+fargs2, {})
             endif
             call s:_r.vimdiff.split([fargs1], -1)
         endif