From fc382fd965abd64babd1a19d89ddf78c5379187e Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Wed, 28 Mar 2012 14:24:36 +1800 Subject: [PATCH] Goto command for existing search windows --- 18/971bf2a04626f17b96969a779ad8cc4aa57035 | 143 ++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 18/971bf2a04626f17b96969a779ad8cc4aa57035 diff --git a/18/971bf2a04626f17b96969a779ad8cc4aa57035 b/18/971bf2a04626f17b96969a779ad8cc4aa57035 new file mode 100644 index 000000000..13c21dd1a --- /dev/null +++ b/18/971bf2a04626f17b96969a779ad8cc4aa57035 @@ -0,0 +1,143 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 013BA431FAF + for ; Tue, 27 Mar 2012 13:25:02 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id FPv8uG6I4HHP for ; + Tue, 27 Mar 2012 13:25:02 -0700 (PDT) +Received: from va3outboundpool.messaging.microsoft.com + (va3ehsobe006.messaging.microsoft.com [216.32.180.16]) + (using TLSv1 with cipher AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 5DEAF431FAE + for ; Tue, 27 Mar 2012 13:25:02 -0700 (PDT) +Received: from mail173-va3-R.bigfish.com (10.7.14.251) by + VA3EHSOBE001.bigfish.com (10.7.40.21) with Microsoft SMTP Server id + 14.1.225.23; Tue, 27 Mar 2012 20:24:48 +0000 +Received: from mail173-va3 (localhost [127.0.0.1]) by + mail173-va3-R.bigfish.com (Postfix) with ESMTP id AF831C038D for + ; Tue, 27 Mar 2012 20:24:47 +0000 (UTC) +X-SpamScore: 0 +X-BigFish: VPS0(zzzz1202hzzz2dh668h839h944hd24h) +X-Forefront-Antispam-Report: CIP:163.181.249.109; KIP:(null); UIP:(null); + IPV:NLI; H:ausb3twp02.amd.com; RD:none; EFVD:NLI +Received: from mail173-va3 (localhost.localdomain [127.0.0.1]) by mail173-va3 + (MessageSwitch) id 1332879885528605_15614; + Tue, 27 Mar 2012 20:24:45 +0000 (UTC) +Received: from VA3EHSMHS013.bigfish.com (unknown [10.7.14.240]) by + mail173-va3.bigfish.com (Postfix) with ESMTP id 77510600C0 for + ; Tue, 27 Mar 2012 20:24:45 +0000 (UTC) +Received: from ausb3twp02.amd.com (163.181.249.109) by + VA3EHSMHS013.bigfish.com (10.7.99.23) with Microsoft SMTP Server id + 14.1.225.23; Tue, 27 Mar 2012 20:24:45 +0000 +X-WSS-ID: 0M1K8PG-02-34Z-02 +X-M-MSG: +Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com + [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 + bits)) (No + client certificate requested) by ausb3twp02.amd.com (Axway MailGate + 3.8.1) + with ESMTP id 2B55BC8121 for ; Tue, 27 Mar 2012 + 15:24:52 -0500 (CDT) +Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep02.amd.com + (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.192.1; + Tue, 27 Mar 2012 15:25:05 -0500 +Received: from adcvmail01.amd.com (163.181.21.78) by sausexhtp02.amd.com + (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.213.0; + Tue, 27 Mar 2012 15:24:56 -0500 +Received: from mhdc-ns01.amd.com (mhdc-ns01.amd.com [165.204.35.147]) by + adcvmail01.amd.com (8.13.8/8.13.8) with ESMTP id q2RKOolB021084 for + ; Tue, 27 Mar 2012 15:24:52 -0500 +Received: from testarossa.amd.com (testarossa.amd.com [165.204.147.44]) by + mhdc-ns01.amd.com (8.13.8+Sun/8.13.8) with ESMTP id q2RKOsKc026864 for + ; Tue, 27 Mar 2012 14:24:54 -0600 (MDT) +Received: (from manderso@localhost) by testarossa.amd.com + (8.13.8/8.13.8/Submit) id q2RKOcAY010042; + Tue, 27 Mar 2012 14:24:38 -0600 +X-Authentication-Warning: testarossa.amd.com: manderso set sender to + MarkR.Anderson@amd.com using -f +From: Mark Anderson +To: Notmuch Mail +Subject: Goto command for existing search windows +User-Agent: Notmuch/0.11.1+251~g1093c24 (http://notmuchmail.org) Emacs/23.2.1 + (i686-pc-linux-gnu) +Date: Tue, 27 Mar 2012 14:24:36 -0600 +Message-ID: <3wd1uod7px7.fsf@testarossa.amd.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +X-OriginatorOrg: amd.com +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Tue, 27 Mar 2012 20:25:03 -0000 + +I was looking for a function which would find a buffer based on one of +my saved searches, and perform the search if it didn't exist. + +I've gotten it a bit closer, if I perform the search that matches a +saved search, then this routine will find it because of the magic in +notmuch-search-buffer-title, but perhaps someone else feels up to +searching through the saved searches directly? + + + +(defun notmuch-goto-or-search (&optional query) + "Find a notmuch-search buffer with the given query, or run +\"notmuch search\" with the given `query' and display results. + +If `query' is nil, it is read interactively from the minibuffer." + (interactive) + (if (null query) + (setq query (notmuch-read-query "Notmuch goto-or-search: "))) + (let ((buffer-name (notmuch-search-buffer-title query))) + (setq buf (get-buffer buffer-name))) + + (if (not buf) + (notmuch-search query) + (switch-to-buffer buf) + ))) + +I then use it something like this: + +(global-set-key [C-f1] (lambda () (interactive) (notmuch-goto-or-search "tag:inbox and tag:unread and not tag:deleted"))) +(global-set-key [C-f2] (lambda () (interactive) (notmuch-goto-or-search "tag:inbox and not tag:deleted"))) +(global-set-key [C-f3] 'notmuch) +(global-set-key [C-f6] (lambda () (interactive) (notmuch-goto-or-search "tag:todo and not tag:deleted"))) + +It would be better if I could use my Inbox, INBOX and todo names for the +saved searches, but how to do that without breaking generality of +searching the body of the email? Do I have to define my own ss: (saved +search) prefix or something, as I believe some others have? + +This is what I'm willing to do today, and it works for me, I could patch +notmuch.el, but I wondered about answering the other questions. + +Also, some elisp master could hint about how to make the binding not so +ugly. ;) + +Another appreciated elisp hint would be how to get the buf variable to +go inside the let, I keep getting complaints about buffer-name not being +defined, thus the "ugly" setq, which works. + +Enjoy, + +-Mark + -- 2.26.2