From: "Marshall T. Vandegrift" Date: 2006-08-16T05:07:01+09:00 Subject: Re: newb: setting up GNU Emacs for Ruby -- help "John Gabriele" writes: >> (autoload 'ruby-mode "ruby-mode" "Mode for editing ruby source files") >> (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode)) >> (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode)) >> (autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process") >> (autoload 'inf-ruby-keys "inf-ruby" "Set local key defs for inf-ruby >> in ruby-mode") > > I appended those to my ~/.emacs file, but there's still no syntax > highlighting when I open a Ruby source file. Which OS / distro are you running? Many provide a package which separately er... packages the Ruby elisp files and makes sure they're in the load path, etc. On Debian (and Ubuntu?) the package is named ruby1.8-elisp for ruby 1.8. > Also, you mention to add ruby-mode.el to the "autoload list", but you > have three lines above for adding stuff to this autoload list. Are > ruby-mode, run-ruby, and inf-ruby-keys three separate thingies inside > ruby-mode.el? What the autoload function does is make Emacs load a particular file (e.g., "ruby-mode") when you user a particular function (e.g., 'ruby-mode). Multiple files generally means multiple autoload invocations. Ask your local Emacs installation for more information with C-h f autoload RET! The "ruby-mode.el" file contains the main Ruby editing mode. The file "ruby-electric.el" contains so-termed "electric" keybindings for the Ruby editing mode (more on that later). The file "inf-ruby" has code for interacting with an "inferior" ruby process communicating with Emacs; i.e., running irb in an Emacs window, sending it code from other buffers, etc. > but I've already got that (global-font-lock-mode t nil (font-lock)) in > my ~/.emacs file. Do I need that "add-hook" line too? Nope. > I've tried appending it to the end of ~/.emacs, but still no syntax > highlighting. If you have global-font-lock-mode enabled and are in Ruby mode, you should see syntax highlighting. Do M-x customize-variable global-font-lock-mode RET to make sure that customization is being loaded properly. If so, when you open a file ending in '.rb' do you see "Ruby" in the modeline? If you don't see it, then your auto-mode-alist addition isn't getting run. Can you manually switch to ruby-mode with M-x ruby-mode RET? If not, then the ruby elisp code isn't being made available to your Emacs instance. > Also, I've read here and there on nntp://gnu.emacs.help that the way > I'm trying to get all spaces (and no tabs at all), with 4-space > indents: > > | > | '(indent-tabs-mode nil) > | '(tab-width 4) > | > > is "evil". Am I doing it right? So far, tabs seem to be coming out > just the way I want. :) Because (1) some tools like 'make' and really old versions of 'sh' consider tabs vs. spaces significant, (2a) you can stomp on the toes of people who do use tabs when editing their files, and (2b) you can create extraneous diffs when editing files which do contain tabs. Emacs largely avoid (1) for you automatically, and as for (2) I think people who use tabs deserve to be stomped on ;-). >> Yes on ruby-mode, maybe on ruby-electric. Drives me bonkers but you >> might like it. > > What does ruby-electric do that ruby-mode doesn't? Do they overlap? > What is it about ruby-electric drives you nuts? What ruby-electric does is make matching syntax elements "electric." For example, if I type ('' being hitting the spacebar): while Emacs with ruby-electric will produce ('><' shows where the point ends up): while >< end Typing a single open paren would then result in: while (><) end You can customize which syntactical elements it treats as electric. I personally find it useful for all the block-level 'end'-ended elements to be electric and highly annoying for all the brackets. Anyway, hope this helps! -Marshall