You can enable Hide-Show for C/C++ code by adding the following to your .emacs:
(add-hook 'c-mode-common-hookYou can hide or show either the current block, or the whole file. To show the former, consider a C-function:
(lambda()
(local-set-key (kbd "C-c <right>") 'hs-show-block)
(local-set-key (kbd "C-c <left>") 'hs-hide-block)
(local-set-key (kbd "C-c <up>") 'hs-hide-all)
(local-set-key (kbd "C-c <down>") 'hs-show-all)
(hs-minor-mode t)))
Now, when calling hs-hide-block, we get:
int my_function (int a, int b)
{
return a + b;
}
HideShow has one problem: the truly bizarre default key bindings, such as 'C-c @ ESC C-s' for hs-show-all. This is the reason I am adding these alternative key bindings in the add-hook above - 'C-c' and the arrow keys; alternatively, you could use the 'Super'-key instead of C-c.
int my_function (int a, int b)...
If you'd like to hide everything by default when you open a file, you can do so by adding
(hs-hide-all)to the above hook function.
Side-note: Even though there are many keys on your keyboard, there is a finite number of easy combinations, especially when the arrow-keys are involved. They are popular, and not just by emacs -- for example, window managers often use Ctrl-Alt-<arrow-key> for switching between virtual desktops. So, it's good to think a little bit where to 'spend' your easiest key bindings.
No comments:
Post a Comment