comparison plugin/autotags.vim @ 14:b8f23bf7b20f

Ability to (re)generate tags when opening a new project.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 29 Jul 2014 16:10:50 -0700
parents 478638833c3b
children b557282af215
comparison
equal deleted inserted replaced
13:16fe881b8d75 14:b8f23bf7b20f
49 endif 49 endif
50 let g:autotags_project_root += ['.git', '.hg', '.bzr', '_darcs'] 50 let g:autotags_project_root += ['.git', '.hg', '.bzr', '_darcs']
51 51
52 if !exists('g:autotags_exclude') 52 if !exists('g:autotags_exclude')
53 let g:autotags_exclude = [] 53 let g:autotags_exclude = []
54 endif
55
56 if !exists('g:autotags_generate_on_new')
57 let g:autotags_generate_on_new = 1
54 endif 58 endif
55 59
56 if !exists('g:autotags_generate_on_missing') 60 if !exists('g:autotags_generate_on_missing')
57 let g:autotags_generate_on_missing = 1 61 let g:autotags_generate_on_missing = 1
58 endif 62 endif
109 endfunction 113 endfunction
110 114
111 " }}} 115 " }}}
112 116
113 " Autotags Setup {{{ 117 " Autotags Setup {{{
118
119 let s:known_tagfiles = []
114 120
115 " Finds the tag file path for the given current directory 121 " Finds the tag file path for the given current directory
116 " (typically the directory of the file being edited) 122 " (typically the directory of the file being edited)
117 function! s:get_tagfile_for(path) abort 123 function! s:get_tagfile_for(path) abort
118 let l:path = s:stripslash(a:path) 124 let l:path = s:stripslash(a:path)
138 if exists('b:autotags_file') && !g:autotags_debug 144 if exists('b:autotags_file') && !g:autotags_debug
139 " This buffer already has autotags support. 145 " This buffer already has autotags support.
140 return 146 return
141 endif 147 endif
142 148
143 " Try and file what tags file we should manage. 149 " Try and find what tags file we should manage.
144 call s:trace("Scanning buffer '" . bufname('%') . "' for autotags setup...") 150 call s:trace("Scanning buffer '" . bufname('%') . "' for autotags setup...")
145 try 151 try
146 let b:autotags_file = s:get_tagfile_for(expand('%:h')) 152 let b:autotags_file = s:get_tagfile_for(expand('%:h'))
147 catch /^autotags\:/ 153 catch /^autotags\:/
148 call s:trace("Can't figure out what tag file to use... no autotags support.") 154 call s:trace("Can't figure out what tag file to use... no autotags support.")
165 execute 'augroup end' 171 execute 'augroup end'
166 172
167 " Miscellaneous commands. 173 " Miscellaneous commands.
168 command! -buffer -bang AutotagsUpdate :call s:manual_update_tags(<bang>0) 174 command! -buffer -bang AutotagsUpdate :call s:manual_update_tags(<bang>0)
169 175
170 " If the tags file doesn't exist, start generating it now. 176 " Add this tags file to the known tags files if it wasn't there already.
171 if g:autotags_generate_on_missing && !filereadable(b:autotags_file) 177 let l:found = index(s:known_tagfiles, b:autotags_file)
172 call s:trace("Generating missing tags file: " . b:autotags_file) 178 if l:found < 0
173 call s:update_tags(1, 0) 179 call add(s:known_tagfiles, b:autotags_file)
180
181 " Generate this new file depending on settings and stuff.
182 if g:autotags_generate_on_missing && !filereadable(b:autotags_file)
183 call s:trace("Generating missing tags file: " . b:autotags_file)
184 call s:update_tags(1, 0)
185 elseif g:autotags_generate_on_new
186 call s:trace("Generating tags file: " . b:autotags_file)
187 call s:update_tags(1, 0)
188 endif
174 endif 189 endif
175 endfunction 190 endfunction
176 191
177 augroup autotags_detect 192 augroup autotags_detect
178 autocmd! 193 autocmd!