changeset 95:d38be34b403b

`Hgannotate` improvements. * `Hgwannotate` opens a wide/verbose version of annotations. * Both commands can take a filename to open first.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 23 Jul 2014 21:39:41 -0700
parents 27d5d85ab918
children 1ea783dd06dd
files doc/lawrencium.txt plugin/lawrencium.vim
diffstat 2 files changed, 47 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/doc/lawrencium.txt	Sun Jul 20 21:39:46 2014 -0700
+++ b/doc/lawrencium.txt	Wed Jul 23 21:39:41 2014 -0700
@@ -203,6 +203,28 @@
                         are available in this window.
                         See |lawrencium-annotate-window|.
 
+                                                *:Hgannotate_f*
+:Hgannotate {file}      Same as |:Hgannotate|, but opens {file} first with
+                        |:Hgedit|.
+
+                                                *:Hgannotate!_f*
+:Hgannotate! {file}     Same as |:Hgannotate_f|, but opens {file} with
+                        |:Hgedit!|.
+
+                                                *:Hgwannotate*
+:Hgwannotate            Same as |:Hgannotate|, but runs the command in
+                        `verbose` mode to get full user names and time of day.
+                        This results in a wider annotation column next to the
+                        file (hence the command name: "Hg wide annotate").
+
+                                                *:Hgwannotate_f*
+:Hgwannotate {file}     Same as |:Hgwannotate|, but opens {file} first with
+                        |:Hgedit|.
+
+                                                *:Hgwannotate!_f*
+:Hgwannotate! {file}    Same as |:Hgwannotate_f|, but opens {file} with
+                        |:Hgedit!|.
+
                                                 *:Hgvimgrep*
 :Hgvimgrep              Runs a |:vimgrep| command inside the current
                         repository. The files in which to search can be
--- a/plugin/lawrencium.vim	Sun Jul 20 21:39:46 2014 -0700
+++ b/plugin/lawrencium.vim	Wed Jul 23 21:39:41 2014 -0700
@@ -643,7 +643,12 @@
 
 " Annotate file
 function! s:read_lawrencium_annotate(repo, path_parts, full_path) abort
-    call a:repo.ReadCommandOutput('annotate', '-c', '-n', '-u', '-d', '-q', a:full_path)
+    let l:cmd_args = ['-c', '-n', '-u', '-d', 'q']
+    if a:path_parts['value'] == 'v=1'
+        call insert(l:cmd_args, '-v', 0)
+    endif
+    call add(l:cmd_args, a:full_path)
+    call a:repo.ReadCommandOutput('annotate', l:cmd_args)
 endfunction
 
 " MQ series
@@ -1125,7 +1130,7 @@
     endif
 endfunction
 
-call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :call s:HgEdit(<bang>0, <f-args>)")
+call s:AddMainCommand("-bang -nargs=1 -complete=customlist,s:ListRepoFiles Hgedit :call s:HgEdit(<bang>0, <f-args>)")
 
 " }}}
 
@@ -1668,12 +1673,18 @@
 
 " Hgannotate {{{
 
-function! s:HgAnnotate() abort
+function! s:HgAnnotate(bang, verbose, ...) abort
+    " Open the file to annotate if needed.
+    if a:0 > 0
+        call s:HgEdit(a:bang, a:1)
+    endif
+
     " Get the Lawrencium path for the annotated file.
     let l:path = expand('%:p')
     let l:bufnr = bufnr('%')
     let l:repo = s:hg_repo()
-    let l:annotation_path = l:repo.GetLawrenciumPath(l:path, 'annotate', '')
+    let l:value = a:verbose ? 'v=1' : ''
+    let l:annotation_path = l:repo.GetLawrenciumPath(l:path, 'annotate', l:value)
     
     " Check if we're trying to annotate something with local changes.
     let l:has_local_edits = 0
@@ -1725,9 +1736,14 @@
         syncbind
 
         " Set the correct window width for the annotations.
-        let l:column_count = strlen(matchstr(getline('.'), '[^:]*:')) + g:lawrencium_annotate_width_offset - 1
-        execute "vertical resize " . l:column_count
-        setlocal winfixwidth
+        let l:last_token = match(getline('.'), '\v\d{4}:\s')
+        if l:last_token < 0
+            echoerr "Can't find the end of the annotation columns."
+        else
+            let l:column_count = l:last_token + 4 + g:lawrencium_annotate_width_offset
+            execute "vertical resize " . l:column_count
+            setlocal winfixwidth
+        endif
     endif
 
     " Make the annotate buffer a Lawrencium buffer.
@@ -1781,7 +1797,8 @@
     endif
 endfunction
 
-call s:AddMainCommand("Hgannotate :call s:HgAnnotate()")
+call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgannotate :call s:HgAnnotate(<bang>0, 0, <f-args>)")
+call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgwannotate :call s:HgAnnotate(<bang>0, 1, <f-args>)")
 
 " }}}