]> Sergey Matveev's repositories - dotfiles.git/blobdiff - vim/.vim/plugin/ctags.vim
Detect already loaded code with simpler <SID> check
[dotfiles.git] / vim / .vim / plugin / ctags.vim
index 0baeb3c2ce6f2013d86be7540a42a0d6e2d4f687..268b27e4ea67e55ba7c6275a7492b3dca51d3c24 100644 (file)
@@ -1,26 +1,33 @@
-" Exuberant Ctags creator
+" Universal Ctags creator
 " Maintainer: Sergey Matveev <stargrave@stargrave.org>
 " License: GNU General Public License version 3 of the License or later
 "
 " Create "tags" file in your project's root first.
 " Then :Ctags LANG to fill it.
 
-function! s:ctags(lang, onlyCmd, verbose)
-    let dst = tagfiles()[0]
-    let src = "/" . join(split(dst, "/")[:-2], "/")
+if exists('*<SID>Ctags') | finish | endif
+
+function! s:Ctags(lang, onlyCmd, verbose)
+    let dst = tagfiles()
+    if len(dst) == 0
+        echohl WarningMsg | echomsg "No tagfiles" | echohl None
+        return
+    endif
+    let dst = sort(dst, {a, b -> len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1})[0]
+    let src = "/" . join(split(dst, "/")[:-3], "/")
     if dst[0] != "/"
-        let dst = getcwd() . "/tags"
+        let dst = getcwd() . "/.tags/tags"
         let src = getcwd()
     endif
     let cmdline = [
-        \'uctags',
-        \'--languages=' . a:lang,
-        \'--kind-python=-i',
-        \'--kind-c++=+p',
-        \'--recurse',
+        \"uctags",
+        \"--languages=" . a:lang,
+        \"--python-kinds=-i",
+        \"--c++-kinds=+p",
+        \"--recurse",
     \]
-    if a:verbose == v:true | let cmdline += ['--verbose'] | endif
-    let cmdline += ['-f', dst, src]
+    if a:verbose == v:true | let cmdline += ["--verbose"] | endif
+    let cmdline += ["-f", dst, src]
     if a:onlyCmd == v:true
         echo join(cmdline, " ")
         return
@@ -29,6 +36,6 @@ function! s:ctags(lang, onlyCmd, verbose)
     if a:verbose != v:true | redraw! | endif
 endfunction
 
-command! -nargs=1 Ctags silent call s:ctags(<f-args>, v:false, v:false)
-command! -nargs=1 Ctagsv silent call s:ctags(<f-args>, v:true, v:false)
-command! -nargs=1 Ctagscmd call s:ctags(<f-args>, v:true, v:true)
+command! -nargs=1 Ctags silent call s:Ctags(<f-args>, v:false, v:false)
+command! -nargs=1 Ctagsv silent call s:Ctags(<f-args>, v:true, v:false)
+command! -nargs=1 Ctagscmd call s:Ctags(<f-args>, v:true, v:true)