Emacs and Ruby

Updated to the latest version. This has pabbrev and it works perfectly now with ruby electric
I have just shifted back to emacs, so there should be a lot more updates coming in.
Right now it beats Textmate hands down - Updated 25th December 2006.

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))

AttachmentSize
Ruby Rails Emacs.zip185.35 KB

Comments

Comment viewing options

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

ruby-electric and pabbrev

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

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?

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

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

Try the instructions here:
http://wiki.rubygarden.org/Ruby/page/show/EmacsExtensions

ruby-mode.el

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

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.

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

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?

does this work?

Yes. If they dont work for

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

Don't use ranari from the zip file

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

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.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 16 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.