Exuberant Ctags and JavaScript

Exuberant Ctags

Exuberant Ctags is an essential complement to Vim: it generates an index of symbol names (tags) for a set of source files. In Vim, just place the cursor on a function name and type C-] to go to its definition.

Ctags works well for most of the languages that I deal with, but falls down badly on modern JavaScript. Its built-in parser simply doesn't handle declarations like these:

Sizzle.selectors.filters.animated = function(elem) { // ...
ajaxSetup: function( settings ) {

I came across Unbad's workaround earlier tonight. His code didn't work for me, so I hacked on it until it did:

--regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/,object/
--regex-js=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/,function/
--regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\(([^)])\)/\1/,function/
--regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/,array/
--regex-js=/([^= ]+)[ \t]*=[ \t]*[^"]'[^']*/\1/,string/
--regex-js=/([^= ]+)[ \t]*=[ \t]*[^']"[^"]*/\1/,string/

Simply add the above to ~/.ctags or $HOME/ctags.cnf.


  • Thanks, some nice stuff in there. I am not getting the form
    --regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\(([^)])\)/\1/,function/

    to work for me though. It looks like it should work, but in testing against this function definition:
    function makeZebraTable () {

    it won't pick it up. I had another function with the same format and moved it to
    working = function() {

    and then it was picked up, so I know it's reading the file and that the earlier function definition format is working.

    Any ideas on what I'm missing in the regex? Sure seems it should work.

  • I have the same problem that
    --regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\(([^)])\)/\1/,function/

    doesn't work.

    I find the last part of the regular expression "\(([^)])\)" :

    For the "(" symbol, it doen't need "\" to escape.

    So the exact expression is "([^)])"

    When I replace the regular expression to :
    --regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*([^)])/\1/,function/

    It works well to detect function pattern like :
    function makeZebraTable () {

    By the way, thanks for this article to give me a guide how to use ctags with self define pattern :D

  • --regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/o,object/
    --regex-JavaScript=/([A-Za-z0-9._$'"()]+)[ \t]*[:][ \t]*function[ \t]*\([^)]*\)/\1/f,function/
    --regex-JavaScript=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/a,array/
    --regex-JavaScript=/([^= ]+)[ \t]*=[ \t]*'[^']*'/\1/s,string/
    --regex-JavaScript=/([^= ]+)[ \t]*=[ \t]*"[^"]*"/\1/s,string/

    I think he miss a *
    regex link egrep () is for groub \1 \2
    and \( \) is literally ( )

  • Благодарность за материалы! :)
    Respect weblogs.asp.net

  • Hey hey hey, take a gdnear at what' you've done

  • Sorry it’s taken so long to respond; I’ve been kind of absnet (read: work projects got BUSY).I didn’t actuadally try it, but it should work just to change the escaped slashes.Examadple: var pattern:RegExp = /(\)/g; var fixed: String = path.replace(pattern,a0“/”);

  • Explanation why nobody is talking over watch and the things that you ought to engage in today.

Comments have been disabled for this content.