changeset 169:95afd985a4c3

Merge pull request #97 from GitHub.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 19 Feb 2017 20:00:13 -0800
parents 34c57ad6eb45 (current diff) e59321cbaff7 (diff)
children 18df731b1563
files autoload/gutentags.vim autoload/gutentags/ctags.vim
diffstat 3 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/gutentags.vim	Sat Feb 18 21:57:52 2017 -0800
+++ b/autoload/gutentags.vim	Sun Feb 19 20:00:13 2017 -0800
@@ -2,6 +2,23 @@
 
 " Utilities {{{
 
+function! gutentags#pwd()
+  if has('nvim')
+    return haslocaldir() ? getcwd(0, 0) : haslocaldir(-1, 0) ? getcwd(-1, 0) : getcwd()
+  else
+    return haslocaldir() ? getcwd(0, 0) : getcwd()
+  endif
+endfunction
+
+function! gutentags#chdir(path)
+  if has('nvim')
+    let chdir = haslocaldir() ? 'lcd' : haslocaldir(-1, 0) ? 'tcd' : 'cd'
+  else
+    let chdir = haslocaldir() ? 'lcd' : 'cd'
+  endif
+  execute chdir a:path
+endfunction
+
 " Throw an exception message.
 function! gutentags#throw(message)
     throw "gutentags: " . a:message
@@ -384,8 +401,8 @@
     " Switch to the project root to make the command line smaller, and make
     " it possible to get the relative path of the filename to parse if we're
     " doing an incremental update.
-    let l:prev_cwd = getcwd()
-    execute "chdir " . fnameescape(l:proj_dir)
+    let l:prev_cwd = gutentags#pwd()
+    call gutentags#chdir(fnameescape(l:proj_dir))
     try
         call call("gutentags#".a:module."#generate",
                     \[l:proj_dir, l:tags_file, a:write_mode])
@@ -394,7 +411,7 @@
         echom v:exception
     finally
         " Restore the current directory...
-        execute "chdir " . fnameescape(l:prev_cwd)
+        call gutentags#chdir(fnameescape(l:prev_cwd))
     endtry
 endfunction
 
--- a/autoload/gutentags/cscope.vim	Sat Feb 18 21:57:52 2017 -0800
+++ b/autoload/gutentags/cscope.vim	Sun Feb 19 20:00:13 2017 -0800
@@ -64,7 +64,7 @@
     let l:cmd .= gutentags#get_execute_cmd_suffix()
 
     call gutentags#trace("Running: " . l:cmd)
-    call gutentags#trace("In:      " . getcwd())
+    call gutentags#trace("In:      " . gutentags#pwd())
     if !g:gutentags_fake
         if !(has('nvim') && exists('*jobwait'))
             if !g:gutentags_trace
--- a/autoload/gutentags/ctags.vim	Sat Feb 18 21:57:52 2017 -0800
+++ b/autoload/gutentags/ctags.vim	Sun Feb 19 20:00:13 2017 -0800
@@ -91,6 +91,7 @@
         " directory, for some reason...
         let l:actual_proj_dir = '.'
         let l:actual_tags_file = fnamemodify(a:tags_file, ':.')
+        call gutentags#chdir(fnameescape(a:proj_dir))
     else
         " else: the tags file goes in a cache directory, so we need to specify
         " all the paths absolutely for `ctags` to do its job correctly.
@@ -168,7 +169,7 @@
         let l:cmd .= gutentags#get_execute_cmd_suffix()
 
         call gutentags#trace("Running: " . l:cmd)
-        call gutentags#trace("In:      " . getcwd())
+        call gutentags#trace("In:      " . gutentags#pwd())
         if !g:gutentags_fake
             " Run the background process.
             if !g:gutentags_trace
@@ -186,7 +187,7 @@
         call gutentags#trace("")
     finally
         " Restore the previous working directory.
-        execute "chdir " . fnameescape(l:prev_cwd)
+        call gutentags#chdir(fnameescape(l:prev_cwd))
     endtry
 endfunction