Commits

ZyX_I committed a8c64ac

Moved some functions from @%aurum/record to @%aurum/tabutils

Comments (0)

Files changed (4)

aurum-addon-info.txt

         "autoload/aurum/record.vim",
         "autoload/aurum/repo.vim",
         "autoload/aurum/status.vim",
+        "autoload/aurum/tabutils.vim",
         "autoload/aurum/track.vim",
         "autoload/aurum/update.vim",
         "autoload/aurum/vimdiff.vim",

autoload/aurum/record.vim

             \            '@%aurum/cache': '2.4',
             \           '@%aurum/commit': '1.3',
             \         '@%aurum/cmdutils': '4.3',
+            \         '@%aurum/tabutils': '0.0',
             \        '@%aurum/lineutils': '0.0',
             \             '@%aurum/edit': '1.5',
             \          '@%aurum/bufvars': '0.0',})
         \}
 let s:_messages={
             \  'recex': 'There is already one AuRecord tab active '.
-            \           '(found tab with t:aurecid set to "AuRecordTab")',
+            \           '(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',
     setlocal nomodifiable
     call cursor(1, 1)
 endfunction
+"▶1 getswheight
+function s:F.getswheight()
+    let height=s:_f.getoption('recheight')
+    if height<=0
+        return winheight(0)/5
+    endif
+    return height
+endfunction
 "▶1 recfunc
 " TODO investigate why closing record tab is causing next character consumption
 "      under wine
             \                                     [], s:_f.fwc.compile)
 function s:_aufunctions.cmd.function(opts, ...)
     if !empty(filter(range(1, tabpagenr('$')),
-                \    'gettabvar(v:val, "aurecid") is# "AuRecordTab"'))
+                \    'gettabvar(v:val, "aurum_tabid") is# "AuRecordTab"'))
         call s:_f.throw('recex')
     endif
     let files=copy(a:000)
     call map(files, 'repo.functions.reltorepo(repo, v:val)')
     tabnew
     setlocal bufhidden=wipe
-    let t:aurecid='AuRecordTab'
-    let w:aurecid='AuRecordLeft'
-    rightbelow vsplit
-    let w:aurecid='AuRecordRight'
+    let t:aurum_tabid='AuRecordTab'
+    call s:_r.tabutils.settoplayout(s:layout)
     let sopts={'record': 1}
     if !empty(files)
         let sopts.files=files
     endif
-    let height=s:_f.getoption('recheight')
-    if height<=0
-        let height=winheight(0)/5
-    endif
-    call s:_r.run('silent botright '.height.'split', 'status', repo, sopts)
+    call s:_r.run('silent botright '.s:F.getswheight().'split', 'status',
+                \ repo, sopts)
     setlocal bufhidden=wipe
-    let w:aurecid='AuRecordStatus'
+    let w:aurum_winid='AuRecordStatus'
     setlocal nomodifiable
     call s:_f.mapgroup.map('AuRecord', bufnr('%'))
     let bvar=s:_r.bufvars[bufnr('%')]
     let bvar.filesbackup={}
     let bvar.newfiles={}
     let bvar.lines=map(copy(bvar.chars), 'v:val." ".bvar.files[v:key]')
-    let bvar.swheight=height
     let bvar.startundo=s:F.curundo()
     let bvar.recopts=extend(copy(a:opts), {'repo': repo})
     let bvar.bufnr=bufnr('%')
     if bufexists(sbvar.bufnr)
         call setbufvar(sbvar.bufnr, '&modified', 0)
     endif
-    if exists('t:aurecid') && t:aurecid is# 'AuRecordTab'
-        unlet t:aurecid
+    if exists('t:aurum_tabid') && t:aurum_tabid is# 'AuRecordTab'
+        unlet t:aurum_tabid
         if tabpagenr('$')>1
             tabclose!
         else
             while !empty(wlist)
                 for wnr in wlist
                     call remove(wlist, 0)
-                    if !empty(getwinvar(wnr, 'aurecid'))
+                    if getwinvar(wnr, 'aurum_winid')[:7] is# 'AuRecord'
                         execute wnr.'wincmd w'
                         close!
                         let wlist=range(1, winnr('$'))
     augroup END
 endfunction
 "▶1 getwnrs
+let s:layout={
+            \   'top': ['AuRecordLeft', 'AuRecordRight'],
+            \'bottom': 'AuRecordStatus',
+            \'bottomheightfun': s:F.getswheight,
+        \}
 function s:F.getwnrs()
-    let lwnr=0
-    let rwnr=0
-    let swnr=0
-    for wnr in range(1, winnr('$'))
-        let wid=getwinvar(wnr, 'aurecid')
-        if wid is# 'AuRecordLeft'
-            let lwnr=wnr
-        elseif wid is# 'AuRecordRight'
-            let rwnr=wnr
-        elseif wid is# 'AuRecordStatus'
-            let swnr=wnr
-        endif
-    endfor
-    if lwnr is 0 || rwnr is 0
-        execute swnr.'wincmd w'
-        let bvar=s:_r.bufvars[bufnr('%')]
-        if winnr('$')>1
-            only!
-        endif
-        topleft new
-        setlocal bufhidden=wipe
-        let w:aurecid='AuRecordLeft'
-        let lwnr=winnr()
-        rightbelow vnew
-        setlocal bufhidden=wipe
-        let w:aurecid='AuRecordRight'
-        let rwnr=winnr()
-        wincmd j
-        let swnr=winnr()
-        execute 'resize' bvar.swheight
-    endif
-    return [lwnr, rwnr, swnr]
+    return s:_r.tabutils.getwnrs(s:layout)
 endfunction
 "▶1 edit
 let s:savedopts=['readonly', 'modifiable', 'scrollbind', 'cursorbind',
     else
         setlocal noreadonly   modifiable
     endif
-    if getwinvar(0, 'aurecid') is# 'AuRecordLeft'
+    if getwinvar(0, 'aurum_winid') is# 'AuRecordLeft'
         call s:_f.mapgroup.map('AuRecordLeft', bufnr('%'))
     endif
 endfunction
     endif
     let sbvar=a:bvar.sbvar
     execute 'silent botright sbuffer' sbuf
-    execute 'resize' sbvar.swheight
+    execute 'resize' s:F.getswheight()
     call winrestview(a:bvar.winview)
     redraw!
-    let w:aurecid='AuRecordStatus'
+    let w:aurum_winid='AuRecordStatus'
     setlocal bufhidden=wipe
     return 1
 endfunction
     endtry
     if r
         call s:F.unload(a:bvar)
-    else
-        let w:aurecid='AuRecordCommitMessage'
     endif
     return 0
 endfunction

autoload/aurum/tabutils.vim

+"▶1 
+scriptencoding utf-8
+execute frawor#Setup('0.0', {'@/resources': '0.0',})
+let s:r={}
+"▶1 getids
+function s:F.getids(layout)
+    return a:layout.top + [a:layout.bottom]
+endfunction
+"▶1 settoplayout
+function s:r.settoplayout(layout)
+    let w:aurum_winid=a:layout.top[0]
+    for id in a:layout.top[1:]
+        rightbelow vnew
+        setlocal bufhidden=wipe
+        let w:aurum_winid=id
+    endfor
+endfunction
+"▶1 getwinnrs
+function s:F.getwinnrs(ids)
+    let curids={}
+    call map(filter(map(range(1, winnr('$')),
+                \'[getwinvar(v:val, "aurum_winid"), v:key+1]'),
+                \'!empty(v:val[0])'),
+                \'extend(curids, {v:val[0]: v:val[1]})')
+    return map(copy(a:ids), 'get(curids, v:val, 0)')
+endfunction
+"▶1 r.getwnrs
+" layout: {
+"   "top": [id],
+"   "bottom": id,
+"   "bottomheightfun": () → N,
+" }
+" r: [topid] + [bottomid]
+function s:r.getwnrs(layout)
+    let r=[]
+    let ids=s:F.getids(a:layout)
+    let winnrs=s:F.getwinnrs(ids)
+    if winnrs[0] is 0 || index(winnrs, 0)==-1
+        return winnrs
+    else
+        execute winnrs[-1].'wincmd w'
+        silent only!
+        topleft new
+        call s:r.settoplayout(a:layout)
+        wincmd j
+        execute 'resize' call(a:layout.bottomheightfun, [], {})
+        return s:F.getwinnrs(ids)
+    endif
+endfunction
+"▶1 Post resource
+call s:_f.postresource('tabutils', s:r)
                 \a:opts)
 endfunction
 for [s:cmd, s:ver, s:opts, s:wipe] in [
-            \['Update',    [0],{'bang': 1},    ["branch","changeset","status"]],
-            \['Move',      [0],{'bang': 1},    [                     "status"]],
-            \['Junk',      [0],{},             [                     "status"]],
-            \['Track',     [0],{},             [                     "status"]],
-            \['Hyperlink', [0],{'range': '%'}, 0                              ],
-            \['Grep',      [0],{},             0                              ],
+            \['Annotate',  [0],{},             0                              ],
             \['Branch',    [0],{'bang': 1},    ["branch","changeset"         ]],
-            \['Name',      [0],{'bang': 1},    ["branch","changeset"         ]],
-            \['Other',     [0],{'bang': 1},    'all'                          ],
-            \['Annotate',  [0],{},             0                              ],
             \['Commit',    [0],{},             'all'                          ],
             \['Diff',      [0],{},             0                              ],
             \['File',      [0],{},             0                              ],
+            \['Grep',      [0],{},             0                              ],
+            \['Hyperlink', [0],{'range': '%'}, 0                              ],
+            \['Junk',      [0],{},             [                     "status"]],
+            \['Log',       [0],{},             0                              ],
+            \['Move',      [0],{'bang': 1},    [                     "status"]],
+            \['Name',      [0],{'bang': 1},    ["branch","changeset"         ]],
+            \['Other',     [0],{'bang': 1},    'all'                          ],
             \['Record',    [0],{},             0                              ],
             \['Status',    [0],{},             0                              ],
+            \['Track',     [0],{},             [                     "status"]],
+            \['Update',    [0],{'bang': 1},    ["branch","changeset","status"]],
             \['VimDiff',   [0],{},             0                              ],
-            \['Log',       [0],{},             0                              ],
             \]
     call s:_f.command.add('Au'.s:cmd,
                 \extend({'function': ['@%aurum/'.tolower(s:cmd), s:ver, 'cmd']},
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.