annotate autoload/gutentags.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 51c1a57811b3
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 " gutentags.vim - Automatic ctags management for Vim
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 " Utilities {{{
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 " Throw an exception message.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 function! gutentags#throw(message)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 let v:errmsg = "gutentags: " . a:message
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 throw v:errmsg
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 " Prints a message if debug tracing is enabled.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 function! gutentags#trace(message, ...)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 if g:gutentags_trace || (a:0 && a:1)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 let l:message = "gutentags: " . a:message
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 echom l:message
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 " Strips the ending slash in a path.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 function! gutentags#stripslash(path)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 return fnamemodify(a:path, ':s?[/\\]$??')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 " Normalizes the slashes in a path.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 function! gutentags#normalizepath(path)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 if exists('+shellslash') && &shellslash
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 return substitute(a:path, '\v/', '\\', 'g')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 elseif has('win32')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 return substitute(a:path, '\v/', '\\', 'g')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 return a:path
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 " Shell-slashes the path (opposite of `normalizepath`).
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 function! gutentags#shellslash(path)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 if exists('+shellslash') && !&shellslash
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 return substitute(a:path, '\v\\', '/', 'g')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 return a:path
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 " Gets a file path in the correct `plat` folder.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 function! gutentags#get_plat_file(filename) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 return g:gutentags_plat_dir . a:filename . g:gutentags_script_ext
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48
75
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
49 " Gets a file path in the resource folder.
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
50 function! gutentags#get_res_file(filename) abort
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
51 return g:gutentags_res_dir . a:filename
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
52 endfunction
d12543f11eb9 Move the default `-R` option to an overridable "global" options file.
Ludovic Chabant <ludovic@chabant.com>
parents: 70
diff changeset
53
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 " Gutentags Setup {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 let s:known_files = []
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 " Finds the first directory with a project marker by walking up from the given
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 " file path.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 function! gutentags#get_project_root(path) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 let l:path = gutentags#stripslash(a:path)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 let l:previous_path = ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 let l:markers = g:gutentags_project_root[:]
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 if exists('g:ctrlp_root_markers')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 let l:markers += g:ctrlp_root_markers
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 while l:path != l:previous_path
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 for root in g:gutentags_project_root
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 if getftype(l:path . '/' . root) != ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 let l:proj_dir = simplify(fnamemodify(l:path, ':p'))
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 return gutentags#stripslash(l:proj_dir)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 let l:previous_path = l:path
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 let l:path = fnamemodify(l:path, ':h')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 endwhile
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 call gutentags#throw("Can't figure out what tag file to use for: " . a:path)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 " Generate a path for a given filename in the cache directory.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 function! gutentags#get_cachefile(root_dir, filename) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 let l:tag_path = gutentags#stripslash(a:root_dir) . '/' . a:filename
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 if g:gutentags_cache_dir != ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 " Put the tag file in the cache dir instead of inside the
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 " projet root.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 let l:tag_path = g:gutentags_cache_dir . '/' .
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 \tr(l:tag_path, '\/:', '---')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 let l:tag_path = substitute(l:tag_path, '/\-', '/', '')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 let l:tag_path = gutentags#normalizepath(l:tag_path)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 return l:tag_path
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 " Setup gutentags for the current buffer.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 function! gutentags#setup_gutentags() abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 if exists('b:gutentags_files') && !g:gutentags_debug
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 " This buffer already has gutentags support.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 return
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102
63
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
103 " Don't setup gutentags for anything that's not a normal buffer
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
104 " (so don't do anything for help buffers and quickfix windows and
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
105 " other such things)
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
106 if &buftype != ''
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
107 return
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
108 endif
0f5b4a36c920 Don't try to setup Gutentags for non normal buffers.
Ludovic Chabant <ludovic@chabant.com>
parents: 59
diff changeset
109
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 " Try and find what tags file we should manage.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 call gutentags#trace("Scanning buffer '" . bufname('%') . "' for gutentags setup...")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 try
56
fca5dc8c8022 call expand with 1 to turn off wildignore jic
dnhgff <null@dnhgff.space>
parents: 55
diff changeset
113 let b:gutentags_root = gutentags#get_project_root(expand('%:p:h', 1))
47
7b419abf7fba Add ability to disable Gutentags if a `.notags` file is at the root.
Ludovic Chabant <ludovic@chabant.com>
parents: 46
diff changeset
114 if filereadable(b:gutentags_root . '/.notags')
7b419abf7fba Add ability to disable Gutentags if a `.notags` file is at the root.
Ludovic Chabant <ludovic@chabant.com>
parents: 46
diff changeset
115 call gutentags#trace("'notags' file found... no gutentags support.")
7b419abf7fba Add ability to disable Gutentags if a `.notags` file is at the root.
Ludovic Chabant <ludovic@chabant.com>
parents: 46
diff changeset
116 return
7b419abf7fba Add ability to disable Gutentags if a `.notags` file is at the root.
Ludovic Chabant <ludovic@chabant.com>
parents: 46
diff changeset
117 endif
7b419abf7fba Add ability to disable Gutentags if a `.notags` file is at the root.
Ludovic Chabant <ludovic@chabant.com>
parents: 46
diff changeset
118
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 let b:gutentags_files = {}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 for module in g:gutentags_modules
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 call call("gutentags#".module."#init", [b:gutentags_root])
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 catch /^gutentags\:/
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 call gutentags#trace("Can't figure out what tag file to use... no gutentags support.")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 return
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 endtry
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 " We know what tags file to manage! Now set things up.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 call gutentags#trace("Setting gutentags for buffer '" . bufname('%'))
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 " Autocommands for updating the tags on save.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 let l:bn = bufnr('%')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 execute 'augroup gutentags_buffer_' . l:bn
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 execute ' autocmd!'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 execute ' autocmd BufWritePost <buffer=' . l:bn . '> call s:write_triggered_update_tags()'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 execute 'augroup end'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 " Miscellaneous commands.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 command! -buffer -bang GutentagsUpdate :call s:manual_update_tags(<bang>0)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 " Add these tags files to the known tags files.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142 for module in keys(b:gutentags_files)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 let l:tagfile = b:gutentags_files[module]
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 let l:found = index(s:known_files, l:tagfile)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 if l:found < 0
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 call add(s:known_files, l:tagfile)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 " Generate this new file depending on settings and stuff.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 if g:gutentags_generate_on_missing && !filereadable(l:tagfile)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 call gutentags#trace("Generating missing tags file: " . l:tagfile)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 call s:update_tags(module, 1, 0)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 elseif g:gutentags_generate_on_new
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 call gutentags#trace("Generating tags file: " . l:tagfile)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 call s:update_tags(module, 1, 0)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162 " Tags File Management {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 " List of queued-up jobs, and in-progress jobs, per module.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 let s:update_queue = {}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 let s:maybe_in_progress = {}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 for module in g:gutentags_modules
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 let s:update_queue[module] = []
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 let s:maybe_in_progress[module] = {}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 " Make a given file known as being currently generated or updated.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 function! gutentags#add_progress(module, file) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 let s:maybe_in_progress[a:module][a:file] = localtime()
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 " Get how to execute an external command depending on debug settings.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178 function! gutentags#get_execute_cmd() abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 if has('win32')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180 let l:cmd = '!start '
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 if g:gutentags_background_update
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 let l:cmd .= '/b '
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 return l:cmd
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186 return '!'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190 " Get the suffix for how to execute an external command.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
191 function! gutentags#get_execute_cmd_suffix() abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
192 if has('win32')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193 return ''
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 return ' &'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 " (Re)Generate the tags file for the current buffer's file.
48
c1b33dc55b1c Fix bug with `GutentagsUpdate` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 47
diff changeset
200 function! s:manual_update_tags(bang) abort
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 for module in g:gutentags_modules
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 call s:update_tags(module, a:bang, 0)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 " (Re)Generate the tags file for a buffer that just go saved.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 function! s:write_triggered_update_tags() abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 if g:gutentags_enabled && g:gutentags_generate_on_write
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 for module in g:gutentags_modules
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 call s:update_tags(module, 0, 1)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 " Update the tags file for the current buffer's file.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 " write_mode:
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 " 0: update the tags file if it exists, generate it otherwise.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218 " 1: always generate (overwrite) the tags file.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 "
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220 " queue_mode:
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 " 0: if an update is already in progress, report it and abort.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 " 1: if an update is already in progress, queue another one.
59
4cda41f830c3 Remove unused code after previous commit.
Ludovic Chabant <ludovic@chabant.com>
parents: 58
diff changeset
223 function! s:update_tags(module, write_mode, queue_mode) abort
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 " Figure out where to save.
59
4cda41f830c3 Remove unused code after previous commit.
Ludovic Chabant <ludovic@chabant.com>
parents: 58
diff changeset
225 let l:tags_file = b:gutentags_files[a:module]
4cda41f830c3 Remove unused code after previous commit.
Ludovic Chabant <ludovic@chabant.com>
parents: 58
diff changeset
226 let l:proj_dir = b:gutentags_root
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 " Check that there's not already an update in progress.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229 let l:lock_file = l:tags_file . '.lock'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230 if filereadable(l:lock_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 if a:queue_mode == 1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232 let l:idx = index(s:update_queue[a:module], l:tags_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 if l:idx < 0
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234 call add(s:update_queue[a:module], l:tags_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 call gutentags#trace("Tag file '" . l:tags_file .
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 \"' is already being updated. Queuing it up...")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 call gutentags#trace("")
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 echom "gutentags: The tags file is already being updated, " .
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 \"please try again later."
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 echom ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 return
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 " Switch to the project root to make the command line smaller, and make
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
248 " it possible to get the relative path of the filename to parse if we're
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249 " doing an incremental update.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 let l:prev_cwd = getcwd()
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 execute "chdir " . fnameescape(l:proj_dir)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 try
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253 call call("gutentags#".a:module."#generate",
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254 \[l:proj_dir, l:tags_file, a:write_mode])
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
255 finally
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256 " Restore the current directory...
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257 execute "chdir " . fnameescape(l:prev_cwd)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
258 endtry
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
259 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
260
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
261 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 " Utility Functions {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265 function! gutentags#rescan(...)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 if exists('b:gutentags_files')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 unlet b:gutentags_files
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 if a:0 && a:1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 let l:trace_backup = g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271 let l:gutentags_trace = 1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
272 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 call s:setup_gutentags()
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
274 if a:0 && a:1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
275 let g:gutentags_trace = l:trace_backup
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
276 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278
46
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
279 function! gutentags#delete_lock_files() abort
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
280 if exists('b:gutentags_files')
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
281 for tagfile in values(b:gutentags_files)
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
282 silent call delete(tagfile.'.lock')
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
283 endfor
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
284 endif
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
285 endfunction
c0f56e4d52bd Make a bunch of advanced commands opt-in only.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
286
41
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
287 function! gutentags#toggletrace(...)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
288 let g:gutentags_trace = !g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
289 if a:0 > 0
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
290 let g:gutentags_trace = a:1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
291 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
292 if g:gutentags_trace
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
293 echom "gutentags: Tracing is enabled."
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
294 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
295 echom "gutentags: Tracing is disabled."
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
296 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
297 echom ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
298 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
299
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
300 function! gutentags#fake(...)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301 let g:gutentags_fake = !g:gutentags_fake
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
302 if a:0 > 0
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
303 let g:gutentags_fake = a:1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
304 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
305 if g:gutentags_fake
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
306 echom "gutentags: Now faking gutentags."
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
307 else
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
308 echom "gutentags: Now running gutentags for real."
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
309 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
310 echom ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
311 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
312
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
313 function! gutentags#inprogress()
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
314 echom "gutentags: generations in progress:"
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
315 for mip in keys(s:maybe_in_progress)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
316 echom mip
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
317 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
318 echom ""
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
320
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
321 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
322
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
323 " Statusline Functions {{{
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
324
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
325 " Prints whether a tag file is being generated right now for the current
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
326 " buffer in the status line.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
327 "
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
328 " Arguments can be passed:
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
329 " - args 1 and 2 are the prefix and suffix, respectively, of whatever output,
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
330 " if any, is going to be produced.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
331 " (defaults to empty strings)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
332 " - arg 3 is the text to be shown if tags are currently being generated.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
333 " (defaults to 'TAGS')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
334
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
335 function! gutentags#statusline(...) abort
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
336 if !exists('b:gutentags_files')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
337 " This buffer doesn't have gutentags.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
338 return ''
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
339 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
340
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
341 " Figure out what the user is customizing.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
342 let l:gen_msg = 'TAGS'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
343 if a:0 > 0
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
344 let l:gen_msg = a:1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
345 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
346
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
347 " To make this function as fast as possible, we first check whether the
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
348 " current buffer's tags file is 'maybe' being generated. This provides a
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
349 " nice and quick bail out for 99.9% of cases before we need to this the
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
350 " file-system to check the lock file.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
351 let l:modules_in_progress = []
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
352 for module in keys(b:gutentags_files)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
353 let l:abs_tag_file = fnamemodify(b:gutentags_files[module], ':p')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
354 let l:progress_queue = s:maybe_in_progress[module]
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
355 let l:timestamp = get(l:progress_queue, l:abs_tag_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
356 if l:timestamp == 0
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
357 return ''
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
358 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
359 " It's maybe generating! Check if the lock file is still there... but
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
360 " don't do it too soon after the script was originally launched, because
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
361 " there can be a race condition where we get here just before the script
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
362 " had a chance to write the lock file.
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
363 if (localtime() - l:timestamp) > 1 &&
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
364 \!filereadable(l:abs_tag_file . '.lock')
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
365 call remove(l:progress_queue, l:abs_tag_file)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
366 return ''
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
367 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
368 call add(l:modules_in_progress, module)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
369 endfor
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
370
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
371 " It's still there! So probably `ctags` is still running...
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
372 " (although there's a chance it crashed, or the script had a problem, and
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
373 " the lock file has been left behind... we could try and run some
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
374 " additional checks here to see if it's legitimately running, and
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
375 " otherwise delete the lock file... maybe in the future...)
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
376 if len(g:gutentags_modules) > 1
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
377 let l:gen_msg .= '['.join(l:modules_in_progress, ',').']'
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
378 endif
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
379 return l:gen_msg
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
380 endfunction
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
381
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
382 " }}}
99328cb71e75 Refactor Gutentags so functionality can be implemented in "modules".
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
383