Sunday, March 11, 2007

Using Exuberant Ctags with Emacs And Objective-C

Below is a small script that generates Emacs tags files for the header files in /System/Library/Frameworks and /usr/include on Mac:

#!/bin/sh
s="\t "
S="[$s]*"
w="_a-zA-Z0-9"
CN="[A-Z][$w]*"
NM="[$w][$w]*"


cat /dev/null > tmp.tags
find /usr/include -name "*.h" -exec \
ctags -e -a -o tmp.tags "{}" ";"

awk -v LINE="" ' { if (LINE != $0) {LINE = $0; print $0;} }' tmp.tags > include.tags

cat /dev/null > tmp.tags
find /System/Library/Frameworks -name "*.h" -exec \
ctags -e -a -o tmp.tags \
--regex-C++="/^@(interface|protocol)$S($CN($S\($CN\))*)/\2/c/" \
--regex-C++="/^$S(\-|\+)$S\($S$NM($S$NM)*$S\**$S\)*$S($NM)$S[:;]/\3/f/" \
"{}" ";"

awk -v LINE="" ' { if (LINE != $0) {LINE = $0; print $0;} }'
tmp.tags > Frameworks.tags
rm tmp.tags

No comments: