From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 063D56DE0FBC for ; Thu, 28 Sep 2017 05:25:38 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.101 X-Spam-Level: X-Spam-Status: No, score=-0.101 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QznYMFb7LCJD for ; Thu, 28 Sep 2017 05:25:36 -0700 (PDT) X-Greylist: delayed 539 seconds by postgrey-1.36 at arlo; Thu, 28 Sep 2017 05:25:36 PDT Received: from mail.koumakan.jp (lincle.koumakan.jp [62.210.203.63]) by arlo.cworth.org (Postfix) with ESMTPS id 893B36DE0FB6 for ; Thu, 28 Sep 2017 05:25:36 -0700 (PDT) Received: from localhost (unknown [10.0.0.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.koumakan.jp (Postfix) with ESMTPSA id A412CC721; Thu, 28 Sep 2017 21:16:34 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oxij.org; s=default; t=1506600995; bh=7UisFsuxVI4+0xeLSN0Bz9gYnQ0Rji/R+MD92RAeO8A=; h=From:To:Subject:In-Reply-To:References:Date; b=NEaZDJmZNtbjTMxMTr46kiHNMYUDRtPvdUtV3u0E25UvsMBIzNG9N3YK+H+nwIpxI TKC4C+eovJF6gGxKg8DrXXkHL+ftfQEehJP7AgEHewPFsyvhS71q8s9kj1a5TlTdYo IRMsQWKVIf1QTd4DckukYA39olEkxmLyNJQes+uU= From: Jan Malakhovski To: Matt Armstrong , Jani Nikula , notmuch@notmuchmail.org Subject: Re: notmuch.el: controlling what does and doesn't get expanded in searches In-Reply-To: References: <87a8gsv787.fsf@nikula.org> Date: Thu, 28 Sep 2017 12:16:17 +0000 Message-ID: <871smraui6.fsf@oxij.org> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Sep 2017 12:25:38 -0000 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)