Code Folding in Emacs


This week I learned Emacs has code folding built in (of course it has!). It's called Hide Show and you enable it with hs-minor-mode and toggle function, class or comment folding/unfolding with hs-cycle. There's many other commands to try: hs-hide-all, hd-show-all and so on.

emacs code folding

The default bindings look pretty wild, like C-c @ C-s, but you know what? For the most part, I've stopped learning new shortcuts the last ten years or so and just use M-x with fuzzy search. Works well enough for me, even for things I use regularly, like eglot-rename and delete-trailing-white-space.

Using smex ensures I always have the last recently used at the top.

Happy folding!


Licensed under CC BY Creative Commons License ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🎥 youtube.com/@skybert