Mercurial > vim-gutentags
comparison autoload/gutentags/ctags.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 |
---|---|
35 endfunction | 35 endfunction |
36 | 36 |
37 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort | 37 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort |
38 " Get to the tags file directory because ctags is finicky about | 38 " Get to the tags file directory because ctags is finicky about |
39 " these things. | 39 " these things. |
40 let l:prev_cwd = getcwd() | 40 let l:prev_cwd = gutentags#pwd() |
41 let l:tags_file_exists = filereadable(a:tags_file) | 41 let l:tags_file_exists = filereadable(a:tags_file) |
42 | 42 |
43 if l:tags_file_exists && g:gutentags_ctags_check_tagfile | 43 if l:tags_file_exists && g:gutentags_ctags_check_tagfile |
44 let l:first_lines = readfile(a:tags_file, '', 1) | 44 let l:first_lines = readfile(a:tags_file, '', 1) |
45 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0 | 45 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0 |
57 " Note that if we don't do this and pass a full path, `ctags` gets | 57 " Note that if we don't do this and pass a full path, `ctags` gets |
58 " confused if the paths have spaces -- but not if you're *in* the | 58 " confused if the paths have spaces -- but not if you're *in* the |
59 " root directory. | 59 " root directory. |
60 let l:actual_proj_dir = '.' | 60 let l:actual_proj_dir = '.' |
61 let l:actual_tags_file = g:gutentags_tagfile | 61 let l:actual_tags_file = g:gutentags_tagfile |
62 execute "chdir " . fnameescape(a:proj_dir) | 62 call gutentags#chdir(fnameescape(a:proj_dir)) |
63 else | 63 else |
64 " else: the tags file goes in a cache directory, so we need to specify | 64 " else: the tags file goes in a cache directory, so we need to specify |
65 " all the paths absolutely for `ctags` to do its job correctly. | 65 " all the paths absolutely for `ctags` to do its job correctly. |
66 let l:actual_proj_dir = a:proj_dir | 66 let l:actual_proj_dir = a:proj_dir |
67 let l:actual_tags_file = a:tags_file | 67 let l:actual_tags_file = a:tags_file |
119 endif | 119 endif |
120 endif | 120 endif |
121 let l:cmd .= gutentags#get_execute_cmd_suffix() | 121 let l:cmd .= gutentags#get_execute_cmd_suffix() |
122 | 122 |
123 call gutentags#trace("Running: " . l:cmd) | 123 call gutentags#trace("Running: " . l:cmd) |
124 call gutentags#trace("In: " . getcwd()) | 124 call gutentags#trace("In: " . gutentags#pwd()) |
125 if !g:gutentags_fake | 125 if !g:gutentags_fake |
126 " Run the background process. | 126 " Run the background process. |
127 if !g:gutentags_trace | 127 if !g:gutentags_trace |
128 silent execute l:cmd | 128 silent execute l:cmd |
129 else | 129 else |
137 call gutentags#trace("(fake... not actually running)") | 137 call gutentags#trace("(fake... not actually running)") |
138 endif | 138 endif |
139 call gutentags#trace("") | 139 call gutentags#trace("") |
140 finally | 140 finally |
141 " Restore the previous working directory. | 141 " Restore the previous working directory. |
142 execute "chdir " . fnameescape(l:prev_cwd) | 142 call gutentags#chdir(fnameescape(l:prev_cwd)) |
143 endtry | 143 endtry |
144 endfunction | 144 endfunction |
145 | 145 |
146 " }}} | 146 " }}} |
147 | 147 |