# HG changeset patch # User Henry Kupty # Date 1476137045 10800 # Node ID e59321cbaff71a67d78ea52307284a2d5b746ed6 # Parent 95092f4fbc4b61812619c4f6bb8c5e77904787ee 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. diff -r 95092f4fbc4b -r e59321cbaff7 autoload/gutentags.vim --- 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 diff -r 95092f4fbc4b -r e59321cbaff7 autoload/gutentags/cscope.vim --- a/autoload/gutentags/cscope.vim Thu Sep 22 21:06:58 2016 -0700 +++ b/autoload/gutentags/cscope.vim Mon Oct 10 19:04:05 2016 -0300 @@ -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 diff -r 95092f4fbc4b -r e59321cbaff7 autoload/gutentags/ctags.vim --- a/autoload/gutentags/ctags.vim Thu Sep 22 21:06:58 2016 -0700 +++ b/autoload/gutentags/ctags.vim Mon Oct 10 19:04:05 2016 -0300 @@ -37,7 +37,7 @@ function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort " Get to the tags file directory because ctags is finicky about " these things. - let l:prev_cwd = getcwd() + let l:prev_cwd = gutentags#pwd() let l:tags_file_exists = filereadable(a:tags_file) if l:tags_file_exists && g:gutentags_ctags_check_tagfile @@ -59,7 +59,7 @@ " root directory. let l:actual_proj_dir = '.' let l:actual_tags_file = g:gutentags_tagfile - execute "chdir " . fnameescape(a:proj_dir) + 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. @@ -121,7 +121,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 @@ -139,7 +139,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