Need some help setting up ruby mode

(francisrammeloo@hotmail.com) #1

Hi all,

I'm an emacs newbie but would like to use the editor for ruby coding.

I have downloaded "ruby-mode.el" and I don't know what to do with it!

I worked my way through the emacs built-in tutorial. I know how to use
modes, but I can't find any information about how to ADD modes to
emacs.

I understand that this may be difficult to explain on the newsgroup.
Any link to helpful information is welcome too!

Best regards,
Francis

PS: Perhaps my basic question is: how do I set up emacs for ruby coding?

(Jim Menard) #2

francisrammeloo@hotmail.com wrote:

Hi all,

I'm an emacs newbie but would like to use the editor for ruby coding.

I have downloaded "ruby-mode.el" and I don't know what to do with it!

I worked my way through the emacs built-in tutorial. I know how to use
modes, but I can't find any information about how to ADD modes to
emacs.

I understand that this may be difficult to explain on the newsgroup.
Any link to helpful information is welcome too!

Put ruby-mode.el somewhere where Emacs can find it. I have a directory where I put that kind of thing, "~/lib/elisp". In my .emacs file I added

(add-to-list 'load-path "~/lib/elisp")

so it can find all of my .el files. Next, add

(autoload 'ruby-mode "ruby-mode" "Ruby mode" t nil)
(autoload 'inf-ruby "inf-ruby" "Ruby inferior process (irb)" t nil)
(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
             interpreter-mode-alist))
(setq auto-mode-alist
       (append '(("\\.rbw?$" . ruby-mode)
      ("\\.rhtml$" . html-mode)
    ("\\.gem\\(spec\\)?$" . ruby-mode)
    ("[Rr]akefile" . ruby-mode))
          auto-mode-alist))

and optionally a ruby-mode-hook for yourself. Here is a subset of mine:

(setq ruby-mode-hook
       (lambda ()
  (define-key ruby-mode-map "\r" 'newline-and-indent)
  (define-key ruby-mode-map "\M-\C-h" 'backward-kill-word)
  (setq c-tab-always-indent nil)
  (abbrev-mode t)
  (font-lock-mode 1)))

Jim

···

--
Jim Menard, jimm@io.com, http://www.io.com/~jimm
"I am sure that like Java, [C#] will be a 'no pointer' language, where the
most common runtime error will be a 'NULL pointer exception'."
    -- Jerry Kott, in comp.lang.smalltalk

(francisrammeloo@hotmail.com) #3

I can find my emacs file. Am I supposed to create it myself? I'm using
Windows XP and GNU Emacs 21.3.1.

(Jim Menard) #4

francisrammeloo@hotmail.com wrote:

I can find my emacs file. Am I supposed to create it myself? I'm using
Windows XP and GNU Emacs 21.3.1.

I set the environment variable HOME to point to my home directory, then I created the file .emacs in that directory. If you don't use HOME, then I think you need to put .emacs in the emacs-XX.Y directory itself.

Jim

···

--
Jim Menard, jimm@io.com, http://www.io.com/~jimm
"I am sure that like Java, [C#] will be a 'no pointer' language, where the
most common runtime error will be a 'NULL pointer exception'."
    -- Jerry Kott, in comp.lang.smalltalk

(francisrammeloo@hotmail.com) #5

Ok I found out that I can create a file called _emacs in C:\
Emacs now reads this file at startup.

Thank you Jim, I copy/pasted the lisp code you posted and now I can
select "M-x ruby-mode".

The problem now is that this doesn't change anything. There is no
syntax highlighting.

Is there something missing?

(Jim Menard) #6

francisrammeloo@hotmail.com wrote:

Ok I found out that I can create a file called _emacs in C:\
Emacs now reads this file at startup.

Thank you Jim, I copy/pasted the lisp code you posted and now I can
select "M-x ruby-mode".

The problem now is that this doesn't change anything. There is no
syntax highlighting.

Is there something missing?

(global-font-lock-mode t) ; always turn on, where available

; Provide "M-x flfb" as a shortcut
(defalias 'flfb 'font-lock-fontify-buffer)

Jim

···

--
Jim Menard, jimm@io.com, http://www.io.com/~jimm
"I am sure that like Java, [C#] will be a 'no pointer' language, where the
most common runtime error will be a 'NULL pointer exception'."
    -- Jerry Kott, in comp.lang.smalltalk

(francisrammeloo@hotmail.com) #7

Thanks Jim, it works now!

Best regards,
Francis