Source

aurum / autoload / aurum / record.vim

Diff from to

autoload/aurum/record.vim

             \               'filter': 'bool'},
         \}
 let s:_messages={
-            \  'recex': 'There is already one AuRecord tab active '.
-            \           '(found tab with t:aurum_tabid set to "AuRecordTab")',
             \ 'bkpmis': 'Backup file %s not found',
             \'delfail': 'Failed to remove file %s',
             \'renfail': 'Failed to move file %s to %s',
     endif
     return height
 endfunction
+"▶1 run
+function s:F.run(cmd, opts, files, container)
+    let files=copy(a:files)
+    if !empty(files) && a:opts.repo is# ':'
+        let repo=s:_r.cmdutils.checkedgetrepo(s:_r.os.path.dirname(files[0]))
+    else
+        let repo=s:_r.cmdutils.checkedgetrepo(a:opts.repo)
+    endif
+    if get(a:opts, 'amend', 0)
+        let state=s:F.genstate(repo)
+        call repo.functions.strip(repo)
+    else
+        let state=0
+    endif
+    call map(files, 'repo.functions.reltorepo(repo, v:val)')
+    let sopts={'record': 1}
+    if !empty(files)
+        let sopts.files=files
+    endif
+    call s:_r.run(a:cmd, 'status', repo, sopts)
+    setlocal nomodifiable
+    call s:_f.mapgroup.map('AuRecord', bufnr('%'))
+    call extend(a:container, [state, repo])
+endfunction
 "▶1 recfunc
 " TODO investigate why closing record tab is causing next character consumption
 "      under wine
 let s:_aufunctions.comp=s:_r.cmdutils.gencompfunc(s:_aufunctions.cmd['@FWC'][0],
             \                                     [], s:_f.fwc.compile)
 function s:_aufunctions.cmd.function(opts, ...)
-    if !empty(filter(range(1, tabpagenr('$')),
-                \    'gettabvar(v:val, "aurum_tabid") is# "AuRecordTab"'))
-        call s:_f.throw('recex')
-    endif
-    let files=copy(a:000)
-    if !empty(files) && a:opts.repo is# ':'
-        let repo=s:_r.cmdutils.checkedgetrepo(s:_r.os.path.dirname(files[0]))
-    else
-        let repo=s:_r.cmdutils.checkedgetrepo(a:opts.repo)
-    endif
-    if get(a:opts, 'amend', 0)
-        let state=s:F.genstate(repo)
-        call repo.functions.strip(repo)
-    endif
-    call map(files, 'repo.functions.reltorepo(repo, v:val)')
-    let sopts={'record': 1}
-    if !empty(files)
-        let sopts.files=files
-    endif
-    call s:_f.tab.create(s:layoutname, s:_r.run, ['status', repo, sopts])
-    setlocal nomodifiable
-    call s:_f.mapgroup.map('AuRecord', bufnr('%'))
+    let container=[]
+    call s:_f.tab.create(s:layoutname, s:F.run, [a:opts, a:000, container])
+    let [state, repo]=container
     let bvar=s:_r.bufvars[bufnr('%')]
     " 0: not included, unmodified
     " 1: not included,   modified
     if empty(bvar.chars)
         bwipeout!
     endif
-    if get(a:opts, 'amend', 0)
+    if !empty(state)
         call s:F.setstate(repo, bvar, state)
     endif
 endfunction
     if bufexists(sbvar.bufnr)
         call setbufvar(sbvar.bufnr, '&modified', 0)
     endif
-    if exists('t:aurum_tabid') && t:aurum_tabid is# 'AuRecordTab'
-        unlet t:aurum_tabid
-        if tabpagenr('$')>1
-            tabclose!
-        else
-            let wlist=range(1, winnr('$'))
-            while !empty(wlist)
-                for wnr in wlist
-                    call remove(wlist, 0)
-                    if getwinvar(wnr, 'aurum_winid')[:7] is# 'AuRecord'
-                        execute wnr.'wincmd w'
-                        close!
-                        let wlist=range(1, winnr('$'))
-                        break
-                    endif
-                endfor
-            endwhile
+    "▶2 Close tab
+    try
+        silent call s:_f.tab.close()
+    catch /\V\^Frawor:\[^:]\+:tidukn:/
+        if s:_f.tab.find(s:layoutname)
+            try
+                call s:_f.tab.close()
+            catch /\V\^Frawor:\[^:]\+:tidukn:/
+            endtry
         endif
-    else
-        return
-    endif
+    endtry
+    "▲2
     let backupfiles=copy(sbvar.backupfiles)
     let newfiles=copy(sbvar.newfiles)
     call filter(backupfiles, 'filereadable(v:key)')
 endfunction
 "▶1 getwnrs
 function s:F.getwnrs()
-    return s:_f.tab.getwnrs(s:layoutname)
+    return s:_f.tab.getwnrs()
 endfunction
-"▶1 register layout
+"▶1 register tab
 let s:layoutname='AuRecordTab'
 call s:_f.tab.new(s:layoutname, {
             \   'top': ['AuRecordLeft', 'AuRecordRight'],