Hideshow mode for ruby-mode.el


(Massimiliano Mirra) #1

The `hideshow’ Emacs minor mode lets you hide the content of a block
of code and only see the first line. This is what I put in my
~/.emacs file to have it work with Ruby:

(defun ruby-custom-setup ()
; [other stuff omitted…]
(add-to-list ‘hs-special-modes-alist
’(ruby-mode
"\(def\|do\)"
“end”
"#"
(lambda (arg) (ruby-end-of-block))
nil
))
(hs-minor-mode t)
)

(add-hook 'ruby-mode-hook 'ruby-custom-setup)

Then with M-x hs-hide-all…

def hello
puts "hello world"
end

…becomes:

def hello…

Beware, it’ll choke on def’s and end’s appearing in strings. I didn’t
care of that, my eyes still ache in front of regexps defined in
elisp. %-)

Massimiliano


(Tobi Reif) #2

Massimiliano Mirra wrote:

The `hideshow’ Emacs minor mode lets you hide the content of a block
of code and only see the first line

just out of curiosity; does Emacs feature folding, in general, or for Ruby?

Tobi

···


http://www.pinkjuice.com/


(Dan Debertin) #3

Massimiliano Mirra writes:

The `hideshow’ Emacs minor mode lets you hide the content of a block
of code and only see the first line. This is what I put in my
~/.emacs file to have it work with Ruby:

Thanks very much! That takes care of one of the two things I think
ruby-mode has been missing. Now, if someone could only implement
def/begin/do->end matching that works like paren-matching does…

Oh well. Gives me a reason to sit down and learn elisp someday.

Dan

···


airboss@nodewarrior.org
www.nodewarrior.org
ignorami: n:
The art of folding problem users into representational shapes.


(Michael Campbell) #4

At least general. You could add ruby w/o much issue, IIRC. I
haven’t used folding mode in a long while, but remember it being a
more general solution.

···

— Tobias Reif tobiasreif@pinkjuice.com wrote:

Massimiliano Mirra wrote:

The `hideshow’ Emacs minor mode lets you hide the content of a
block
of code and only see the first line

just out of curiosity; does Emacs feature folding, in general, or
for Ruby?

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com


(Massimiliano Mirra) #5

With the few lines I posted it supports the `hideshow’ style folding
for Ruby. You can find about other general and less general folding
modes at http://www.emacswiki.org/cgi-bin/wiki.pl?CategoryOutline.

Massimiliano

···

On Sun, Jul 07, 2002 at 06:10:46AM +0900, Tobias Reif wrote:

The `hideshow’ Emacs minor mode lets you hide the content of a block
of code and only see the first line

just out of curiosity; does Emacs feature folding, in general, or for Ruby?


(Mark Slagell) #6

The `hideshow’ Emacs minor mode lets you hide the content of a

block

of code and only see the first line

There is also emacs’ selective-display facility, which shows or hides
based on the existing indentation. So it basically borrows the logic of
ruby-mode or whatever. --Mark

;; ~/.emacs excerpt
;; Use function keys f9 through f12 as a ‘zoom’ control.
(defun zoom-way-out() (interactive)
(set-selective-display 0))
(defun zoom-way-in() (interactive)
(set-selective-display 2))
(defun zoom-out() (interactive)
(set-selective-display
(if selective-display
(if (or (= selective-display 0) (= selective-display 10))
0
(+ selective-display 2))
0)))
(defun zoom-in() (interactive)
(set-selective-display
(if selective-display
(if (= selective-display 0)
10
(if (= selective-display 2)
2
(- selective-display 2)))
10)))

(global-set-key [f9] 'zoom-way-out)
(global-set-key [f10] 'zoom-out)
(global-set-key [f11] 'zoom-in)
(global-set-key [f12] 'zoom-way-in)