I just figured out how to use code block hiding in emacs22, using hs-minor-mode. That stands for HideShow minor mode. I wanted to call this post "How to Get Code Folding in Emacs", but apparently "Folding" means something different to some people, and there is a different mode for that.
Anyway, to turn on hs-minor-mode simply enter "M-x hs-minor-mode". (M stands for the Meta key, usually Alt, and C stands for the Ctrl key.) Then you can use the following key combinations:
Frankly, though, I think it is harder to remember those than to just use the commands they point to:
The ones I use most are hs-hide-all and hs-toggle-hiding, which can be used in abbreviated form:
Also, here is something which you can add to your .emacs file:
This will start up hs-minor-mode automatically when you open code files for some languages, and will also allow you to us the hs-toggle-hiding command by pressing C-\, which is a bit faster.
Things probably work a little bit differently in graphical Emacs, but since I only use emacs22-nox, you'll have to figure that out yourself.
Anyway, to turn on hs-minor-mode simply enter "M-x hs-minor-mode". (M stands for the Meta key, usually Alt, and C stands for the Ctrl key.) Then you can use the following key combinations:
C-c @ ESC C-s show all
C-c @ ESC C-h hide all
C-c @ C-s show block
C-c @ C-h hide block
C-c @ C-c toggle hide/show
Frankly, though, I think it is harder to remember those than to just use the commands they point to:
M-x hs-hide-all
M-x hs-hide-block
M-x hs-show-all
M-x hs-show-block
M-x hs-toggle-hiding
The ones I use most are hs-hide-all and hs-toggle-hiding, which can be used in abbreviated form:
M-x hs-hide-a
M-x hs-t
Also, here is something which you can add to your .emacs file:
(global-set-key (kbd "C-\\") 'hs-toggle-hiding)
(add-hook 'c-mode-common-hook 'hs-minor-mode)
(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
(add-hook 'java-mode-hook 'hs-minor-mode)
(add-hook 'lisp-mode-hook 'hs-minor-mode)
(add-hook 'perl-mode-hook 'hs-minor-mode)
(add-hook 'sh-mode-hook 'hs-minor-mode)
This will start up hs-minor-mode automatically when you open code files for some languages, and will also allow you to us the hs-toggle-hiding command by pressing C-\, which is a bit faster.
Things probably work a little bit differently in graphical Emacs, but since I only use emacs22-nox, you'll have to figure that out yourself.


Leave a comment