1

Is there some way to collapse Lisp functions in Emacs? I found these answers:

emacs collapsing functions in class using outline-minor-mode

Is it possible to collapse a function in emacs?

But they use add-hook, which gives me an "undefined function" error. What am I missing?

Daniel
  • 11,332
  • 9
  • 44
  • 72
Kotlopou
  • 415
  • 3
  • 13
  • what is undefined? `hs-minor-mode` is autoloaded and installed by default in newer emacs versions and is designed to do this specifically. What version of emacs are you using? – Rorschach Nov 10 '18 at 17:27
  • GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) of 2018-08-27 – Kotlopou Nov 10 '18 at 21:18
  • `C-h f` `hs-minor-mode` – Rorschach Nov 10 '18 at 21:48
  • The help suggests the keyboard shortcut C-c @ C-d (for example), but upon typing C-c @ I get the message "C-c @ is undefined". – Kotlopou Nov 10 '18 at 23:54
  • 1
    maybe a windows problem? you can bind functions to whatever keys you want, or just call the function directly to try it out, eg `M-x hs-minor-mode` – Rorschach Nov 11 '18 at 02:24
  • You are reporting errors with things which should categorically not cause errors, which makes it very hard to assist. Please *show* the failing configuration(s) in your question, so we can see exactly what code you are using. – phils Nov 12 '18 at 09:15
  • Luckily, I figured it out, sidestepping the problem by just calling the function manually as jenesaisquoi suggested (less of a pain than figuring out where the issue is or reconfiguring stuff I don't understand). – Kotlopou Nov 12 '18 at 21:16

2 Answers2

0

You can try origami-mode.

You can find detailed information about it in the Github page, but in short, just install it and call origami-recursively-toggle-node to fold and unfold a function.

There's no need for adding hooks or what not. You probably have something wrong with your config, possibly a require missing somewhere.

Daniel
  • 11,332
  • 9
  • 44
  • 72
0

I use hs-minor-mode, as recommended in a comment by Rorschach in the question. The hs-minor-mode came with my emacs install and it works well.

To determine the useful commands, I typed Ctrl-h v hs-minor-mode-map and examined the keyboard map when hs-minor-mode is active (I added the comments so that the actual key sequences are easily read):

 (3 keymap ; Ctrl-C
    (64 keymap ; @ (at-sign)
        (5 . hs-toggle-hiding) ; Ctrl-E
        (4 . hs-hide-block) ; Ctrl-D
        (20 . hs-hide-all) ; SPACE
        (1 . hs-show-all) ; Ctrl-A
        (3 . hs-toggle-hiding) ; Ctrl-C
        (12 . hs-hide-level) ; Ctrl-L
        (27 keymap ; ESC
            (19 . hs-show-all) ; Ctrl-S
            (8 . hs-hide-all)) ; Ctrl-H
        (19 . hs-show-block) ; Ctrl-S
        (8 . hs-hide-block)))) ; Ctrl-H

The recommended keystrokes are difficult to type. I decided to assign Alt-H to the following elisp (it's not exactly what I want yet, but I do like to assign one keystroke to do multiple things):

(lambda () (interactive)
    (hs-minor-mode 1)
    (if (hs-find-block-beginning)
            (hs-toggle-hiding)
        (let ((from (point-min))
                (to (point-max)))
            (while (and
                (not (hs-overlay-at from))
                (setq from (next-overlay-change from))
                (not (= to from)))) ; locate first hs-overlay
            (if (= to from) ; hs-overlay-was-not-found
                (hs-hide-all)
                (hs-show-all))))))
Paul
  • 442
  • 4
  • 9