Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs equivalent of Vim's foldmethod = indent

Question: Does Emacs have a canonical equivalent of Vim's Folding with Foldmethod=indent?

I am particularly interested in something that can work alongside any Emacs major mode and any file. The Emacs searches have not turned up a definitive answer.

like image 989
dreftymac Avatar asked Dec 20 '08 02:12

dreftymac


3 Answers

Seems like it can, though I don't use folding myself, so I've not tried it. Not surprisingly, the Python folks are all about this feature. See the following:

  • http://mail.python.org/pipermail/tutor/2002-September/017482.html
  • http://www.nabble.com/Code-folder-with-Emacs-td16189193.html
  • http://groups.google.ca/group/comp.lang.python/msg/956f1c2d37f93995
like image 60
Joe Casadonte Avatar answered Oct 16 '22 20:10

Joe Casadonte


maybe selective-display? I have the following function bound to [f2]

;; http://emacs.wordpress.com/2007/01/16/quick-and-dirty-code-folding/
(defun jao-toggle-selective-display (column)
  (interactive "P")
  (set-selective-display
   (if selective-display nil (or column 1))))

That's pretty bare-bones, though, and you'd really want it to be Pythony-indentation sensitive....

UPDATE: I was staring at this last night, and realized that I was tired of C-u entering the column I was on (plus 1).... so I coded it up:

(defun toggle-selective-display-column ()
  "set selective display fold everything greater than the current column, or toggle off if active"
  (interactive)
  (set-selective-display
   (if selective-display nil (or (+ (current-column) 1) 1))))

Further elaboration should combine the two functions.

See also: How to achieve code folding effects in emacs

like image 25
Michael Paulukonis Avatar answered Oct 16 '22 22:10

Michael Paulukonis


I tried all of the suggestions by Joe Casadonte and Michael Paulukonis, but none works as nicely as the vim's one. So it seems that the more accurate answer to the OP's question may be NO at the moment.

like image 2
tbear Avatar answered Oct 16 '22 20:10

tbear