Skip to content

Commit

Permalink
Change the per-project option file to be .gutctags and process it f…
Browse files Browse the repository at this point in the history
…irst.

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.
  • Loading branch information
ludovicchabant committed Jul 16, 2015
1 parent 8ae5b65 commit 3e2a65a
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion autoload/gutentags/ctags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ if !exists('g:gutentags_auto_set_tags')
let g:gutentags_auto_set_tags = 1
endif

if !exists('g:gutentags_ctags_options_file')
let g:gutentags_ctags_options_file = '.gutctags'
endif

" }}}

" Gutentags Module Interface {{{
Expand Down Expand Up @@ -57,8 +61,11 @@ function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
if g:gutentags_pause_after_update
let l:cmd .= ' -c'
endif
let l:proj_options_file = a:proj_dir . '/.ctags'
let l:proj_options_file = a:proj_dir . '/' .
\g:gutentags_ctags_options_file
if filereadable(l:proj_options_file)
let l:proj_options_file = s:process_options_file(
\a:proj_dir, l:proj_options_file)
let l:cmd .= ' -o "' . l:proj_options_file . '"'
endif
if g:gutentags_trace
Expand Down Expand Up @@ -99,3 +106,58 @@ endfunction

" }}}

" Utilities {{{

function! s:process_options_file(proj_dir, path) abort
if g:gutentags_cache_dir == ""
" If we're not using a cache directory to store tag files, we can
" use the options file straight away.
return a:path
endif

" See if we need to process the options file.
let l:do_process = 0
let l:proj_dir = gutentags#stripslash(a:proj_dir)
let l:out_path = gutentags#get_cachefile(l:proj_dir, 'options')
if !filereadable(l:out_path)
call gutentags#trace("Processing options file '".a:path."' because ".
\"it hasn't been processed yet.")
let l:do_process = 1
elseif getftime(a:path) > getftime(l:out_path)
call gutentags#trace("Processing options file '".a:path."' because ".
\"it has changed.")
let l:do_process = 1
endif
if l:do_process == 0
" Nothing's changed, return the existing processed version of the
" options file.
return l:out_path
endif

" We have to process the options file. Right now this only means capturing
" all the 'exclude' rules, and rewrite them to make them absolute.
"
" This is because since `ctags` is run with absolute paths (because we
" want the tag file to be in a cache directory), it will do its path
" matching with absolute paths too, so the exclude rules need to be
" absolute.
let l:lines = readfile(a:path)
let l:outlines = []
for line in l:lines
let l:exarg = matchend(line, '\v^\-\-exclude=')
if l:exarg < 0
call add(l:outlines, line)
continue
endif
let l:fullp = gutentags#normalizepath(l:proj_dir.'/'.
\strpart(line, l:exarg + 1))
let l:ol = '--exclude='.l:fullp
call add(l:outlines, l:ol)
endfor

call writefile(l:outlines, l:out_path)
return l:out_path
endfunction

" }}}

0 comments on commit 3e2a65a

Please sign in to comment.