changeset 85:ac2c226f1bac

Merge pull request #1 from shaneharper/fix_blank_line_appended_to_hg_output Fix: remove blank line added by HgRepo.ReadCommandOutput().
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 20 Apr 2014 20:30:01 -0700
parents a383a816d975 (current diff) b82babe7fdf8 (diff)
children 685dfc4b5862
files
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugin/lawrencium.vim	Fri Mar 07 00:42:06 2014 -0800
+++ b/plugin/lawrencium.vim	Sun Apr 20 20:30:01 2014 -0700
@@ -345,13 +345,22 @@
     return system(l:hg_command)
 endfunction
 
-" Runs a Mercurial command in the repo and read it output into the current
+" Runs a Mercurial command in the repo and reads its output into the current
 " buffer.
 function! s:HgRepo.ReadCommandOutput(command, ...) abort
+    function! s:PutOutputIntoBuffer(command_line)
+        let l:was_buffer_empty = (line('$') == 1 && getline(1) == '')
+        execute '0read!' . escape(a:command_line, '%#\')
+        if l:was_buffer_empty  " (Always true?)
+            " '0read' inserts before the cursor, leaving a blank line which needs to be deleted:
+            normal! Gdd
+        endif
+    endfunction
+
     let l:all_args = [a:command] + a:000
     let l:hg_command = call(self['GetCommand'], l:all_args, self)
     call s:trace("Running Mercurial command: " . l:hg_command)
-    execute '0read !' . escape(l:hg_command, '%#\')
+    call s:PutOutputIntoBuffer(l:hg_command)
 endfunction
 
 " Build a Lawrencium path for the given file and action.