Alternatives to Ctags/Cscope with Objective-c?
Asked Answered
L

9

17

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?

Lido answered 3/6, 2010 at 17:56 Comment(3)
Maybe a bit late to answer, but several patches have been proposed to add objective C support for ctags, so it should be for the next version. As for when will it be released, that's a really different problem...Aglet
There is now a working Objective C parser in trunk... see my answerBridging
Use Universal Ctags the most maintained ctags now.Deprivation
B
30

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!

Bridging answered 26/4, 2011 at 13:9 Comment(7)
Have a problem even with latest ctags: now tags file is generated, but taglist doesn't show anything. Do you have any idea what's wrong?Gorga
check 1. your tags are loaded in that list :set tags 2. you have set taglist settings :let tlist_objc_settings (see point 4. of my answer) 3. taglist will automatically show tags for an open buffer 4. even without taglist you can check your tags are fine by using standard vim commands like jump to tag look at :help tagsBridging
Thank you, you've made my day! It finally works :-) Initially tags were working using standard vim commands, but no in taglist, after changing settings it just stalled every time taglist was opened. So finally I've deleted ctags I had (I've installed them from github and though it was recent enough) and reinstalled using brew as you initially suggested and... voila! Hope that will help if somebody has similar symptoms.Gorga
great news! I forgot a simple thing to check tags are correctly generated... vim tags tags files are readable in a simple format :)Bridging
I just tried using brew install ctags --HEAD and while ctags successfully installed, calling --version does not return a version number. This is problematic for the Tagbar plugin which checks the version number before launching. The Tagbar plugin fails to load.Clypeate
$ ctags --langmap=ObjectiveC:.m.h ctags: Warning: Unknown language "ObjectiveC:.m.h" in "langmap" optionBrainpan
It doesn't work very well IMHO. It routinely misses tags for C code that's inside .m files. This is an open ticket: github.com/universal-ctags/ctags/issues/907Candlemas
S
3

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;
Survival answered 12/4, 2017 at 18:2 Comment(0)
C
1

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.

Clericals answered 4/6, 2010 at 1:25 Comment(0)
R
1

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

Rockies answered 13/8, 2010 at 6:27 Comment(0)
H
1

You can also try objcscope which is written by me.

objcsope

Haynie answered 17/12, 2012 at 2:41 Comment(0)
Z
0

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.

Zielinski answered 17/8, 2010 at 14:56 Comment(2)
But will etags create a suitable tags file to work with VIM. I'm crippled in EmacsLido
Yes. I don’t use EMACS, and only use vi, vim, or MacVim.Zielinski
F
0

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

Fanfani answered 28/10, 2013 at 13:45 Comment(1)
The obj-c output from this is abysmal. I am sorely disappointed with it.Comintern
S
0

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.

Sibie answered 23/4, 2014 at 13:11 Comment(0)
C
0

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++.

Calutron answered 18/3, 2017 at 8:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.