Pragmatic Development Notes


Improved Emacs Customization

Filed under: Emacs,Ruby & RubyOnRails — Boško Ivanišević @ 14:44
Tags: , , , , ,

While I was writing first three articles about Emacs:

with somewhat clumsy titles because they are related to Linux too, I was changing my .emacs file. (Due to the WordPress restrictions I had to rename it. If you want to download it just right click on the link and save it somewhere under .emacs name. It is pure text file although it has .doc extension.)

I’ll briefly describe all changes I’ve made. First I’ve defined variable my-root. It points to the root folder where directory .emacs.d is. I needed this just because of frequent switches between Ubuntu and Vista. This change makes it easier to update Emacs configuration no matter whether it was changed on Ubuntu and copied to Windows or opposite. I only need to set my-root to path according to the system I work on.

I’ve also started Emacs server. With it only one instance of Emacs can be used, both on Linux or Windows, when various files are edited. If you want to be able to use it from Windows shell you’ll need Emacs Shell Extension Registry File. Right click on the link, save it with .reg extension and double click on saved file. It will add ‘Open in Emacs’ item in file pop-up menu on Windows.

Next change is related to font setting. It is well documented in .emacs file so I’ll not write about it here. Just will point out that if you want to find XFLD name of the font on Windows you’ll have to switch to *scratch* buffer and type:

(w32-select-font nil t)

After that just press C-j (Ctrl-j) at the end of the buffer and after you select font you want you’ll get the name you should use in your .emacs file.

I’ve also set default tab width to 2, enabled ANSI colors in the shell and set mode for editing .ini files.

Near the end of .emacs file there are several lines related to Cygwin. If you want to use Windows (GNU) version of Emacs under Cygwin you’ll have to uncomment these lines and to download cygwin-mount.el package.

Final change is something I really like, so I’ll describe it in more details. If you read previous articles you already know that I really enjoy working on Ruby and Ruby on Rails projects in Emacs. There was only one thing I was missing – navigation within the file. In Rails mode pressing M-S-down (Alt-Shift-down arrow) pops up menu for quick switch to files related to current context. For example if you do that while you have controller file opened you’ll get pop up menu with items to jump to Functional Test, Helper or views.

Pop up menu in Rails mode.

Pop up menu in Rails mode

What I needed is similar functionality but for navigation within the file which will make it easier to jump to function definition. Under IMENU menu item you can find all function definitions and you can switch to each of them but you must use mouse. There is one more way to do it with the mouse C-mouse 3 (pressing right mouse button while keeping Ctrl button pressed). (BTW two other useful shortcuts are C-mouse 1 (Ctrl and left mouse click) which opens buffers menu and C-mouse 2 (Ctrl and middle mouse click) which opens text properties menu.) Lets get back to navigation problem. Obviously I could use mouse to navigate through a file but I didn’t like it. I prefer to have keyboard shortcut for that. On the Web I’ve found are few examples related to Emacs pop-up menu and keyboard handling, and that was my starting point. I’ve modified these examples and made small menu-util.el package loaded at the end of .emacs file.

This package adds few things I really like. With C-M-down (Ctrl-Alt-down arrow) it will display major mode menu (which is the list of functions in Ruby file, for example).

Easier navigation in Emacs.

Easier navigation in Emacs

C-M-up (Ctrl-Alt-up arrow) pops up main menu so you will not need mouse any more.

Main menu as a pop up.

Main menu as pop up

Finally M-up will open completion pop-up menu while you are working on your code.

Completion menu in Emacs

Completion menu in Emacs

Since I really do not know Lisp I’m sure all these could be made much better. If any Lisp guru has an idea how to do that I’ll be very happy to hear suggestions. Until then I can live with what I’ve made and I hope you’ll find it useful too.



  1. Great series of articles!

    In following your Emacs and Rails setup will I be able to fully use Emacs as a Rails IDE?

    For example, to create a new Rails app such as “Blog” what are the commands I use within Emacs? Do I need to open a shell (fyi, I am using winxp) and type rails blog OR is this some bindings within Emacs to do this?

    Thank you again.

    Comment by Pete Hanlon — 2009-06-29 @ 23:24

  2. I use Emacs for Rails development, sot I guess it will suite you too. But if you really want to try Emacs I suggest you read article on my new blog where I wrote about much easier Emacs setup.

    Regarding new Rails applications here are my steps:

    M-x eshell (open Emacs’ shell)
    rails my_new_app (create new Rails app)

    and that’s it.

    Comment by Boško Ivanišević — 2009-06-30 @ 7:09

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: