Mercurial > vim-gutentags
comparison autoload/gutentags/ctags.vim @ 158:bba76de4371a
Add option to specify that a custom file lister returns absolute paths.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 15 Feb 2017 17:15:00 -0800 |
parents | b178f2251982 |
children | 1b980f5071a0 |
comparison
equal
deleted
inserted
replaced
157:6b00f4383708 | 158:bba76de4371a |
---|---|
37 | 37 |
38 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort | 38 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort |
39 " Get to the tags file directory because ctags is finicky about | 39 " Get to the tags file directory because ctags is finicky about |
40 " these things. | 40 " these things. |
41 let l:prev_cwd = getcwd() | 41 let l:prev_cwd = getcwd() |
42 execute "chdir " . fnameescape(a:proj_dir) | |
43 | |
42 let l:tags_file_exists = filereadable(a:tags_file) | 44 let l:tags_file_exists = filereadable(a:tags_file) |
43 | 45 |
44 if l:tags_file_exists && g:gutentags_ctags_check_tagfile | 46 if l:tags_file_exists && g:gutentags_ctags_check_tagfile |
45 let l:first_lines = readfile(a:tags_file, '', 1) | 47 let l:first_lines = readfile(a:tags_file, '', 1) |
46 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0 | 48 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0 |
52 endif | 54 endif |
53 endif | 55 endif |
54 | 56 |
55 if empty(g:gutentags_cache_dir) | 57 if empty(g:gutentags_cache_dir) |
56 " If we don't use the cache directory, let's just use the tag filename | 58 " If we don't use the cache directory, let's just use the tag filename |
57 " as specified by the user, and change the working directory to the | 59 " as specified by the user, since it's relative to the project root, |
58 " project root. | 60 " and we are already `chdir`'d into it. |
59 " Note that if we don't do this and pass a full path, `ctags` gets | 61 " Note that if we don't do this and pass a full path, `ctags` gets |
60 " confused if the paths have spaces -- but not if you're *in* the | 62 " confused if the paths have spaces -- but not if you're *in* the |
61 " root directory. | 63 " root directory. |
62 let l:actual_proj_dir = '.' | 64 let l:actual_proj_dir = '.' |
63 let l:actual_tags_file = g:gutentags_tagfile | 65 let l:actual_tags_file = g:gutentags_tagfile |
64 execute "chdir " . fnameescape(a:proj_dir) | |
65 else | 66 else |
66 " else: the tags file goes in a cache directory, so we need to specify | 67 " else: the tags file goes in a cache directory, so we need to specify |
67 " all the paths absolutely for `ctags` to do its job correctly. | 68 " all the paths absolutely for `ctags` to do its job correctly. |
68 let l:actual_proj_dir = a:proj_dir | 69 let l:actual_proj_dir = a:proj_dir |
69 let l:actual_tags_file = a:tags_file | 70 let l:actual_tags_file = a:tags_file |
82 endif | 83 endif |
83 let l:cmd .= ' -s "' . l:cur_file_path . '"' | 84 let l:cmd .= ' -s "' . l:cur_file_path . '"' |
84 else | 85 else |
85 let l:file_list_cmd = gutentags#get_project_file_list_cmd(l:actual_proj_dir) | 86 let l:file_list_cmd = gutentags#get_project_file_list_cmd(l:actual_proj_dir) |
86 if !empty(l:file_list_cmd) | 87 if !empty(l:file_list_cmd) |
88 let l:suffopts = matchstrpos(l:file_list_cmd, '///') | |
89 if l:suffopts[1] > 0 | |
90 let l:suffoptstr = strpart(l:file_list_cmd, l:suffopts[2]) | |
91 let l:file_list_cmd = strpart(l:file_list_cmd, 0, l:suffopts[1]) | |
92 if l:suffoptstr == 'absolute' | |
93 let l:cmd .= ' -A' | |
94 endif | |
95 endif | |
87 let l:cmd .= ' -L ' . '"' . l:file_list_cmd. '"' | 96 let l:cmd .= ' -L ' . '"' . l:file_list_cmd. '"' |
88 endif | 97 endif |
89 endif | 98 endif |
90 if empty(get(l:, 'file_list_cmd', '')) | 99 if empty(get(l:, 'file_list_cmd', '')) |
91 " Pass the Gutentags recursive options file before the project | 100 " Pass the Gutentags recursive options file before the project |