Commits

ZyX_I committed e9afd6b

Move some functions from “if isrecord” branches in *status.vim to @%aurum/record

  • Participants
  • Parent commits 88c97a7

Comments (0)

Files changed (4)

File autoload/aurum/commit.vim

             \                  '@/options': '0.0',
             \                       '@/os': '0.0',
             \                      '@/fwc': '0.0',
-            \             '@%aurum/status': '1.2',
+            \             '@%aurum/status': '2.0',
             \           '@%aurum/cmdutils': '4.3',
             \            '@%aurum/bufvars': '0.0',
             \            '@%aurum/vimdiff': '1.1',

File autoload/aurum/record.vim

         let state=0
     endif
     call map(files, 'repo.functions.reltorepo(repo, v:val)')
-    let sopts={'record': 1}
+    let sopts={'prefix': '-'}
     if !empty(files)
         let sopts.files=files
     endif
     let bvar.bufnr=bufnr('%')
     let bvar.oldbufs={}
     let bvar.bwfunc=s:F.unload
-    let bvar.getwnrs=s:F.getwnrs
-    let bvar.recrunmap=s:F.runstatmap
+    let bvar.switchwindow=s:F.switchwindow
+    let bvar.openfiles=s:F.openfiles
+    let bvar.foreignactions=s:foreignactions
+    let bvar.foreignmap=s:F.foreignmap
     let bvar.write=s:F.write
     let bvar.savedopts={'undolevels': &undolevels,
                 \        'scrollopt': &scrollopt,
     "▶2 action
     call s:_r.undo.doaction(bvar, 1, s:F.runaction, a:action,buf,isundo)
 endfunction
+"▶1 foreignmap
+let s:foreignactions={
+            \'track': 1,
+            \'commit': 1,
+            \'forget': 1,
+        \}
+function s:F.foreignmap(action, visual)
+    if a:action is# 'track'
+        return s:F.runstatmap(((a:visual)?('v'):('')).'add')
+    elseif a:action is# 'commit'
+        return s:F.runstatmap('commit')
+    elseif a:action is# 'forget'
+        return s:F.runstatmap(((a:visual)?('v'):('')).'remove')
+    endif
+endfunction
+"▶1 switchwindow
+function s:F.switchwindow()
+    let [lwnr, rwnr, swnr]=s:F.getwnrs()
+    execute lwnr.'wincmd w'
+endfunction
+"▶1 openfiles
+function s:F.openfiles(file2, fargs1, fargs2)
+    let [lwnr, rwnr, swnr]=s:F.getwnrs()
+    if a:file2 isnot 0
+        execute 'silent edit' fnameescape(a:file2)
+    else
+        call call(s:_r.mrun, ['silent edit']+a:fargs2, {})
+    endif
+    diffthis
+    execute rwnr.'wincmd w'
+    call call(s:_r.mrun, ['silent edit']+a:fargs1, {})
+    diffthis
+    wincmd p
+endfunction
 "▶1 runaction
 function s:F.runaction(bvar, action, buf, isundo)
     if s:F.sactions[a:action](a:action, a:bvar, a:buf)

File autoload/aurum/status.vim

 "▶1 
 scriptencoding utf-8
-execute frawor#Setup('1.2', {'@%aurum/cmdutils': '4.3',
+execute frawor#Setup('2.0', {'@%aurum/cmdutils': '4.3',
+            \                 '@%aurum/vimdiff': '1.1',
             \                    '@%aurum/edit': '1.0',
             \                     '@/functions': '0.1',
             \                           '@/fwc': '0.0',
         \}
 let s:_options={
             \'usestatwin': {'default': 1, 'filter': 'bool'},
+            \'statwincmd': {'default': 'c',
+            \               'checker': 'match /\v^[jkhlwWtbpc]$/'},
         \}
 let s:defshow=['modified', 'added', 'removed', 'deleted', 'unknown']
 let s:allshow=s:defshow+['ignored', 'clean']
 let s:showchars={}
 call map(copy(s:statchars), 'extend(s:showchars, {v:val            : v:key})')
 call map(copy(s:allshow),   'extend(s:showchars, {toupper(v:val[0]): v:val})')
+"▶1 switchwindow
+function s:F.switchwindow()
+    execute 'wincmd' s:_f.getoption('statwincmd')
+endfunction
+"▶1 openfiles
+function s:F.openfiles(file2, fargs1, fargs2)
+    if a:file2 isnot 0
+        execute 'silent edit' fnameescape(a:file2)
+    else
+        call call(s:_r.mrun, ['silent edit']+a:fargs2, {})
+    endif
+    call s:_r.vimdiff.split([a:fargs1], -1)
+endfunction
 "▶1 parseshow :: [Either type tabbr] → [type]
 function s:F.parseshow(show)
     if index(a:show, 'all')!=-1
     for key in filter(['rev', 'wdrev'], 'has_key(opts, v:val)')
         let opts[key]=a:repo.functions.getrevhex(a:repo, opts[key])
     endfor
-    let bvar={}
+    let bvar={'switchwindow': s:F.switchwindow, 'openfiles': s:F.openfiles,
+                \'foreignactions': {}}
     let requiresclean=0
     let requiresignored=0
     if has_key(opts, 'show')
     let bvar.types=[]
     let bvar.chars=[]
     let bvar.files=[]
-    let isrecord=get(opts, 'record', 0)
     let statlines=[]
     for [type, files] in filter(sort(items(status)), 'index(show,v:val[0])!=-1')
         let char=has_key(s:statchars, type)? s:statchars[type]: toupper(type[0])
             if ignore
                 continue
             endif
-            let statlines+=[((isrecord)?('-'):('')).char.' '.file]
+            let statlines+=[get(opts, 'prefix', '').char.' '.file]
             let bvar.types+=[type]
             let bvar.chars+=[char]
             let bvar.files+=[file]
 call s:_f.newcommand({
             \'function': s:F.setup,
             \ 'options': {'list': ['files', 'show'],
-            \             'bool': ['record'],
-            \              'str': ['rev', 'wdrev'],
+            \              'str': ['rev', 'wdrev', 'prefix'],
             \             'pats': ['files'],},
             \'filetype': 'aurumstatus',
             \})

File doc/aurum.txt

          respectively. Same for |aurum://status| “rev1” and “rev2” options.
     1.1: Added |:AuStatus| changes.
     1.2: Made _r.status.parseshow handle “all” “status”.
+    2.0: Refactored code to ease use with special tabs (like |:AuRecord|)
 @%aurum/commit:
     1.0: Added fifth argument to _r.commit.commit().
     1.1: Added sixth optional argument to _r.commit.commit().