changeset 40:a63ec818ab21

Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 30 Mar 2012 15:29:10 -0700
parents 42c40b8144f8
children decbefcf74db
files doc/lawrencium.txt plugin/lawrencium.vim
diffstat 2 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/doc/lawrencium.txt	Thu Feb 23 21:25:48 2012 -0800
+++ b/doc/lawrencium.txt	Fri Mar 30 15:29:10 2012 -0700
@@ -141,6 +141,19 @@
                         again.
                         Mapped to <C-R>.
 
+                                                *:Hgstatusqnew*
+:Hgstatusqnew {patch} {message}.
+                        If you have the 'mq' extension enabled, creates a new
+                        patch with the file currently mentioned in the buffer,
+                        or in the current selection. You must give a patch name,
+                        and may optionally write a commit message for the patch
+                        (without surrounding quotes).
+
+                                                *:Hgstatusqrefresh*
+:Hgstatusqrefresh       If you have the 'mq' extension enabled, refreshes the
+                        current patch with the files currently mentioned in the
+                        buffer, or in the current selection.
+
                                                 *lawrencium-status-mappings*
 A few other mappings are available in the status window:
 
--- a/plugin/lawrencium.vim	Thu Feb 23 21:25:48 2012 -0800
+++ b/plugin/lawrencium.vim	Fri Mar 30 15:29:10 2012 -0700
@@ -370,6 +370,8 @@
     command! -buffer -range   Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>)
     command! -buffer -range=% -bang Hgstatuscommit  :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 0)
     command! -buffer -range=% -bang Hgstatusvcommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 1)
+    command! -buffer -range=% -nargs=+ Hgstatusqnew :call s:HgStatus_QNew(<line1>, <line2>, <f-args>)
+    command! -buffer -range=% Hgstatusqrefresh      :call s:HgStatus_QRefresh(<line1>, <line2>)
 
     " Add some handy mappings.
     if g:lawrencium_define_mappings
@@ -463,6 +465,38 @@
     call s:HgDiff('%:p', a:vertical)
 endfunction
 
+function! s:HgStatus_QNew(linestart, lineend, patchname, ...) abort
+    " Get the selected filenames.
+    let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
+    if len(l:filenames) == 0
+        call s:error("No files in selection or file to create patch.")
+    endif
+
+    " Run `Hg qnew` on those paths.
+    let l:repo = s:hg_repo()
+    call insert(l:filenames, a:patchname, 0)
+    if a:0 > 0
+        call insert(l:filenames, '-m', 0)
+        let l:message = '"' . join(a:000, ' ') . '"'
+        call insert(l:filenames, l:message, 1)
+    endif
+    call l:repo.RunCommand('qnew', l:filenames)
+endfunction
+
+function! s:HgStatus_QRefresh(linestart, lineend) abort
+    " Get the selected filenames.
+    let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
+    if len(l:filenames) == 0
+        call s:error("No files in selection or file to refresh the patch.")
+    endif
+
+    " Run `Hg qrefresh` on those paths.
+    let l:repo = s:hg_repo()
+    call insert(l:filenames, '-s', 0)
+    call l:repo.RunCommand('qrefresh', l:filenames)
+endfunction
+
+
 function! s:HgStatus_GetSelectedFile() abort
     let l:filenames = s:HgStatus_GetSelectedFiles()
     return l:filenames[0]