ZyX_I avatar ZyX_I committed 5dd5694

ftplugin/aurumcommit: Added Prev/Next AuCommit mappings. Fixes #51
doc: Mentioned phases, fixed getnthparent type, added getnthparent(, 0)

Comments (0)

Files changed (4)

                                               *aurum-m-AuCommitMessage_Commit*
     Mapname  LHS  Description ~
     Commit    i   Finish writing commit message and commit changes
+    Prev      J   Recalls commit message from working directory revision or 
+                  its {count}’th generation grand-parent (i.e. first parent 
+                  for {count}=1, first parent of first parent for {count}=2, 
+                  etc) if count is given.
+                  Note: If count was not given and it was first time mapping 
+                        was used, then commit message of working directory 
+                        revision is recalled. In all other cases (i.e. count 
+                        was given or one of Prev/Next mappings was already 
+                        used at least once) ancestor’s commit message is 
+                        recalled, acting like if {count}=1 was given.
+                  Note: If text of previously recalled message was found 
+                        unmodified, then it will be replaced. In other cases 
+                        message will be inserted before the first line of the 
+                        buffer.
+    Next      K   Like above, but works for descendants.
 
     Note These mappings are defined for aurumcommit filetype.
 
 Diff       d   a  flS  g  Shows diff between rev and WD for current file
                           (status: between two current revisions)
 Rdiff      c   a  fls     Shows changes done in current rev to current file
-Prev/Next J/K  a dfl      Go to previous/next revision
+Prev/Next J/K  acdfl      Go to previous/next revision
 Open       o   a d ls  g  Opens current file as it was at current revision
 Annotate   a   a   ls  g  Annotates current file at current revision
 Update     U   a dfl      Update working directory to current revision
     |aurum-cs.hex|.
   getwork :: () -> cs                                       *aurum-rf-getwork*
     Get changeset object for the working directory revision.
-  getnthparent :: hex, n -> [ cs ]                     *aurum-rf-getnthparent*
+  getnthparent :: hex, n -> cs                         *aurum-rf-getnthparent*
     Get nth generation grand-parent of given revision. Use negative n to get 
-    nth generation child instead.
+    nth generation child instead. With n equal to zero it must work like 
+    |aurum-rf-getcs|(hex).
   getchangesets :: () -> [ cs ]                       *aurum-rf-getchangesets*
     Pull all changesets contained in repository into |aurum-repo.changesets| 
     dictionary. If this function is not called, then |aurum-repo.changesets| 
              (|aurum-cs.files| + |aurum-cs.removes|)
 renames      Dictionary {newname : oldname}                 *aurum-cs.renames*
 copies       Dictionary {copyname : originname}              *aurum-cs.copies*
+phase        String, one of public, draft, secret, unknown    *aurum-cs.phase*
 
 ==============================================================================
 9. Creating your own driver                                 *aurum-new-driver*

ftplugin/aurumcommit.vim

             \           '@%aurum/bufvars': '0.0',
             \            '@%aurum/commit': '1.0',})
 "▶1 com.runcommap
-function s:F.runcommap(action)
+function s:F.runcommap(count, action)
     let buf=bufnr('%')
     let bvar=s:_r.bufvars[buf]
     if a:action is# 'commit'
     elseif a:action is# 'discard'
         bwipeout!
         stopinsert
+    elseif a:action[:5] is# 'recall'
+        if has_key(bvar, 'recallcs')
+            let cnt=(a:count ? a:count : 1)
+            let oldmsg=split(bvar.recallcs.description, "\n", 1)
+            if !empty(oldmsg)
+                let morelen=len(oldmsg)-1
+                let moremsg=oldmsg[1:]
+                for line in range(1, line('$'))
+                    if getline(line) is# oldmsg[0] &&
+                                \(morelen ?
+                                \   getline(line+1, line+morelen) ==# moremsg :
+                                \   1)
+                        execute 'silent' line.','.(line+morelen).'delete _'
+                        undojoin
+                        break
+                    endif
+                endfor
+            endif
+        else
+            let bvar.recallcs=bvar.repo.functions.getwork(bvar.repo)
+            let cnt=a:count
+            if empty(getline(1))
+                silent 1 delete _
+                undojoin
+            endif
+        endif
+        let cnt=((a:action[6:] is# 'prev')?(cnt):(-cnt))
+        let bvar.recallcs=bvar.repo.functions.getnthparent(bvar.repo,
+                    \                                      bvar.recallcs.hex,
+                    \                                      cnt)
+        call append(0, split(bvar.recallcs.description, "\n", 1))
     endif
     if has_key(bvar, 'sbvar')
         call bvar.sbvar.recunload(bvar.sbvar)
     endif
 endfunction
 "▶1 AuCommitMessage mapping group
-function s:F.gm(...)
-    return '<C-\><C-n>'.
-                \':call call(<SID>Eval("s:F.runcommap"), '.string(a:000).', '.
-                \           '{})<CR>'
+function s:F.mapwrapper(...)
+    return "\<C-\>\<C-n>".
+                \":call call(\<SNR>".s:_sid."_Eval('s:F.runcommap'), ".
+                \            string([v:count]+a:000).', '.
+                \           "{})\n"
 endfunction
 call s:_f.mapgroup.add('AuCommitMessage', {
-            \ 'Commit': {'lhs': 'i', 'rhs': s:F.gm('commit') },
-            \   'Exit': {'lhs': 'X', 'rhs': s:F.gm('discard')},
-        \}, {'mode': 'in', 'silent': 1, 'leader': '<LocalLeader>'})
+            \ 'Commit': {'lhs': 'i', 'rhs': ['commit']    },
+            \   'Prev': {'lhs': 'J', 'rhs': ['recallprev']},
+            \   'Next': {'lhs': 'K', 'rhs': ['recallnext']},
+            \   'Exit': {'lhs': 'X', 'rhs': ['discard']   },
+        \}, {'mode': 'in', 'silent': 1, 'leader': '<LocalLeader>',
+        \    'func': s:F.mapwrapper})
 "▶1
 call frawor#Lockvar(s:, '_r')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

test/cmd+maps-commit.in

 :W{{{1 files
 :call append('$', 'New text 3')
 :silent write
-:bwipeout!
 :R silent AuCommit **
 Pqr,i
 :
 :WT
+:W{{{1 ,J mapping
+:call append('$', 'Last new text')
+:silent write
+:bwipeout!
+:W{{{2 First ,J (insert)
+:R silent AuCommit **
+,J:call WriteFile(getline(1, '$'))
+:W{{{2 ,J after ,J
+,J:call WriteFile(getline(1, '$'))
+:W{{{2 3,J
+3,J:call WriteFile(getline(1, '$'))
+:W{{{2 ,J after edit
+ggx,J:call WriteFile(getline(1, '$'))
+:W{{{1 ,K mapping
+:W{{{2 ,K after ,J
+,K:call WriteFile(getline(1, '$'))
+:W{{{2 2,K
+2,K:call WriteFile(getline(1, '$'))
+:W{{{2 ,K after edit
+ggx,K:call WriteFile(getline(1, '$'))
+:bwipeout!
+:W{{{2 First ,K (insert)
+:R silent AuCommit **
+,K:call WriteFile(getline(1, '$'))
+:bwipeout!
 :source addmessages.vim

test/cmd+maps-commit.ok

 @  Changeset 31
 |  Tags: tip
 |  @ Pqr
+{{{1 ,J mapping
+{{{2 First ,J (insert)
+Pqr
+# Modified nohglinesrev.lst
+{{{2 ,J after ,J
+Def ghi
+# Modified nohglinesrev.lst
+{{{2 3,J
+Multiline
+commit
+comment
+# Modified nohglinesrev.lst
+{{{2 ,J after edit
+Added .hgignore
+Added directory/file
+ultiline
+commit
+comment
+# Modified nohglinesrev.lst
+{{{1 ,K mapping
+{{{2 ,K after ,J
+Multiline
+commit
+comment
+ultiline
+commit
+comment
+# Modified nohglinesrev.lst
+{{{2 2,K
+Def ghi
+ultiline
+commit
+comment
+# Modified nohglinesrev.lst
+{{{2 ,K after edit
+Def ghi
+ef ghi
+ultiline
+commit
+comment
+# Modified nohglinesrev.lst
+{{{2 First ,K (insert)
+Pqr
+Def ghi
+ef ghi
+ultiline
+commit
+comment
+# Modified nohglinesrev.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.