Code folding in Emacs
Sometimes I want to fold a block of text. In Vim you have easy folding without fuzz. Without to add any special characters like "markers" or specific regex like {{{
. I would like to select a region and fold it, without messing with the structure.
When looking around, it seems there were already questions about code folding in Emacs. Someone said that there was "no perfect solution". For example, I created a clip of simple codefolding in Vim:
Vim plain folding
+ Fairly simple, select a region and fold it.
+ It's persistent. When you kill the buffer/close Vim. And reopen the file, the folds are still there.
+ You get a highlight bar, to easily see what's folded.
There are many other folding configurations for Vim. I'm happy with Emacs, but this is one thing that I miss. Other alternatives that I tried, for example HideShow:
HideShow
Evil's alternative with hide-show minor mode
. I found it unusable:
- I'm not able to select a region and folding it. It folds on code blocks.
- There's no higlihgting bar or something, to attend you it's folded. You could easily miss it.
- It's not persistent. If you reopen the file, the folds are gone.
There is another package, Fold this:
Fold this
- It's a pretty alternative. However, it mess with the indentation, because the text under the fold gets placed next to the fold... (?).
- It's able to just visually select the region and fold it. But it breaks the indendation, so the overview gets messed up. Not very handy.
- There is no higlihgting bar or something, to attend you it's folded. You could easily miss it.
What's the issue?
I would like to replicate how Vim does folding. But when I searched around, it seems it's very hard to do that in Emacs. So I wonder if there something in emacs or its architecture that makes it difficult to replicate this? What are the limits?