Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Add Clojure support to exuberant ctags and vim-tagbar

ctags

Add the following to ~/.ctags (thanks, xzj / clojure.ctags):

--langdef=Clojure
--langmap=Clojure:.clj
--regex-clojure=/\([ \t]*create-ns[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/n,namespace/
--regex-clojure=/\([ \t]*def[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/d,definition/
--regex-clojure=/\([ \t]*defn[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/f,function/
--regex-clojure=/\([ \t]*defn-[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/p,private function/
--regex-clojure=/\([ \t]*defmacro[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/m,macro/
--regex-clojure=/\([ \t]*definline[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/i,inline/
--regex-clojure=/\([ \t]*defmulti[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/a,multimethod definition/
--regex-clojure=/\([ \t]*defmethod[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/b,multimethod instance/
--regex-clojure=/\([ \t]*defonce[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/c,definition (once)/
--regex-clojure=/\([ \t]*defstruct[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/s,struct/
--regex-clojure=/\([ \t]*intern[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/v,intern/
--regex-clojure=/\([ \t]*ns[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/n,namespace/

vim-tagbar

Fork vladh/tagbar or change autoload/tagbar.vim as per this diff:

diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim
index 2b555c3..07fdcb4 100644
--- a/autoload/tagbar.vim
+++ b/autoload/tagbar.vim
@@ -277,6 +277,24 @@ function! s:InitTypes() abort
         \ {'short' : 's', 'long' : 'sections',          'fold' : 0, 'stl' : 1}
     \ ]
     let s:known_types.cobol = type_cobol
+    " Clojure {{{3
+    let type_clojure = s:TypeInfo.New()
+    let type_clojure.ctagstype = 'clojure'
+    let type_clojure.kinds     = [
+        \ {'short' : 'n', 'long' : 'namespace',                'fold' : 0, 'stl' : 1},
+        \ {'short' : 'd', 'long' : 'definition',               'fold' : 0, 'stl' : 1},
+        \ {'short' : 'f', 'long' : 'function',                 'fold' : 0, 'stl' : 1},
+        \ {'short' : 'p', 'long' : 'private function',         'fold' : 0, 'stl' : 1},
+        \ {'short' : 'm', 'long' : 'macro',                    'fold' : 0, 'stl' : 1},
+        \ {'short' : 'i', 'long' : 'inline',                   'fold' : 0, 'stl' : 1},
+        \ {'short' : 'a', 'long' : 'multimethod definition',   'fold' : 0, 'stl' : 1},
+        \ {'short' : 'b', 'long' : 'multimethod instance',     'fold' : 0, 'stl' : 1},
+        \ {'short' : 'c', 'long' : 'definition (once)',        'fold' : 0, 'stl' : 1},
+        \ {'short' : 's', 'long' : 'struct',                   'fold' : 0, 'stl' : 1},
+        \ {'short' : 'v', 'long' : 'intern',                   'fold' : 0, 'stl' : 1},
+        \ {'short' : 'n', 'long' : 'namespace',                'fold' : 0, 'stl' : 1}
+    \ ]
+    let s:known_types.clojure = type_clojure
     " DOS Batch {{{3
     let type_dosbatch = s:TypeInfo.New()
     let type_dosbatch.ctagstype = 'dosbatch'
@@ -447,7 +465,6 @@ function! s:InitTypes() abort
         \ {'short' : 'f', 'long' : 'functions', 'fold' : 0, 'stl' : 1}
     \ ]
     let s:known_types.lisp = type_lisp
-    let s:known_types.clojure = type_lisp
     " Lua {{{3
     let type_lua = s:TypeInfo.New()
     let type_lua.ctagstype = 'lua'

maio commented May 14, 2015

Thanks!

I'm also using this for .cljx / .cljs files

--langmap=Clojure:.clj
--langmap=Clojure:+.cljx
--langmap=Clojure:+.cljs

I don't know why, but when i have a function like
(defn- model->jgp [] ...)
(defn- model->pdf [] ..)
Tagbar window only shows
model-
model-

fatihict commented May 20, 2017 edited

I know this is a pretty old thread, but I had the same issue as @alan-saar and the fix is simply adding a '>' char in the defn/defn- regex. So --regex-clojure=/\([ \t]*defn[ \t]+([->[:alnum:]*+!_:\/.?]+)/\1/f,function/ would fix it :).

Anyways, thanks for the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment