Katipo Project Survival Kit

Katipo Developers Blog

Installing and Configuring Aquamacs (Emacs 22 for Mac OS X) with Ruby and Ruby on Rails Development Niceties

Personally, I like a highly portable text editor that is powerful enough to use as an IDE. TextMate, from what I hear, is pretty darn great, but by being limited to only Macs, TextMate doesn’t cut it for me. Emacs being emacs, it is quite possible to set it up to be as nice if not nicer than TextMate for Rails development. A good overview can be found at http://www.credmp.org/index.php/2006/11/28/ruby-on-rails-and-emacs/.

And WOW is emacs 22’s Tramp for remote file editing via SSH/SCP awesome! More on that at the end of this post.

For years I have been using the emacs included with Mac OS X happily from either iTerm or the Terminal App. I have tried a few emacs to GUI versions on Mac ports in the past and found them lacking. Thankfully that has changed. Aquamacs has arrived.

Installation is simply a matter of downloading the latest version from http://aquamacs.org, double-click the resulting DMG file, drag the Aquamacs App to /Applications, and you are ready to roll. Start up the application and you are greeted with the “What’s New” section of Aquamacs Help. This is actually very useful for finding out how to customize your installation. Going up to the Table of Contents lead me to how to turn off the “opening new files opens new ‘frames’” behavior that distinguishes Aquamacs from standard Emacs. It’s as simple as going to the Aquamacs “Options” and unchecking the “Display Buffers in Separate Frames” option and selecting “Save Options” from the same menu.

Aquamacs saves its customizations under ~/Library/Preferences/Aquamacs Emacs/, rather than the normal ~/.emacs file. However, if a .emacs file is present, it will load it (first, so Aquamacs’s customizations.el override .emacs), too. Since I’ll also be using most of my Ruby and Rails options on Debian servers as well, I have chosen to stick most customizations in the standard ~/.emacs file. For things that are specific to Aquamacs, I’ll configure things through the included Options -> Customize Emacs features which write to /Library/Preferences/Aquamacs Emacs/customizations.el or add things not handled by that to ~/Library/Preferences/Aquamacs Emacs/preferences.el.

The top of http://wiki.rubyonrails.org/rails/pages/HowToUseEmacsWithRails outlines most of what you need, but where do you install it and how do you set it up? At this point, I’m going to assume that have made the decision to use MacPorts to install the Ruby on Rails stack. A good guide to this is found here.

Unless you start Aquamacs from the command line ($ open -a ‘/Applications/Aquamacs\ Emacs.app’), whatever PATH you set in ~/.bash_profile will be prepended with a PATH that Aquamacs derives from whatever environment it is opened from, for example opening from the Finder. The problem with this is that it means that things installed in the default directories, /usr/bin for example, take precedence over what you have in ~/.bash_profile. Very annoying when you use /opt/local/bin via MacPorts to install more up to date executables! The solution is to add the following to ~/Library/Preferences/Aquamacs Emacs/Preferences.el:

(setenv “PATH” (concat “/opt/local/bin” “:” (getenv “PATH”)))

Ok, now to add Ruby and Ruby on Rails niceties.

$ cd ~/Library/Preferences/Aquamacs Emacs
$ curl -L http://www.kazmier.com/computer/snippet.el -O
$ curl -L http://www.webweavertech.com/ovidiu/emacs/find-recursive.txt -o find-recursive.el

YAML mode is also nice to have:

$ svn co http://svn.clouder.jp/repos/public/yaml-mode/trunk yaml-mode
$ mv yaml-mode/yaml-mode.el ./
$ rm -rf yaml-mode

You’ll also want to grab the latest version of mmm-mode (mixed modes for ruby within html, i.e. rhtml) and ECB, untar them, and move them to the same directory. Aquamacs actually includes the most of the other ruby and rails related stuff already, you just have to turn it on in your .emacs file.

Here’s mine: dot-emacs.txt

Put this in ~/.emacs and edit to suit. I would think about specifying the mmm-mode submode-faces ala http://www.credmp.org/index.php/2006/11/28/ruby-on-rails-and-emacs/, too.

Here’s my complete Preferences.el, too: http://waltermcginnis.com/Preferences.el.txt

Here are some other steps you might find useful (included in my .emacs and Preferences.el files):

  • Turn off Tool Bar (icons at top of window): add “(tool-bar-mode 0)” to your .emacs file or Preferences.el file
  • If you want Apple-N and Apple-W to work the way you might expect, while still maintaining the default emacs behavior for new buffers (not a new frame), check out this topic

Now just a short plug for using emacs 22’s Tramp. Holy crap is it easy and nice. If you have ssh keys set up already, simply open a file like you normally would, but when you are specifying the path add the hostname and if necessary the username like so (note the doubleslash before hostname and colon after):

Find File: /whatever/local_dir/you/are/currently/in//remote_hostname:/your_remote/dir/remote-file.txt

Tramp will cache the file locally and scp it over when you save it (is my guess). For editing files as a different remote user, use add “username@” when your specify your remote host:

Find File: /whatever/local_dir/you/are/currently/in//remote_username@remote_hostname:/your_remote/dir/remote-file.txt

You’ll be prompted for password (if password access is allowed) if necessary.

Tramp even works with Dired. This will give you Dired for the remote directory as you would expect:

Find File: /whatever/local_dir/you/are/currently/in//remote_username@remote_hostname:/your_remote/dir/

I might just drop using screen as a result of this.

Cheers,
Walter

3 Responses to “Installing and Configuring Aquamacs (Emacs 22 for Mac OS X) with Ruby and Ruby on Rails Development Niceties”

  1. walter Says:

    For a good cheat on Emacs commands for version control (also available from the Tools > Version Control menu), check out the following:

    http://badgertronics.com/writings/cvs/emacs.html

    Good ole MarkD from my ArsDigita days…

    Enjoy,
    Walter

  2. walter Says:

    Ooh. Here’s a nice one for macheads. Add this to your ~/Library/Preferences/Aquamacs Emacs/Preferences.el

    ; iTunes control
    ;; Control iTunes from Emacs
    (setq itunes-key [f4])
    (require ‘osx-itunes)

    Then do something like this (or another directory in your emacs load path):

    sudo curl -L http://www.mahalito.net/~harley/elisp/osx-osascript.el -o /Applications/Aquamacs\ Emacs.app/Contents/Resources/site-lisp/osx-osascript.el

    and

    sudo curl -L http://www.mahalito.net/~harley/elisp/osx-itunes.el -o /Applications/Aquamacs\ Emacs.app/Contents/Resources/site-lisp/osx-itunes.el

    Restart Aquamacs and then hit F4 key plus whatever key for the action you want. See the osx-itunes.el for the breakdown.

    Enjoy,
    Walter

  3. walter Says:

    Here are a couple of other posts that you might be interested in:

    http://blog.katipo.co.nz/?p=41 – w3m web browser in Aquamacs
    http://blog.katipo.co.nz/?p=39 – ERC irc client in Aquamacs

Leave a Reply

You must be logged in to post a comment.


Katipo Developers Blog is proudly powered by WordPress
Entries (RSS) and Comments (RSS).