Showing posts with label Aquamacs. Show all posts
Showing posts with label Aquamacs. Show all posts

October 4, 2007

Ruby on Rails with Aquamacs

A friend of mine recently suggested that I look into Aquamacs. According to the website, Aquamacs is an Aqua-native build of the powerful Emacs text editor.

So, I went ahead and downloaded it. First thing I noticed is that it supported stuff for Ruby development right out of the box as the original Emacs. The only problems is, it's got a hard time working with regular indentations, with tabs and so on. I spent a few hours investigating and picking up hints from many places/sources I've put together a LISP script that makes using Aquamacs really nice for Ruby on Rails development.



; stuff for ruby on rails development
(add-to-list 'load-path
"~/Library/Preferences/Aquamacs Emacs/ruby")
(require 'ruby-mode)

; loads ruby mode when a .rb file is opened.
(setq auto-mode-alist
(cons '(".rb$" . ruby-mode) auto-mode-alist))

(setq auto-mode-alist
(cons '(".rhtml$" . html-mode) auto-mode-alist))

; this allows us to have constant indentation as
; we progress in the code from line to line.
(defun create-newline-and-indent()
(local-set-key [return] 'newline-and-indent))

(add-hook 'ruby-mode-hook 'create-newline-and-indent)


; enables ruby electric for easier editing of
; rb and rhtml files
(add-hook 'ruby-mode-hook
(lambda()
(add-hook 'local-write-file-hooks
'(lambda()
(save-excursion
(untabify (point-min) (point-max))
(delete-trailing-whitespace)
)))

; forces ruby-mode to use tabs for indentation with
; an indent level of 4
(setq indent-tabs-mode 1)
(setq ruby-indent-level 4)

; allows the [tab] key to work with width 4
(define-key ruby-mode-map "\t" 'self-insert-command)
(set (make-local-variable 'tab-width) 4)

(define-key ruby-mode-map "C-m" 'newline-and-indent)

; setting up ruby-electric
(require 'ruby-electric)
(ruby-electric-mode t)
))


The script can just be copied and pasted in your "Preferences.el" file which is used instead of the usual ".emacs.el". The Preferences.el file can be found in "~/Library/Preferences/Aquamacs Emacs".

Hope this saves a few hours for some people out there.

Cheers!