unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jan Malakhovski <oxij@oxij.org>
To: Matt Armstrong <marmstrong@google.com>,
	Jani Nikula <jani@nikula.org>,
	notmuch@notmuchmail.org
Subject: Re: notmuch.el: controlling what does and doesn't get expanded in searches
Date: Thu, 28 Sep 2017 12:16:17 +0000	[thread overview]
Message-ID: <871smraui6.fsf@oxij.org> (raw)
In-Reply-To: <qf57fbw4fx4.fsf@marmstrong-linux.kir.corp.google.com>

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)

      parent reply	other threads:[~2017-09-28 12:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 15:54 notmuch.el: controlling what does and doesn't get expanded in searches Matt Armstrong
2016-08-04 16:17 ` Jani Nikula
2016-08-04 17:12   ` Matt Armstrong
2016-08-04 19:44     ` Carl Worth
2016-08-04 20:49       ` Jani Nikula
2016-09-16  6:32         ` Matt Armstrong
2017-09-28 12:16     ` Jan Malakhovski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871smraui6.fsf@oxij.org \
    --to=oxij@oxij.org \
    --cc=jani@nikula.org \
    --cc=marmstrong@google.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).