diff autoload/gutentags.vim @ 168:e59321cbaff7

Use scope-local functions This avoids overriding local cwd settings, as vim allows `lcd` for window-local working directory and neovim supports additionally `tcd` for tab-local working directory.
author Henry Kupty <hkupty@gmail.com>
date Mon, 10 Oct 2016 19:04:05 -0300
parents 286e5b3095d0
children 95afd985a4c3
line wrap: on
line diff
--- a/autoload/gutentags.vim	Thu Sep 22 21:06:58 2016 -0700
+++ b/autoload/gutentags.vim	Mon Oct 10 19:04:05 2016 -0300
@@ -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)
     let v:errmsg = "gutentags: " . a:message
@@ -362,8 +379,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])
@@ -372,7 +389,7 @@
         echom v:exception
     finally
         " Restore the current directory...
-        execute "chdir " . fnameescape(l:prev_cwd)
+        call gutentags#chdir(fnameescape(l:prev_cwd))
     endtry
 endfunction