Skip to content

Instantly share code, notes, and snippets.

@mads-hartmann
Created April 7, 2011 07:44
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save mads-hartmann/907245 to your computer and use it in GitHub Desktop.
Save mads-hartmann/907245 to your computer and use it in GitHub Desktop.
ctags definitions for Coffeescript. Very basic for now. "> ctags -e -R source_folder" and then M-. to jump to the definition of any function or variable (if you're using emacs)
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=.*->.*$/\1/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
@dimroc
Copy link

dimroc commented Aug 24, 2011

Thanks for this great post.

I'm currently using vim and was wondering if you knew of a way to gave these tags listed in tagbar or taglist (http://majutsushi.github.com/tagbar/ or http://vim-taglist.sourceforge.net/). I'm currently resorting to basic vim tag usage which allows me to hop around tags but doesn't allow me to easily visualize all the tags available to me.

@mads-hartmann
Copy link
Author

Hi, I'm happy you found this useful. I'm afraid I've never used Vim so can't help you out there :-/

@lorensr
Copy link

lorensr commented Aug 29, 2011

Thanks! Also, the full identifier regex is [a-zA-Z_$][0-9a-zA-Z_$]* and functions can be bound (=> instead of ->).

@mads-hartmann
Copy link
Author

Feel free to fork it! :)

@joeytwiddle
Copy link

To make ctags use these rules automatically, just add the lines above to ~/.ctags

To make the generated tags available in vim's TagList, add this line to your .vimrc

    let g:tlist_coffee_settings = 'coffee;f:function;v:variable'

Hopefully that answer dimroc's question.

@hupili
Copy link

hupili commented Aug 25, 2012

This is one helpful example. The above notes for vim+tlist also helped a lot.

@benjie
Copy link

benjie commented Nov 14, 2013

For others that find this gist and want more --regex-coffee to add to their ~/.ctags, take a look here:

--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/

@dreki
Copy link

dreki commented Oct 27, 2014

👍 @benjie

@coderofsalvation
Copy link

I've added these 2 lines to ~/.ctags (after the lines which benjies pasted above)

--regex-coffee=/[ \t](.*\.)?([A-Za-z_0-9]+[ \t]=.*\))/\2/f/ 
--regex-coffee=/^([A-Za-z_.0-9]+[ \t]=.*\))/\1/f/

That allows completion out of the box in vim without snipMate:

in insertmode, after typing few characters, ctrl-x ctrl-] will popup any matching function with arguments

@sysmon
Copy link

sysmon commented Aug 19, 2015

Very important to include

'(tags-case-fold-search nil)

This will make the tag search case sensitive, and that makes quite a bit of difference to navigation(reduces extraneous matches). Also, make sure to --exclude=anything_you_don't_care_about.

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