comparison autoload/gutentags/ctags.vim @ 41:99328cb71e75

Refactor Gutentags so functionality can be implemented in "modules". The first module is Ctags generation, obviously.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 20 Feb 2015 14:13:51 -0800
parents
children 64de69ca7195
comparison
equal deleted inserted replaced
40:8b3c611a4d3b 41:99328cb71e75
1 " Ctags module for Gutentags
2
3 " Global Options {{{
4
5 if !exists('g:gutentags_ctags_executable')
6 let g:gutentags_executable = 'ctags'
7 endif
8
9 if !exists('g:gutentags_ctags_options_file')
10 let g:gutentags_ctags_options_file = ''
11 endif
12
13 if !exists('g:gutentags_tagfile')
14 let g:gutentags_tagfile = 'tags'
15 endif
16
17 if !exists('g:gutentags_auto_set_tags')
18 let g:gutentags_auto_set_tags = 1
19 endif
20
21 " }}}
22
23 " Gutentags Module Interface {{{
24
25 let s:runner_exe = gutentags#get_plat_file('update_tags')
26
27 function! gutentags#ctags#init(project_root) abort
28 " Figure out the path to the tags file.
29 let b:gutentags_files['ctags'] = gutentags#get_cachefile(
30 \a:project_root, g:gutentags_tagfile)
31
32 " Set the tags file for Vim to use.
33 if g:gutentags_auto_set_tags
34 execute 'setlocal tags^=' . fnameescape(b:gutentags_files['ctags'])
35 endif
36 endfunction
37
38 function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
39 " Get to the tags file directory because ctags is finicky about
40 " these things.
41 let l:prev_cwd = getcwd()
42 let l:work_dir = fnamemodify(a:tags_file, ':h')
43 execute "chdir " . fnameescape(l:work_dir)
44
45 try
46 " Build the command line.
47 let l:cmd = gutentags#get_execute_cmd() . s:runner_exe
48 let l:cmd .= ' -e "' . g:gutentags_executable . '"'
49 let l:cmd .= ' -t "' . a:tags_file . '"'
50 let l:cmd .= ' -p "' . a:proj_dir . '"'
51 if a:write_mode == 0 && filereadable(a:tags_file)
52 let l:full_path = expand('%:p')
53 let l:cmd .= ' -s "' . l:full_path . '"'
54 endif
55 for ign in split(&wildignore, ',')
56 let l:cmd .= ' -x ' . '"' . ign . '"'
57 endfor
58 for exc in g:gutentags_exclude
59 let l:cmd .= ' -x ' . '"' . exc . '"'
60 endfor
61 if g:gutentags_pause_after_update
62 let l:cmd .= ' -c'
63 endif
64 if len(g:gutentags_options_file)
65 let l:cmd .= ' -o "' . g:gutentags_options_file . '"'
66 endif
67 if g:gutentags_trace
68 if has('win32')
69 let l:cmd .= ' -l "' . a:tags_file . '.log"'
70 else
71 let l:cmd .= ' > "' . a:tags_file . '.log" 2>&1'
72 endif
73 else
74 if !has('win32')
75 let l:cmd .= ' > /dev/null 2>&1'
76 endif
77 endif
78 let l:cmd .= gutentags#get_execute_cmd_suffix()
79
80 call gutentags#trace("Running: " . l:cmd)
81 call gutentags#trace("In: " . getcwd())
82 if !g:gutentags_fake
83 " Run the background process.
84 if !g:gutentags_trace
85 silent execute l:cmd
86 else
87 execute l:cmd
88 endif
89
90 " Flag this tags file as being in progress
91 let l:full_tags_file = fnamemodify(a:tags_file, ':p')
92 call gutentags#add_progress('ctags', l:full_tags_file)
93 else
94 call gutentags#trace("(fake... not actually running)")
95 endif
96 call gutentags#trace("")
97 finally
98 " Restore the previous working directory.
99 execute "chdir " . fnameescape(l:prev_cwd)
100 endtry
101 endfunction
102
103 " }}}
104