Commits

Ludovic Chabant committed a63ec81

Added `qnew` and `qrefresh` commands to the `Hgstatus` window.

  • Participants
  • Parent commits 42c40b8

Comments (0)

Files changed (2)

File doc/lawrencium.txt

                         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:
 

File plugin/lawrencium.vim

     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>)
  1. Mihai Sucan

    Why not also alias these two commands as follows:

    • Hgstatusqnew to Hgqnew
    • Hgstatusqrefresh to Hgqrefresh

    The status word is superfluous considering cases where users come from the terminal and they already have the habit to type hg qseries and hg qrefresh. At least, I do that.

    Thanks!

    1. Ludovic Chabant author

      The reasoning was to make all commands that are available only in the "status" window start with Hgstatus. So the Hgstatusqnew would create a new MQ patch with the currently mentioned files.

      This is by opposition to another command that could be called Hgqnew, which would create a new MQ patch with the current buffer or something.

      1. Mihai Sucan

        I see your point, but that brings me to another gripe of mine with lawrencium. ;)

        Hgdiff gives me the vim diff for the current buffer file. Ouch. I'm used to hg diff giving me the diff for all files, as a patch, not as a reall diff between the current file and the committed file. Browsing through changes in actual diff format is easier for me and I can see what I did overall. Why not make Hgdiff behave as hg diff? I can see why you made Hgdiff to show the vim diff for the current buffer file - it makes sense for a big patch, for a lot of changes - you want to clearly see the differences and to focus on the file. Just I'd like that to not be the default. For the current behavior you could allow Hgdiff ..

        I tried using Hg[!] diff but colors are lost. Maybe you could open a buffer and automatically set ft=diff for Hg diff and Hg qdiff. I also use qdiff a lot.

        Going back to qnew: in hg I'm used to hg qnew making a new patch with the currently changed files (all files) - like Hgstatusqnew. If you propose that Hgqnew only adds the current buffer to the new patch ... ouch, that would be the equivalent of Hgdiff and it would break user's expectations.

        My main point here: make it easy for existing hg users to use your vim script, and offer "perks" - cool stuff that they don't usually have. Hgstatus is exactly that - it doesn't break habits and it is very nice to use - easy add/remove files.

        Thanks!

        1. Ludovic Chabant author

          I pushed a new version of Lawrencium that adds the ability to set the file type (syntax highlighting) for Hg! buffers based on the command. By default, it will set a nice syntax for Hg diff and Hg glog. I realized I forgot to add it for Hg qdiff but you can set it yourself too (see the help on global settings).

          I'll take your other remarks into consideration while coming up with MQ integration.

 
     " Add some handy mappings.
     if g:lawrencium_define_mappings
     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]