annotate autoload/gutentags/ctags.vim @ 254:52be4cf89810

Don't complain when the job gets killed when Vim exits. This happens on Neovim, where the jobs seem to get killed before Vim exits, and so Gutentags has enough time to print a warning.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 26 Oct 2019 00:40:18 -0700
parents ec292bfbd633
children 950647497ae5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 " Ctags module for Gutentags
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 " Global Options {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
119
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
5 let g:gutentags_ctags_executable = get(g:, 'gutentags_ctags_executable', 'ctags')
165
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
6 let g:gutentags_ctags_tagfile = get(g:, 'gutentags_ctags_tagfile', 'tags')
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
7 let g:gutentags_ctags_auto_set_tags = get(g:, 'gutentags_ctags_auto_set_tags', 1)
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
8
119
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
9 let g:gutentags_ctags_options_file = get(g:, 'gutentags_ctags_options_file', '.gutctags')
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
10 let g:gutentags_ctags_check_tagfile = get(g:, 'gutentags_ctags_check_tagfile', 0)
160
1b980f5071a0 Post-processing for `tags` files, extra args for `ctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 158
diff changeset
11 let g:gutentags_ctags_extra_args = get(g:, 'gutentags_ctags_extra_args', [])
1b980f5071a0 Post-processing for `tags` files, extra args for `ctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 158
diff changeset
12 let g:gutentags_ctags_post_process_cmd = get(g:, 'gutentags_ctags_post_process_cmd', '')
86
7872cc9bbc2d Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents: 84
diff changeset
13
165
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
14 let g:gutentags_ctags_exclude = get(g:, 'gutentags_ctags_exclude', [])
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
15 let g:gutentags_ctags_exclude_wildignore = get(g:, 'gutentags_ctags_exclude_wildignore', 1)
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
16
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
17 " Backwards compatibility.
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
18 function! s:_handleOldOptions() abort
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
19 let l:renamed_options = {
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
20 \'gutentags_exclude': 'gutentags_ctags_exclude',
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
21 \'gutentags_tagfile': 'gutentags_ctags_tagfile',
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
22 \'gutentags_auto_set_tags': 'gutentags_ctags_auto_set_tags'
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
23 \}
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
24 for key in keys(l:renamed_options)
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
25 if exists('g:'.key)
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
26 let newname = l:renamed_options[key]
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
27 echom "gutentags: Option 'g:'".key." has been renamed to ".
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
28 \"'g:'".newname." Please update your vimrc."
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
29 let g:[newname] = g:[key]
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
30 endif
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
31 endfor
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
32 endfunction
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
33 call s:_handleOldOptions()
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 " Gutentags Module Interface {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
185
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
38 let s:did_check_exe = 0
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 let s:runner_exe = gutentags#get_plat_file('update_tags')
115
bc6ef3d0b84f ctags: fix output redirection on tcsh
Ilya Tumaykin <itumaykin@gmail.com>
parents: 114
diff changeset
40 let s:unix_redir = (&shellredir =~# '%s') ? &shellredir : &shellredir . ' %s'
226
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
41 let s:wildignores_options_path = ''
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
42 let s:last_wildignores = ''
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 function! gutentags#ctags#init(project_root) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 " Figure out the path to the tags file.
165
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
46 " Check the old name for this option, too, before falling back to the
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
47 " globally defined name.
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
48 let l:tagfile = getbufvar("", 'gutentags_ctags_tagfile',
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
49 \getbufvar("", 'gutentags_tagfile',
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
50 \g:gutentags_ctags_tagfile))
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 let b:gutentags_files['ctags'] = gutentags#get_cachefile(
141
7bc4df0225d1 Add support for specifying buffer-specific tagfiles.
Ludovic Chabant <ludovic@chabant.com>
parents: 136
diff changeset
52 \a:project_root, l:tagfile)
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 " Set the tags file for Vim to use.
165
cbc1ebe23ef1 Rename all ctags-related options to have "ctags" in their name.
Ludovic Chabant <ludovic@chabant.com>
parents: 160
diff changeset
55 if g:gutentags_ctags_auto_set_tags
249
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
56 if has('win32') || has('win64')
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
57 execute 'setlocal tags^=' . fnameescape(b:gutentags_files['ctags'])
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
58 else
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
59 " spaces must be literally escaped in tags path
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
60 let l:literal_space_escaped = substitute(fnameescape(b:gutentags_files['ctags']), '\ ', '\\\\ ', 'g')
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
61 execute 'setlocal tags^=' . l:literal_space_escaped
36dabe30ab6e Double escape spaces when setting tags path
Yukun Lin <me@yukun.io>
parents: 241
diff changeset
62 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 endif
93
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
64
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
65 " Check if the ctags executable exists.
185
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
66 if s:did_check_exe == 0
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
67 if g:gutentags_enabled && executable(expand(g:gutentags_ctags_executable, 1)) == 0
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
68 let g:gutentags_enabled = 0
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
69 echoerr "Executable '".g:gutentags_ctags_executable."' can't be found. "
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
70 \."Gutentags will be disabled. You can re-enable it by "
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
71 \."setting g:gutentags_enabled back to 1."
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
72 endif
685b81826b68 Only check for the ctags executable once.
Ludovic Chabant <ludovic@chabant.com>
parents: 184
diff changeset
73 let s:did_check_exe = 1
93
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
74 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
77 function! gutentags#ctags#generate(proj_dir, tags_file, gen_opts) abort
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
78 let l:write_mode = a:gen_opts['write_mode']
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
79
84
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
80 let l:tags_file_exists = filereadable(a:tags_file)
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
81
252
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
82 " If the tags file exists, we may want to do a sanity check to prevent
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
83 " weird errors that are hard to troubleshoot.
86
7872cc9bbc2d Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents: 84
diff changeset
84 if l:tags_file_exists && g:gutentags_ctags_check_tagfile
84
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
85 let l:first_lines = readfile(a:tags_file, '', 1)
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
86 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
87 call gutentags#throw(
148
b178f2251982 Only set `v:errmsg` when we throw an actual error.
Ludovic Chabant <ludovic@chabant.com>
parents: 141
diff changeset
88 \"File ".a:tags_file." doesn't appear to be ".
84
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
89 \"a ctags file. Please delete it and run ".
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
90 \":GutentagsUpdate!.")
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
91 return
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
92 endif
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
93 endif
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
94
252
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
95 " Get a tags file path relative to the current directory, which
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
96 " happens to be the project root in this case.
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
97 " Since the given tags file path is absolute, and since Vim won't
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
98 " change the path if it is not inside the current directory, we
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
99 " know that the tags file is "local" (i.e. inside the project)
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
100 " if the path was shortened (an absolute path will always be
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
101 " longer than a true relative path).
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
102 let l:tags_file_relative = fnamemodify(a:tags_file, ':.')
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
103 let l:tags_file_is_local = len(l:tags_file_relative) < len(a:tags_file)
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
104 let l:use_tag_relative_opt = 0
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
105
173
2cf3fb66285b Use absolute paths for `ctags` if the tags file is not local.
Ludovic Chabant <ludovic@chabant.com>
parents: 171
diff changeset
106 if empty(g:gutentags_cache_dir) && l:tags_file_is_local
167
34c57ad6eb45 Always use the potentially custom name for the tags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 165
diff changeset
107 " If we don't use the cache directory, we can pass relative paths
34c57ad6eb45 Always use the potentially custom name for the tags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 165
diff changeset
108 " around.
34c57ad6eb45 Always use the potentially custom name for the tags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 165
diff changeset
109 "
34c57ad6eb45 Always use the potentially custom name for the tags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 165
diff changeset
110 " Note that if we don't do this and pass a full path for the project
34c57ad6eb45 Always use the potentially custom name for the tags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 165
diff changeset
111 " root, some `ctags` implementations like Exhuberant Ctags can get
34c57ad6eb45 Always use the potentially custom name for the tags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 165
diff changeset
112 " confused if the paths have spaces -- but not if you're *in* the root
252
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
113 " directory, for some reason... (which will be the case, we're running
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
114 " the jobs from the project root).
98
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
115 let l:actual_proj_dir = '.'
181
0b4ccd0deceb Fix broken test for whether the tag file is inside the project root.
Ludovic Chabant <ludovic@chabant.com>
parents: 179
diff changeset
116 let l:actual_tags_file = l:tags_file_relative
252
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
117
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
118 let l:tags_file_dir = fnamemodify(l:actual_tags_file, ':h')
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
119 if l:tags_file_dir != '.'
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
120 " Ok so now the tags file is stored in a subdirectory of the
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
121 " project root, instead of at the root. This happens if, say,
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
122 " someone set `gutentags_ctags_tagfile` to `.git/tags`, which
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
123 " seems to be fairly popular.
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
124 "
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
125 " By default, `ctags` writes paths relative to the current
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
126 " directory (the project root) but in this case we need it to
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
127 " be relative to the tags file (e.g. adding `../` in front of
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
128 " everything if the tags file is `.git/tags`).
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
129 "
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
130 " Thankfully most `ctags` implementations support an option
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
131 " just for this.
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
132 let l:use_tag_relative_opt = 1
56dc6f8e5472 Use tag-relative paths in ctags when needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 249
diff changeset
133 endif
98
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
134 else
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
135 " else: the tags file goes in a cache directory, so we need to specify
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
136 " all the paths absolutely for `ctags` to do its job correctly.
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
137 let l:actual_proj_dir = a:proj_dir
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
138 let l:actual_tags_file = a:tags_file
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
139 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
141 " Build the command line.
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
142 let l:cmd = [s:runner_exe]
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
143 let l:cmd += ['-e', '"' . s:get_ctags_executable(a:proj_dir) . '"']
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
144 let l:cmd += ['-t', '"' . l:actual_tags_file . '"']
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
145 let l:cmd += ['-p', '"' . l:actual_proj_dir . '"']
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
146 if l:write_mode == 0 && l:tags_file_exists
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
147 let l:cur_file_path = expand('%:p')
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
148 if empty(g:gutentags_cache_dir) && l:tags_file_is_local
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
149 let l:cur_file_path = fnamemodify(l:cur_file_path, ':.')
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
150 endif
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
151 let l:cmd += ['-s', '"' . l:cur_file_path . '"']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
152 else
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
153 let l:file_list_cmd = gutentags#get_project_file_list_cmd(l:actual_proj_dir)
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
154 if !empty(l:file_list_cmd)
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
155 if match(l:file_list_cmd, '///') > 0
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
156 let l:suffopts = split(l:file_list_cmd, '///')
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
157 let l:suffoptstr = l:suffopts[1]
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
158 let l:file_list_cmd = l:suffopts[0]
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
159 if l:suffoptstr == 'absolute'
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
160 let l:cmd += ['-A']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
161 endif
133
6f15299869fc Don't pass absolute paths to `ctags` when we want relative paths from it.
Ludovic Chabant <ludovic@chabant.com>
parents: 119
diff changeset
162 endif
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
163 let l:cmd += ['-L', '"' . l:file_list_cmd. '"']
75
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
164 endif
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
165 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
166 if empty(get(l:, 'file_list_cmd', ''))
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
167 " Pass the Gutentags recursive options file before the project
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
168 " options file, so that users can override --recursive.
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
169 " Omit --recursive if this project uses a file list command.
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
170 let l:cmd += ['-o', '"' . gutentags#get_res_file('ctags_recursive.options') . '"']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
171 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
172 if !empty(g:gutentags_ctags_extra_args)
253
ec292bfbd633 Simpler implementation for tag relative option.
Ludovic Chabant <ludovic@chabant.com>
parents: 252
diff changeset
173 let l:extra_args = join(g:gutentags_ctags_extra_args)
ec292bfbd633 Simpler implementation for tag relative option.
Ludovic Chabant <ludovic@chabant.com>
parents: 252
diff changeset
174 if l:use_tag_relative_opt
ec292bfbd633 Simpler implementation for tag relative option.
Ludovic Chabant <ludovic@chabant.com>
parents: 252
diff changeset
175 let l:extra_args .= " --tag-relative=yes"
ec292bfbd633 Simpler implementation for tag relative option.
Ludovic Chabant <ludovic@chabant.com>
parents: 252
diff changeset
176 endif
ec292bfbd633 Simpler implementation for tag relative option.
Ludovic Chabant <ludovic@chabant.com>
parents: 252
diff changeset
177 let l:cmd += ['-O', shellescape(l:extra_args)]
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
178 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
179 if !empty(g:gutentags_ctags_post_process_cmd)
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
180 let l:cmd += ['-P', shellescape(g:gutentags_ctags_post_process_cmd)]
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
181 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
182 let l:proj_options_file = a:proj_dir . '/' .
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
183 \g:gutentags_ctags_options_file
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
184 if filereadable(l:proj_options_file)
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
185 let l:proj_options_file = s:process_options_file(
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
186 \a:proj_dir, l:proj_options_file)
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
187 let l:cmd += ['-o', '"' . l:proj_options_file . '"']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
188 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
189 if g:gutentags_ctags_exclude_wildignore
226
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
190 call s:generate_wildignore_options()
230
a798f7ad11c5 Fix bug for when `wildignore` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 226
diff changeset
191 if !empty(s:wildignores_options_path)
a798f7ad11c5 Fix bug for when `wildignore` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 226
diff changeset
192 let l:cmd += ['-x', shellescape('@'.s:wildignores_options_path, 1)]
a798f7ad11c5 Fix bug for when `wildignore` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 226
diff changeset
193 endif
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
194 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
195 for exc in g:gutentags_ctags_exclude
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
196 let l:cmd += ['-x', '"' . exc . '"']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
197 endfor
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
198 if g:gutentags_pause_after_update
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
199 let l:cmd += ['-c']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
200 endif
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
201 if g:gutentags_trace
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
202 let l:cmd += ['-l', '"' . l:actual_tags_file . '.log"']
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
203 endif
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
204 let l:cmd = gutentags#make_args(l:cmd)
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
206 call gutentags#trace("Running: " . string(l:cmd))
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
207 call gutentags#trace("In: " . getcwd())
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
208 if !g:gutentags_fake
226
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
209 let l:job_opts = gutentags#build_default_job_options('ctags')
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
210 let l:job = gutentags#start_job(l:cmd, l:job_opts)
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
211 call gutentags#add_job('ctags', a:tags_file, l:job)
198
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
212 else
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
213 call gutentags#trace("(fake... not actually running)")
5fb056a9eefb Don't change the current working directory more often than needed.
Ludovic Chabant <ludovic@chabant.com>
parents: 185
diff changeset
214 endif
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
215 endfunction
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
216
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
217 function! gutentags#ctags#on_job_exit(job, exit_val) abort
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
218 call gutentags#remove_job_by_data('ctags', a:job)
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
219
254
52be4cf89810 Don't complain when the job gets killed when Vim exits.
Ludovic Chabant <ludovic@chabant.com>
parents: 253
diff changeset
220 if a:exit_val != 0 && !g:__gutentags_vim_is_leaving
241
ac312dc3c111 Don't duplicate the `gutentags:` message prefix.
Ludovic Chabant <ludovic@chabant.com>
parents: 231
diff changeset
221 call gutentags#warning("ctags job failed, returned: ".
202
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
222 \string(a:exit_val))
b50b6d0f82dd Refactor for Vim8/Neovim job support.
Ludovic Chabant <ludovic@chabant.com>
parents: 199
diff changeset
223 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
228 " Utilities {{{
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
229
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
230 " Get final ctags executable depending whether a filetype one is defined
89
8bf96f9f649c Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
231 function! s:get_ctags_executable(proj_dir) abort
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
232 "Only consider the main filetype in cases like 'python.django'
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
233 let l:ftype = get(split(&filetype, '\.'), 0, '')
89
8bf96f9f649c Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
234 let l:proj_info = gutentags#get_project_info(a:proj_dir)
8bf96f9f649c Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
235 let l:type = get(l:proj_info, 'type', l:ftype)
119
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
236 let exepath = exists('g:gutentags_ctags_executable_{l:type}')
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
237 \ ? g:gutentags_ctags_executable_{l:type} : g:gutentags_ctags_executable
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
238 return expand(exepath, 1)
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
239 endfunction
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
240
226
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
241 function! s:generate_wildignore_options() abort
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
242 if s:last_wildignores == &wildignore
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
243 " The 'wildignore' setting didn't change since last time we did this.
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
244 call gutentags#trace("Wildignore options file is up to date.")
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
245 return
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
246 endif
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
247
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
248 if s:wildignores_options_path == ''
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
249 if empty(g:gutentags_cache_dir)
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
250 let s:wildignores_options_path = tempname()
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
251 else
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
252 let s:wildignores_options_path =
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
253 \gutentags#stripslash(g:gutentags_cache_dir).
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
254 \'/_wildignore.options'
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
255 endif
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
256 endif
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
257
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
258 call gutentags#trace("Generating wildignore options: ".s:wildignores_options_path)
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
259 let l:opt_lines = []
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
260 for ign in split(&wildignore, ',')
231
740cd9065423 Fix `wildignore` patterns file... it's not an options file!
Ludovic Chabant <ludovic@chabant.com>
parents: 230
diff changeset
261 call add(l:opt_lines, ign)
226
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
262 endfor
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
263 call writefile(l:opt_lines, s:wildignores_options_path)
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
264 let s:last_wildignores = &wildignore
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
265 endfunction
f2fd7d5835d9 Place all the `wildignore` exclude patterns in a generated options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 202
diff changeset
266
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
267 function! s:process_options_file(proj_dir, path) abort
116
be8d47e88ab1 ctags: use empty() instead of comparing with ""
Ilya Tumaykin <itumaykin@gmail.com>
parents: 115
diff changeset
268 if empty(g:gutentags_cache_dir)
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
269 " If we're not using a cache directory to store tag files, we can
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
270 " use the options file straight away.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
271 return a:path
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
272 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
273
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
274 " See if we need to process the options file.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
275 let l:do_process = 0
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
276 let l:proj_dir = gutentags#stripslash(a:proj_dir)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
277 let l:out_path = gutentags#get_cachefile(l:proj_dir, 'options')
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
278 if !filereadable(l:out_path)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
279 call gutentags#trace("Processing options file '".a:path."' because ".
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
280 \"it hasn't been processed yet.")
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
281 let l:do_process = 1
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
282 elseif getftime(a:path) > getftime(l:out_path)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
283 call gutentags#trace("Processing options file '".a:path."' because ".
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
284 \"it has changed.")
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
285 let l:do_process = 1
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
286 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
287 if l:do_process == 0
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
288 " Nothing's changed, return the existing processed version of the
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
289 " options file.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
290 return l:out_path
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
291 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
292
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
293 " We have to process the options file. Right now this only means capturing
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
294 " all the 'exclude' rules, and rewrite them to make them absolute.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
295 "
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
296 " This is because since `ctags` is run with absolute paths (because we
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
297 " want the tag file to be in a cache directory), it will do its path
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
298 " matching with absolute paths too, so the exclude rules need to be
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
299 " absolute.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
300 let l:lines = readfile(a:path)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
301 let l:outlines = []
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
302 for line in l:lines
99
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
303 let l:exarg_idx = matchend(line, '\v^\-\-exclude=')
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
304 if l:exarg_idx < 0
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
305 call add(l:outlines, line)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
306 continue
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
307 endif
99
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
308
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
309 " Don't convert things that don't look like paths.
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
310 let l:exarg = strpart(line, l:exarg_idx + 1)
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
311 let l:do_convert = 1
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
312 if l:exarg[0] == '@' " Manifest file path
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
313 let l:do_convert = 0
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
314 endif
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
315 if stridx(l:exarg, '/') < 0 && stridx(l:exarg, '\\') < 0 " Filename
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
316 let l:do_convert = 0
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
317 endif
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
318 if l:do_convert == 0
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
319 call add(l:outlines, line)
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
320 continue
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
321 endif
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
322
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
323 let l:fullp = l:proj_dir . gutentags#normalizepath('/'.l:exarg)
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
324 let l:ol = '--exclude='.l:fullp
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
325 call add(l:outlines, l:ol)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
326 endfor
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
327
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
328 call writefile(l:outlines, l:out_path)
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
329 return l:out_path
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
330 endfunction
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
331
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
332 " }}}