Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new flag to always generate tags as absolute. #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions autoload/gutentags/ctags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,23 @@ function! gutentags#ctags#generate(proj_dir, tags_file, gen_opts) abort
endif
endif

" Get a tags file path relative to the current directory, which
" happens to be the project root in this case.
" Since the given tags file path is absolute, and since Vim won't
" change the path if it is not inside the current directory, we
" know that the tags file is "local" (i.e. inside the project)
" if the path was shortened (an absolute path will always be
" longer than a true relative path).
let l:tags_file_relative = fnamemodify(a:tags_file, ':.')
let l:tags_file_is_local = len(l:tags_file_relative) < len(a:tags_file)
let l:use_tag_relative_opt = 0

if (g:gutentags_always_absolute)
let l:tags_file_relative = a:tags_file
let l:tags_file_is_local = 2 > 1 "True
let l:use_tag_relative_opt = 0
else
" Get a tags file path relative to the current directory, which
" happens to be the project root in this case.
" Since the given tags file path is absolute, and since Vim won't
" change the path if it is not inside the current directory, we
" know that the tags file is "local" (i.e. inside the project)
" if the path was shortened (an absolute path will always be
" longer than a true relative path).
let l:tags_file_relative = fnamemodify(a:tags_file, ':.')
let l:tags_file_is_local = len(l:tags_file_relative) < len(a:tags_file)
let l:use_tag_relative_opt = 0
endif

if empty(g:gutentags_cache_dir) && l:tags_file_is_local
" If we don't use the cache directory, we can pass relative paths
Expand Down Expand Up @@ -169,8 +176,12 @@ function! gutentags#ctags#generate(proj_dir, tags_file, gen_opts) abort
" Omit --recursive if this project uses a file list command.
let l:cmd += ['-o', '"' . gutentags#get_res_file('ctags_recursive.options') . '"']
endif
if l:use_tag_relative_opt
let l:cmd += ['-O', shellescape("--tag-relative=yes")]
if (g:gutentags_always_absolute)
let l:cmd += ['-O', shellescape("--tag-relative=never")]
else
if l:use_tag_relative_opt
let l:cmd += ['-O', shellescape("--tag-relative=yes")]
endif
endif
for extra_arg in g:gutentags_ctags_extra_args
let l:cmd += ['-O', shellescape(extra_arg)]
Expand Down
6 changes: 6 additions & 0 deletions doc/gutentags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ g:gutentags_project_root_finder
behaviour by calling
`gutentags#default_get_project_root`.

*gutentags_always_absolute*
g:gutentags_always_absolute
Always resolve tags file as absolute, even if tags
file is local.
Defaults to 0.

*gutentags_generate_on_missing*
g:gutentags_generate_on_missing
If set to 1, Gutentags will start generating an initial
Expand Down
1 change: 1 addition & 0 deletions plugin/gutentags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if g:gutentags_add_default_project_roots
endif

let g:gutentags_project_root_finder = get(g:, 'gutentags_project_root_finder', '')
let g:gutentags_always_absolute = get(g:, 'gutentags_always_absolute', 0)

let g:gutentags_project_info = get(g:, 'gutentags_project_info', [])
call add(g:gutentags_project_info, {'type': 'python', 'file': 'setup.py'})
Expand Down