
ソースコードにタグ付けするctagsはObjective-Cに対応していませんが、設定ファイルにパターンを書くことである程度対応させることができるようです。
設定ファイル~/.ctagsに以下を貼り付けます。
1# ~/.ctags
2--langdef=objc
3--langmap=objc:.m.h
4--regex-objc=/^[[:space:]]*[-+][[:space:]]*\([[:alpha:]]+[[:space:]]*\*?\)[[:space:]]*([[:alnum:]]+):[[:space:]]*\(/\1/m,method/
5--regex-objc=/^[[:space:]]*[-+][[:space:]]*\([[:alpha:]]+[[:space:]]*\*?\)[[:space:]]*([[:alnum:]]+)[[:space:]]*\{/\1/m,method/
6--regex-objc=/^[[:space:]]*[-+][[:space:]]*\([[:alpha:]]+[[:space:]]*\*?\)[[:space:]]*([[:alnum:]]+)[[:space:]]*\;/\1/m,method/
7--regex-objc=/^[[:space:]]*\@property[[:space:]]+.*[[:space:]]+\*?(.*);$/\1/p,property/
8--regex-objc=/^[[:space:]]*\@implementation[[:space:]]+(.*)$/\1/c,class/
9--regex-objc=/^[[:space:]]*\@interface[[:space:]]+(.*)[[:space:]]+:.*{/\1/i,interface/
この状態で普通に使えばobjcをいい感じに処理してくれます。
before/after
検証にということでオープンソースのライブラリ、SVProgressHUDのソースコードにctagsをかけてみました。
ctagsのコマンドなどは次の通りです。
1$ git clone https://github.com/samvermette/SVProgressHUD.git
2$ co SVProgressHUD
3$ ctags -R -f tag-file-name .
before
~/.ctagsへ設定を書く前の結果がこちら。
https://gist.github.com/pi-chan/9796636
インデックスは18行分作られています。ヘッダーファイルしか解析できない上、Objective−Cの文法を解釈してくれないので必要な情報がほとんどとれていません。
after
それに対して、~/.ctagsへObjective-Cの設定を書いたあとで作ったタグファイルがこちら。
https://gist.github.com/pi-chan/9796649
インデックスファイルは119行あります。設定を書く前には解釈出来なかった部分を解釈できるようになっているということがわかります。
参考
Exuberant Ctags: Adding support for a new language
How to Add Support for a New Language to Exuberant Ctags
Objective-C Exuberant Ctags Regex | gregsexton.org
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.