notmuch.el: controlling what does and doesn't get expanded in searches

Jan Malakhovski oxij at oxij.org
Thu Sep 28 05:16:17 PDT 2017


Hi.

I struggled with the same problem and wrote the following bit of code to
solve it. I've been using it for a couple of years now and I'm so happy
with it, that I forgot I wanted to get around to fix those TODOs. Feel
free do whatever with it. Hope it helps.

Cheers,
  Jan

;; A bit of notmuch-show-hook magic
;;
;; It makes notmuch-show
;; * show messages matching the specific query and hide the rest, or, if the query matches the whole thread,
;; * show unread or flagged messages of the thread and hide the rest, or, if there're no such messages,
;; * show all the messages
;; and jump to the very first one of those.
;;
;; This saves a lot of key presses.
;;
;; TODO: more generic one: by search query
;; TODO: rewrite using notmuch-show-mapc
(defun oxij/notmuch-show-only-tags (tags)
  "In notmuch-show-mode show messages matching tags, hide the rest"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (loop do
      (let ((props (notmuch-show-get-message-properties)))
           (if (remove-if-not (lambda (e) (member e tags))
                              (plist-get props :tags))
               (notmuch-show-message-visible props t)
               (notmuch-show-message-visible props nil)))
    until (not (notmuch-show-goto-message-next)))))

;; TODO: how do I break out of mapc?
(defun oxij/notmuch-show-interesting ()
  "Hide boring messages when all messages in the buffer match the specified query"
  (let ((all-matched t))
    (notmuch-show-mapc (lambda ()
      (let ((props (notmuch-show-get-message-properties)))
        (unless (plist-get props :match)
          (setq all-matched nil)))))
    (when all-matched
      (oxij/notmuch-show-only-tags '("unread" "flagged")))))

;; notmuch-show-goto-first-wanted-message will be called just after
;; this hook and will undo the result of this when
;; oxij/notmuch-show-interesting hides everything. see the source of
;; notmuch-show-goto-first-wanted-message for details
(add-hook 'notmuch-show-hook 'oxij/notmuch-show-interesting)


More information about the notmuch mailing list