<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>@Lathi.net: Navigating Your Projects in Emacs</title>
    <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>Navigating Your Projects in Emacs</title>
      <description>&lt;p&gt;One of the things that&amp;#8217;s really nice about TextMate is the Cmd-T navigation of files in your project.  It pops up this little dialog with fancy pattern matching input to select one of the files in your project and then jumps to that file.  There&amp;#8217;s a similar command once your in a file to jump to symbols in that file.  I&amp;#8217;ve tried a couple things to achieve that behavior in emacs that I&amp;#8217;d like to talk about.&lt;/p&gt;


	&lt;p&gt;The first thing I tried was a method called &lt;code&gt;find-file-in-project&lt;/code&gt;.  It was originally implemented by &lt;a href="http://technomancy.us/"&gt;Phil Hagelberg&lt;/a&gt; as part of his &amp;#8220;Another Ruby on Rails Mode&amp;#8221; (arorem) and then also ported over to the current &lt;a href="http://rinari.rubyforge.org/"&gt;Rinari Is Not a Rails &lt;span class="caps"&gt;IDE&lt;/span&gt;&lt;/a&gt;.  Basically, it indexes all the files in a &amp;#8220;project&amp;#8221; and then provides a nice interactive completing read to switch between them.  It basically works just like Cmd-T in TextMat.  I did quite a bit of work optimizing the completing read so that it would behave nicely.  The problem is that emacs is slow to index the files in your project.&lt;/p&gt;


	&lt;p&gt;What I&amp;#8217;m using now is the tried and true &lt;code&gt;find-tag&lt;/code&gt; method which is part of &lt;code&gt;etags.el&lt;/code&gt;.  ETags depends on an external &lt;code&gt;TAGS&lt;/code&gt; file as an index of all the symbols in your project.  When you invoke &lt;code&gt;find-tag&lt;/code&gt; (by default bound to M-.) it prompts you with completing read for the symbol to find.  It then jumps directly to the file and location where that symbol is defined.  It&amp;#8217;s basically combining the find-file-in-project with find-symbol-in-buffer.  It&amp;#8217;s also very, very fast.&lt;/p&gt;


	&lt;p&gt;As an added bonus, you can use &lt;code&gt;tags-search&lt;/code&gt; to search through your project finding places that tag is used.  This is similar to TextMate&amp;#8217;s slowly grep all the files and render a buffer with those results in it, but much faster.&lt;/p&gt;


	&lt;p&gt;The bad news is you have to manually build the &lt;code&gt;TAGS&lt;/code&gt; file periodically.  Emacs is pretty good about continuing to work when you&amp;#8217;ve made modifications to the files, but if you add new methods, new files, or refactor significantly where thing are located then it gets confused.  When that happens, simply rebuild the &lt;code&gt;TAGS&lt;/code&gt; file.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://onestepback.org/"&gt;Jim Weirich&lt;/a&gt; gave me a nice little rake task to do the job:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;module Tags
  RUBY_FILES = FileList['**/*.rb'].exclude(&amp;quot;pkg&amp;quot;)
end

namespace &amp;quot;tags&amp;quot; do
  task :emacs =&amp;gt; Tags::RUBY_FILES do
    puts &amp;quot;Making Emacs TAGS file&amp;quot;
    sh &amp;quot;xctags -e #{Tags::RUBY_FILES}&amp;quot;, :verbose =&amp;gt; false
  end
end

task :tags =&amp;gt; [&amp;quot;tags:emacs&amp;quot;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Just put that in &lt;code&gt;lib/tasks/tags.rake&lt;/code&gt; and then run &lt;code&gt;rake tags:emacs&lt;/code&gt; when you invoke &lt;code&gt;find-tag&lt;/code&gt; and it can&amp;#8217;t find it.  That shouldn&amp;#8217;t happen very often.  I&amp;#8217;ve found it&amp;#8217;s also very fast to build the &lt;code&gt;TAGS&lt;/code&gt; file.  I might consider putting that tags task as part of the normal run tests task, but I&amp;#8217;m not sure that&amp;#8217;s necessary.&lt;/p&gt;


	&lt;p&gt;The other catch here is that the rake task above calls out the &lt;a href="http://ctags.sourceforge.net/"&gt;exuberant ctags&lt;/a&gt; rather than the ctags that comes with emacs.  The exuberant ctags knows how to parse ruby files whereas the ctags that comes with emacs can&amp;#8217;t.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve installed exuberant ctags from MacPorts.  It is xctags even though MacPorts doesn&amp;#8217;t install it that way.  So (for better or worse) I&amp;#8217;ve renamed the ctags files installed with ports to xctags.  This also gets around the conflict that MacPorts thinks there is between the ctags installed with emacs and the exuberant ctags.&lt;/p&gt;


	&lt;p&gt;Give this a spin and let me know what you think.  I&amp;#8217;ve found it to be very accurate and very fast.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;:&lt;/strong&gt;  I&amp;#8217;ve added a github repository for my &lt;a href="http://github.com/dougalcorn/find-file-in-project/tree/master"&gt;find-file-in-project&lt;/a&gt;.  Feel free to do with it as you will.&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 10:04:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:75998427-5d70-4875-a222-b755d83f4b9a</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs</link>
      <category>Emacs</category>
      <category>Programming</category>
      <category>Lisp</category>
      <category>Ruby on Rails</category>
      <category>Mac OS X</category>
      <category>TextMate</category>
      <category>Ruby</category>
      <category>emacs</category>
      <category>rinari</category>
      <category>xctags</category>
      <category>etags</category>
    </item>
    <item>
      <title>"Navigating Your Projects in Emacs" by Doug Alcorn</title>
      <description>&lt;p&gt;I&amp;#8217;ve looked into adding ido support into find-tag.  It&amp;#8217;s like a personal quest of mine to use ido for everything.  It&amp;#8217;s not trivial though.  &lt;code&gt;ido-completing-read&lt;/code&gt; is supposed to be a drop in replacement for &lt;code&gt;completing-read&lt;/code&gt; but doesn&amp;#8217;t in this case.&lt;/p&gt;</description>
      <pubDate>Sun, 02 Dec 2007 19:20:04 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:3cdd0b5a-8374-4000-9bf5-f82c22213213</guid>
      <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs#comment-414</link>
    </item>
    <item>
      <title>"Navigating Your Projects in Emacs" by Phil</title>
      <description>&lt;p&gt;The whole executable naming mess is pretty crazy. I can&amp;#8217;t figure out how to explicitly call the exuberant variant of ctags, but I&amp;#8217;m trying it out for indexing my elisp with great success:&lt;/p&gt;


	&lt;p&gt;(defun my-generate-elisp-tags ()
  (interactive)
  (shell-command &amp;#8220;find ~/.emacs.d ~/src/emacs -name \\*el | xargs etags -o ~/.emacs.d/TAGS&amp;#8221;))&lt;/p&gt;


	&lt;p&gt;Now if I could only get find-tag to use ido. Lazyweb?&lt;/p&gt;</description>
      <pubDate>Sun, 02 Dec 2007 15:33:17 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:2dfc1484-d841-46b6-8fe2-e6fce6656f17</guid>
      <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs#comment-412</link>
    </item>
    <item>
      <title>"Navigating Your Projects in Emacs" by David</title>
      <description>&lt;p&gt;Would you post your optimized find-file-in-project?  find-tag is great, but I&amp;#8217;m really just trying to find a decent cmd-t replacement.&lt;/p&gt;</description>
      <pubDate>Fri, 30 Nov 2007 14:10:56 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:b9e5d5b6-c4ff-495d-9d77-29b14820f197</guid>
      <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs#comment-406</link>
    </item>
    <item>
      <title>"Navigating Your Projects in Emacs" by Phil</title>
      <description>&lt;p&gt;Thanks for the succinct explanation. Might finally be about time for me to give this a whirl.&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 11:29:25 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:6869b941-3053-4a8d-870b-a099f9fb506c</guid>
      <link>http://blog.lathi.net/articles/2007/11/07/navigating-your-projects-in-emacs#comment-402</link>
    </item>
  </channel>
</rss>
