Emacs and Ruby

Code moved to GitHub.
http://github.com/wnoronha/dotemacs/tree/master

My Ruby Rails Emacs package.

Here is a bunch of modes to help you be more productive when you are coding Ruby. These modes have been tested on Emacs 21.3.1 MacOS X.

This package contains support for RHTML among other things. Click on the link below to download the file.

.emacs snip

;; Simple Lisp Files
(add-to-list 'load-path "~/.site-lisp/el")
(require 'pabbrev)

;; Ruby Mode
(add-to-list 'load-path "~/.site-lisp/ruby-mode")

(require 'ruby-mode)
(require 'ruby-electric)

(defun ruby-eval-buffer () (interactive)
"Evaluate the buffer with ruby."
(shell-command-on-region (point-min) (point-max) "ruby"))

(defun my-ruby-mode-hook ()
(font-lock-mode t)
(setq standard-indent 2)
(pabbrev-mode t)
(ruby-electric-mode t)
(define-key ruby-mode-map "\C-c\C-a" 'ruby-eval-buffer))
(add-hook 'ruby-mode-hook 'my-ruby-mode-hook)

(setq auto-mode-alist (cons '("\\.rb\\'" . rhtml-mode) auto-mode-alist))

;; Rinari Mode (Rails)
(add-to-list 'load-path "~/.site-lisp/rinari")
(add-to-list 'load-path "~/.site-lisp/rinari/rhtml")
(require 'rinari)
(setq auto-mode-alist (cons '("\\.rhtml\\'" . rhtml-mode) auto-mode-alist))

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

ruby-electric and pabbrev

Anonymous's picture

Great modes. It seems though that ruby-electric and pabbrev don't play nicely together. When they are both enabled, tab completion shows you what word you can use, but hitting the tab key does not perform the completion.

Lacking any sort of elisp understanding, looks like I'll have to choose between the two. Hmmm, tab completion or closure completion. hmmmm, hard choice.

I'm no emacs wizard.. but

Anonymous's picture

I'm no emacs wizard.. but after fetching the latest ruby, rails, pabbrev, and ruby-electric modes, I was able to tab and insert just fine (emacs CVS, btw).

.emacs:

(require 'ruby-electric)
(add-hook 'ruby-mode-hook '(lambda () (ruby-electric-mode)))

(require 'pabbrev)
(add-hook 'ruby-mode-hook '(lambda () (pabbrev-mode)))

Maybe that's the wrong way to do it but it works for now!

Where can I download these el files?

Anonymous's picture

Subject says it all. The top 10 google hits for 'emacs ruby mode' give me pages with no download links for ruby-mode.el..

A google tip

Anonymous's picture

You can google for a specific type of file via google's filetype: operator. For example, "ruby filetype:el".

Try the Ruby Wiki for instructions

Anonymous's picture

ruby-mode.el

Anonymous's picture

Can be found here:
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/misc/ruby-mode.el

Just pick the latest revision.

Invalid character escape syntax

Anonymous's picture

This is on windows emacs -- so not sure if that is what's causing the problem. Running emacs version 21.3.

The line of code that it seems to choke on is: (search-forward-regexp (concat "def\s" action))

(defun rhtml-find-action ()
(interactive)
(let ((action (file-name-sans-extension (file-name-nondirectory buffer-file-name))))
(find-file (rhtml-controller-name-from-view))
(beginning-of-buffer)
(search-forward-regexp (concat "def\s" action))
(recenter)))

---
I'm don't code lisp much -- never have. the '\s' is where it's having issues, and this was the first place it complained about. Looks like it's a reg-exp, and \s implies a white-space character in the reg-exp. Well I guess emacs lisp somehow thinks this is an escaped character. I'm not sure if the proper replacement would be "def\\s" -- so you're escaping the '\' to actually mean '\' inside the string.

Thoughts?

---

See below:

Debugger entered--Lisp error: (error "Invalid escape character syntax")
eval-buffer(#> nil "rhtml-navigation" nil t)
load-with-code-conversion("c:/emacs-site/rinari/rhtml/rhtml-navigation.el" "rhtml-navigation" nil t)
require(rhtml-navigation)
eval-buffer(#> nil "rhtml-mode" nil t)
load-with-code-conversion("c:/emacs-site/rinari/rhtml/rhtml-mode.el" "rhtml-mode" nil t)
require(rhtml-mode)
eval-buffer(#> nil "rinari" nil t)
load-with-code-conversion("c:/emacs-site/rinari/rinari.el" "rinari" nil t)
require(rinari)
eval-buffer(# nil "~/.emacs" nil t)
load-with-code-conversion("c:/.emacs" "~/.emacs" t t)
load("~/.emacs" t t)

I'm getting the same error.

Anonymous's picture

I'm getting the same error. Have you resolved it by replacing the \s with \\s? I noticed there are quite a number of \s, not just in that single line.

Encoding

Anonymous's picture

It's the encoding, I'm not sure which character it is that is western roman utf-8 or whatever but if you type it out you should be ok.

does this work?

Anonymous's picture

does this work?

Yes. If they dont work for

wnoronha's picture

Yes. If they dont work for you pop me a email. And ill help you figure it out, its pretty easy though.

cvs repo link no longer works...

Anonymous's picture

Don't use ranari from the zip file

Anonymous's picture

d/l the current svn trunk
http://rubyforge.org/scm/?group_id=2249

Solves the "Invalid escape character syntax" emacs barfs out.

This is fantastic. Well

Anonymous's picture

This is fantastic. Well done. I thought textmate was cute, but I am a server guy and typically only have access to vi or emacs. I love emacs, and am thrilled to have something like this available. Thanks!

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <quote> <code> <blockcode>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.