Code searching
posted Tue 9 Dec 2008 by Michael Galloy under IDLSearching through directories of code can be difficult because there are often many files and directories that should normally be ignored i.e. version control information like .svn and .cvs directories, binary files, etc. ack
solves this problem very nicely: it’s easy to use, fast, and only requires Perl to be installed.
One caveat: ack
doesn’t search .pro
files by default. Insert the following at line 1046 to add an IDL file type:
idl => [qw( pro )],
Add other types as desired. There is an --all-types
command line switch to search all files, but I found that negates much of the ack
’s benefit.
UPDATE: put
–type-set=IDL=.pro
in an .ackrc file
in your home directory.
If you use TextMate, there is an Ack in Project bundle which allows you to use ack
from within TextMate. Ack in Project uses its own copy of ack
, so modify the ack-standalone.sh file inside the Ack in Project bundle if you want to do the above modification to search .pro files.
December 9th, 2008 at 2:42 pm
On OS X installed via fink there is no line 1046. However, you can define a new type on the command line like so:
ack –type-set IDL=.pro,.prg –IDL Bertrand
Ack documentation implies you should be able to add a type therefore with just the ~/.ackrc, not editing the source, but
–type-set IDL=.pro
in ~/.ackrc and then –type=IDL does not seem to work. I’ll follow up with the developer.
December 9th, 2008 at 2:56 pm
Nevermind not an ack bug, the correct syntax is:
–type-set=IDL=.pro,.prg
in .ackrc
December 9th, 2008 at 4:12 pm
Ah, I couldn’t get it to work, but -type-set=IDL=.pro seems to do it. I’ve updated the original post to reflect this. Thanks!
December 12th, 2008 at 11:37 am
Do you use VI at all? I use something called ‘project’ (http://www.vim.org/scripts/script.php?script_id=69) and it would be nice to replace its native ‘grep’ function with ‘ack’… not sure how to do it though.
December 12th, 2008 at 11:41 am
update: http://use.perl.org/~Ovid/journal/36430 has the solution, I think. Anyway, thanks for the tip!