While installing Universal Ctags from source on a new machine I ran into the following error during the autogen.sh step:
error: possibly undefined macro: AC_DEFINE
Fortunately, the solution was as simple as installing pkg-config:
apt-get install pkg-config
Exuberant Ctags is a lovely, obscure tool developers use to index source code. Unfortunately, the project went dormant after 2009. Thankfully, Masatake Yamato resuscitated the project as Universal Ctags in 2014.
Since then there have been well over 1,000 commits from several significant contributors. There's even a pull request open at the moment to bring in support for PHP 7.
Before installing the shiny new ctags, one needs to expunge the existing installation. If you installed it from source, as discussed in an earlier blog post, "walk this way:"
cd <path to where you keep source code>/ctags sudo make uninstall
But if you have it installed via a packge, here's one example of how to "put the candle back:"
sudo apt-get remove exuberant-ctags
"Give my creature liiiife!"
cd <path to where you keep source code> git clone https://github.com/universal-ctags/ctags.git universal-ctags cd universal-ctags ./autogen.sh ./configure make sudo make install
"Oh, sweet mystery of life at last I've found you..." From my quick examination, things are working perfectly with Effortless Ctags with Git and Ctags for SVN.
The workflow tools at my prior job were built around Subversion. When I started working there, I was sad to give up "Effortless Ctags with Git" and Fugitive. Porting those concepts was necessary to keep my sanity. Itchy, meet Scratchy: Ctags for SVN. A small tweak to our workflow tools got it call ctags_for_svn.sh when appropriate.
I also made a symlink called cs in my bin directory pointing to the ctags_for_svn.sh script. So updating a checkout's ctags is as simple as typing cs.
The concepts in Tim's Effortless Ctags blog post use Git's init.templatedir setting. Git added the feature in the 1.7.1 release. When I first read the post, my box was running an earlier version. If you're in this boat, the simplest workaround is to putting the hooks into Git's system wide template dir, /usr/share/git-core/templates.
Other alternatives, in case you need them, are either setting the $GIT_TEMPLATE_DIR environment variable or manually specifying the template dir on the command line: git init --template ~/.git_template
By default, the ctags parser tracks where variables are declared. So if your code follows the standard of naming object variables for the class they're instantiated from, hitting CTRL-] on a class name means you'll get brought to the tag-menulist instead of going directly to the desired class. And if it's a popular name, that means wading through pages of chafe. Plus it bloats the tags file.
Disabling this sillyness is as simple as passing the --php-kinds=-v argument to the ctags command.
A bug in Exuberant Ctags 5.8 causes comments in PHP files to be parsed. When comments contains the word function, the subsequent word is parsed as the name of a function. This can wind up filling the Tag List view with meaningless entries. Below is a demonstration of the problem and instructions on how to get the fix by installing ctags from source.
First, let's see the problem. Copy this first code block into a script named example.php:
<?php /** * ctags 5.8 parses this function incorrectly by not * ignoring the word function inside comments */ function real_function() {}
Install the default ctags package available at the moment, 5.8:
sudo apt-get install exuberant-ctags
And parse the file:
ctags -f ./tags example.php
This screen shot shows incorrectly and inside in the tag list on the left:
Fortunately, one day after 5.8 was released, jafl committed revision 729 to fix the problem. Here's how to obtain that on your system:
UPDATE: I just learned of the Universal Ctags project, an actively maintained fork of the Exuberant Ctags code base. Use these instructions to install ctags. Skip the following code block, which is only here for historical purposes.
# See UPDATE note, above. # DON'T EXECUTE THE COMMANDS IN THIS BLOCK # Get rid of 5.8. sudo apt-get remove exuberant-ctags # autoconf is needed to assemble the configure files sudo apt-get install autoconf autoconf-doc svn checkout svn://svn.code.sf.net/p/ctags/code/trunk/ ctags cd ctags autoconf ./configure make sudo make install
Time to re-parse the file using the repaired version of ctags:
ctags -f ./tags example.php
Voila! The only thing in the tag list is real_function.
A few years ago, I bit the bullet and started using Vim, cold turkey. It's been rewarding. My first step was forking Andrei Zmievski's vim-settings repository.
One very handy thing in Andrei's setup is Yegappan Lakshmanan's Tag List plugin. To that I added Tim Pope's Fugitive plugin. Combining those together with installing Darren Hiebert's Exuberant Ctags and the Git hook concepts in SeƱor Pope's "Effortless Ctags with Git" moves Vim from a good source code editor to an excellent one.
You can jump from where a function is used to where it is declared by hitting CTRL-]. Hitting F5 produces a pane on the left listing functions in the current file. Tab completion is available. Tag lists are automatically updated when git checkouts, pulls or commits are done.
But, there were a handful of annoying shortcomings. I'll address the bigger issues in separate blog posts. Below are resolutions for the small stuff...
The default process of jumping to a tag opens the file in a new buffer in the current window. I have yet to learn to use The Force, so find tabs easier to use. Therefore, I adjust the tag jump to open a new tab:
nnoremap <C-]> :tab tjump <C-r><C-w><CR>
It seems the syntax highlighter is inefficient or buggy. Large PHP files make vim very slow to respond. An easy fix is to disable syntax highlighting in big files:
au BufReadPost * if getfsize(bufname("%")) > 102400 | set syntax= | endif
Maybe it's just me, but the default colors of MatchParen are very simliar to some colors used by syntax highlighting. This made it difficult to figure out what's what. Tweaking the colors is pretty simple:
highlight MatchParen ctermbg=Blue ctermfg=White
I tend to write more PHP and text than HTML. So having matchpairs add a > everytime I type a < got annoying pretty fast. Placing the following to .vimrc increased my glee:
autocmd BufRead * set matchpairs=(:),{:},[:]
Part of what my Ubuntu Laptop Installation script does is put all of these components in place.