changeset 43:fc20a265551d

Added auto cd'ing into the repo root for `:Hg`. This can be disabled with the `lawrencium_auto_cd` global.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 14 Aug 2012 22:26:59 -0700
parents 2ab1b802c070
children 95f8e7cb5ca2
files doc/lawrencium.txt plugin/lawrencium.vim
diffstat 2 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/doc/lawrencium.txt	Tue Aug 14 21:49:58 2012 -0700
+++ b/doc/lawrencium.txt	Tue Aug 14 22:26:59 2012 -0700
@@ -37,6 +37,11 @@
                         specified with the root of the repository the current
                         file belongs to, and it will auto-complete any
                         standard command or option.
+                        
+                        Also, unless the `lawrencium_auto_cd` global is set to
+                        `0`, it will temporarily set the current directory to be
+                        the root of the repository so that auto-completed
+                        filenames work out of the box.
 
                                                 *:Hg!*
 :Hg! {args}             Like |:Hg|, but the output of the command is placed in
--- a/plugin/lawrencium.vim	Tue Aug 14 21:49:58 2012 -0700
+++ b/plugin/lawrencium.vim	Tue Aug 14 22:26:59 2012 -0700
@@ -20,6 +20,10 @@
     let g:lawrencium_hg_executable = 'hg'
 endif
 
+if !exists('g:lawrencium_auto_cd')
+    let g:lawrencium_auto_cd = 1
+endif
+
 if !exists('g:lawrencium_trace')
     let g:lawrencium_trace = 0
 endif
@@ -257,7 +261,15 @@
 
 function! s:Hg(bang, ...) abort
     let l:repo = s:hg_repo()
+    if g:lawrencium_auto_cd:
+        " Temporary set the current directory to the root of the repo
+        " to make auto-completed paths work magically.
+        execute 'cd! ' . l:repo.root_dir
+    endif
     let l:output = call(l:repo.RunCommand, a:000, l:repo)
+    if g:lawrencium_auto_cd:
+        execute 'cd! -'
+    endif
     if a:bang
         " Open the output of the command in a temp file.
         let l:temp_file = s:tempname('hg-output-', '.txt')