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 <someguy@example.com> (May 27) (replied)
Subject: About this
To: Some Other Guy <someotherguy@example.com>
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 <someguy@example.com> (May 27) (replied)
Subject: About this
To: Some Other Guy <someotherguy@example.com>
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
  • Welcome to Emacs.SE! Can you explain what you have tried so far that didn't work? – Dan Jun 5 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. – Rune Kaagaard Jun 5 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 Jun 5 at 19:48
  • Hi @Dan. Sure I added what I tried for hs-minor-mode. Thx. – Rune Kaagaard Jun 5 at 20:15
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)))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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