]> Sergey Matveev's repositories - dotfiles.git/blob - vim/.vim/plugin/ctags.vim
Detect already loaded code with simpler <SID> check
[dotfiles.git] / vim / .vim / plugin / ctags.vim
1 " Universal Ctags creator
2 " Maintainer: Sergey Matveev <stargrave@stargrave.org>
3 " License: GNU General Public License version 3 of the License or later
4 "
5 " Create "tags" file in your project's root first.
6 " Then :Ctags LANG to fill it.
7
8 if exists('*<SID>Ctags') | finish | endif
9
10 function! s:Ctags(lang, onlyCmd, verbose)
11     let dst = tagfiles()
12     if len(dst) == 0
13         echohl WarningMsg | echomsg "No tagfiles" | echohl None
14         return
15     endif
16     let dst = sort(dst, {a, b -> len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1})[0]
17     let src = "/" . join(split(dst, "/")[:-3], "/")
18     if dst[0] != "/"
19         let dst = getcwd() . "/.tags/tags"
20         let src = getcwd()
21     endif
22     let cmdline = [
23         \"uctags",
24         \"--languages=" . a:lang,
25         \"--python-kinds=-i",
26         \"--c++-kinds=+p",
27         \"--recurse",
28     \]
29     if a:verbose == v:true | let cmdline += ["--verbose"] | endif
30     let cmdline += ["-f", dst, src]
31     if a:onlyCmd == v:true
32         echo join(cmdline, " ")
33         return
34     endif
35     execute "!" . join(cmdline, " ")
36     if a:verbose != v:true | redraw! | endif
37 endfunction
38
39 command! -nargs=1 Ctags silent call s:Ctags(<f-args>, v:false, v:false)
40 command! -nargs=1 Ctagsv silent call s:Ctags(<f-args>, v:true, v:false)
41 command! -nargs=1 Ctagscmd call s:Ctags(<f-args>, v:true, v:true)