ZyX_I avatar ZyX_I committed 452b4f7

Added `i' (commit) mapping to aurum://status
Made :AuCommit choose files to commit smarter (untested, old tests are still passing)
Changed :AuRecord Commit mapping: it now is `I', not `i' which is taken by aurum://status.

Comments (0)

Files changed (8)

ftplugin/aurumstatus.vim

 setlocal nomodeline
 execute frawor#Setup('0.0', {'@aurum/bufvars': '0.0',
             \                '@aurum/vimdiff': '0.0',
+            \                 '@aurum/commit': '0.0',
             \                    '@/mappings': '0.0',
             \                          '@/os': '0.0',})
 "▶1 runmap
 let s:noacttypes.revdiff    = s:noacttypes.diff
 let s:noacttypes.revvimdiff = s:noacttypes.vimdiff
 function s:F.runmap(action)
-    let bvar=s:_r.bufvars[bufnr('%')]
+    let buf=bufnr('%')
+    let bvar=s:_r.bufvars[buf]
     if empty(bvar.types)
         return ''
     endif
                 \index(s:noacttypes[a:action], bvar.types[line('.')-1])!=-1
         return ''
     endif
-    if get(bvar.opts, 'record', 0)
-        let [lwnr, rwnr, swnr]=bvar.getwnrs()
-        execute lwnr.'wincmd w'
-    else
-        wincmd c
+    if a:action[-6:] isnot# 'commit'
+        if get(bvar.opts, 'record', 0)
+            let [lwnr, rwnr, swnr]=bvar.getwnrs()
+            execute lwnr.'wincmd w'
+        else
+            wincmd c
+        endif
     endif
     if a:action is# 'open'
         execute 'silent e' fnameescape(s:_r.os.path.join(bvar.repo.path,file))
         execute 'silent edit' fnameescape('aurum://file:'.epath.':'.rev1.
                     \                                           ':'.file)
         AuAnnotate
+    elseif a:action[-6:] is# 'commit'
+        let visual=(a:action[0] is# 'v')
+        if visual
+            let files=map(range(line("'<"), line("'>"),
+                        \      ((line("'<")>line("'>")?(1):(-1)))),
+                        \ 'bvar.files[v:val-1]')
+        else
+            let files=bvar.files[line('.')-1:line('.')-1+v:count1-1]
+        endif
+        if s:_r.commit.commit(bvar.repo, bvar.opts, files, bvar.status)
+            silent edit!
+        else
+            augroup AuStatusCommit
+                execute 'autocmd BufWipeOut <buffer> '.
+                            \'if bufexists('.buf.') | '.
+                            \   'execute "autocmd AuStatusCommit '.
+                            \                    'BufEnter <buffer='.buf.'> '.
+                            \                    'nested '.
+                            \               'execute \"autocmd! AuStatusCommit '.
+                            \                           'BufEnter '
+                            \                           '<buffer='.buf.'>\" | '.
+                            \                   'silent edit!" | '.
+                            \'endif'
+            augroup END
+        endif
     endif
 endfunction
+let s:_augroups+=['AuStatusCommit']
 "▶1 AuStatus mapping group
 "▶2 getrhs
 function s:F.getrhs(...)
-    return ':call call(<SID>Eval("s:F.runmap"), '.string(a:000).', {})<CR>'
+    return ':<C-u>call call(<SID>Eval("s:F.runmap"), '.string(a:000).', {})<CR>'
 endfunction
 "▲2
-" TODO Add K/J, «,i» (Commit) mappings
+" TODO Add K/J mappings
 call s:_f.mapgroup.add('AuStatus', {
+            \    'Exit': {'lhs':  'X',   'rhs': ':<C-u>bwipeout!<CR>'    },
             \    'Open': {'lhs': '<CR>', 'rhs': s:F.getrhs(       'open')},
             \   'ROpen': {'lhs':  'o',   'rhs': s:F.getrhs(    'revopen')},
             \  'RFdiff': {'lhs': 'gd',   'rhs': s:F.getrhs(   'fulldiff')},
             \   'Vdiff': {'lhs':  'D',   'rhs': s:F.getrhs(    'vimdiff')},
             \  'RVdiff': {'lhs':  'C',   'rhs': s:F.getrhs( 'revvimdiff')},
             \'Annotate': {'lhs':  'a',   'rhs': s:F.getrhs(   'annotate')},
-            \    'Exit': {'lhs':  'X',   'rhs': ':<C-u>bwipeout!<CR>'    },
+            \  'Commit': {'lhs':  'i',   'rhs': s:F.getrhs(     'commit')},
+            \ 'Vcommit': {'lhs':  'i',   'rhs': s:F.getrhs(    'vcommit'),
+            \             'mode': 'v'},
             \}, {'func': s:F.runmap, 'silent': 1, 'mode': 'n'})
 "▶1
 call frawor#Lockvar(s:, '_r')

plugin/aurum/cmdutils.vim

             \'nodfile': 'Failed to deduce which file to diff with',
             \'noffile': 'Failed to deduce which file to show',
             \ 'nocurf': 'Failed to deduce which file was meant',
+            \'nocfile': 'Unsure what should be commited',
         \}
 "▶1 globtopattern :: glob → pattern
 function s:F.globtopattern(glob)
     let file=0
     "▶2 a:opts.file file → (repo?)
     if has_key(a:opts, 'file') && a:opts.file isnot# ':'
-        if a:ann!=-1 && a:opts.repo is# ':'
+        if a:ann>=0 && a:opts.repo is# ':'
             let repo=s:_r.repo.get(s:_r.os.path.dirname(a:opts.file))
             let file=repo.functions.reltorepo(repo, a:opts.file)
         else
             let hasbuf=1
         "▶2 +aurum://copy bvar → (file), file → (repo), (rev=0)
         elseif bvar.command is# 'copy'
-            if a:ann!=-1
+            if a:ann>=0
                 let repo=s:_r.repo.get(s:_r.os.path.dirname(bvar.file))
             endif
             let  rev=0
             let repo=bvar.repo
             let  rev=get(bvar.opts, 'rev1', 0)
             if empty(bvar.files)
-                call s:_f.throw(a:failmsg)
+                if a:failmsg isnot 0
+                    call s:_f.throw(a:failmsg)
+                endif
             else
                 let file=bvar.files[line('.')-1]
             endif
-            if a:ann!=-1
+            if a:ann>=0
                 topleft new
             endif
         "▶2 |aurum://diff bvar → (repo, rev, file?)
         elseif bvar.command is# 'diff'
             let repo=bvar.repo
             let  rev=empty(bvar.rev2) ? bvar.rev1 : bvar.rev2
-            let file=s:F.getdifffile(bvar)
-            if file is 0
-                return s:rrffailresult
-            endif
-            if a:ann!=-1
-                leftabove vnew
+            if a:ann==-2
+                let files=bvar.files
+            else
+                let file=s:F.getdifffile(bvar)
+                if file is 0
+                    return s:rrffailresult
+                endif
+                if a:ann>=0
+                    leftabove vnew
+                endif
             endif
         "▶2 *aurum://commit bvar → (repo, file?)
         elseif bvar.command is# 'commit'
             let repo=bvar.repo
-            let file=s:F.getfile(bvar.files)
-            if file is 0
-                return s:rrffailresult
-            endif
-            if a:ann!=-1
-                topleft new
+            if a:ann==-2
+                let files=bvar.files
+            else
+                let file=s:F.getfile(bvar.files)
+                if file is 0
+                    return s:rrffailresult
+                endif
+                if a:ann>=0
+                    topleft new
+                endif
             endif
         "▶2 -aurum://annotate bvar → (repo, file), "." → (rev)
         elseif bvar.command is# 'annotate'
             let repo=bvar.repo
             let file=bvar.file
-            if !has_key(a:opts, 'rev')
-                let rev=matchstr(getline('.'), '\v\d+')
-                let rev=repo.functions.getrevhex(repo, rev)
-                let annrev=repo.functions.getrevhex(repo, bvar.rev)
-                if rev is# annrev
-                    if a:ann!=1
-                        " Don't do the following if we are not annotating
-                    elseif has_key(bvar, 'annbuf') && bufwinnr(bvar.annbuf)!=-1
+            if a:ann!=-2
+                if !has_key(a:opts, 'rev')
+                    let rev=matchstr(getline('.'), '\v\d+')
+                    let rev=repo.functions.getrevhex(repo, rev)
+                    let annrev=repo.functions.getrevhex(repo, bvar.rev)
+                    if rev is# annrev
+                        if a:ann!=1
+                            " Don't do the following if we are not annotating
+                        elseif has_key(bvar, 'annbuf') &&
+                                    \bufwinnr(bvar.annbuf)!=-1
+                            execute bufwinnr(bvar.annbuf).'wincmd w'
+                        else
+                            let epath=escape(repo.path, ':\')
+                            setlocal scrollbind
+                            execute 'silent rightbelow vsplit'
+                                        \fnameescape('aurum://file:'.epath.':'.
+                                        \                            rev.  ':'.
+                                        \                            file)
+                            let bvar.annbuf=bufnr('%')
+                            setlocal scrollbind
+                        endif
+                        return s:rrffailresult
+                    endif
+                endif
+                if a:ann>=0
+                    if winnr('$')>1
+                        wincmd c
+                    endif
+                    if has_key(bvar, 'annbuf') && bufwinnr(bvar.annbuf)!=-1
                         execute bufwinnr(bvar.annbuf).'wincmd w'
-                    else
-                        let epath=escape(repo.path, ':\')
-                        setlocal scrollbind
-                        execute 'silent rightbelow vsplit'
-                                    \fnameescape('aurum://file:'.epath.':'.
-                                    \                            rev.  ':'.
-                                    \                            file)
-                        let bvar.annbuf=bufnr('%')
-                        setlocal scrollbind
                     endif
-                    return s:rrffailresult
-                endif
-            endif
-            if a:ann!=-1
-                if winnr('$')>1
-                    wincmd c
-                endif
-                if has_key(bvar, 'annbuf') && bufwinnr(bvar.annbuf)!=-1
-                    execute bufwinnr(bvar.annbuf).'wincmd w'
                 endif
             endif
         "▶2 Unknown command
-        else
+        elseif a:failmsg isnot 0
             call s:_f.throw(a:failmsg)
         endif
     "▶2 buf → (repo, file), (rev=0)
         endif
         let hasbuf=1
     "▲2
-    else
+    elseif a:failmsg isnot 0
         call s:_f.throw(a:failmsg)
     endif
     if a:ann!=-1
             let file=repo.functions.reltorepo(repo, file)
         endif
         "▶2 rev
-        if exists('rev')
+        if a:ann==-2
+            let rev=0
+        elseif exists('rev')
             if rev isnot 0
                 let rev=repo.functions.getrevhex(repo, rev)
             endif
         endif
         "▲2
     endif
-    return [hasbuf, exists('repo') ? repo : 0, rev, file]
+    return [hasbuf, exists('repo') ? repo : 0, rev,
+                \((a:ann==-2)?
+                \   ((exists('files'))?
+                \       (files):
+                \   ((file is 0)?
+                \       (0):
+                \       ([file]))):
+                \   (file))]
 endfunction
 "▶1 checkrepo
 function s:F.checkrepo(repo)

plugin/aurum/commit.vim

 endfunction
 "▶1 commfunc
 function s:commfunc.function(opts, ...)
-    let repo=a:opts.repo
+    let [repo, rev, files]=s:_r.cmdutils.getrrf(a:opts,
+                \                               ((a:0)?(0):('nocfile')),
+                \                               -2)[1:]
     call s:_r.cmdutils.checkrepo(repo)
     let status=repo.functions.status(repo)
     "▶2 Get file list
                 let files+=curfiles
             endif
         endfor
-    elseif filereadable(expand('%'))
-        let files=[repo.functions.reltorepo(repo, expand('%'))]
-        if !repo.functions.dirty(repo, files[0])
-            call s:_f.throw('nocfile')
-        endif
-    else
+    elseif files is 0
         call s:_f.throw('nocfile')
     endif
     "▲2
     return s:F.commit(repo, a:opts, files, status)
 endfunction
 let s:commfunc['@FWC']=['-onlystrings '.
-            \           '{  repo '.s:_r.cmdutils.repoarg.
+            \           '{  repo '.s:_r.cmdutils.nogetrepoarg.
             \           ' *?type      (either (in [modified added removed '.
             \                                     'deleted uknown] ~start, '.
             \                                 'match /\v^[MARDU?!]+$/))'.

plugin/aurum/record.vim

             \    'Add': {'lhs': 'A', 'rhs': s:F.gm('add')    },
             \ 'Remove': {'lhs': 'R', 'rhs': s:F.gm('remove') },
             \   'Edit': {'lhs': 'O', 'rhs': s:F.gm('edit')   },
-            \ 'Commit': {'lhs': 'i', 'rhs': s:F.gm('commit') },
+            \ 'Commit': {'lhs': 'I', 'rhs': s:F.gm('commit') },
             \   'Undo': {'lhs': 'u', 'rhs': s:F.gm('undo')   },
             \   'Vadd': {'lhs': 'A', 'rhs': s:F.gm('vadd'),    'mode': 'v'},
             \'Vremove': {'lhs': 'R', 'rhs': s:F.gm('vremove'), 'mode': 'v'},
 call s:_f.mapgroup.add('AuRecordLeft', {
             \'Discard': {'lhs': 'x', 'rhs': s:F.gml('discard')   },
             \   'Exit': {'lhs': 'X', 'rhs': s:F.gml('discardall')},
-            \ 'Commit': {'lhs': 'i', 'rhs': s:F.gml('commit')    },
+            \ 'Commit': {'lhs': 'I', 'rhs': s:F.gml('commit')    },
             \ 'Remove': {'lhs': 'R', 'rhs': s:F.gml('remove')    },
         \}, {'mode': 'n', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶1
-:W{{{1 i mapping
+:W{{{1 I mapping
 :R AuRecord
 /M
-AiAbc:silent write
+AIAbc:silent write
 :WT
 :W{{{1 BufWriteCmd event
 :R AuRecord
 A:silent write
 Def:silent write
 :WT
-:W{{{1 ARiX
+:W{{{1 ARIX
 :R AuRecord
-ARiX:WT
-:W{{{1 2A2RiX
+ARIX:WT
+:W{{{1 2A2RIX
 :R AuRecord
-2A2RiX:WT
+2A2RIX:WT
 :W{{{1 message, {count}A
 :R AuRecord message Ghi
-2Ai:WT
+2AI:WT
 :W{{{1 message, user, date
 :let date=strftime('%Y-%m-%d_%H:%M', 1200873600)
 :exe 'R AuRecord message Jkl user B\ <b@example.org> date '.date
-Ai:WT!
+AI:WT!
 :W{{{1 edit-discard
 :R silent edit nohglinesrev.lst
 :call append('$', 'This is a new text')
 :bwipeout!
 :R AuRecord message Mno
 OGdo:silent write
-,xiX:WT
+,xIX:WT
 :W{{{1 edit-discardall
 :R AuRecord message Mno
 OGdo:silent write
 :W{{{1 edit-edit-ignore
 :R AuRecord message Mno
 OGdo:silent write
-jOzRggdd,RiX:WT
+jOzRggdd,RIX:WT
 :W{{{1 edit-commit
 :R AuRecord message Mno
-OGdo,i:WT
+OGdo,I:WT
 :source addmessages.vim
-{{{1 i mapping
+{{{1 I mapping
 @  Changeset 23
 |  Tags: tip
 |  @ Abc
 @  Changeset 24
 |  Tags: tip
 |  @ Def
-{{{1 ARiX
+{{{1 ARIX
 @  Changeset 24
 |  Tags: tip
 |  @ Def
-{{{1 2A2RiX
+{{{1 2A2RIX
 @  Changeset 24
 |  Tags: tip
 |  @ Def
 :W{{{1 <CR>
-:silent cd `=g:curtest.'repo'`
-:AuStatus
+:R AuStatus
 /^M
 
 :call WriteFile(bufname('%'))
 :bwipeout!
 :W{{{1 o
-:AuStatus
+:R AuStatus
 /^M
 o:call WriteFile(bufname('%'))
 :bwipeout!
 :W{{{1 gc
-:AuStatus
+:R AuStatus
 /^M
 gc:call WriteFile(bufname('%'))
 :bwipeout!
 :W{{{1 c
-:AuStatus
+:R AuStatus
 /^M
 c:call WriteFile(bufname('%'))
 :bwipeout!
 :W{{{1 C
-:AuStatus
+:R AuStatus
 /^M
 C:call WriteFile(bufname('%'), bufname(winbufnr(winnr('#'))), 'w$: '.winnr('$').', d:'.&diff)
 :bwipeout!
 :bwipeout!
 :W{{{1 gd
-:AuStatus
+:R AuStatus
 /^M
 gd:call WriteFile(bufname('%'))
 :bwipeout!
 :W{{{1 d
-:AuStatus
+:R AuStatus
 /^M
 d:call WriteFile(bufname('%'))
 :bwipeout!
 :W{{{1 D
-:AuStatus
+:R AuStatus
 /^M
 D:call WriteFile(bufname('%'), bufname(winbufnr(winnr('#'))), 'w$: '.winnr('$').', d:'.&diff)
 :bwipeout!
 :bwipeout!
-:silent cd ..
+:W{{{1 i
+:R AuStatus
+idd02x:silent write
+:WT
+:W{{{1 2i
+2iddgg0G0ld:silent write
+:WT
+:W{{{1 Vi
+GVidd02x:silent write
+:WT
+:call WriteFile(getline(1, '$'))
 :source addmessages.vim
 aurum://file:%TMPDIR%/test/statmapsrepo:54d2db605eec15091bb4b194499d6db40e2af027:nohglinesrev.lst
 %TMPDIR%/test/statmapsrepo/nohglinesrev.lst
 w$: 2, d:1
+{{{1 i
+@  Changeset 23
+|  Tags: tip
+|  @ Added addeddef
+{{{1 2i
+@  Changeset 24
+|  Tags: tip
+|  @ Modified nohglinesrev.lst
+|  @ Removed nohglines.lst
+{{{1 Vi
+@  Changeset 25
+|  Tags: tip
+|  @ Removed hglines2.lst
+? hglinesrev.lst
+>>> Messages:
+
+
+<<< Messages^
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.