Code folding is a feature I’ve taken for granted in Windows IDEs, but now I am using Emacs more and more, I wanted it there too, and it turns out getting it is straightforward enough.
- Download Folding Mode and save folding.el in the Emacs site lisp directory (on my Debian machine that is
/usr/share/emacs23/site-lisp/
, probably the same on any Linux).Surprisingly there’s noor.deb
package for itapt-get install emacs-goodies-el
. - Add the following to your
~/.emacs
:(load "folding" 'nomessage 'noerror) (folding-add-to-marks-list 'haskell-mode "--{{{" "--}}}" nil t) (folding-mode-add-find-file-hook) (add-hook 'haskell-mode-hook 'folding-mode) (folding-add-to-marks-list 'tuareg-mode "(*{{{" "(*}}}*)" nil t) (add-hook 'tuareg-mode-hook 'folding-mode)
Lines 4 and 7 cause
folding-mode
to be automatically entered afterhaskell-mode
ortuareg-mode
respectively, which seems to be necessary, rather than just loading it on Emacs startup withauto-load
. This is slightly different from the instructions on the page, perhaps it was written for an older Emacs. - Delimit the code with the appropriate markers. These can be anything you put in
.emacs
,{{{
and}}}
in conjunction with the language’s own comment characters seems to be a convention. Unfortunately Emacs doesn’t seem to be able to do this automagically the way other language-sensitive editors would (then again, those editors don’t allow you to define folding positions yourself, they always do it on functions or other obvious blocks)
As an example you can then toggle between:
And:
With right-click.
Of course, there is a .deb package. folding.el is included in emacs-goodies-el 🙂
Hah, intuitive 🙂
Annoyingly it wants a bunch of dependencies which it doesn’t really need, as it runs perfectly if you install it by hand. Like,
perl-doc
, I don’t even like Perl… And if you do it throughdselect
it also wants to install a new IM client!That’s probably because the package contains other extentions with some needs. Besides, apt-cache would have found it if the description of emacs-goodies-el did contain “folding”… but it doesn’t. But then, one might to check if it’s the case for other extesions as well before submitting a bugreport.
Pingback: Komodo 6 | So I decided to take my work back underground
you might want to give a try: http://ddlookup.com/tool/jfold. no “markers” are needed, since no specially added markers are appropriate.