views:

2130

answers:

6

An excellent feature of Dreamweaver is code folding of any lines of text -- recursively!

It's fantastic, I can fold any text or code, regardless of language. I work with existing systems; I don't edit well-written code or code in one language etc. mostly HTML mixed with god-knows-what. Folding lines makes understanding a lot easier and quicker. Sadly, this is the only feature I like in Dreamweaver.

Is there any code folding for Emacs in a similar aim?

+6  A: 

There's folding mode, a minor mode. Unfortunately it's intrusive: you have to manually annotate the folds with specialized comments, which clutter the code when you aren't using the mode (or when sharing code with others who don't use it). A better mode would not change your code to work.

Let me add: there's a duplicate of this that's worth a look: How to achieve code folding effects in Emacs.

quark
Thanks, I'd already looked at that question and it doesn't answer my question because I don't want to have to edit my code to do it. But I'll accept this as an answer anyway, i.e. "no." It looks like I'm going to have to write this myself or migrate to vim.
Christopher Done
In case anyone comes searching this page later, this tagging based folding library might be of interest: http://lisperati.com/tagging.html
Christopher Done
If you *do* end up writing it let us all know! I've been wanting a proper folding mode for Emacs for quite a while. I'd basically given up and started using other editors.
quark
+3  A: 

hide-show (hs-minor-mode) is a minor mode that will do something like this...

The default key-binding to trigger the folding is C-c @ C-c which I find pretty cumbersome. But then I don't use it much, either.

dmckee
For more details, see: http://www.emacswiki.org/emacs/HideShow
Pete
I've already seen this. I really need something to hide a given region rather than it trying to understand the syntax, as I said above. Thanks though.
Christopher Done
A: 

Something else you might look into is nxhtml-mode; it doesn't fold code, but it does highlight mixed code (i.e. HTML and PHP) differently depending on its type. That gives you a similar gain in comprehensibility without the awkwardness of folding-mode. I think that approach is more suited to Emacs anyway, first because code-folding seems like a mouse-oriented idea that doesn't adapt well to the basically keyboard-centric Emacs interface, and second because Emacs eases navigating a large file to an extent that code can stay visible without getting in your way.

JasonFruit
+1  A: 

You might want to look up the function set-selective-display and the variable selective-display. Not exactly what you want but it lets you hide lines based on indentation level.

RamyenHead
Cheers, I managed to [cook up something][1] using `set-selective-display` to at least demonstrate this folding idea for future discussion. It's not a solution because it messes with the code, but it's a good demonstration. I'm going to try using tagging.el as an example from which to gain ideas to implement this properly.[1]: http://chrisdone.com/blog/html/2009-08-01-emacs-folding.html#video
Christopher Done
+1  A: 

I use fold-dwim.el. From the emacs wiki:

fold-dwim.el is a unified user interface for Emacs folding/outlining modes. It supports folding.el, hideshow.el, outline.el, TeX-fold.el, and nxml-outln.el

You can get it here:

http://www.emacswiki.org/emacs/FoldDwim

I have this in my .emacs:

(require 'fold-dwim)
(global-set-key [(C kp-4)] 'fold-dwim-hide-all)
(global-set-key [(C kp-5)] 'fold-dwim-toggle)
(global-set-key [(C kp-6)] 'fold-dwim-show-all)

Keep in mind that you still need to activate hs-minor-mode, folding-mode, etc. but I find it easier to use them this way.

A: 

If you actually need "something to hide a given region rather than it trying to understand the syntax" (unlike hideshow and other solutions based on parsing) and you "don't want to have to edit my code" (unlike folding), then, I assume, you mean you don't want the regions to be persistent between different editing sessions. Then you might use http://www.emacswiki.org/emacs/HideRegion to hide user-selected regions...

(But that's strange. The folding minor mode with persistent marks seems to be a far more convenient solution.)

imz