Mercurial > vim-gutentags
comparison autoload/gutentags/ctags.vim @ 62:106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
When using Gutentags with a cache directory put all the tag files in, the
`ctags` executable will be run against absolute paths, because the output paths
in the tag file will also need to be absolute in order to make it possible to
open them in an editor. This means exclude rules need to be run against
absolute paths too, so we make those rules absolute and store the result in a
temporary file that we pass to `ctags` as the real options file.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 15 Jul 2015 22:46:49 -0700 |
parents | 9e768b83d701 |
children | 6900302dae0b |
comparison
equal
deleted
inserted
replaced
61:735fce322ae4 | 62:106757c129cb |
---|---|
10 let g:gutentags_tagfile = 'tags' | 10 let g:gutentags_tagfile = 'tags' |
11 endif | 11 endif |
12 | 12 |
13 if !exists('g:gutentags_auto_set_tags') | 13 if !exists('g:gutentags_auto_set_tags') |
14 let g:gutentags_auto_set_tags = 1 | 14 let g:gutentags_auto_set_tags = 1 |
15 endif | |
16 | |
17 if !exists('g:gutentags_ctags_options_file') | |
18 let g:gutentags_ctags_options_file = '.gutctags' | |
15 endif | 19 endif |
16 | 20 |
17 " }}} | 21 " }}} |
18 | 22 |
19 " Gutentags Module Interface {{{ | 23 " Gutentags Module Interface {{{ |
55 let l:cmd .= ' -x ' . '"' . exc . '"' | 59 let l:cmd .= ' -x ' . '"' . exc . '"' |
56 endfor | 60 endfor |
57 if g:gutentags_pause_after_update | 61 if g:gutentags_pause_after_update |
58 let l:cmd .= ' -c' | 62 let l:cmd .= ' -c' |
59 endif | 63 endif |
60 let l:proj_options_file = a:proj_dir . '/.ctags' | 64 let l:proj_options_file = a:proj_dir . '/' . |
65 \g:gutentags_ctags_options_file | |
61 if filereadable(l:proj_options_file) | 66 if filereadable(l:proj_options_file) |
67 let l:proj_options_file = s:process_options_file( | |
68 \a:proj_dir, l:proj_options_file) | |
62 let l:cmd .= ' -o "' . l:proj_options_file . '"' | 69 let l:cmd .= ' -o "' . l:proj_options_file . '"' |
63 endif | 70 endif |
64 if g:gutentags_trace | 71 if g:gutentags_trace |
65 if has('win32') | 72 if has('win32') |
66 let l:cmd .= ' -l "' . a:tags_file . '.log"' | 73 let l:cmd .= ' -l "' . a:tags_file . '.log"' |
97 endtry | 104 endtry |
98 endfunction | 105 endfunction |
99 | 106 |
100 " }}} | 107 " }}} |
101 | 108 |
109 " Utilities {{{ | |
110 | |
111 function! s:process_options_file(proj_dir, path) abort | |
112 if g:gutentags_cache_dir == "" | |
113 " If we're not using a cache directory to store tag files, we can | |
114 " use the options file straight away. | |
115 return a:path | |
116 endif | |
117 | |
118 " See if we need to process the options file. | |
119 let l:do_process = 0 | |
120 let l:proj_dir = gutentags#stripslash(a:proj_dir) | |
121 let l:out_path = gutentags#get_cachefile(l:proj_dir, 'options') | |
122 if !filereadable(l:out_path) | |
123 call gutentags#trace("Processing options file '".a:path."' because ". | |
124 \"it hasn't been processed yet.") | |
125 let l:do_process = 1 | |
126 elseif getftime(a:path) > getftime(l:out_path) | |
127 call gutentags#trace("Processing options file '".a:path."' because ". | |
128 \"it has changed.") | |
129 let l:do_process = 1 | |
130 endif | |
131 if l:do_process == 0 | |
132 " Nothing's changed, return the existing processed version of the | |
133 " options file. | |
134 return l:out_path | |
135 endif | |
136 | |
137 " We have to process the options file. Right now this only means capturing | |
138 " all the 'exclude' rules, and rewrite them to make them absolute. | |
139 " | |
140 " This is because since `ctags` is run with absolute paths (because we | |
141 " want the tag file to be in a cache directory), it will do its path | |
142 " matching with absolute paths too, so the exclude rules need to be | |
143 " absolute. | |
144 let l:lines = readfile(a:path) | |
145 let l:outlines = [] | |
146 for line in l:lines | |
147 let l:exarg = matchend(line, '\v^\-\-exclude=') | |
148 if l:exarg < 0 | |
149 call add(l:outlines, line) | |
150 continue | |
151 endif | |
152 let l:fullp = gutentags#normalizepath(l:proj_dir.'/'. | |
153 \strpart(line, l:exarg + 1)) | |
154 let l:ol = '--exclude='.l:fullp | |
155 call add(l:outlines, l:ol) | |
156 endfor | |
157 | |
158 call writefile(l:outlines, l:out_path) | |
159 return l:out_path | |
160 endfunction | |
161 | |
162 " }}} | |
163 |