I know the thread about having folds for LaTex. However, I want folds for C++/Java when I code.
How can you have either automatic or manual folds in Emacs for C++/Java?
I know the thread about having folds for LaTex. However, I want folds for C++/Java when I code.
How can you have either automatic or manual folds in Emacs for C++/Java?
hs-minor-mode is what you want.
esc x hs-minor-mode
toggles it. On minor modes in general, see gnu.org/software/emacs/manual/html_node/emacs/Minor-Modes.html
My customization for hs-minor-mode is as follows
(add-hook 'c-mode-common-hook
(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)))
You can use CEDET to do this. This package provides global-semantic-tag-folding-mode, that allows to fold functions, classes/structures, comments, namespaces, etc. It works more properly than other packages, as it has all syntactic information about code.
There is introduction article about CEDET, that allows to quickly start work with it
Make sure you have folding-mode.el. Then, insert
// {{{
// }}}
Around your code. Reload your buffer, and voila! You'll have folds.
You could experiment with selective-display. It's more of a quick folding of all your code according to its indentation level. It's great for getting class/function summaries or for moving around quickly.
But if folding up blocks of code is what you want, then HideShow, like Arkadiy pointed out, is probably more suitable.