diff plugin/lawrencium.vim @ 51:671f5e18b515

Added "diff summary" commands to use `hg diff` instead of Vim's diff. Added documenation for the new commands. Got rid of the useless hard-coded revision numbers.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 10 Nov 2012 11:17:34 -0800
parents dffb41c2067c
children cd0b1cea326c
line wrap: on
line diff
--- a/plugin/lawrencium.vim	Fri Nov 09 05:52:34 2012 -0800
+++ b/plugin/lawrencium.vim	Sat Nov 10 11:17:34 2012 -0800
@@ -674,10 +674,9 @@
 " Hgdiff {{{
 
 function! s:HgDiff(filename, vertical, ...) abort
-    " Default revisions to diff: the working directory (special Lawrencium 
-    " hard-coded syntax) and the parent of the working directory (using 
-    " Mercurial's revsets syntax).
-    let l:rev1 = 'lawrencium#_wdir_'
+    " Default revisions to diff: the working directory (null string) 
+    " and the parent of the working directory (using Mercurial's revsets syntax).
+    let l:rev1 = ''
     let l:rev2 = 'p1()'
     if a:0 == 1
         let l:rev2 = a:1
@@ -697,7 +696,7 @@
     let l:diff_buffers = []
 
     " Get the first file and open it.
-    if l:rev1 == 'lawrencium#_wdir_'
+    if l:rev1 == ''
         if bufexists(l:path)
             execute 'buffer ' . fnameescape(l:path)
         else
@@ -724,7 +723,7 @@
     if a:vertical
         let l:diffsplit = 'vertical diffsplit'
     endif
-    if l:rev2 == 'lawrencium#_wdir_'
+    if l:rev2 == ''
         execute l:diffsplit . ' ' . fnameescape(l:path)
     else
         let l:temp_file = tempname()
@@ -816,6 +815,41 @@
 
 " }}}
 
+" HgdiffSummary {{{
+
+function! s:HgDiffSummary(split, filename, ...) abort
+    " Default revisions to diff: the working directory (null string) 
+    " and the parent of the working directory (using Mercurial's revsets syntax).
+    let l:revs = ''
+    if a:0 == 1
+        let l:revs = a:1
+    elseif a:0 >= 2
+        let l:revs = a:1 . ',' . a:2
+    endif
+
+    " Get the current repo, and expand the given filename in case it contains
+    " fancy filename modifiers.
+    let l:repo = s:hg_repo()
+    let l:path = expand(a:filename)
+    call s:trace("Diff'ing revisions: '".l:revs."' on file: ".l:path)
+    let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs)
+    if a:split == 1
+        split
+    elseif a:split == 2
+        vsplit
+    endif
+    execute 'edit ' . l:special
+    " Open all folds by default.
+    " TODO: maybe set `nofoldenable` instead?
+    %foldopen!
+endfunction
+
+call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiffsum       :call s:HgDiffSummary(0, '%:p', <f-args>)")
+call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiffsumsplit  :call s:HgDiffSummary(1, '%:p', <f-args>)")
+call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiffsumsplit :call s:HgDiffSummary(2, '%:p', <f-args>)")
+
+" }}}
+
 " Hgcommit {{{
 
 function! s:HgCommit(bang, vertical, ...) abort
@@ -1115,8 +1149,10 @@
             else
                 call l:repo.ReadCommandOutput('diff', '-r', l:rev1, '-r', l:rev2, l:comps['path'])
             endif
+        elseif l:comps['value'] != ''
+            call l:repo.ReadCommandOutput('diff', '-c', l:comps['value'], l:comps['path'])
         else
-            call l:repo.ReadCommandOutput('diff', '-c', l:comps['value'], l:comps['path'])
+            call l:repo.ReadCommandOutput('diff', l:comps['path'])
         endif
         setlocal filetype=diff
     endif