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 A1E426DE024A for ; Fri, 14 Oct 2016 23:54:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.027 X-Spam-Level: X-Spam-Status: No, score=0.027 tagged_above=-999 required=5 tests=[AWL=-0.103, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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 SR7kp_bnTVed for ; Fri, 14 Oct 2016 23:54:13 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id CEF4E6DE00AC for ; Fri, 14 Oct 2016 23:54:12 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id 79so1406546wmy.3 for ; Fri, 14 Oct 2016 23:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=Werca2HdiuTjVYvOWTL17su9os87bK49fOw83iNvU4Y=; b=byxEbSbf4NtxtrOadzr8Pb7fFNI0SphnRElE8fJLK60PSQywd2n7PxsLVMHXEWb6xe 6AHSwcl/tFTTyegYtNNmSwAKh/rC/pIxdLru0DnTjAq+SeIbw0zG4MukY/YPW95DW+D5 7RwYaQYm1IoFP5h0s9Kl1aWVdTqaQ+QbFULJBrUVMDAQowyfu2CawMQHnHzKBx7FNKeN TX3WnUZxuCoZJlx9Q2dX0+Xa6hQBehQ6oEC9VFPlbumaxoVLOO7REMV7+U4s7OxIAn8Y 18oorPP4VLlIyk+7NzKX6qizRCsT/mduIf4AmtLBVxiwPQSaG+RF4ZSN06oqGtjy6sED FPLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=Werca2HdiuTjVYvOWTL17su9os87bK49fOw83iNvU4Y=; b=XgRXMiv0QlQMb401AOzCDfNm3ntXik+y4xK5q69XKrcBppEjXCZee+Afe4lmxmV0Gx D47M1cTjnYp6Mxw0sD1Yn4v6bT0oCjxsZxD+KTElaXFOouhfQoxVBbvMWnwjIC78fNbQ QNWnmLsp1H+xqbvpycFi9wH+qBmxxekCyuUDwBUj04kAedumwDLxtuis+qxO7o4ESeM7 NxvZ4hV/NjD6zxVF8Aiibn05PS/9o83C5lN9VlC15HGxU6GcizaTQzEqnmA87ty9IS+o JHV+525120ytwxPTAIndZ/x9/hDdUqSvhZXj/M10xSSeMLoaZ0l46Qs8aGA1ht4U1RdM 8NGw== X-Gm-Message-State: AA6/9RnN144jfu5w+9BGhNbBXc3xLZBqIJzqhgRfOyKjM+tzjnQ9Go6aKppWkWhr8ZBxHg== X-Received: by 10.28.66.205 with SMTP id k74mr877530wmi.124.1476514449463; Fri, 14 Oct 2016 23:54:09 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id e4sm1980138wma.20.2016.10.14.23.54.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Oct 2016 23:54:08 -0700 (PDT) From: Mark Walters To: Matt Armstrong , notmuch@notmuchmail.org Subject: Re: [PATCH v3] Add notmuch-show--build-queries. In-Reply-To: <1476387478-11506-2-git-send-email-marmstrong@google.com> References: <1476387478-11506-1-git-send-email-marmstrong@google.com> <1476387478-11506-2-git-send-email-marmstrong@google.com> Date: Sat, 15 Oct 2016 07:54:08 +0100 Message-ID: <87vawu5chb.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Sat, 15 Oct 2016 06:54:13 -0000 On Thu, 13 Oct 2016, Matt Armstrong wrote: > notmuch-show--build-buffer now queries a list of queries built by the > former. This simplifies the logic. It also provides an easy place to > experiment with alternate sets of queries for given notmuch-show-* > variables (e.g. users can use advice-add to do so in a surgical way). This is looking pretty good. I suggest a couple of further changes below. > --- > emacs/notmuch-show.el | 36 ++++++++++++++++++++++-------------- > 1 file changed, 22 insertions(+), 14 deletions(-) > > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el > index f2487ab..b393c11 100644 > --- a/emacs/notmuch-show.el > +++ b/emacs/notmuch-show.el > @@ -1261,6 +1261,20 @@ matched." > (message "No messages matched the query!") > nil)))) > > +(defun notmuch-show--build-queries () > + "Return a list of queries to try for this search. > + > +If `notmuch-show-query-context` is not nil, the first query is > +the conjunction of it and `notmuch-show-thread-id`. The next > +query is `notmuch-show-thread-id` alone, and serves as a fallback > +if the prior matches no messages." > + (let* ((thread notmuch-show-thread-id) > + (context notmuch-show-query-context) > + queries) > + (push (list thread) queries) > + (if context (push (list thread "and (" context ")") queries)) > + queries)) > + We may want to call this from tree-mode later, so I wonder whether passing it notmuch-show-thread-id and notmuch-show-query-context as arguments would make sense. I quite like the idea of this function being self contained (ie not referencing global state variables). My instinct is that referencing truly global variables like customise variables is fine, but I am less keen on referencing buffer-local global variables. However, some of this depends on what your later plans are. > (defun notmuch-show--build-buffer (&optional state) > "Display messages matching the current buffer context. > > @@ -1268,25 +1282,19 @@ Apply the previously saved STATE if supplied, otherwise show the > first relevant message. > > If no messages match the query return NIL." > - (let* ((basic-args (list notmuch-show-thread-id)) > - (args (if notmuch-show-query-context > - (append (list "\'") basic-args > - (list "and (" notmuch-show-query-context ")\'")) > - (append (list "\'") basic-args (list "\'")))) > - (cli-args (cons "--exclude=false" > + (let* ((cli-args (cons "--exclude=false" > (when notmuch-show-elide-non-matching-messages > (list "--entire-thread=false")))) > - > - (forest (or (notmuch-query-get-threads (append cli-args args)) > - ;; If a query context reduced the number of > - ;; results to zero, try again without it. > - (and notmuch-show-query-context > - (notmuch-query-get-threads (append cli-args basic-args))))) > - > + (queries (notmuch-show--build-queries)) > + (forest nil) > ;; Must be reset every time we are going to start inserting > ;; messages into the buffer. > (notmuch-show-previous-subject "")) > - > + ;; Use results from the first query that returns some. > + (while (and (not forest) (consp queries)) > + (setq forest (notmuch-query-get-threads > + (append cli-args (list "'") (car queries) (list "'")))) > + (setq queries (cdr queries))) One small style point: you can replace the (consp queries) test just with queries: the empty list equals "nil". Best wishes Mark > (when forest > (notmuch-show-insert-forest forest) > > -- > 2.8.0.rc3.226.g39d4020 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch