Pragmatic Development Notes

Software development related stuff

Easy Emacs

First step

In my previous articles 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.

Fortunately there is a solution. Just clone Emacs starter kit 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 Elpa packaging and is very easy to configure. But let’s start from the beginning.

Clone Emacs starter kit with Git, to your empty .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 download 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.

Emacs starter kit has some packages that are still not in Elpa but you’ll have to install additional packages required for Ruby and RoR. Let’s do it now:

1
M-x package-list-packages

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’ll definitely need Rinari. It will install all dependent packages.

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 yasnippets-rails, but more about that later. Installing packages is very easy. Just place cursor on the package line and press ‘i’. When you are finished with selection press ‘x’ and packages will be installed. At any time you can press ‘h’ to get quick help for Elpa packaging system. In order to uninstall package you have to press ‘d’ (and ‘x’ after that).

Further customization

When you are done with packages installation just restart Emacs and you are ready to continue work in your favorite language – Ruby and framework – 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.

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’ve used theme from color-theme library put color-theme-library.el in this folder and add, for example, line

1
(color-theme-deep-blue)

to any of .el files in this folder. I keep all my additional settings in customization.el file.

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:

1
git clone git://github.com/eschulte/yasnippets-rails.git

Directory yasnippets-rails should be in the directory with your user name under .emacs.d. Add following lines to your customization.el file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(add-to-list 'load-path 
   (concat dotfiles-dir "/<user-name>/yasnippets-rails"))

(add-hook 'ruby-mode-hook ; or rails-minor-mode-hook ?
          '(lambda ()
             (make-variable-buffer-local 'yas/trigger-key)
             (setq yas/trigger-key [tab])))

(require 'yasnippet)
(add-to-list 'yas/extra-mode-hooks
             'ruby-mode-hook)

(yas/initialize)
(setq yas/window-system-popup-function 'yas/x-popup-menu-for-template)
(yas/load-directory (concat dotfiles-dir "/<user-name>/yasnippet/snippets"))

(yas/load-directory 
   (concat 
      dotfiles-dir "/<user-name>/yasnippets-rails/rails-snippets/"))

(make-variable-buffer-local 'yas/trigger-key)

and you will be ready for using new snippets during development.

Final word

My previous articles were based on Rails reloaded package for RoR development in Emacs. It is good library and if you like fancy GUI things you can still use it. There is a new version on Github.

Still, I would recommend trying Rinari that is a package from Elpa. It doesn’t have any GUI features but once your fingers “learn” all shortcuts your RoR development will be much easier and faster.

  1. pete says:

    after installing the emacs-starter-kit does the main screen that shows up say scratch? what do i do next?

  2. Bosko Ivanisevic says:

    Yes, after installing emacs-starter-kit and starting Emacs you will see *scratch* buffer (one of Emacs' buffers). You can install additional packages like Rinari (for Ruby on Rails development) or js2 (for JavaScript), etc. Just do M-x package-list-packages and new buffer with a list of available packages will open. You can select package for installation by pressing 'i' (letter i) while on package's line and at the end pressing 'x'. Open up some file (if you work in RoR open any controller, for example) and you'll see Emacs changing menu, status bar, etc.

  3. Pete Hanlon says:

    I must say I am very impressed by your Emacs/ROR posts at http://pragmaticdevnotes.wordpress.com/2008/11/25/emacs-on-windows-ruby-ruby-on-rails/.

    I think after a few hours of going step by step, that I've implemented all the includes and plugins you outline.

    Now after reading this current blog post about emacs-starter-kit, I am curious if this provides the same amount of functionality as the setup described at http://pragmaticdevnotes.wordpress.com.

    Do you have an opinion on which is the best way to go?

    Thanks!

  4. Bosko Ivanisevic says:

    Personally, I've moved to emacs-starter-kit and Rinari for Rails development. Main reason for this is that within few minutes I have complete setup for Rails. Using ESK and Rinari does not require so much customizations. There are just few remained like color scheme and few additional packages that I like to have but are not crucial for Rails and Ruby.

    Rinari features cover everything needed for everyday working on Rails projects. It does not have any "fancy" gui add-ons like context menu but once developer learns most common key combinations productivity definitely increases.

    In short I would suggest you to try ESK and Rinary. Luckily it is easy to keep your existing Emacs setup - just rename .emacs.d folder and unpack ESK in the new one. If you do not like it you can always return to the previous setup within seconds.

  5. Pete Hanlon says:

    Thanks. I've followed your directions for ESK and Rinari. When I start Emacs, the last thing stated in the lower buffer is "Loading hi-lock...done."

    Is there a way for me to check that everything is being loaded properly? I may not have completely understood the directions above after "First create sub-directory in .emacs.d directory with your user name on the system you are using. "

    Thanks!

  6. Bosko Ivanisevic says:

    Location of subdirectory .emacs.d depends on your Windows version (if you are on Windows). On XP it is in c:\Documents And Settings\<your_user_name> and on Vista it should be in c:\Users\<your_user_name>AppData\Roaming\. If you are on Linux then this folder should be in your home folder (usually /home/<your_user_name>).

    Simplest way to check whether ESK is loaded is to type:

    M-x package_list_packages

    This should open list of available ELPA packages which you can install from the ELPA server.

    If you want to check whether your Rinari is working just load any file from your Rails project (for example controller) and you'll see Rinari in the status line which means that Emacs is working in Rinari mode.

  7. Александар says:

    Мора да кажем да ми се јако ђасви блог. Хвала за имакс савет!

  8. Kinu says:

    thank you, this is an awesome thing to share! many would celsoly guard such a thing as an advantageous personal tool, but as it is becoming more clear everyday, openness and sharing can go even furthersecondly, i'd like to ask a question but i don't intend at ALL to be negative with some of its possible implications:why is this a pdf? don't RoR and all the web 2.0 concepts, essentially lead to the conclusion that your cheatsheet should be a shared, group editable document, available anywhere at it's newest possible state?it just seems weird that a tool which enables the creation of collaborative web apps, and collaborative documents would have a subtool (your cheatsheet) that does not take advantage of the very technology that it is helping to enable.perhaps not!looking forward to hear back,trevor

  9. Txe says:

    Hi
    I find your stuff very documented indeed but it is about things that I do not use and I can not test, so... One thing I am almost a week trying to get it works, its yasnippet unsuccessfully (well rainbow mode only works after some working around I found at the 1001 one web page I read). Guidelines at https://github.com/capitaomorte/yasnippet are uncompleted/useless. I am fear there are a lot things developers assume about users (but they are wrong, obviously, then, how wrong they are about thins that we user are no trained for test). I came here looking for a way of uninstalling yasnippet from elpa, thaks for that, anyway...

  10. szybka pozyczka says:

    Hey There. I discovered your blog using msn. This is an extremely smartly written article.
    I'll make sure to bookmark it and return to read more of your useful information. Thank you for the post. I'll definitely comeback.

Post a comment


(lesstile enabled - surround code blocks with ---)