comparison 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
comparison
equal deleted inserted replaced
140:95092f4fbc4b 168:e59321cbaff7
1 " gutentags.vim - Automatic ctags management for Vim 1 " gutentags.vim - Automatic ctags management for Vim
2 2
3 " Utilities {{{ 3 " Utilities {{{
4
5 function! gutentags#pwd()
6 if has('nvim')
7 return haslocaldir() ? getcwd(0, 0) : haslocaldir(-1, 0) ? getcwd(-1, 0) : getcwd()
8 else
9 return haslocaldir() ? getcwd(0, 0) : getcwd()
10 endif
11 endfunction
12
13 function! gutentags#chdir(path)
14 if has('nvim')
15 let chdir = haslocaldir() ? 'lcd' : haslocaldir(-1, 0) ? 'tcd' : 'cd'
16 else
17 let chdir = haslocaldir() ? 'lcd' : 'cd'
18 endif
19 execute chdir a:path
20 endfunction
4 21
5 " Throw an exception message. 22 " Throw an exception message.
6 function! gutentags#throw(message) 23 function! gutentags#throw(message)
7 let v:errmsg = "gutentags: " . a:message 24 let v:errmsg = "gutentags: " . a:message
8 throw v:errmsg 25 throw v:errmsg
360 endif 377 endif
361 378
362 " Switch to the project root to make the command line smaller, and make 379 " Switch to the project root to make the command line smaller, and make
363 " it possible to get the relative path of the filename to parse if we're 380 " it possible to get the relative path of the filename to parse if we're
364 " doing an incremental update. 381 " doing an incremental update.
365 let l:prev_cwd = getcwd() 382 let l:prev_cwd = gutentags#pwd()
366 execute "chdir " . fnameescape(l:proj_dir) 383 call gutentags#chdir(fnameescape(l:proj_dir))
367 try 384 try
368 call call("gutentags#".a:module."#generate", 385 call call("gutentags#".a:module."#generate",
369 \[l:proj_dir, l:tags_file, a:write_mode]) 386 \[l:proj_dir, l:tags_file, a:write_mode])
370 catch /^gutentags\:/ 387 catch /^gutentags\:/
371 echom "Error while generating ".a:module." file:" 388 echom "Error while generating ".a:module." file:"
372 echom v:exception 389 echom v:exception
373 finally 390 finally
374 " Restore the current directory... 391 " Restore the current directory...
375 execute "chdir " . fnameescape(l:prev_cwd) 392 call gutentags#chdir(fnameescape(l:prev_cwd))
376 endtry 393 endtry
377 endfunction 394 endfunction
378 395
379 " }}} 396 " }}}
380 397