Objective-C Exuberant Ctags Regex

I just finished taking a look at improving my Objective-C ctags regex, as Exuberant Ctags doesn’t support the language directly. I wasn’t really able to find anything helpful so for anyone interested these are the lines in my ~/.ctags file that I use for Objective-C tags creation. They’re certainly not perfect but they do a reasonable job for me. Suggestions and improvements are very welcome.


--langdef=objc
--langmap=objc:.m.h
--regex-objc=/^[[:space:]]*[-+][[:space:]]*\([[:alpha:]]+[[:space:]]*\*?\)[[:space:]]*([[:alnum:]]+):[[:space:]]*\(/\1/m,method/
--regex-objc=/^[[:space:]]*[-+][[:space:]]*\([[:alpha:]]+[[:space:]]*\*?\)[[:space:]]*([[:alnum:]]+)[[:space:]]*\{/\1/m,method/
--regex-objc=/^[[:space:]]*[-+][[:space:]]*\([[:alpha:]]+[[:space:]]*\*?\)[[:space:]]*([[:alnum:]]+)[[:space:]]*\;/\1/m,method/
--regex-objc=/^[[:space:]]*\@property[[:space:]]+.*[[:space:]]+\*?(.*);$/\1/p,property/
--regex-objc=/^[[:space:]]*\@implementation[[:space:]]+(.*)$/\1/c,class/
--regex-objc=/^[[:space:]]*\@interface[[:space:]]+(.*)[[:space:]]+:.*{/\1/i,interface/

For completeness this is the line in my ~/.vimrc for use with the TagList plugin.

let tlist_objc_settings    = 'objc;i:interface;c:class;m:method;p:property'

Leave a Reply

(required)

Responses to “Objective-C Exuberant Ctags Regex”

  1. Thank you for posting this. It was very helpful in my battle to get tags working correctly for obj-c files. Just curious- do you use autotag.vim or easytags.vim scripts to keep your tag file(s) up to date?

    • No I don’t use either of those. I do have this in my .vimrc to help with tags generation though:

      "build ctags for the cwd
      :nmap <leader>ct :!ctags -R *<CR>

      I then override this for specific file types if I want to add flags, for example in C# I use this.

      autocmd FileType cs :nmap <buffer> <leader>ct :exec "!ctags -R --extra=+fq --fields=+ianmzS --c\\#-kinds=cimnp ."<CR>

  2. Yes indeed, thanks for sharing!

    I just found a reference to a ctags fork with Objective-C support, but I haven’t tried it yet — hope that work can get merged upstream:

    https://github.com/mcormier/ctags-ObjC-5.8.1

    • @Ches Martin- Have you had a chance to try it yet? I can’t seem to get it to work. The tag file I create using version 5.8.1 of ctags only seemed to have @properties (no methods)

    • This looks like a great find. It’s about time ctags got some attention. I might have a play with this if I can find some time!

  3. It works!
    Do you know how to support “.mm” file?
    .mm file can support objective-c and c++.
    I modified .ctags –langmap to add .mm, but it does not work!

    • I mean Taglist not works!

      • When I open a *.mm file in Vim it detects it as of ‘nroff’ filetype. This means that the taglist plugin won’t be using objective-c definitions to generate the tags. Try issuing :set ft=objc on a *.mm file. This should allow taglist to work. You can have this automatically happen by putting the following autocmd in your .vimrc.

        autocmd BufRead,BufNewFile *.mm :set ft=objc

        Hope this helps. Let me know how you get on.

        • Awesome!
          It works!
          I don’t know ‘autocmd’ before,
          but enriching my knowledge now.
          Thank you very much!

        • Do you use other vim plugins (e.g. cocoa.vim, snipMate.vim) to finish something like
          method/class/variable completion?

          if Yes, could you introduce the plugins?
          thanks!

  4. Mario Gajardo Tassara December 15th, 2011 - 10:30 pm

    Thank you very much !!!

    I was searching this for ages, now i can do my objective-c coding more pleasant !!, thank again.

  5. |

  • Kyle Wellwood Jerseys
  • -->