clojure and ctags, catching def* forms

433 views Asked by At

So I found the following snippet from a Gist a while back:

--langdef=Clojure                                                                         
--langmap=Clojure:.clj                                                                    
--langmap=Clojure:+.cljx                                                                  
--langmap=Clojure:+.cljs                                                                  
--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]*defmacro[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/m,macro/               
--regex-clojure=/\([ \t]*definline[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/i,inline/             
--regex-clojure=/\([ \t]*defmulti[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/a,multimethod definitio
--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/   

However other libraries have introduced their own macros like defroutes and defhtml. I am looking to create a wildcard regex that selects def*.

I tried adding * to def and it didn't work so obviously that regex is wrong. What would a wildcard catchall regex look like?

2

There are 2 answers

0
AudioBubble On BEST ANSWER

def* would match things like defffffff. In a regex, the star does not mean match anything. It means match the previous pattern any number of times. In your case, the previous pattern is f. Try def[a-z]* to match def followed by any combination of lowercase letters.

1
Lee On

Thanks to @broma0's help, my .ctags now has the following:

--langdef=Clojure                                                               
--langmap=Clojure:.clj                                                          
--langmap=Clojure:+.cljx                                                        
--langmap=Clojure:+.cljs                                                        
--regex-clojure=/\([ \t]*create-ns[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/n,namespace/
--regex-clojure=/\([ \t]*def[a-z]*[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/s,symbol/   
--regex-clojure=/\([ \t]*intern[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/v,intern/      
--regex-clojure=/\([ \t]*ns[ \t]+([-[:alnum:]*+!_:\/.?]+)/\1/n,namespace/       

def* anything just gets classified as 'symbol`