tag:pragdevnotes.com,2008:/emacs Emacs - Pragmatic Development Notes 2009-06-05T10:29:23Z Enki Boško Ivanišević bosko.ivanisevic@gmail.com tag:pragdevnotes.com,2008:Post/5 2009-06-05T03:29:23Z 2009-06-05T10:29:23Z Still on CVS? Too Bad! <p>At the and of May 2009 Savannah disks crashed. You can read more about it <a href="http://lists.gnu.org/archive/html/savannah-users/2009-05/msg00023.html">here</a>. This is something no one can predict. You never know when your hardware will let you down, and there is no cure for that. Disks will be replaced, system reinstalled, backups restored and that&#8217;s it. Or is it?</p> <p>Not completely if you are using <span class="caps">CVS</span> or <span class="caps">SVN</span> and there were some commits after the last backup. Emacs developers spent few days in the <a href="http://lists.gnu.org/archive/html/emacs-devel/2009-06/msg00056.html">discussion</a> to determine what commits they lost.</p> <p>Luckily they had Git mirror of <span class="caps">CVS</span> repository but what surprises me is they didn&#8217;t move to Git yet. If they were using Git they would have been able to restore complete repository in a few minutes (maybe longer for large repositories). Since they already have Git mirror for Emacs code I really do not understand why do they not switch to Git completely. Having full history at each developer&#8217;s computer is a huge benefit. Not to mention that Git gives you possibilities you can only dream of in <span class="caps">CVS</span> and <span class="caps">SVN</span>.</p> tag:pragdevnotes.com,2008:Post/3 2009-05-20T03:35:54Z 2009-05-20T10:35:54Z Easy Emacs <h3>First step</h3> <p>In my <a href="http://pragmaticdevnotes.wordpress.com">previous articles</a> I wrote a lot about Emacs, its customization and adjusting it for Ruby and Ruby on Rails development. Although these articles give detailed instructions how to set everything up, following all steps are somewhat cumbersome and require quite a lot of work.</p> <p>Fortunately there is a solution. Just clone <a href="http://github.com/technomancy/emacs-starter-kit/tree/master">Emacs starter kit</a> from Github and you will be able to develop Ruby and RoR applications in Emacs in just a few simple steps. Emacs starter kit uses <a href="http://tromey.com/elpa/">Elpa</a> packaging and is very easy to configure. But let&#8217;s start from the beginning.</p> <p>Clone <a href="http://github.com/technomancy/emacs-starter-kit/tree/master">Emacs starter kit</a> with <a href="http://git-scm.com/">Git</a>, to your <strong>empty</strong> .emacs.d directory. Be sure that init.el file is in .emacs.d folder. If you do not use Git (do you realize what you are missing?) you can get archived sources if you press <em>download</em> button on Emacs starter kit page on Github. Unpack archive to the .emacs.d and be sure that init.el is in .emacs.d folder.</p> <p>Emacs starter kit has some packages that are still not in Elpa but you&#8217;ll have to install additional packages required for Ruby and RoR. Let&#8217;s do it now:</p><table class="CodeRay"><tr> <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt> </tt></pre></td> <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">M-x package-list-packages<tt> </tt></pre></td> </tr></table> <p>New buffer with list of available packages will open and you can select those you want to install. If you plan to use Emacs for Ruby and RoR you&#8217;ll definitely need <em>Rinari</em>. It will install all dependent packages.</p> <p>There are few other that might come in handy like css-mode, javascript or yasnippet but you can always add them later. If you install yasnippet you should probably need <a href="http://github.com/eschulte/yasnippets-rails/tree/master">yasnippets-rails</a>, but more about that later. Installing packages is very easy. Just place cursor on the package line and press &#8216;i&#8217;. When you are finished with selection press &#8216;x&#8217; and packages will be installed. At any time you can press &#8216;h&#8217; to get quick help for Elpa packaging system. In order to uninstall package you have to press &#8216;d&#8217; (and &#8216;x&#8217; after that).</p> <h3>Further customization</h3> <p>When you are done with packages installation just restart Emacs and you are ready to continue work in your favorite language &#8211; Ruby and framework &#8211; Ruby on Rails :) But what if you want to adjust some settings or keep some of those you set according to my previous articles? Luckily that is easy to do, too.</p> <p>First create sub-directory in .emacs.d directory with your user name on the system you are using. Put your .el files there and Emacs starter kit will load them automatically during Emacs start up. If you have changed color theme and you&#8217;ve used theme from color-theme library put color-theme-library.el in this folder and add, for example, line</p><table class="CodeRay"><tr> <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt> </tt></pre></td> <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">(color-theme-deep-blue)<tt> </tt></pre></td> </tr></table> <p>to any of .el files in this folder. I keep all my additional settings in customization.el file.</p> <p>I already mentioned yasnippet and yasnippets-rails packages. Simplest way to install yasnippet library is from Elpa system following above mentioned procedure. Unfortunately yasnippets-rails cannot be installed that way so you should clone it from the Github:</p><table class="CodeRay"><tr> <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt> </tt></pre></td> <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">git clone git://github.com/eschulte/yasnippets-rails.git<tt> </tt></pre></td> </tr></table> <p>Directory yasnippets-rails should be in the directory with your user name under .emacs.d. Add following lines to your customization.el file:</p><table class="CodeRay"><tr> <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt> </tt>2<tt> </tt>3<tt> </tt>4<tt> </tt>5<tt> </tt>6<tt> </tt>7<tt> </tt>8<tt> </tt>9<tt> </tt><strong>10</strong><tt> </tt>11<tt> </tt>12<tt> </tt>13<tt> </tt>14<tt> </tt>15<tt> </tt>16<tt> </tt>17<tt> </tt>18<tt> </tt>19<tt> </tt><strong>20</strong><tt> </tt>21<tt> </tt></pre></td> <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">(add-to-list 'load-path <tt> </tt> (concat dotfiles-dir &quot;/&lt;user-name&gt;/yasnippets-rails&quot;))<tt> </tt><tt> </tt>(add-hook 'ruby-mode-hook ; or rails-minor-mode-hook ?<tt> </tt> '(lambda ()<tt> </tt> (make-variable-buffer-local 'yas/trigger-key)<tt> </tt> (setq yas/trigger-key [tab])))<tt> </tt><tt> </tt>(require 'yasnippet)<tt> </tt>(add-to-list 'yas/extra-mode-hooks<tt> </tt> 'ruby-mode-hook)<tt> </tt><tt> </tt>(yas/initialize)<tt> </tt>(setq yas/window-system-popup-function 'yas/x-popup-menu-for-template)<tt> </tt>(yas/load-directory (concat dotfiles-dir &quot;/&lt;user-name&gt;/yasnippet/snippets&quot;))<tt> </tt><tt> </tt>(yas/load-directory <tt> </tt> (concat <tt> </tt> dotfiles-dir &quot;/&lt;user-name&gt;/yasnippets-rails/rails-snippets/&quot;))<tt> </tt><tt> </tt>(make-variable-buffer-local 'yas/trigger-key)<tt> </tt></pre></td> </tr></table> <p>and you will be ready for using new snippets during development.</p> <h3>Final word</h3> <p>My previous articles were based on Rails reloaded package for RoR development in Emacs. It is good library and if you like fancy <span class="caps">GUI</span> things you can still use it. There is a <a href="http://github.com/dima-exe/emacs-rails-reloaded/tree/master">new version</a> on Github.</p> <p>Still, I would recommend trying Rinari that is a package from Elpa. It doesn&#8217;t have any <span class="caps">GUI</span> features but once your fingers &#8220;learn&#8221; all shortcuts your RoR development will be much easier and faster.</p>