What are Ctags? From the horse’s mouth …
Ctags generates an index (or tag) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility.
In other words, Ctags will allow you to select a language object (function, constant, variable, etc.) in your text editor, invoke a command, and immediately jump to the file where that object is defined.
I just started working in an OS X only environment again and had to setup my Ctags install and thought you, dear reader, might benefit
Download the Ctags Source and Extract
As previously mentioned, the version of Ctags that ships with OS X only supports a limited subset of languages. We’ll want to download and install the Exuberant Ctags package
$ curl -LO 'http://prdownloads.sourceforge.net/ctags/ctags-5.6.tar.gz' $ tar -zxvf ctags-5.6.tar.gz
Next, the Holy Unix Trinity. I was able to install without any extra trickery on 10.4.x. The –prefix ensures the package will be installed to the /usr/local folder, which will prevent Apple from overwriting anything with a future software update.
$ cd ctags-5.6 $ ./configure --prefix=/usr/local $ make $ sudo make install
For the paranoid, check your install
$ /usr/local/bin/ctags --version
Setup BBEdit Alias
BBEdit has a specific set of options they recommend using with Ctags, so I like to setup an alias in my .bash_profile. (the following is all one line)
alias ctags-bbedit='/usr/local/bin/ctags --excmd=number --tag-relative=no --fields=+a+m+n+S -R `pwd`'
See Chapter 14: Working With Development Tools of the BBEdit manual for more information.
Also, if you haven’t already, you may want to add /usr/local to your shell path, but I’ll leave that as an exercise for the viewer.
Tag a Source Tree
Almost there! Pick a project, navigate the to root of your source, and run the Ctags command. BBEdit makes no attempt to automate this, so you’ll want to run this whenever you make significant changes to the source (either through edits or source updates).
$ cd /path/to/source $ ctags-bbedit $ cat tags
I setup a cron job for each project that runs daily. Other options include some source control voodoo or adding a step to your build system.
Find a Definition!
You should now be able to open a file in your source tree, select an object (function name, constant name, etc), and invoke the Search ->Find in Definition option to jump to the file/line where the symbol is defined.