Commits

ZyX_I  committed 602de5e

Save information about previous tab and add recautowrite option

  • Participants
  • Parent commits 662d399

Comments (0)

Files changed (3)

File autoload/aurum/record.vim

 "▶1 
 scriptencoding utf-8
-execute frawor#Setup('0.1', {'@/options': '0.0',
+execute frawor#Setup('0.2', {'@/options': '0.0',
             \                     '@/os': '0.0',
             \               '@/mappings': '0.0',
             \              '@/functions': '0.1',
             \             '@%aurum/undo': '0.0',
             \          '@%aurum/bufvars': '0.0',})
 let s:_options={
-            \'recheight': {'default': 0,
-            \               'filter': '(if type "" earg _  range 0 inf)'},
-            \'fullundo':  {'default': 1,
-            \               'filter': 'bool'},
+            \'recheight':    {'default': 0,
+            \                  'filter': '(if type "" earg _  range 0 inf)'},
+            \'fullundo':     {'default': 1,
+            \                  'filter': 'bool'},
+            \'recautowrite': {'default': 1,
+            \                  'filter': 'bool'},
         \}
 let s:_messages={
             \ 'bkpmis': 'Backup file %s not found',
         endif
         execute lwnr.'wincmd w'
         call s:F.edit(a:bvar, 'aurum://edit:'.fullpath, 0)
+        if s:_f.getoption('recautowrite')
+            augroup AuRecordAutowrite
+                autocmd! BufWinLeave,BufLeave <buffer> nested
+                            \ write
+            augroup END
+        endif
         if a:bvar.undo_full
             let ebvar=s:_r.bufvars[bufnr('%')]
             let ebvar.undoleaf=undoleaf
     endif
     return 1
 endfunction
+let s:_augroups+=['AuRecordAutowrite']
 "▶2 sactions.commit
 function s:F.sactions.commit(action, bvar, buf)
     let files=filter(copy(a:bvar.files), 'a:bvar.statuses[v:key]>1')

File autoload/aurum/tabutils.vim

     endif
 endfunction
 "▶1 f.cons.create :: {f}, tabid, botfun, botargs → + vim
+let s:last_prevtabmark=0
+let s:prevtabs={}
 function s:f.cons.create(plugdict, fdict, tabid, botfun, botargs)
     "▶2 Check arguments
     if type(a:tabid)!=type('') || !has_key(a:fdict, a:tabid)
         call s:_f.throw('tabex', a:tabid)
     endif
     let tabspec=a:fdict[a:tabid]
+    if !exists('t:aurum_tabmark')
+        let t:aurum_tabmark=s:last_prevtabmark
+        let s:last_prevtabmark+=1
+    endif
+    let tabmark = t:aurum_tabmark
     tabnew
     setlocal bufhidden=wipe
     let t:aurum_tabid=tabspec.id
                 \{})
     setlocal bufhidden=wipe
     let w:aurum_winid=tabspec.layout.bottom
+    let s:prevtabs[tabspec.id]=tabmark
 endfunction
 "▶1 f.cons.find :: {f}, tabid
 function s:f.cons.find(plugdict, fdict, tabid)
     unlet t:aurum_tabid
     if tabpagenr('$')>1
         tabclose!
+        if has_key(s:prevtabs, tabid)
+            let tabmark=s:prevtabs[tabid]
+            let tabnr=index(map(range(1, tabpagenr('$')),
+                        \       'gettabvar(v:val, "aurum_tabmark")'), tabmark)+1
+            if tabnr
+                execute 'tabnext' tabnr
+            endif
+        endif
     else
         let wlist=range(1, winnr('$'))
         while !empty(wlist)
             endfor
         endwhile
     endif
+    if has_key(s:prevtabs, tabid)
+        unlet s:prevtabs[tabid]
+    endif
     return 1
 endfunction
 "▶1 f.unloadpre :: {f}
 "▶1 Post resource
 call s:_f.newfeature('tab', s:f)
 "▶1
-call frawor#Lockvar(s:, 'tabs')
+call frawor#Lockvar(s:, 'tabs,prevtabs,last_prevtabmark')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File doc/aurum.txt

     Default: winheight/5 (in empty tab |winheight()| will return roughly the 
              same value as 'lines').
 
+recautowrite                                            *g:aurum_recautowrite*
+    Boolean. Determines whether files opened for editing should be 
+    automatically written on |BufWinLeave| and |BufLeave| events.
+    See |aurum-m-AuRecord_Edit|.
+    Default: 1.
+
 fullundo                                                    *g:aurum_fullundo*
     Boolean. Determines whether full undo tree should be kept for status 
     window. With this option you will be able to undo changes done while using 
     0.2: Added optional argument to _r.maputils.getnthparentfile().
 @%aurum/record:
     0.1: Added |:AuRecord| amend.
+    0.2: Officially added |g:aurum_fullundo|, added |g:aurum_recautowrite|.
 
 vim: ft=help:tw=78