The Emacs Code Browser

June 13, 2007 at 4:33 pm 15 comments

This tutorial is a bit out dated now.  I have created a new version of it over on my new blog which is an updated version of this one.

This is the third post in a series where I have been talking about why I decided to learn emacs and getting started with it on Windows or OS X. In this post, I will explain some of the customisations I made to fulfil my Rails development wishlist.

File Browsing

Textmate boasts an impressive feature, which is a file browsing pane, giving you easy access to all the files in your project. Luckily Emacs has something similar, called the Emacs Code Browser (ECB), but you have to figure out how to install it, which is not difficult, but it takes some time.


Unfortunately, ECB relies on the presence of three other Emacs plugins so the first thing is to gather up all the files you need.

  • Semantic is used to help build text parsing applications in Emacs. Don’t worry about it beyond installing. I grabbed semantic-1.4.4 from here.
  • Eieio is also required. Again, I am not sure what its for beyond being required. I got eieio-0.17 here.
  • Speedbar is a code browser, that is also used by ECB. I downloaded speedbar-0.14beta4 here.
  • Finally, get ECB itself


Now we have the 4 downloads, we need to put them somewhere. On Windows, I created a directory called plugins inside my emacs directory, giving me C:\emacs-22.1\plugins

On the Mac, I created a directory called .emacs_includes/plugins in my home directory.

I am pretty sure Emacs gurus would tell me these files should go somewhere else, but this works for me and the location is not really important. Extract each of the 4 downloads into the plugins directory.

Installing Emacs plugins generally involves putting some files in a known location, and telling Emacs about them using the .emacs file. Open your .emacs file (or _emacs see the last post for more information) and add the following (this is a Windows example, edit the paths for OS X):

;Allows syntax highlighting to work, among other things
(global-font-lock-mode 1)
;These lines are required for ECB
(add-to-list 'load-path "C:/emacs-22.1/plugins/eieio-0.17")
(add-to-list 'load-path "C:/emacs-22.1/plugins/speedbar-0.14beta4")
(add-to-list 'load-path "C:/emacs-22.1/plugins/semantic-1.4.4")
(setq semantic-load-turn-everything-on t)
(require 'semantic-load)
; This installs ecb - it is activated with M-x ecb-activate
(add-to-list 'load-path "C:/emacs-22.1/plugins/ecb-2.32")
(require 'ecb-autoloads)

Loading ECB

Restart Emacs and start ECB by typing ALT-x ecb-activate

The Emacs window will change, adding a new section with 4 windows on the left side. In this default mode, the top window shows directories, next files, then history and finally methods in the current file.

To close ECB enter ALT-x ecb-deactivate

I changed this default layout to show only a combined directory and file listing and opened file history by adding the following lines to my .emacs:

(setq ecb-layout-name "left14")
(setq ecb-layout-window-sizes (quote (("left14" (0.2564102564102564 . 0.6949152542372882) (0.2564102564102564 . 0.23728813559322035)))))

The final thing you need to do, is add a list of directories containing the files you wish to browse, for example:

(setq ecb-source-path (quote ("d:/myRailsProject" "d:/useful scripts")))

There is a lot to configure in ECB if you wish. All the details are available in the packaged manual, which you can view by typing ALT-x ecb-show-help.

Some commands I have learned so far include:

  • Jump to the directory window CTRL-. gd
  • Jump to the history window CTRL-. gh
  • Jump to the last window you were in CTRL-. gl
  • Jump to the first editor window CTRL-. g1

The directory browser can be controlled without using the mouse too – just use the arrow keys and enter – give it a go!

As you can see, setting up ECB is not difficult, and its well worth it in my opinion. In the next article, I will add some Ruby customisations to our Emacs installation.


Entry filed under: emacs.

Getting started Emacs Ruby Foo

15 Comments Add your own

  • 1. peters  |  January 30, 2008 at 3:06 am

    How do you open the file in directory window? I tried double clicking the folder, it’s not expanding to show my files and subfolders. How can I expand the main folder and click on the file in subdirectories?

  • 3. Stephen  |  January 30, 2008 at 9:59 pm

    Thanks for the question – to expand and open files in the code browser, you need to use the middle mouse button. Apparently you can change what mouse button opens and expands the files, but I haven’t looked into it.

    You can also use the keyboard (great when your in a terminal session) – use the left and right arrows and the return key.

  • 4. Jonathan Groll  |  February 15, 2008 at 9:34 am

    To set the left mouse button for click
    M-X customize-option
    and customize ecb-primary-secondary-mouse-buttons
    to be button 1

  • 5. mc  |  April 29, 2008 at 6:06 pm

    The keyboard commands you mentioned aren’t correct.

    The correct ones are

    Directories: Ctrl-c . g d
    Methods: Ctrl-c . g m
    Sources: Ctrl-c . g s
    History: Ctrl-c . g h

  • 6. Phil  |  September 18, 2008 at 8:30 pm

    On Debian-based systems installation is much, much easier:

    $ sudo apt-get install ecb

  • 7. Zach  |  October 23, 2008 at 3:11 pm

    thanks man, everything worked following your instructions. it’s nice to find tutorials that work 🙂

  • 8. Zach  |  October 26, 2008 at 7:01 pm

    one difficult thing is that on both windows and mac i’m having to hit return/enter to expose the files contained within a directory. I can expose subdirectories with middle click (mac) or left-click (windows). Then the dir is highlighted. Then i have to press enter/return to see files.

  • 9. andrei  |  November 2, 2008 at 6:29 am

    Thanks so much for this. I was having a hard time setting ecb up on my mac. Everything worked perfectly.

  • 10. Noah Sussman  |  February 22, 2009 at 11:41 pm

    For those using Macports, installation is one line:

    > sudo port install speedbar eieio semantic ecb

    Great tutorial, thanks! I’ve been using Emacs for a while but never knew about ECB.

  • 11. Noah Sussman  |  February 23, 2009 at 7:50 pm

    Oops I spoke a bit too soon about installing ECB and its dependencies with Macports. While installation is indeed one line using the older Macports version 1.6, it is a bit more complex using the current version 1.7 of Macports. It seems that speedbar, semantic and eieio are now available in a single package, CEDET. But the port of ECB still looks for the old dependencies; so it fails to install.

    So I wound up doing the following installation routine:

    sudo port install cedet-devel
    open ecb-2.32.tar.gz
    sudo mv ecb-2.32 /usr/share/emacs/site-lisp/

    and then in my .emacs:

    (load-file “/opt/local/var/macports/software/cedet-devel/1.0pre4_0/opt/local/share/emacs/site-lisp/common/cedet.el”)
    (add-to-list ‘load-path “/usr/share/emacs/site-lisp/ecb-2.32”)
    (require ‘ecb)
    (require ‘ecb-autoloads

    I hope this information will be useful to other users of Aquamacs and Macports. See also

    Thanks again for all the tips in this tutorial! ECB seems like a great tool so far.

  • 12. Vic  |  July 31, 2009 at 3:27 pm

    Great read, thanks for posting it.

  • 13. Brent  |  June 9, 2010 at 5:03 am


    I’m a relative emacs newb and I really appreciate your guide for setting up ECB. I’ve included your settings for ECB in my .emacs file. When I do I get the following error:

    “eval-buffer: Cannot open load file: semantic-load”

    ;Allows syntax highlighting to work, among other things
    (global-font-lock-mode 1)
    ;These lines are required for ECB

    (add-to-list ‘load-path “/emacs/lisp/cednet1.0pre6/eieio”)
    (add-to-list ‘load-path “/emacs/lisp/cednet1.0pre6/speedbar”)
    (add-to-list ‘load-path “/emacs/lisp/cednet1.0pre6/semantic”)

    (setq semantic-load-turn-everything-on t)
    (require ‘semantic-load)
    ; This installs ecb – it is activated with M-x ecb-activate
    (add-to-list ‘load-path “/emacs/lisp/ecb”)
    (require ‘ecb-autoloads)

    I thought I might have referenced the directory location of semantic incorrectly, so I change the reference to:

    (add-to-list ‘load-path “C:\emacs\lisp\cednet1.0pre6\semantic”)

    but that had no affect. Any suggestions on what I’m doing incorrectly would be greatly appreciated.

  • […] also like the Emacs Code Browser (ECB), here are the […]

  • 15. miltonlab  |  November 30, 2010 at 11:15 pm

    Interesante el pequeñ articulo, yo tambien llevo tiempo usando el ecb y es bastante bueno. Se puede encontrar todos los comando en la parte inferior de emas haciendo Alt+X y luego escribiendo ecb-TAB
    Perdon por escribir en español


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

Trackback this post  |  Subscribe to the comments via RSS Feed


%d bloggers like this: