views:

460

answers:

3

I am having a difficult time loading ruby-mode in emacs on my mac.

The .emacs file is located at ~/.emacs I've added several commands to it (many pasted from this site) and none seem to get loaded. Any advise? I"m not sure if the file isn't loading or I have the command syntax wrong.

All I need is the following

  • 4 space indent (auto-intedent would be great as well)
  • ruby mode loaded for .rb files.

Thanks!

+1  A: 

This is how emacs finds the .emacs file.

57.6.4 How Emacs Finds Your Init File

Normally Emacs uses the environment variable HOME (see HOME) to find .emacs; that's what ‘~’ means in a file name. If .emacs is not found inside ~/ (nor .emacs.el), Emacs looks for ~/.emacs.d/init.el (which, like ~/.emacs.el, can be byte-compiled).

However, if you run Emacs from a shell started by su, Emacs tries to find your own .emacs, not that of the user you are currently pretending to be. The idea is that you should get your own editor customizations even if you are running as the super user.

More precisely, Emacs first determines which user's init file to use. It gets your user name from the environment variables LOGNAME and USER; if neither of those exists, it uses effective user-ID. If that user name matches the real user-ID, then Emacs uses HOME; otherwise, it looks up the home directory corresponding to that user name in the system's data base of users.

From http://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init

Zitrax
poulh$ echo $HOME/Users/poulhpoulh$ ls $HOME/.emacs/Users/poulh/.emacsThanks for the comment. From reading that it seems my .emacs is in the correct place... am I mistaken?Thanks.
Poul
+1  A: 

Put the line (warn "Loading .emacs") as the first line of .emacs. When you start emacs does it show you that message in a warning buffer? If so, it at least started loading the file.

If this does nothing, try opening the file in emacs, and running M-x eval-buffer.

Also, at startup, does the Messages buffer indicate any errors in your .emacs? This is the most common reason for a .emacs not to take effect.

Justin Smith
That worked! I see the warning. Thanks. So... now it seems my syntax is incorrect. Do you (or anyone else) know what I need to add to have ruby mode (and by this I mean syntax hi-liting and help with indenting) load by default? Thanks again.
Poul
(add-to-list 'load-path "/path/to/ruby/mode")(require 'ruby-mode)Those two lines should suffice. Change /path/to/ruby/mode to the actual directory containing ruby-mode.elAlso it may be easier to set things like indentation level at runtime via:"M-x customize-group ruby", not having the ruby mode installed, and not being a ruby programmer, I do not know the specific options that ruby mode provides
Justin Smith
Thanks Justin. I got it working. Here is how I did it.I went to this site and downloaded the rdoc-mode.el file and put it at ~/: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/misc/rdoc-mode.el?view=logI added the following lines to my .emacs file (which is also located at ~/)(add-to-list 'load-path "~/rdoc-mode.el") (require 'ruby-mode)When I loaded a .rb file it was properly hi-lited.As a note, I have emacs 21 and from this site it seems this file is included with emacs 23: http://www.emacswiki.org/emacs/RubyMode
Poul
You could swap out (add-to-list 'load-path "~/rdoc-mode.el") for (add-to-list 'load-path "~/"), the load path just needs to lead to the directory, it does not need to specify the file.
Justin Smith
A: 

hi, I have the same problem and I followed the directions above: 1. downloaded rdoc-mode.el and put it in my home (~) 2. created a .emacs file in $HOME and put the following (global-font-lock-mode 1) ; loads ruby mode when a .rb file is opened.
(add-to-list 'load-path "/Users/minadoroudi/") (require 'ruby-mode) (autoload 'ruby-mode "ruby-mode" "Major mode for editing ruby scripts." t) (setq auto-mode-alist (cons '(".rb$" . ruby-mode) auto-mode-alist)) (setq auto-mode-alist (cons '(".rhtml$" . html-mode) auto-mode-alist))

; set parantheses highlight on
(show-paren-mode 1)

I still have problem with Ruby in color mode.

Thanks

mina