Skip to content

Instantly share code, notes, and snippets.

@jesstelford
Forked from bjornharrtell/Coffeescript ctags
Last active February 20, 2017 04:04
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jesstelford/6134172 to your computer and use it in GitHub Desktop.
Save jesstelford/6134172 to your computer and use it in GitHub Desktop.
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z_][A-Za-z0-9_]+\.)*([A-Za-z_][A-Za-z0-9_]+)( extends ([A-Za-z][A-Za-z0-9_.]*)+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?(([A-Za-z][A-Za-z0-9_.]*)+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+):[^->\n]*$/\1/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?/\3/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){0}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){1}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){2}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){3}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){4}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){5}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){6}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){7}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){8}/\8/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){9}/\8/f,field/

Coffeescript ctags regexes

Usage

Save the file as ~/.ctags (or for a project specific, just as .ctags in the directory you generate the tags in)

Example Coverage

These regexes should cover all of the following:

Classes

class MyAwesomeClass                         # tag = MyAwesomeClass
class my_Class                               # tag = my_Class
class Namespace.MyClass                      # tag = MyClass
class Namespace.Child extends Namespace.Base # tag = Child

Methods / Functions

doIt: ->                # tag = doIt
zip = ->                # tag = zip
fooBar: (param) ->      # tag = fooBar
bazZoo: => x * x        # tag = bazZoo
exports.bar: ->         # tag = bar
module.exports.@foo: => # tag = foo
module.exports.cat = -> # tag = cat

Variables / Fields

my_Var = 'foo'     # tag = myVar
@local_Var = 'bar' # tag = localVar
prop: 'bar'        # tag = prop
@bam: 'zoo'        # tag = bam

Variables / Fields declared within the parameter list of constructor() / initialize()

constructor: (@foo) ->                # tag = foo
constructor: (@bar, @zip) ->          # tags = bar, zip
initialize: (@prop = {}) ->           # tag = prop
initialize: (@baz={}, @me = 'foo') -> # tags = baz, me

Thanks

@bjornharrtell for the original gist @Tyderion for additions to the original

@bergman
Copy link

bergman commented Sep 25, 2014

Gives an error on all the last examples. The tags do get written though.

$ ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Dec 10 2013, 17:00:12
  Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex
$ cat examples.coffee
class Ex1
  constructor: (@foo) ->                # tag = foo
class Ex2
  constructor: (@bar, @zip) ->          # tags = bar, zip
class Ex3
  initialize: (@prop = {}) ->           # tag = prop
class Ex4
  initialize: (@baz={}, @me = 'foo') -> # tags = baz, me
$ ctags -f - examples.coffee
ctags: Warning: examples.coffee:2: null expansion of name pattern "\8"
ctags: Warning: examples.coffee:4: null expansion of name pattern "\8"
ctags: Warning: examples.coffee:6: null expansion of name pattern "\8"
ctags: Warning: examples.coffee:8: null expansion of name pattern "\8"
Ex1     examples.coffee /^class Ex1$/;" c
Ex2     examples.coffee /^class Ex2$/;" c
Ex3     examples.coffee /^class Ex3$/;" c
Ex4     examples.coffee /^class Ex4$/;" c
bar     examples.coffee /^  constructor: (@bar, @zip) ->          # tags = bar, zip$/;" f
baz     examples.coffee /^  initialize: (@baz={}, @me = 'foo') -> # tags = baz, me$/;"  f
constructor     examples.coffee /^  constructor: (@bar, @zip) ->          # tags = bar, zip$/;" m
constructor     examples.coffee /^  constructor: (@foo) ->                # tag = foo$/;"       m
foo     examples.coffee /^  constructor: (@foo) ->                # tag = foo$/;"       f
initialize      examples.coffee /^  initialize: (@baz={}, @me = 'foo') -> # tags = baz, me$/;"  m
initialize      examples.coffee /^  initialize: (@prop = {}) ->           # tag = prop$/;"      m
me      examples.coffee /^  initialize: (@baz={}, @me = 'foo') -> # tags = baz, me$/;"  f
prop    examples.coffee /^  initialize: (@prop = {}) ->           # tag = prop$/;"      f
zip     examples.coffee /^  constructor: (@bar, @zip) ->          # tags = bar, zip$/;" f

@kflu
Copy link

kflu commented Oct 8, 2014

Hi I've a patch, could you pull from my fork? Here's the link to the fork at the change you should pull. Here's the diff.

I fix the issue where the below class definition isn't recognized:

class Foo extends require('some_module').BaseClass

Diff:

commit e8337bd54bbf57961f1e945b44b3be0de205650d
Author: KFL <kfldev@outlook.com>
Date:   Wed Oct 8 00:00:00 2014 -0700

    Fix class regex where the extend <BaseClass> doesn't recognize base class when it is in the form of require('sth').BaseClass

diff --git a/.ctags b/.ctags
index e9c2906..b69c4df 100644
--- a/.ctags
+++ b/.ctags
@@ -1,6 +1,6 @@
 --langdef=coffee
 --langmap=coffee:.coffee
---regex-coffee=/(^|=[ \t])*class ([A-Za-z_][A-Za-z0-9_]+\.)*([A-Za-z_][A-Za-z0-9_]+)( extends ([A-Za-z][A-Za-z0-9_.]*)+)?$/\3/c,class/
+--regex-coffee=/(^|=[ \t])*class ([A-Za-z_][A-Za-z0-9_]+\.)*([A-Za-z_][A-Za-z0-9_]+)( extends .+)?$/\3/c,class/
 --regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?(([A-Za-z][A-Za-z0-9_.]*)+):.*[-=]>.*$/\3/m,method/
 --regex-coffee=/^[ \t]*(module\.)?(exports\.)?(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=.*[-=]>.*$/\3/f,function/
 --regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/v,variable/
@@ -17,4 +17,4 @@
 --regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){6}/\8/f,field/
 --regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){7}/\8/f,field/
 --regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){8}/\8/f,field/
---regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){9}/\8/f,field/
\ No newline at end of file
+--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?(,[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?){9}/\8/f,field/

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