Commits

ZyX_I committed a3827e0

@%aurum/record: Added VimLeave event that will restore backups in case record
was not finished

  • Participants
  • Parent commits 1ec7b54

Comments (0)

Files changed (1)

autoload/aurum/record.vim

             \        '@%aurum/lineutils': '0.0',
             \             '@%aurum/edit': '1.0',
             \          '@%aurum/bufvars': '0.0',})
+let s:hasundo=exists('*undotree')
 let s:_options={
             \'recheight': {'default': 0,
             \               'filter': '(if type "" earg _  range 0 inf)'},
                 \     'autowriteall': &autowriteall,
                 \         'autoread': &autoread,}
     setglobal noautowrite noautowriteall noautoread
-    if !bvar.startundo
+    if !s:hasundo
         setglobal undolevels=-1
     endif
     setlocal noreadonly buftype=acwrite
+    augroup AuRecordVimLeave
+        execute 'autocmd! VimLeave * '.
+                    \   ':if has_key(s:_r.bufvars,'.bvar.bufnr.')'.
+                    \   '|  call s:F.unload(s:_r.bufvars.'.bvar.bufnr.')'.
+                    \   '|endif'
+    augroup END
     if empty(bvar.chars)
         bwipeout!
     endif
 endfunction
 "▶1 curundo :: () → UInt
-if exists('*undotree')
+if s:hasundo
     function s:F.curundo()
         return undotree().seq_cur
     endfunction
     endfor
     let a:bvar.prevct=b:changedtick
     let a:bvar.reset=1
-    if a:bvar.startundo
+    if s:hasundo
         let a:bvar.startundo=s:F.curundo()
         let savedundolevels=&undolevels
         setglobal undolevels=-1
             call setbufvar(buf, '&'.opt, optval)
         endfor
     endfor
+    augroup AuRecordVimLeave
+        autocmd!
+    augroup END
 endfunction
 "▶1 getwnrs
 function s:F.getwnrs()
         return
     endif
     if a:action[-2:] is# 'do'
-        if !bvar.startundo
+        if !s:hasundo
             call s:_f.warn('noundo')
             return
         endif