Mercurial > vim-gutentags
annotate plugin/gutentags.vim @ 37:0c67b56abc63
Attempt at better error handling with the Windows update script.
* Use `call` to run Ctags because apparently, the way Vim runs background
Windows scripts means the whole thing will abort if there's an error.
But here we want to keep going so we get a chance to unlock the tags file
if possible.
* Add some `ERRORLEVEL` handling code.
* Log more stuff to the log file.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 15 Dec 2014 13:00:04 -0800 |
parents | 186b65facdb1 |
children | 8b3c611a4d3b |
rev | line source |
---|---|
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1 " gutentags.vim - Automatic ctags management for Vim |
0 | 2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com> |
3 " Version: 0.0.1 | |
4 | |
5 " Globals {{{ | |
6 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
7 if !exists('g:gutentags_debug') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
8 let g:gutentags_debug = 0 |
0 | 9 endif |
10 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
11 if (exists('g:loaded_gutentags') || &cp) && !g:gutentags_debug |
0 | 12 finish |
13 endif | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
14 if (exists('g:loaded_gutentags') && g:gutentags_debug) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
15 echom "Reloaded gutentags." |
0 | 16 endif |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
17 let g:loaded_gutentags = 1 |
0 | 18 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
19 if !exists('g:gutentags_trace') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
20 let g:gutentags_trace = 0 |
0 | 21 endif |
22 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
23 if !exists('g:gutentags_fake') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
24 let g:gutentags_fake = 0 |
0 | 25 endif |
26 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
27 if !exists('g:gutentags_background_update') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
28 let g:gutentags_background_update = 1 |
0 | 29 endif |
30 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
31 if !exists('g:gutentags_pause_after_update') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
32 let g:gutentags_pause_after_update = 0 |
11
478638833c3b
Fix Win32 update script, add option to pause it.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
33 endif |
478638833c3b
Fix Win32 update script, add option to pause it.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
34 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
35 if !exists('g:gutentags_enabled') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
36 let g:gutentags_enabled = 1 |
0 | 37 endif |
38 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
39 if !exists('g:gutentags_executable') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
40 let g:gutentags_executable = 'ctags' |
0 | 41 endif |
42 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
43 if !exists('g:gutentags_tagfile') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
44 let g:gutentags_tagfile = 'tags' |
0 | 45 endif |
46 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
47 if !exists('g:gutentags_project_root') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
48 let g:gutentags_project_root = [] |
0 | 49 endif |
30
217be2e61ed4
Add .svn in gutentags_project_root
Santiago Ag?ero <aguerosantiale@gmail.com>
parents:
27
diff
changeset
|
50 let g:gutentags_project_root += ['.git', '.hg', '.svn', '.bzr', '_darcs'] |
0 | 51 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
52 if !exists('g:gutentags_options_file') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
53 let g:gutentags_options_file = '' |
16
c11616828595
Add an option to specify a `ctags` options file to be used.
Ludovic Chabant <ludovic@chabant.com>
parents:
15
diff
changeset
|
54 endif |
c11616828595
Add an option to specify a `ctags` options file to be used.
Ludovic Chabant <ludovic@chabant.com>
parents:
15
diff
changeset
|
55 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
56 if !exists('g:gutentags_exclude') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
57 let g:gutentags_exclude = [] |
3 | 58 endif |
59 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
60 if !exists('g:gutentags_generate_on_new') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
61 let g:gutentags_generate_on_new = 1 |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
62 endif |
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
63 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
64 if !exists('g:gutentags_generate_on_missing') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
65 let g:gutentags_generate_on_missing = 1 |
3 | 66 endif |
67 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
68 if !exists('g:gutentags_generate_on_write') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
69 let g:gutentags_generate_on_write = 1 |
3 | 70 endif |
71 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
72 if !exists('g:gutentags_auto_set_tags') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
73 let g:gutentags_auto_set_tags = 1 |
3 | 74 endif |
75 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
76 if !exists('g:gutentags_cache_dir') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
77 let g:gutentags_cache_dir = '' |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
78 else |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
79 let g:gutentags_cache_dir = fnamemodify(g:gutentags_cache_dir, ':s?[/\\]$??') |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
80 endif |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
81 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
82 if g:gutentags_cache_dir != '' && !isdirectory(g:gutentags_cache_dir) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
83 call mkdir(g:gutentags_cache_dir, 'p') |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
84 endif |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
85 |
0 | 86 " }}} |
87 | |
88 " Utilities {{{ | |
89 | |
90 " Throw an exception message. | |
91 function! s:throw(message) | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
92 let v:errmsg = "gutentags: " . a:message |
0 | 93 throw v:errmsg |
94 endfunction | |
95 | |
96 " Prints a message if debug tracing is enabled. | |
97 function! s:trace(message, ...) | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
98 if g:gutentags_trace || (a:0 && a:1) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
99 let l:message = "gutentags: " . a:message |
0 | 100 echom l:message |
101 endif | |
102 endfunction | |
103 | |
104 " Strips the ending slash in a path. | |
105 function! s:stripslash(path) | |
106 return fnamemodify(a:path, ':s?[/\\]$??') | |
107 endfunction | |
108 | |
109 " Normalizes the slashes in a path. | |
110 function! s:normalizepath(path) | |
111 if exists('+shellslash') && &shellslash | |
112 return substitute(a:path, '\v/', '\\', 'g') | |
113 elseif has('win32') | |
114 return substitute(a:path, '\v/', '\\', 'g') | |
115 else | |
116 return a:path | |
117 endif | |
118 endfunction | |
119 | |
120 " Shell-slashes the path (opposite of `normalizepath`). | |
121 function! s:shellslash(path) | |
122 if exists('+shellslash') && !&shellslash | |
123 return substitute(a:path, '\v\\', '/', 'g') | |
124 else | |
125 return a:path | |
126 endif | |
127 endfunction | |
128 | |
129 " }}} | |
130 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
131 " Gutentags Setup {{{ |
0 | 132 |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
133 let s:known_tagfiles = [] |
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
134 |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
135 " Finds the first directory with a project marker by walking up from the given |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
136 " file path. |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
137 function! s:get_project_root(path) abort |
0 | 138 let l:path = s:stripslash(a:path) |
139 let l:previous_path = "" | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
140 let l:markers = g:gutentags_project_root[:] |
5
12f4f50f4d3a
Use CtrlP root markers if they've been defined.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
141 if exists('g:ctrlp_root_markers') |
12f4f50f4d3a
Use CtrlP root markers if they've been defined.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
142 let l:markers += g:ctrlp_root_markers |
12f4f50f4d3a
Use CtrlP root markers if they've been defined.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
143 endif |
0 | 144 while l:path != l:previous_path |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
145 for root in g:gutentags_project_root |
0 | 146 if getftype(l:path . '/' . root) != "" |
27
173f055bde34
Make sure we get a clean project dir.
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
147 let l:proj_dir = simplify(fnamemodify(l:path, ':p')) |
173f055bde34
Make sure we get a clean project dir.
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
148 return s:stripslash(l:proj_dir) |
0 | 149 endif |
150 endfor | |
151 let l:previous_path = l:path | |
152 let l:path = fnamemodify(l:path, ':h') | |
153 endwhile | |
154 call s:throw("Can't figure out what tag file to use for: " . a:path) | |
155 endfunction | |
156 | |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
157 " Get the tag filename for a given project root. |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
158 function! s:get_tagfile(root_dir) abort |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
159 let l:tag_path = s:stripslash(a:root_dir) . '/' . g:gutentags_tagfile |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
160 if g:gutentags_cache_dir != "" |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
161 " Put the tag file in the cache dir instead of inside the |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
162 " projet root. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
163 let l:tag_path = g:gutentags_cache_dir . '/' . |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
164 \tr(l:tag_path, '\/:', '---') |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
165 let l:tag_path = substitute(l:tag_path, '/\-', '/', '') |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
166 endif |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
167 let l:tag_path = s:normalizepath(l:tag_path) |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
168 return l:tag_path |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
169 endfunction |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
170 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
171 " Setup gutentags for the current buffer. |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
172 function! s:setup_gutentags() abort |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
173 if exists('b:gutentags_file') && !g:gutentags_debug |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
174 " This buffer already has gutentags support. |
0 | 175 return |
176 endif | |
3 | 177 |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
178 " Try and find what tags file we should manage. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
179 call s:trace("Scanning buffer '" . bufname('%') . "' for gutentags setup...") |
0 | 180 try |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
181 let b:gutentags_root = s:get_project_root(expand('%:h')) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
182 let b:gutentags_file = s:get_tagfile(b:gutentags_root) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
183 catch /^gutentags\:/ |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
184 call s:trace("Can't figure out what tag file to use... no gutentags support.") |
0 | 185 return |
186 endtry | |
187 | |
3 | 188 " We know what tags file to manage! Now set things up. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
189 call s:trace("Setting gutentags for buffer '" . bufname('%') . "' with tagfile: " . b:gutentags_file) |
0 | 190 |
3 | 191 " Set the tags file for Vim to use. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
192 if g:gutentags_auto_set_tags |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
193 execute 'setlocal tags^=' . b:gutentags_file |
3 | 194 endif |
195 | |
196 " Autocommands for updating the tags on save. | |
0 | 197 let l:bn = bufnr('%') |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
198 execute 'augroup gutentags_buffer_' . l:bn |
0 | 199 execute ' autocmd!' |
3 | 200 execute ' autocmd BufWritePost <buffer=' . l:bn . '> call s:write_triggered_update_tags()' |
0 | 201 execute 'augroup end' |
202 | |
3 | 203 " Miscellaneous commands. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
204 command! -buffer -bang GutentagsUpdate :call s:manual_update_tags(<bang>0) |
3 | 205 |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
206 " Add this tags file to the known tags files if it wasn't there already. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
207 let l:found = index(s:known_tagfiles, b:gutentags_file) |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
208 if l:found < 0 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
209 call add(s:known_tagfiles, b:gutentags_file) |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
210 |
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
211 " Generate this new file depending on settings and stuff. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
212 if g:gutentags_generate_on_missing && !filereadable(b:gutentags_file) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
213 call s:trace("Generating missing tags file: " . b:gutentags_file) |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
214 call s:update_tags(1, 0) |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
215 elseif g:gutentags_generate_on_new |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
216 call s:trace("Generating tags file: " . b:gutentags_file) |
14
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
217 call s:update_tags(1, 0) |
b8f23bf7b20f
Ability to (re)generate tags when opening a new project.
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
218 endif |
3 | 219 endif |
0 | 220 endfunction |
221 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
222 augroup gutentags_detect |
0 | 223 autocmd! |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
224 autocmd BufNewFile,BufReadPost * call s:setup_gutentags() |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
225 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_gutentags()|endif |
0 | 226 augroup end |
227 | |
228 " }}} | |
229 | |
230 " Tags File Management {{{ | |
231 | |
232 let s:runner_exe = expand('<sfile>:h:h') . '/plat/unix/update_tags.sh' | |
233 if has('win32') | |
234 let s:runner_exe = expand('<sfile>:h:h') . '\plat\win32\update_tags.cmd' | |
235 endif | |
236 | |
237 let s:update_queue = [] | |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
238 let s:maybe_in_progress = {} |
0 | 239 |
240 " Get how to execute an external command depending on debug settings. | |
241 function! s:get_execute_cmd() abort | |
242 if has('win32') | |
243 let l:cmd = '!start ' | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
244 if g:gutentags_background_update |
0 | 245 let l:cmd .= '/b ' |
246 endif | |
247 return l:cmd | |
248 else | |
249 return '!' | |
250 endif | |
251 endfunction | |
252 | |
3 | 253 " Get the suffix for how to execute an external command. |
254 function! s:get_execute_cmd_suffix() abort | |
255 if has('win32') | |
256 return '' | |
257 else | |
258 return ' &' | |
259 endif | |
260 endfunction | |
261 | |
0 | 262 " (Re)Generate the tags file for the current buffer's file. |
263 function! s:manual_update_tags(bang) abort | |
264 call s:update_tags(a:bang, 0) | |
265 endfunction | |
266 | |
3 | 267 " (Re)Generate the tags file for a buffer that just go saved. |
268 function! s:write_triggered_update_tags() abort | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
269 if g:gutentags_enabled && g:gutentags_generate_on_write |
3 | 270 call s:update_tags(0, 1) |
271 endif | |
272 endfunction | |
273 | |
0 | 274 " Update the tags file for the current buffer's file. |
275 " write_mode: | |
276 " 0: update the tags file if it exists, generate it otherwise. | |
277 " 1: always generate (overwrite) the tags file. | |
278 " | |
279 " queue_mode: | |
280 " 0: if an update is already in progress, report it and abort. | |
281 " 1: if an update is already in progress, queue another one. | |
282 " | |
283 " An additional argument specifies where to write the tags file. If nothing | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
284 " is specified, it will go to the gutentags-defined file. |
0 | 285 function! s:update_tags(write_mode, queue_mode, ...) abort |
286 " Figure out where to save. | |
287 if a:0 == 1 | |
288 let l:tags_file = a:1 | |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
289 let l:proj_dir = fnamemodify(a:1, ':h') |
0 | 290 else |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
291 let l:tags_file = b:gutentags_file |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
292 let l:proj_dir = b:gutentags_root |
0 | 293 endif |
35 | 294 |
0 | 295 " Check that there's not already an update in progress. |
296 let l:lock_file = l:tags_file . '.lock' | |
297 if filereadable(l:lock_file) | |
298 if a:queue_mode == 1 | |
299 let l:idx = index(s:update_queue, l:tags_file) | |
300 if l:idx < 0 | |
301 call add(s:update_queue, l:tags_file) | |
302 endif | |
303 call s:trace("Tag file '" . l:tags_file . "' is already being updated. Queuing it up...") | |
304 call s:trace("") | |
305 else | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
306 echom "gutentags: The tags file is already being updated, please try again later." |
0 | 307 echom "" |
308 endif | |
309 return | |
310 endif | |
311 | |
312 " Switch to the project root to make the command line smaller, and make | |
313 " it possible to get the relative path of the filename to parse if we're | |
314 " doing an incremental update. | |
315 let l:prev_cwd = getcwd() | |
316 let l:work_dir = fnamemodify(l:tags_file, ':h') | |
317 execute "chdir " . l:work_dir | |
318 | |
319 try | |
320 " Build the command line. | |
321 let l:cmd = s:get_execute_cmd() . s:runner_exe | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
322 let l:cmd .= ' -e "' . g:gutentags_executable . '"' |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
323 let l:cmd .= ' -t "' . l:tags_file . '"' |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
324 let l:cmd .= ' -p "' . l:proj_dir . '"' |
0 | 325 if a:write_mode == 0 && filereadable(l:tags_file) |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
326 let l:full_path = expand('%:p') |
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
327 let l:cmd .= ' -s "' . l:full_path . '"' |
0 | 328 endif |
3 | 329 for ign in split(&wildignore, ',') |
35 | 330 let l:cmd .= ' -x ' . '"' . ign . '"' |
3 | 331 endfor |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
332 for exc in g:gutentags_exclude |
35 | 333 let l:cmd .= ' -x ' . '"' . exc . '"' |
3 | 334 endfor |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
335 if g:gutentags_pause_after_update |
36
186b65facdb1
Remove conflicting options to update scripts.
Ludovic Chabant <ludovic@chabant.com>
parents:
35
diff
changeset
|
336 let l:cmd .= ' -c' |
11
478638833c3b
Fix Win32 update script, add option to pause it.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
337 endif |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
338 if len(g:gutentags_options_file) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
339 let l:cmd .= ' -o "' . g:gutentags_options_file . '"' |
16
c11616828595
Add an option to specify a `ctags` options file to be used.
Ludovic Chabant <ludovic@chabant.com>
parents:
15
diff
changeset
|
340 endif |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
341 if g:gutentags_trace |
3 | 342 if has('win32') |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
343 let l:cmd .= ' -l "' . l:tags_file . '.log"' |
3 | 344 else |
19
d48b0e48283b
Add support for storing tags files out of the way.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
345 let l:cmd .= ' > "' . l:tags_file . '.log" 2>&1' |
9
f0f1d20d6f5c
On Unix, either log to file or don't log at all.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
346 endif |
f0f1d20d6f5c
On Unix, either log to file or don't log at all.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
347 else |
f0f1d20d6f5c
On Unix, either log to file or don't log at all.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
348 if !has('win32') |
f0f1d20d6f5c
On Unix, either log to file or don't log at all.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
349 let l:cmd .= ' > /dev/null 2>&1' |
3 | 350 endif |
0 | 351 endif |
3 | 352 let l:cmd .= s:get_execute_cmd_suffix() |
353 | |
0 | 354 call s:trace("Running: " . l:cmd) |
355 call s:trace("In: " . l:work_dir) | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
356 if !g:gutentags_fake |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
357 " Run the background process. |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
358 if !g:gutentags_trace |
0 | 359 silent execute l:cmd |
360 else | |
361 execute l:cmd | |
362 endif | |
35 | 363 |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
364 " Flag this tags file as being in progress |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
365 let l:full_tags_file = fnamemodify(l:tags_file, ':p') |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
366 let s:maybe_in_progress[l:full_tags_file] = localtime() |
0 | 367 else |
368 call s:trace("(fake... not actually running)") | |
369 endif | |
370 call s:trace("") | |
371 finally | |
372 " Restore the current directory... | |
373 execute "chdir " . l:prev_cwd | |
374 endtry | |
375 endfunction | |
376 | |
377 " }}} | |
378 | |
379 " Manual Tagfile Generation {{{ | |
380 | |
381 function! s:generate_tags(bang, ...) abort | |
382 call s:update_tags(1, 0, a:1) | |
383 endfunction | |
384 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
385 command! -bang -nargs=1 -complete=file GutentagsGenerate :call s:generate_tags(<bang>0, <f-args>) |
0 | 386 |
387 " }}} | |
388 | |
3 | 389 " Toggles and Miscellaneous Commands {{{ |
0 | 390 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
391 command! GutentagsToggleEnabled :let g:gutentags_enabled=!g:gutentags_enabled |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
392 command! GutentagsToggleTrace :call gutentags#trace() |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
393 command! GutentagsUnlock :call delete(b:gutentags_file . '.lock') |
0 | 394 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
395 if g:gutentags_debug |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
396 command! GutentagsToggleFake :call gutentags#fake() |
10
b853ad0e7afd
Only define `:AutotagsToggleFake` if debug mode is on.
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
397 endif |
b853ad0e7afd
Only define `:AutotagsToggleFake` if debug mode is on.
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
398 |
0 | 399 " }}} |
400 | |
401 " Autoload Functions {{{ | |
402 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
403 function! gutentags#rescan(...) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
404 if exists('b:gutentags_file') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
405 unlet b:gutentags_file |
0 | 406 endif |
407 if a:0 && a:1 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
408 let l:trace_backup = g:gutentags_trace |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
409 let l:gutentags_trace = 1 |
0 | 410 endif |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
411 call s:setup_gutentags() |
0 | 412 if a:0 && a:1 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
413 let g:gutentags_trace = l:trace_backup |
0 | 414 endif |
415 endfunction | |
416 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
417 function! gutentags#trace(...) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
418 let g:gutentags_trace = !g:gutentags_trace |
0 | 419 if a:0 > 0 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
420 let g:gutentags_trace = a:1 |
0 | 421 endif |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
422 if g:gutentags_trace |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
423 echom "gutentags: Tracing is enabled." |
0 | 424 else |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
425 echom "gutentags: Tracing is disabled." |
0 | 426 endif |
427 echom "" | |
428 endfunction | |
429 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
430 function! gutentags#fake(...) |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
431 let g:gutentags_fake = !g:gutentags_fake |
0 | 432 if a:0 > 0 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
433 let g:gutentags_fake = a:1 |
0 | 434 endif |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
435 if g:gutentags_fake |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
436 echom "gutentags: Now faking gutentags." |
0 | 437 else |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
438 echom "gutentags: Now running gutentags for real." |
0 | 439 endif |
440 echom "" | |
441 endfunction | |
442 | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
443 function! gutentags#inprogress() |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
444 echom "gutentags: generations in progress:" |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
445 for mip in keys(s:maybe_in_progress) |
3 | 446 echom mip |
447 endfor | |
448 echom "" | |
449 endfunction | |
450 | |
0 | 451 " }}} |
452 | |
3 | 453 " Statusline Functions {{{ |
454 | |
455 " Prints whether a tag file is being generated right now for the current | |
456 " buffer in the status line. | |
457 " | |
458 " Arguments can be passed: | |
459 " - args 1 and 2 are the prefix and suffix, respectively, of whatever output, | |
460 " if any, is going to be produced. | |
461 " (defaults to empty strings) | |
462 " - arg 3 is the text to be shown if tags are currently being generated. | |
463 " (defaults to 'TAGS') | |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
464 |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
465 function! gutentags#statusline(...) abort |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
466 if !exists('b:gutentags_file') |
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
467 " This buffer doesn't have gutentags. |
3 | 468 return '' |
469 endif | |
470 | |
471 " Figure out what the user is customizing. | |
472 let l:gen_msg = 'TAGS' | |
25
a20588c2c020
Fix for gutentags#statusline() with no args.
Morton Fox <github@qslw.com>
parents:
22
diff
changeset
|
473 if a:0 > 0 |
3 | 474 let l:gen_msg = a:1 |
475 endif | |
476 | |
477 " To make this function as fast as possible, we first check whether the | |
478 " current buffer's tags file is 'maybe' being generated. This provides a | |
479 " nice and quick bail out for 99.9% of cases before we need to this the | |
480 " file-system to check the lock file. | |
22
4e1b0253f71a
Renamed project to "Gutentags" (thanks Sylvain!).
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
481 let l:abs_tag_file = fnamemodify(b:gutentags_file, ':p') |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
482 let l:timestamp = get(s:maybe_in_progress, l:abs_tag_file) |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
483 if l:timestamp == 0 |
3 | 484 return '' |
485 endif | |
15
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
486 " It's maybe generating! Check if the lock file is still there... but |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
487 " don't do it too soon after the script was originally launched, because |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
488 " there can be a race condition where we get here just before the script |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
489 " had a chance to write the lock file. |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
490 if (localtime() - l:timestamp) > 1 && |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
491 \!filereadable(l:abs_tag_file . '.lock') |
b557282af215
Fix race condition between the statusline and the lock file.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
492 call remove(s:maybe_in_progress, l:abs_tag_file) |
3 | 493 return '' |
494 endif | |
495 " It's still there! So probably `ctags` is still running... | |
496 " (although there's a chance it crashed, or the script had a problem, and | |
497 " the lock file has been left behind... we could try and run some | |
498 " additional checks here to see if it's legitimately running, and | |
499 " otherwise delete the lock file... maybe in the future...) | |
500 return l:gen_msg | |
501 endfunction | |
502 | |
503 " }}} | |
504 |