annotate autoload/gutentags/ctags.vim @ 135:4c9e2de7d46a

Rename ctags.options to ctags_recursive.options According to https://github.com/ludovicchabant/vim-gutentags/issues/33, ctags' --recursive option was moved to an option file to allow it to be overridden by user options files. This change makes it clear what the purpose of this options file is.
author Stephen Kent <smkent@smkent.net>
date Fri, 22 Jul 2016 19:25:01 -0700
parents 6f15299869fc
children 286e5b3095d0
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')
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
6 let g:gutentags_tagfile = get(g:, 'gutentags_tagfile', 'tags')
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
7 let g:gutentags_auto_set_tags = get(g:, 'gutentags_auto_set_tags', 1)
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
8 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
9 let g:gutentags_ctags_check_tagfile = get(g:, 'gutentags_ctags_check_tagfile', 0)
86
7872cc9bbc2d Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents: 84
diff changeset
10
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 " Gutentags Module Interface {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 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
16 let s:unix_redir = (&shellredir =~# '%s') ? &shellredir : &shellredir . ' %s'
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 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
19 " Figure out the path to the tags file.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 let b:gutentags_files['ctags'] = gutentags#get_cachefile(
98
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
21 \a:project_root, g:gutentags_tagfile)
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 " Set the tags file for Vim to use.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 if g:gutentags_auto_set_tags
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 execute 'setlocal tags^=' . fnameescape(b:gutentags_files['ctags'])
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 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
27
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
28 " Check if the ctags executable exists.
119
a66d90fd758b expand() g:gutentags_ctags_executable
Justin M. Keyes <justinkz@gmail.com>
parents: 117
diff changeset
29 if g:gutentags_enabled && executable(expand(g:gutentags_ctags_executable, 1)) == 0
93
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
30 let g:gutentags_enabled = 0
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
31 echoerr "Executable '".g:gutentags_ctags_executable."' can't be found. "
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
32 \."Gutentags will be disabled. You can re-enable it by "
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
33 \."setting g:gutentags_enabled back to 1."
edd488d8d37e Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents: 89
diff changeset
34 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 " Get to the tags file directory because ctags is finicky about
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 " these things.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 let l:prev_cwd = getcwd()
84
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
41 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
42
86
7872cc9bbc2d Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents: 84
diff changeset
43 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
44 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
45 if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
46 call gutentags#throw("File ".a:tags_file." doesn't appear to be ".
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
47 \"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
48 \":GutentagsUpdate!.")
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
49 return
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
50 endif
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
51 endif
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
52
116
be8d47e88ab1 ctags: use empty() instead of comparing with ""
Ilya Tumaykin <itumaykin@gmail.com>
parents: 115
diff changeset
53 if empty(g:gutentags_cache_dir)
98
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
54 " If we don't use the cache directory, let's just use the tag filename
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
55 " as specified by the user, and change the working directory to the
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
56 " project root.
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
57 " Note that if we don't do this and pass a full path, `ctags` gets
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
58 " confused if the paths have spaces -- but not if you're *in* the
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
59 " root directory.
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
60 let l:actual_proj_dir = '.'
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
61 let l:actual_tags_file = g:gutentags_tagfile
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
62 execute "chdir " . fnameescape(a:proj_dir)
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
63 else
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
64 " 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
65 " 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
66 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
67 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
68 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 try
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 " Build the command line.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 let l:cmd = gutentags#get_execute_cmd() . s:runner_exe
89
8bf96f9f649c Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
73 let l:cmd .= ' -e "' . s:get_ctags_executable(a:proj_dir) . '"'
98
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
74 let l:cmd .= ' -t "' . l:actual_tags_file . '"'
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
75 let l:cmd .= ' -p "' . l:actual_proj_dir . '"'
84
96bfe5c37f37 Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents: 75
diff changeset
76 if a:write_mode == 0 && l:tags_file_exists
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
77 let l:cur_file_path = expand('%:p')
6f15299869fc Don't pass absolute paths to `ctags` when we want relative paths from it.
Ludovic Chabant <ludovic@chabant.com>
parents: 119
diff changeset
78 if empty(g:gutentags_cache_dir)
6f15299869fc Don't pass absolute paths to `ctags` when we want relative paths from it.
Ludovic Chabant <ludovic@chabant.com>
parents: 119
diff changeset
79 let l:cur_file_path = fnamemodify(l:cur_file_path, ':.')
6f15299869fc Don't pass absolute paths to `ctags` when we want relative paths from it.
Ludovic Chabant <ludovic@chabant.com>
parents: 119
diff changeset
80 endif
6f15299869fc Don't pass absolute paths to `ctags` when we want relative paths from it.
Ludovic Chabant <ludovic@chabant.com>
parents: 119
diff changeset
81 let l:cmd .= ' -s "' . l:cur_file_path . '"'
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 endif
135
4c9e2de7d46a Rename ctags.options to ctags_recursive.options
Stephen Kent <smkent@smkent.net>
parents: 133
diff changeset
83 " Pass the Gutentags recursive options file before the project
4c9e2de7d46a Rename ctags.options to ctags_recursive.options
Stephen Kent <smkent@smkent.net>
parents: 133
diff changeset
84 " options file, so that users can override --recursive.
4c9e2de7d46a Rename ctags.options to ctags_recursive.options
Stephen Kent <smkent@smkent.net>
parents: 133
diff changeset
85 let l:cmd .= ' -o "' . gutentags#get_res_file('ctags_recursive.options') . '"'
114
979fab641f29 ctags: remove trailing space
Ilya Tumaykin <itumaykin@gmail.com>
parents: 113
diff changeset
86 let l:proj_options_file = a:proj_dir . '/' .
75
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
87 \g:gutentags_ctags_options_file
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
88 if filereadable(l:proj_options_file)
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
89 let l:proj_options_file = s:process_options_file(
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
90 \a:proj_dir, l:proj_options_file)
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
91 let l:cmd .= ' -o "' . l:proj_options_file . '"'
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
92 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 for ign in split(&wildignore, ',')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 let l:cmd .= ' -x ' . '"' . ign . '"'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 for exc in g:gutentags_exclude
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 let l:cmd .= ' -x ' . '"' . exc . '"'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 if g:gutentags_pause_after_update
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 let l:cmd .= ' -c'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 if g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 if has('win32')
98
d645125192aa Fix more problems with paths and spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents: 96
diff changeset
104 let l:cmd .= ' -l "' . l:actual_tags_file . '.log"'
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 else
115
bc6ef3d0b84f ctags: fix output redirection on tcsh
Ilya Tumaykin <itumaykin@gmail.com>
parents: 114
diff changeset
106 let l:cmd .= ' ' . printf(s:unix_redir, '"' . l:actual_tags_file . '.log"')
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 if !has('win32')
115
bc6ef3d0b84f ctags: fix output redirection on tcsh
Ilya Tumaykin <itumaykin@gmail.com>
parents: 114
diff changeset
110 let l:cmd .= ' ' . printf(s:unix_redir, '/dev/null')
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 let l:cmd .= gutentags#get_execute_cmd_suffix()
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 call gutentags#trace("Running: " . l:cmd)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 call gutentags#trace("In: " . getcwd())
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 if !g:gutentags_fake
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 " Run the background process.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 if !g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 silent execute l:cmd
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 execute l:cmd
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 " Flag this tags file as being in progress
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 let l:full_tags_file = fnamemodify(a:tags_file, ':p')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 call gutentags#add_progress('ctags', l:full_tags_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 call gutentags#trace("(fake... not actually running)")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 call gutentags#trace("")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 finally
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 " Restore the previous working directory.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 execute "chdir " . fnameescape(l:prev_cwd)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 endtry
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
140 " Utilities {{{
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
141
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
142 " 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
143 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
144 "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
145 let l:ftype = get(split(&filetype, '\.'), 0, '')
89
8bf96f9f649c Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents: 86
diff changeset
146 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
147 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
148 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
149 \ ? 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
150 return expand(exepath, 1)
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
151 endfunction
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
152
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
153 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
154 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
155 " 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
156 " 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
157 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
158 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
159
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
160 " 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
161 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
162 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
163 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
164 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
165 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
166 \"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
167 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
168 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
169 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
170 \"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
171 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
172 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
173 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
174 " 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
175 " 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
176 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
177 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
178
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
179 " 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
180 " 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
181 "
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
182 " 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
183 " 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
184 " 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
185 " absolute.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
186 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
187 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
188 for line in l:lines
99
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
189 let l:exarg_idx = matchend(line, '\v^\-\-exclude=')
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
190 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
191 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
192 continue
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
193 endif
99
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
194
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
195 " 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
196 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
197 let l:do_convert = 1
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
198 if l:exarg[0] == '@' " Manifest file path
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
199 let l:do_convert = 0
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
200 endif
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
201 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
202 let l:do_convert = 0
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
203 endif
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
204 if l:do_convert == 0
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
205 call add(l:outlines, line)
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
206 continue
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
207 endif
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
208
05fc1e2172cc Fixes in the processing of `.gutctags`.
Ludovic Chabant <ludovic@chabant.com>
parents: 98
diff changeset
209 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
210 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
211 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
212 endfor
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
213
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
214 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
215 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
216 endfunction
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
217
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
218 " }}}