0

I've been trying various combinations of folding modes for Emacs, trying to get them to work with notmuch-show-mode, but to no avail:

Given two messages like this:

Summary: Some Guy <[email protected]> (May 27) (replied)
Subject: About this
To: Some Other Guy <[email protected]>
Date: Wed, 27 May 2020 13:45:51 +0200

[ multipart/related ]
[ text/html ]
Dear some guy

This is a reply to your mail.

------------------------------------------------
HEADERS_HERE
This is my original mail.

Summary: Some Guy <[email protected]> (May 27) (replied)
Subject: About this
To: Some Other Guy <[email protected]>
Date: Wed, 27 May 2020 13:45:51 +0200

[ multipart/related ]
[ text/html ]
This is my original mail.

I want to collapse the part from "-----------." and until the next "Summary: ".

I spend the most time trying to get hs-minor-mode working with this in my init.el:

(with-eval-after-load 'hideshow
   (add-to-list 'hs-special-modes-alist
                '(notmuch-show-mode
                  "---------" ; START
                  "Summary:" ;END
                  "" ; COMMENT-START
                  nil ; FORWARD-SEXP-FUNC
                  nil ; ADJUST-BEG-FUNC
                  )))

But calling M-x hs-minor-mode gives this error:

hs-grok-mode-type: notmuch-show Mode doesn’t support Hideshow Minor Mode
4
  • Welcome to Emacs.SE! Can you explain what you have tried so far that didn't work?
    – Dan
    Commented Jun 5, 2020 at 17:51
  • Hi @Dan, thank you so much, good to be here :) Most of the process was me trying different things while yelling at the screen, so it's not very well documented. In broad strokes I've tried the following approaches. hs-minor-mode: I've tried adding a setting for notmuch-show-mode to hs-special-modes-alist, but I wasn't allowed to enable to mode in the buffer. Using the same code for ruby-mode worked. folding.el: Tried to configure it for notmuch-show-mode, but it complained about unmatched terms. vimfold-mode/origami: Tried to configure them but folding did not work. Commented Jun 5, 2020 at 19:45
  • If you can edit your post to include the code you tried, someone familiar with those packages might be able to help you figure out how to make it work.
    – Dan
    Commented Jun 5, 2020 at 19:48
  • Hi @Dan. Sure I added what I tried for hs-minor-mode. Thx. Commented Jun 5, 2020 at 20:15

1 Answer 1

0

The "hs-grok-mode-type: notmuch-show Mode doesn’t support Hideshow Minor Mode" error was solved by setting comment-start to a fake value. After that I needed to provide custom FORWARD-SEXP-FUNC and ADJUST-BEG-FUNC values to hs-special-modes-alist. I ended up with the following in my init.el:

(defun my-notmuch-show-hs-forward-sexp (a)
  (re-search-forward "Summary:")
  (beginning-of-line)
  (backward-char 1))

(defun my-notmuch-show-hs-adjust-block-beginning (pos)
  (save-excursion (goto-char pos) (previous-line) (previous-line) (end-of-line)
    (point)))

(setq hs-special-modes-alist
   '((notmuch-show-mode "----------\n" "Summary:" "///IDONTNEEDTHIS"
      my-notmuch-show-hs-forward-sexp my-notmuch-show-hs-adjust-block-beginning)))

(add-hook 'notmuch-show-mode-hook
  (lambda ()
    (setq-local comment-start "///IDONTNEEDTHIS")
    (hs-minor-mode)))

(setq hs-set-up-overlay
  (defun my-display-code-line-counts (ov)
    (when (eq 'code (overlay-get ov 'hs))
      (overlay-put ov 'display
                   (propertize
                    (format "\n... <%d>"
                            (count-lines (overlay-start ov)
                                         (overlay-end ov)))
                    'face 'font-lock-type-face)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.