ctagsをObjective-Cに対応させる
移転しました →
ソースコードにタグ付けするctagsはObjective-Cに対応していませんが、設定ファイルにパターンを書くことである程度対応させることができるようです。
設定ファイル~/.ctags
に以下を貼り付けます。
# ~/.ctags --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/
この状態で普通に使えばobjcをいい感じに処理してくれます。
before/after
検証にということでオープンソースのライブラリ、SVProgressHUDのソースコードにctagsをかけてみました。
ctagsのコマンドなどは次の通りです。
$ git clone https://github.com/samvermette/SVProgressHUD.git $ co SVProgressHUD $ ctags -R -f tag-file-name .
before
~/.ctags
へ設定を書く前の結果がこちら。
https://gist.github.com/xoyip/9796636
インデックスは18行分作られています。ヘッダーファイルしか解析できない上、Objective−Cの文法を解釈してくれないので必要な情報がほとんどとれていません。
after
それに対して、~/.ctags
へObjective-Cの設定を書いたあとで作ったタグファイルがこちら。
https://gist.github.com/xoyip/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.