Commits

ZyX_I committed ac2a09c

ftplugin/aurumcommit: Added Vdiff and FVdiff mappings
Ref #72

Comments (0)

Files changed (6)

     type you can’t use this with |:read|.
     Local mappings (mgid=AuCommitMessage, default leader: "<LocalLeader>"):
                                                  *g:frawormap_AuCommitMessage*
-                                          *g:frawormap_AuCommitMessage_Commit*
-                                              *aurum-m-AuCommitMessage_Commit*
+       *g:frawormap_AuCommitMessage_Commit* *g:frawormap_AuCommitMessage_Prev*
+       *g:frawormap_AuCommitMessage_Vdiff*  *g:frawormap_AuCommitMessage_Next*
+       *g:frawormap_AuCommitMessage_FVdiff*
+           *aurum-m-AuCommitMessage_Commit*     *aurum-m-AuCommitMessage_Prev*
+           *aurum-m-AuCommitMessage_Vdiff*      *aurum-m-AuCommitMessage_Next*
+           *aurum-m-AuCommitMessage_FVdiff*
     Mapname  LHS  Description ~
     Commit    i   Finish writing commit message and commit changes
     Prev      J   Recalls commit message from working directory revision or 
                         message will be inserted before the first line of the 
                         buffer.
     Next      K   Like above, but works for descendants.
+    Vdiff     D   Open a vimdiff split with the selected file (uses file under 
+                  cursor or prompts user).
+    FVdiff   gD   Open a number of vimdiff splits with all files to be 
+                  committed.
 
     Note These mappings are defined for aurumcommit filetype.
 
 Date       gM       l      Shows revisions committed in the current month
 Branch     gb       l      Shows revisions that have the same branch
 Rev        gr       l      Shows revisions that are descendants of the current
-FVdiff     gD   a D lS  g  Shows full vimdiff between current revision and WD
+FVdiff     gD   acD lS  g  Shows full vimdiff between current revision and WD
                            (status and diff: between two current revisions)
 RFVdiff    gC   a   ls     Shows changes done in current rev as full vimdiff
-Vdiff       D   a Df S  g  Shows vimdiff between cur. rev. and WD for file
+Vdiff       D   acDf S  g  Shows vimdiff between cur. rev. and WD for file
                            (status and diff: between two current revisions)
 RVdiff      C   a  f s     Shows changes to file in cur. rev. as a vimdiff
 Fdiff      gd   a   lS  g  Shows diff between current revision and working dir
     1.1: Added “requiresbvar” _f.newcommand option.
     1.2: Added “mgroup” _f.newcommand option and mrun resource.
     1.3: Added prevbuf function.
-    1.4: Added “plstrgen” _f.newcommand option
+    1.4: Added “plstrgen” _f.newcommand option.
 @%aurum/vimdiff:
     0.1: Added full, untracked, onlymodified and files options to |:AuVimDiff|
     0.2: Added _r.vimdiff.full.
 @%aurum/status:
     1.0: Renamed |:AuStatus| “rev1” and “rev2” options to “rev” and “wdrev” 
          respectively. Same for |aurum://status| “rev1” and “rev2” options.
-    1.1: Added |:AuStatus| changes
-    1.2: Made _r.status.parseshow handle “all” “status”
+    1.1: Added |:AuStatus| changes.
+    1.2: Made _r.status.parseshow handle “all” “status”.
 @%aurum/commit:
     1.0: Added fifth argument to _r.commit.commit().
     1.1: Added sixth optional argument to _r.commit.commit()

ftplugin/aurumcommit.vim

 setlocal noswapfile
 setlocal nomodeline
 execute frawor#Setup('0.0', {'@/mappings': '0.0',
+            \                      '@/os': '0.0',
             \           '@%aurum/bufvars': '0.0',
-            \            '@%aurum/commit': '1.0',})
-"▶1 com.runcommap
+            \          '@%aurum/maputils': '0.0',
+            \           '@%aurum/vimdiff': '1.1',
+            \            '@%aurum/commit': '1.0',
+            \              '@%aurum/edit': '1.0',})
+"▶1 listfiles
+function s:F.listfiles(bvar)
+    if has_key(a:bvar, 'revstatus')
+        return keys(a:bvar.revstatus)
+    elseif !empty(a:bvar.files)
+        return a:bvar.files
+    else
+        let status=a:bvar.repo.functions.status(a:bvar.repo, 0, 0, a:bvar.files)
+        let status=filter(copy(status), 'index(s:defstats, v:key)!=-1')
+        let revstatus={}
+        call map(copy(a:status), 'map(copy(v:val),'.
+                    \              '"extend(revstatus,{v:val:''".v:key."''})")')
+        let a:bvar.revstatus=revstatus
+        return keys(a:bvar.revstatus)
+    endif
+endfunction
+"▶1 getfile
+let s:defstats=['added', 'removed', 'modified']
+function s:F.getfile(bvar)
+    let files=s:F.listfiles(a:bvar)
+    let file=matchstr(getline('.'), '\v(^\#\ \S+\ )@<=.*$')
+    if !empty(file) && index(files, file)!=-1
+        return file
+    endif
+    let file=expand('<cfile>')
+    if index(files, file)!=-1
+        return file
+    endif
+    return 0
+endfunction
+"▶1 vimdiffcb
+function s:F.vimdiffcb(file, bvar, hex)
+    execute 'silent tabnew'
+                \ fnameescape(s:_r.os.path.join(a:bvar.repo.path, a:file))
+    return s:_r.vimdiff.split([['file', a:bvar.repo, a:hex, a:file]], 0)
+endfunction
+"▶1 vimdiffrecordcb
+function s:F.vimdiffrecordcb(file, bvar, hex)
+    let [lwnr, rwnr, swnr]=a:bvar.sbvar.getwnrs()
+
+    execute lwnr.'wincmd w'
+    let file=s:_r.os.path.join(a:bvar.repo.path, a:file)
+    let existed=bufexists(file)
+    execute 'silent edit' fnameescape(file)
+    if !existed
+        setlocal bufhidden=wipe
+    endif
+    diffthis
+
+    execute rwnr.'wincmd w'
+    let existed=s:_r.run('silent edit', 'file', a:bvar.repo, a:hex, a:file)
+    if !existed
+        setlocal bufhidden=wipe
+    endif
+    diffthis
+
+    execute lwnr.'wincmd w'
+endfunction
+"▶1 runcommap
 function s:F.runcommap(count, action)
     let buf=bufnr('%')
     let bvar=s:_r.bufvars[buf]
                     \                                      bvar.recallcs.hex,
                     \                                      cnt)
         call append(0, split(bvar.recallcs.description, "\n", 1))
+    elseif a:action is# 'vimdiff'
+        let file=s:F.getfile(bvar)
+        let hex=bvar.repo.functions.getworkhex(bvar.repo)
+        let cbargs=[((has_key(bvar, 'sbvar'))?
+                    \   (s:F.vimdiffrecordcb):
+                    \   (s:F.vimdiffcb)), bvar, hex]
+        if file is 0
+            let pvargs=[s:_r.maputils.readfilewrapper, bvar.repo, hex]
+            return s:_r.maputils.promptuser(s:F.listfiles(bvar), cbargs, pvargs)
+        else
+            return call(cbargs[0], [file]+cbargs[1:], {})
+        endif
+    elseif a:action is# 'fullvimdiff'
+        return s:_r.vimdiff.full(bvar.repo,
+                    \            [0, bvar.repo.functions.getworkhex(bvar.repo)],
+                    \            1, s:F.listfiles(bvar), 0)
     endif
 endfunction
 "▶1 AuCommitMessage mapping group
                 \           "{})\n"
 endfunction
 call s:_f.mapgroup.add('AuCommitMessage', {
-            \ 'Commit': {'lhs': 'i', 'rhs': ['commit']    },
-            \   'Prev': {'lhs': 'J', 'rhs': ['recallprev']},
-            \   'Next': {'lhs': 'K', 'rhs': ['recallnext']},
-            \   'Exit': {'lhs': 'X', 'rhs': ['discard']   },
+            \ 'Commit': {'lhs':  'i', 'rhs': ['commit'     ]},
+            \   'Prev': {'lhs':  'J', 'rhs': ['recallprev' ]},
+            \   'Next': {'lhs':  'K', 'rhs': ['recallnext' ]},
+            \  'Vdiff': {'lhs':  'D', 'rhs': ['vimdiff'    ]},
+            \ 'FVdiff': {'lhs': 'gD', 'rhs': ['fullvimdiff']},
+            \   'Exit': {'lhs':  'X', 'rhs': ['discard'    ]},
         \}, {'mode': 'in', 'silent': 1, 'leader': '<LocalLeader>',
         \    'func': s:F.mapwrapper})
 "▶1

test/cmd+maps-commit.in

+:W{{{1 ,D mapping
+:W{{{2 On comment line
+:R silent AuCommit **
+G,D:WTabs
+:bwipeout!
+:W{{{2 With prompt
+gg,D2
+
+:WTabs
+:bwipeout!
+:W{{{1 ,gD mapping
+,gD:WTabs
+,X:bwipeout!
 :W{{{1
 :R silent edit nohglinesrev.lst
 :silent AuCommit

test/cmd+maps-commit.ok

+{{{1 ,D mapping
+{{{2 On comment line
+ 1*1: aurum://commit:%ETMPDIR%%-test%-cmd+maps-commitrepo:::0:addeddef;nohglinesrev.lst;hglines2.lst
+ 1#2: 
+*2#1: aurum://file:%ETMPDIR%%-test%-cmd+maps-commitrepo:504f74154456dbb0e9441326514e42ce66279e62:hglines2.lst
+*2*2: %TMPDIR%/test/cmd+maps-commitrepo/hglines2.lst
+{{{2 With prompt
+ 1*1: aurum://commit:%ETMPDIR%%-test%-cmd+maps-commitrepo:::0:addeddef;nohglinesrev.lst;hglines2.lst
+ 1#2: 
+*2#1: aurum://file:%ETMPDIR%%-test%-cmd+maps-commitrepo:504f74154456dbb0e9441326514e42ce66279e62:hglines2.lst
+*2*2: %TMPDIR%/test/cmd+maps-commitrepo/hglines2.lst
+{{{1 ,gD mapping
+ 1*1: aurum://commit:%ETMPDIR%%-test%-cmd+maps-commitrepo:::0:addeddef;nohglinesrev.lst;hglines2.lst
+ 1#2: 
+ 2*1: 
+ 2#2: %TMPDIR%/test/cmd+maps-commitrepo/addeddef
+ 3*1: aurum://file:%ETMPDIR%%-test%-cmd+maps-commitrepo:504f74154456dbb0e9441326514e42ce66279e62:hglines2.lst
+ 3#2: 
+*4*1: aurum://file:%ETMPDIR%%-test%-cmd+maps-commitrepo:504f74154456dbb0e9441326514e42ce66279e62:nohglinesrev.lst
+*4#2: %TMPDIR%/test/cmd+maps-commitrepo/nohglinesrev.lst
 {{{1
 @  Changeset 27
 |  Tags: tip
 # Modified nohglinesrev.lst
 >>> Messages:
 
+Frawor:autoload/aurum/maputils:plinst:If you install Command-T, Ctrlp, FuzzyFinder, unite, ku or tlib you will be prompted with much less sucking interface
+
 
 
 

test/cmd-record.in

 :W{{{1 i mapping
 :R AuRecord
-/M
+:silent 1/M
 AiAbc:silent write
 :
 :
 :Run silent AuStatus
 :bwipeout!
 :
+:W{{{1 edit-commit-vimdiff
+:R call writefile([''], 'hglines.lst')
+:R AuRecord
+:silent 1/M
+AiG,D
+:WW
+:wincmd j
+:bwipeout!
+:
+:bwipeout!
+:
 :source addmessages.vim

test/cmd-record.ok

 |  Tags: tip
 |  @ Added 1 and 2
 ? 3
+{{{1 edit-commit-vimdiff
+*1: %TMPDIR%/test/cmd-recordrepo/hglines.lst
+#2: aurum://file:%ETMPDIR%%-test%-cmd-recordrepo:d209c426a492359a9010d3e0f06b7732781283bf:hglines.lst
+ 3: aurum://commit:%ETMPDIR%%-test%-cmd-recordrepo:::0:hglines.lst
 >>> Messages:
 
 
 Frawor:autoload/aurum/record:recnof:No files were selected for commiting
 Frawor:autoload/aurum/record:recnof:No files were selected for commiting
 
+
 <<< 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.