Mercurial > vim-gutentags
annotate autoload/gutentags/ctags.vim @ 93:edd488d8d37e
Give some error message if there's no available `ctags` on the system.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 17 Feb 2016 23:30:24 -0800 |
parents | 8bf96f9f649c |
children | e03a661dc983 |
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 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 if !exists('g:gutentags_ctags_executable') |
60
9e768b83d701
Fix missing renames of `gutentags_ctags_executable`.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
6 let g:gutentags_ctags_executable = 'ctags' |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 if !exists('g:gutentags_tagfile') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 let g:gutentags_tagfile = 'tags' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 endif |
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 if !exists('g:gutentags_auto_set_tags') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 let g:gutentags_auto_set_tags = 1 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 |
62
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
17 if !exists('g:gutentags_ctags_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
|
18 let g:gutentags_ctags_options_file = '.gutctags' |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
19 endif |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
20 |
86
7872cc9bbc2d
Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
21 if !exists('g:gutentags_ctags_check_tagfile') |
7872cc9bbc2d
Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
22 let g:gutentags_ctags_check_tagfile = 0 |
7872cc9bbc2d
Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
23 endif |
7872cc9bbc2d
Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
24 |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 " }}} |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 " Gutentags Module Interface {{{ |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 let s:runner_exe = gutentags#get_plat_file('update_tags') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 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
|
32 " 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
|
33 let b:gutentags_files['ctags'] = gutentags#get_cachefile( |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 \a:project_root, g:gutentags_tagfile) |
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 " 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
|
37 if g:gutentags_auto_set_tags |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 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
|
39 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
|
40 |
edd488d8d37e
Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents:
89
diff
changeset
|
41 " Check if the ctags executable exists. |
edd488d8d37e
Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents:
89
diff
changeset
|
42 if g:gutentags_enabled && executable(g:gutentags_ctags_executable) == 0 |
edd488d8d37e
Give some error message if there's no available `ctags` on the system.
Ludovic Chabant <ludovic@chabant.com>
parents:
89
diff
changeset
|
43 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
|
44 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
|
45 \."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
|
46 \."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
|
47 endif |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
48 endfunction |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 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
|
51 " 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
|
52 " these things. |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 let l:prev_cwd = getcwd() |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
54 let l:work_dir = fnamemodify(a:tags_file, ':h') |
84
96bfe5c37f37
Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents:
75
diff
changeset
|
55 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
|
56 |
86
7872cc9bbc2d
Check existing tags file as an opt-in thing for now.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 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
|
61 \"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
|
62 \":GutentagsUpdate!.") |
96bfe5c37f37
Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents:
75
diff
changeset
|
63 return |
96bfe5c37f37
Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents:
75
diff
changeset
|
64 endif |
96bfe5c37f37
Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents:
75
diff
changeset
|
65 endif |
96bfe5c37f37
Error and abort if we'll be overwriting a non-ctags file.
Ludovic Chabant <ludovic@chabant.com>
parents:
75
diff
changeset
|
66 |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 execute "chdir " . fnameescape(l:work_dir) |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
69 try |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
70 " Build the command line. |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
71 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
|
72 let l:cmd .= ' -e "' . s:get_ctags_executable(a:proj_dir) . '"' |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 let l:cmd .= ' -t "' . a:tags_file . '"' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 let l:cmd .= ' -p "' . a: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
|
75 if a:write_mode == 0 && l:tags_file_exists |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
76 let l:full_path = expand('%:p') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
77 let l:cmd .= ' -s "' . l:full_path . '"' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
78 endif |
75
d12543f11eb9
Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents:
70
diff
changeset
|
79 " Pass the Gutentags options file first, and then the project specific |
d12543f11eb9
Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents:
70
diff
changeset
|
80 " one, so that users can override the default behaviour. |
d12543f11eb9
Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents:
70
diff
changeset
|
81 let l:cmd .= ' -o "' . gutentags#get_res_file('ctags.options') . '"' |
d12543f11eb9
Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents:
70
diff
changeset
|
82 let l:proj_options_file = a:proj_dir . '/' . |
d12543f11eb9
Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents:
70
diff
changeset
|
83 \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
|
84 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
|
85 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
|
86 \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
|
87 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
|
88 endif |
41
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 for ign in split(&wildignore, ',') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 let l:cmd .= ' -x ' . '"' . ign . '"' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 endfor |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 for exc in g:gutentags_exclude |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 let l:cmd .= ' -x ' . '"' . exc . '"' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 endfor |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 if g:gutentags_pause_after_update |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 let l:cmd .= ' -c' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 if g:gutentags_trace |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 if has('win32') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 let l:cmd .= ' -l "' . a:tags_file . '.log"' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 else |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 let l:cmd .= ' > "' . a:tags_file . '.log" 2>&1' |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 else |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
105 if !has('win32') |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
106 let l:cmd .= ' > /dev/null 2>&1' |
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 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 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
|
110 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 call gutentags#trace("Running: " . l:cmd) |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 call gutentags#trace("In: " . getcwd()) |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
113 if !g:gutentags_fake |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 " Run the background process. |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 if !g:gutentags_trace |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 silent execute l:cmd |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 else |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 execute l:cmd |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
120 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 " 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
|
122 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
|
123 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
|
124 else |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 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
|
126 endif |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 call gutentags#trace("") |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
128 finally |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 " Restore the previous working directory. |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 execute "chdir " . fnameescape(l:prev_cwd) |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 endtry |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
132 endfunction |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
133 |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
134 " }}} |
99328cb71e75
Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
135 |
62
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
136 " Utilities {{{ |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
137 |
70
661a97eaf608
Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
138 " 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
|
139 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
|
140 "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
|
141 let l:ftype = get(split(&filetype, '\.'), 0, '') |
89
8bf96f9f649c
Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
142 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
|
143 let l:type = get(l:proj_info, 'type', l:ftype) |
8bf96f9f649c
Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
144 if exists('g:gutentags_ctags_executable_{l:type}') |
8bf96f9f649c
Add support for project types.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
145 return g:gutentags_ctags_executable_{l:type} |
70
661a97eaf608
Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
146 else |
661a97eaf608
Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
147 return g:gutentags_ctags_executable |
661a97eaf608
Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
148 endif |
661a97eaf608
Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
149 endfunction |
661a97eaf608
Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
150 |
62
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
151 function! s:process_options_file(proj_dir, path) abort |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
152 if g:gutentags_cache_dir == "" |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
153 " 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
|
154 " 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
|
155 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
|
156 endif |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
157 |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
158 " 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 \"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
|
165 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
|
166 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
|
167 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
|
168 \"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
|
169 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
|
170 endif |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
171 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
|
172 " 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
|
173 " 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
|
174 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
|
175 endif |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
176 |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
177 " 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
|
178 " 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
|
179 " |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
180 " 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
|
181 " 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
|
182 " 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
|
183 " absolute. |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
184 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
|
185 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
|
186 for line in l:lines |
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:exarg = matchend(line, '\v^\-\-exclude=') |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
188 if l:exarg < 0 |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
189 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
|
190 continue |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
191 endif |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
192 let l:fullp = gutentags#normalizepath(l: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
|
193 \strpart(line, l:exarg + 1)) |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
194 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
|
195 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
|
196 endfor |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
197 |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
198 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
|
199 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
|
200 endfunction |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
201 |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
202 " }}} |
106757c129cb
Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents:
60
diff
changeset
|
203 |