annotate autoload/gutentags/ctags.vim @ 75:d12543f11eb9

Move the default `-R` option to an overridable "global" options file. This makes it possible for a `.gutctags` file to disable the `-R` flag. Also fixes Github issue #33.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 27 Jul 2015 14:18:10 -0700
parents 661a97eaf608
children 96bfe5c37f37
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
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
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 " }}}
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 " Gutentags Module Interface {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 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
26
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 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
28 " 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
29 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
30 \a:project_root, g:gutentags_tagfile)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 " 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
33 if g:gutentags_auto_set_tags
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 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
35 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 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
39 " 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
40 " these things.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 let l:prev_cwd = getcwd()
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 let l:work_dir = fnamemodify(a:tags_file, ':h')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 execute "chdir " . fnameescape(l:work_dir)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 try
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 " Build the command line.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 let l:cmd = gutentags#get_execute_cmd() . s:runner_exe
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
48 let l:cmd .= ' -e "' . s:get_ctags_executable() . '"'
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 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
50 let l:cmd .= ' -p "' . a:proj_dir . '"'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 if a:write_mode == 0 && filereadable(a:tags_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 let l:full_path = expand('%:p')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 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
54 endif
75
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
55 " 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
56 " 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
57 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
58 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
59 \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
60 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
61 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
62 \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
63 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
64 endif
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 for ign in split(&wildignore, ',')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 let l:cmd .= ' -x ' . '"' . ign . '"'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 for exc in g:gutentags_exclude
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 let l:cmd .= ' -x ' . '"' . exc . '"'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 if g:gutentags_pause_after_update
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 let l:cmd .= ' -c'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 if g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 if has('win32')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 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
77 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 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
79 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 if !has('win32')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 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
83 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 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
86
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 call gutentags#trace("Running: " . l:cmd)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 call gutentags#trace("In: " . getcwd())
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 if !g:gutentags_fake
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 " Run the background process.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 if !g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 silent execute l:cmd
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 execute l:cmd
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 " 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
98 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
99 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
100 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 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
102 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 call gutentags#trace("")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 finally
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 " Restore the previous working directory.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 execute "chdir " . fnameescape(l:prev_cwd)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 endtry
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109
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
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
112 " Utilities {{{
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
113
70
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
114 " Get final ctags executable depending whether a filetype one is defined
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
115 function! s:get_ctags_executable() abort
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
116 "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
117 let l:ftype = get(split(&filetype, '\.'), 0, '')
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
118 if exists('g:gutentags_ctags_executable_{l:ftype}')
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
119 return g:gutentags_ctags_executable_{l:ftype}
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
120 else
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
121 return g:gutentags_ctags_executable
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
122 endif
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
123 endfunction
661a97eaf608 Move `get_ctags_executable` to the `ctags` module.
Ludovic Chabant <ludovic@chabant.com>
parents: 69
diff changeset
124
62
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
125 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
126 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
127 " 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
128 " 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
129 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
130 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
131
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
132 " 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
133 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
134 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
135 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
136 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
137 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
138 \"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
139 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
140 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
141 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
142 \"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
143 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
144 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
145 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
146 " 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
147 " 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
148 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
149 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
150
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
151 " 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
152 " 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
153 "
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
154 " 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
155 " 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
156 " 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
157 " absolute.
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
158 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
159 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
160 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
161 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
162 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
163 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
164 continue
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
165 endif
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
166 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
167 \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
168 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
169 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
170 endfor
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
171
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
172 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
173 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
174 endfunction
106757c129cb Change the per-project option file to be `.gutctags` and process it first.
Ludovic Chabant <ludovic@chabant.com>
parents: 60
diff changeset
175
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