Mercurial > vim-lawrencium
changeset 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 | b484fe88c500 |
children | cd0b1cea326c |
files | doc/lawrencium.txt plugin/lawrencium.vim |
diffstat | 2 files changed, 77 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/lawrencium.txt Fri Nov 09 05:52:34 2012 -0800 +++ b/doc/lawrencium.txt Sat Nov 10 11:17:34 2012 -0800 @@ -90,16 +90,48 @@ *:Hgdiff* :Hgdiff Diffs the current file against its parent revision. + This splits the current window to show both the + current file and the parent revision file, using Vim's + |diff| abilities. *:Hgdiff_f* -:Hgdiff {revspec} Diffs the current file against the specified revision. +:Hgdiff {revspec} Same as |:Hgdiff| but shows a diff of the current file + with the specified revision. Any revision number, hash + or spec that can be passed to `hg cat` is valid. *:Hgvdiff* -:Hgvdiff Same as |:Hgdiff| but uses a vertical split. +:Hgvdiff Same as |:Hgdiff| but uses a vertical split instead of + a horizontal split. *:Hgvdiff_f* :Hgvdiff {revspec} Same as |:Hgdiff_f| but uses a vertical split. + *:Hgdiffsum* +:Hgdiffsum Shows the "diff summary" (the output of `hg diff`) + of the current file against its parent revision. + + *:Hgdiffsum_f* +:Hgdiffsum {revspec} Same as |:Hgdiffsum| but shows a "diff summary" of the + current file with the specified revision. Any revision + number, hash or spec that can be passed to `hg diff` + is valid. + + *:Hgdiffsumsplit* + *:Hgdiffsumsplit_f* +:Hgdiffsumsplit +:Hgdiffsumsplit {revspec} + Same as |:Hgdiffsum| and |:Hgdiffsum_f| respectively, + but opens the diff summary in a split window instead + of the current window. + + *:Hgvdiffsumsplit* + *:Hgvdiffsumsplit_f* +:Hgvdiffsumsplit +:Hgvdiffsumsplit {revspec} + Same as |:Hgdiffsumsplit| and |:Hgdiffsumsplit_f| + respectively, but uses a vertical split window instead + of a horizontal split window. + *:Hgcommit* :Hgcommit Opens a new window to edit a commit message into a temporary file and, upon quitting the buffer, if that
--- 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