From fbae5e904ec8901e2e7989c22642f76bf96bcb58 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Fri, 30 Mar 2012 09:47:14 +1800 Subject: [PATCH] Re: Goto command for existing search windows --- a8/b57e50dc5bda4b1af728a3199d3ed665d329d4 | 178 ++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 a8/b57e50dc5bda4b1af728a3199d3ed665d329d4 diff --git a/a8/b57e50dc5bda4b1af728a3199d3ed665d329d4 b/a8/b57e50dc5bda4b1af728a3199d3ed665d329d4 new file mode 100644 index 000000000..1b44939de --- /dev/null +++ b/a8/b57e50dc5bda4b1af728a3199d3ed665d329d4 @@ -0,0 +1,178 @@ +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 F1258431FAF + for ; Thu, 29 Mar 2012 08:47:31 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 3ydh3ENk5T2S for ; + Thu, 29 Mar 2012 08:47:31 -0700 (PDT) +Received: from db3outboundpool.messaging.microsoft.com + (db3ehsobe002.messaging.microsoft.com [213.199.154.140]) + (using TLSv1 with cipher AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0026A431FAE + for ; Thu, 29 Mar 2012 08:47:30 -0700 (PDT) +Received: from mail3-db3-R.bigfish.com (10.3.81.253) by + DB3EHSOBE002.bigfish.com (10.3.84.22) with Microsoft SMTP Server id + 14.1.225.23; Thu, 29 Mar 2012 15:47:28 +0000 +Received: from mail3-db3 (localhost [127.0.0.1]) by mail3-db3-R.bigfish.com + (Postfix) with ESMTP id 45BA6220CC0 for ; + Thu, 29 Mar 2012 15:47:28 +0000 (UTC) +X-SpamScore: -9 +X-BigFish: VPS-9(zz1432N98dKzz1202hzz8275bhz2dh668h839h944hd24h) +X-Forefront-Antispam-Report: CIP:163.181.249.108; KIP:(null); UIP:(null); + IPV:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI +Received: from mail3-db3 (localhost.localdomain [127.0.0.1]) by mail3-db3 + (MessageSwitch) id 1333036045508084_5422; + Thu, 29 Mar 2012 15:47:25 +0000 (UTC) +Received: from DB3EHSMHS019.bigfish.com (unknown [10.3.81.228]) by + mail3-db3.bigfish.com (Postfix) with ESMTP id 7942B4E012C for + ; Thu, 29 Mar 2012 15:47:25 +0000 (UTC) +Received: from ausb3twp01.amd.com (163.181.249.108) by + DB3EHSMHS019.bigfish.com (10.3.87.119) with Microsoft SMTP Server id + 14.1.225.23; Thu, 29 Mar 2012 15:47:22 +0000 +X-WSS-ID: 0M1NL6V-01-0YV-02 +X-M-MSG: +Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com + [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 + bits)) (No + client certificate requested) by ausb3twp01.amd.com (Axway MailGate + 3.8.1) with ESMTP id 28CAAD10005 for ; + Thu, 29 Mar 2012 10:47:19 -0500 (CDT) +Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep01.amd.com + (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.192.1; + Thu, 29 Mar 2012 10:47:35 -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; + Thu, 29 Mar 2012 10:47:19 -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 q2TFlGX1013600; + Thu, 29 Mar 2012 10:47:16 -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 q2TFlIHI003604; + Thu, 29 Mar 2012 09:47:18 -0600 (MDT) +Received: (from manderso@localhost) by testarossa.amd.com + (8.13.8/8.13.8/Submit) id q2TFlEPT008760; + Thu, 29 Mar 2012 09:47:14 -0600 +X-Authentication-Warning: testarossa.amd.com: manderso set sender to + MarkR.Anderson@amd.com using -f +From: Mark Anderson +To: Notmuch Mail +Subject: Re: Goto command for existing search windows +In-Reply-To: <3wd1uod7px7.fsf@testarossa.amd.com> +References: <3wd1uod7px7.fsf@testarossa.amd.com> +User-Agent: Notmuch/0.11.1+251~g1093c24 (http://notmuchmail.org) Emacs/23.2.1 + (i686-pc-linux-gnu) +Date: Thu, 29 Mar 2012 09:47:14 -0600 +Message-ID: <3wdmx6z5rzx.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: Thu, 29 Mar 2012 15:47:32 -0000 + +On Tue, 27 Mar 2012 14:24:36 -0600, Mark Anderson wrote: +> 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 have a slightly better-for-me version now: + +(defun notmuch-goto-or-search (&optional query) + "Find a notmuch saved-search query with the given name, or a +search with the given query, switching to an existing buffer +without changes in preference to automatically refreshing or +creating the search buffer. + +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 ((saved-search-tuple (assoc query notmuch-saved-searches))) + (setq expanded-query + (if (null saved-search-tuple) + query + (cdr saved-search-tuple)))) + (let ((buffer-name (notmuch-search-buffer-title expanded-query))) + (setq buf (get-buffer buffer-name))) + (if (not buf) + (notmuch-search expanded-query) + (switch-to-buffer buf) + )) + +This does search the saved searches to see if you entered a saved search +name. With this I don't have to duplicate my query for saved searches +in key bindings. + +(global-set-key [f8] (lambda () (interactive) (notmuch-goto-or-search "Inbox"))) +(global-set-key [f9] (lambda () (interactive) (notmuch-goto-or-search "INBOX"))) +(global-set-key [f10] (lambda () (interactive) (notmuch-goto-or-search "todo"))) + + +> 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