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 0F7806DE0927 for ; Thu, 13 Oct 2016 12:38:17 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.449 X-Spam-Level: X-Spam-Status: No, score=-0.449 tagged_above=-999 required=5 tests=[AWL=-0.127, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.211, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] 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 dlX7F4VHThxQ for ; Thu, 13 Oct 2016 12:38:16 -0700 (PDT) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by arlo.cworth.org (Postfix) with ESMTPS id E649D6DE02DA for ; Thu, 13 Oct 2016 12:38:15 -0700 (PDT) Received: by mail-pa0-f53.google.com with SMTP id ry6so41028744pac.3 for ; Thu, 13 Oct 2016 12:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FIiIHsGus/fn2SHxZoL+0IIaGjSnClsD5KDdupSxPF0=; b=Yi1n+srRuFqHOwbV4MsIxLib+B/lKRpP/cbPMf9I+r/t78xWIxX/3dPherJNhFnLGH KeHQxWXulaYd8fDf4tDCKNOeErpgJshWb7zekeD4pL+d8K7NBnAYykOSm6dsCzeph2VH idc3W4nnfPmAVLO5CTEYm8n8+iZr3b8Y11ab1wCQ/Y78mvs6oS2LmIoCAbJHUZWWB4uu hSFTfk02GqfyBjANQO93h15Dv5JJk/7/VuYWBVs7Yx18LxFOaFG1mi1/CX0gza5ziKmw WOsDiTFY95qXZp6QxtWiP6+zcDZMGk0vG7NipB9NOkbolddViQoy1txFWyOOelH0J5qT GwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FIiIHsGus/fn2SHxZoL+0IIaGjSnClsD5KDdupSxPF0=; b=lPS7CNmNEVjyQAB/xNKVTHoDBRiwnC+yaTNlPen16M9w4MfqfU37rmdwKIsCwvnmTI ylqU/UpPvVUOugek+awps6nYnx4GQ7ehMy8TzzcjIuBHsFFcKILwC20BbxV0NDGsLgrw 1Rn0Zhn1Wxjch/vLwkpT4damM7nz57LreoYAP33DnZ0ty2DlEY7T+d/lS0hcYE8meVoX Z+8yr6sFQlABZAE/PH2jFSZc45NiLvMdPHaM9ucPvTB/4AYDbc6io/61kLE2bLMSd7v8 tqw63rpCPFK4XLIrED2/F1kmc4Z/e5lX7YGNIvkaaOr2YzgVRaN70S/3hJ6AOqhQndF0 wPpg== X-Gm-Message-State: AA6/9Rns/Wus2T7Qj+1hqXTYL20+7yNhAkLQKkWkOjqj9GqlKaUCo65XswI6xWOvZ0wJa2gr X-Received: by 10.67.3.10 with SMTP id bs10mr10508786pad.165.1476387495169; Thu, 13 Oct 2016 12:38:15 -0700 (PDT) Received: from marmstrong-linux.kir.corp.google.com ([100.119.200.73]) by smtp.gmail.com with ESMTPSA id a10sm2747481pao.35.2016.10.13.12.38.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Oct 2016 12:38:14 -0700 (PDT) From: Matt Armstrong To: notmuch@notmuchmail.org Subject: [PATCH v3] Add notmuch-show--build-queries. Date: Thu, 13 Oct 2016 12:37:58 -0700 Message-Id: <1476387478-11506-2-git-send-email-marmstrong@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1476387478-11506-1-git-send-email-marmstrong@google.com> References: <1476387478-11506-1-git-send-email-marmstrong@google.com> 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: Thu, 13 Oct 2016 19:38:17 -0000 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). --- 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)) + (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))) (when forest (notmuch-show-insert-forest forest) -- 2.8.0.rc3.226.g39d4020