Question

Are there any alternatives to ctags and cscope with Objective-c support. This does pertain to cocoa development, so inevitably it seems I will be using Xcode (and probably should). I was just wondering what are my Vim options.

Maybe there is some type of plugin system like eclim, but for xcode?

EDIT

So it seems that other than updating ctags to support objective-c, I'm out of luck. Does anyone know if cscope is the same?

Was it helpful?

Solution

a long time after this question, "playing" with vim, I wanted ObjC support, especially with taglist plugin. I found that question, then digged a bit, and here is a not so dirty solution:

  1. An ObjectiveC parser has been added to Exuberant CTags trunk, it is not released (yet?)
  2. You can easily install it on OSX via homebrew:

    $ brew install ctags --HEAD

  3. Note that when using ctags, .m is treated as Matlab and .h is treated as C++. To override, use:

    $ ctags --langmap=ObjectiveC:.m.h

  4. Then I added something like this to my .vimrc for taglist support:

    let tlist_objc_settings = 'ObjectiveC;P:protocols;i:interfaces;types(...)'

    add any type interests you from that list:

    ctags --list-kinds=all
    ObjectiveC
        i  class interface
        I  class implementation
        p  Protocol
        m  Object's method
        c  Class' method
        v  Global variable
        F  Object field
        f  A function
        p  A property
        t  A type alias
        s  A type structure
        e  An enumeration
        M  A preprocessor macro
    

I hope that will help someone!

OTHER TIPS

AFAIK, ctags support you to define some rules for a new language, I did that when I did some development using laszlo(similiar to flex). You can read the manpage of ctags to get more details, that is not hard to do.

I find there is a vim filetype plugin that support development under cocoa here, hope it is helpful for you.

There is an option to use ctags for objective-c. You can use etags in ctags mode. etags derived from ctags some time ago, and in its source code ctags compatible tags will be generated by defining a certain macro switch.

In fact the man page in Mac Os already documents etags and ctags in the same page. It states that objective-c is supported in ctags. You should be able to generate a tag file using the following command: ctags -l objc *.[mh]

Unfortunately the ctags program in Mac OS behaves not as documented since Apple messed it up. I however managed to install this kind of ctags using Ubuntu Linux and it works great!!! There you have to install the emacs22-bin-common package.

So under Mac OS all you have to do is to compile this package for yourself.

  • Download the corresponding source package e.g. from the Debian server (link).
  • exctract it and change to the source directory
  • run ./configure
  • configure returns with an error because it cannot find lispref
  • I deleted all targets in varible config_files in the created file config.status despite the ones with lib-src
  • run ./config.status
  • cd lib-src
  • make
  • Copy ctags e.g. to /usr/local/bin and change permissions
    • sudo cp ctags /usr/local/bin
    • chmod a+rx /usr/local/bin/ctags

You are done. Happy tagging!!!

You can also try objcscope which is written by me.

objcsope

Apropos the other answer: you can install EMACS with MacPorts fairly easily and it will include a version of etags at /opt/local/bin that has Objective-C support compiled in.

% sudo port install emacs
% find . -name ‘*.[hm]’ -print0 | xargs −0 /opt/local/bin/etags

And then inside vim:

:setlocal tags=TAGS

This works well for me with MacVim.

You can try Fishman fork of Exuberant Ctags which has Objective C and CSS support.

I found it difficult getting ctags to generate tags for tagbar. It was easier to use a vim plugin for the Objective-C editor. XVim works with XCode. If you use Appcode like me, IdeaVim is well integrated.

Though you won't get to full Vi/Vim functionality with the plugin. I find mix usage with native IDE commands is enough to compensate.

If I am not wrong :

Latest ctags by now parsing the @property keyword incorrectly, which could cause that all the words after @property in the source code are parsed to be properties, leading to a mess in file tags.

I have to recompile ctags (https://sourceforge.net/p/ctags/code/HEAD/tree/) by commenting all of the property keyword processing in ObjC.c as a workaround. Even though, it only helps to get a little better for reading source code in the Taglist.

It still can't jump (e.g. to the implementation methods with parameters) correctly.

I also tried this(https://github.com/mcormier/ctags-ObjC-5.8.1), but unfortunately this can't jump at all.

Summary : there seems no ctags for ObjC as workable as for C/C++.

Universal-ctags(https://ctags.io) can capture properties of Objective-C.

[jet@localhost objectivec_property.h.d]$ cat input.h 

@interface Person : NSObject {
    @public
        NSString *m_name;
    @private
        int m_age;
}

@property(copy) NSString *personName;
@property(readonly) int personAge;

-(id)initWithAge:(int)age;
@end
[jet@localhost objectivec_property.h.d]$ ../../../ctags -x -o - input.h 
Person           interface     2 input.h          @interface Person : NSObject {
initWithAge:     method       12 input.h          -(id)initWithAge:(int)age;
m_age            field         6 input.h          int m_age;
m_name           field         4 input.h          NSString *m_name;
personAge        property     10 input.h          @property(readonly) int personAge;
personName       property      9 input.h          @property(copy) NSString *personName;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top