Python-style indentation for Ruby, in 8 lines of Emacs Lisp! 
Author Message
 Python-style indentation for Ruby, in 8 lines of Emacs Lisp!

I like Ruby a lot, but I really dislike seeing the following in the
middle of my code all the time:

      end
    end
  end

I'm not offended nearly so much by some other languages'

      }
    }
  }

because there's much less clutter and my eye isn't fooled into saying
'Ooh, a word, it must be important!'  (For the same reason, I use _
instead of self when I write python code.)

Anyway, it occured to me that there might be an easy way to get 90% of
what I want, just by making the keyword 'end' be almost invisible.
With this change, Ruby code looks just like Python (whose style I
like, and if you don't, just stop reading here instead of expressing
your disapproval), except with a few more blank-with-subliminal-text
lines.

Here's how I did it.

1. Put the following code in your .emacs or wherever:

  (defface font-lock-subliminal-face
    '((t  :inherit default :foreground "#eee"))
    "Font Lock mode face used for subliminal text."
    :group 'font-lock-highlighting-faces)

  (defvar font-lock-subliminal-face   'font-lock-subliminal-face
    "Face name to use for things that should be barely visible.")

2. In ruby-mode.el, add the marked two lines at the beginning of the
   definition of ruby-font-lock-keywords:

  (defvar ruby-font-lock-keywords
    (list

+      2 font-lock-subliminal-face)
     (cons (concat

            (mapconcat
             'identity
             '("alias"
               "and"
               "begin"

Use M-x customize-face if you don't like the color choice.

This simple change increased the comprehensibility of Ruby code by a
large amount for me.  Your mileage will undoubtedly vary, but if you
think you might like it, give it a shot.

Dan

--
http://www.*-*-*.com/



Wed, 08 Jun 2005 08:59:59 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Lisp indentation in Emacs

2. Modifying indentation in emacs lisp-mode

3. My style to K@R Tcl style indentation tool

4. Extracting a random line from a file in Emacs Lisp

5. REXX Indentation Style

6. Ruby Emacs-mode with Emacs 21.1.1

7. IF indentation styles

8. Indentation style...

9. Indentation style...

10. Emacs indentation

11. Emacs' indentation problem

12. Emacs support for Verilog indentation

 

 
Powered by phpBB® Forum Software