From 52a0ccc677bcb1bcb30505aad0fa6bc2624cadb2 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Mon, 23 Jun 2014 22:06:46 +0100 Subject: [PATCH] [PATCH v2] emacs: set default in notmuch-read-query --- da/33ffb9e940960a6a3e43e03cc164e10bd71850 | 162 ++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 da/33ffb9e940960a6a3e43e03cc164e10bd71850 diff --git a/da/33ffb9e940960a6a3e43e03cc164e10bd71850 b/da/33ffb9e940960a6a3e43e03cc164e10bd71850 new file mode 100644 index 000000000..ab10e9c05 --- /dev/null +++ b/da/33ffb9e940960a6a3e43e03cc164e10bd71850 @@ -0,0 +1,162 @@ +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 04552431FAF + for ; Mon, 23 Jun 2014 14:07:02 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + 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 k4pWurzcqH0e for ; + Mon, 23 Jun 2014 14:06:56 -0700 (PDT) +Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com + [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 5320B431FAE for ; Mon, 23 Jun 2014 14:06:56 -0700 + (PDT) +Received: by mail-wg0-f41.google.com with SMTP id a1so6937775wgh.0 + for ; Mon, 23 Jun 2014 14:06:54 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=BpqOnTUMRM3NxllU/+RHRQrpszvTI4c4dlyDHevdj+Y=; + b=Gd2Oja41g7dfWwRH2dBFYdA+gyamX8mMMNmW6Nu+uGnUR//84aG7SMBayb2ie6XI18 + PEL3th/bEYxGksGD281uAM6ifvr0VMzePFNZn0T2wV/+WLkZn6xPRfkVwENENuLBMZVk + EIUB2WadbWd1JcxTl5mRgMPftQMCG47iJ345youcWM6OSwO5Cm3zDZRv8UpPgqS3quuf + sLtDfBFFBOq1DhGJSm1F01EhG3N3u131NJCjalktQXBQkznyUGABTcCvPx2HrHDq7TGx + TiWXTY0qiV+foVgZvrP3GUnmX+o9yBuNsisj8EMK8zmtTjnHMh+IAF3D5hgeL5qw6lM0 + GU6A== +X-Received: by 10.180.198.226 with SMTP id jf2mr28730479wic.35.1403557613784; + Mon, 23 Jun 2014 14:06:53 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id + hb8sm28389256wib.12.2014.06.23.14.06.52 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 23 Jun 2014 14:06:53 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH v2] emacs: set default in notmuch-read-query +Date: Mon, 23 Jun 2014 22:06:46 +0100 +Message-Id: <1403557606-13397-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <874n134bbi.fsf@qmul.ac.uk> +References: <874n134bbi.fsf@qmul.ac.uk> +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: Mon, 23 Jun 2014 21:07:02 -0000 + +This adds the current query as a "default value" to +notmuch-read-qeury. The default value is available via a down-arrow as +opposed to history which is available from the up arrow. + +Note if a user presses return in the minibuffer this value is not +returned. + +The implementation is simple but notmuch-read-query could be called +via notmuch-search/notmuch-tree etc from any buffer so it makes sense +to put the decision of how to extract the current query in +notmuch-read-query rather than in each of the callers. +--- + +v2 keeps the logic for extracting a query in the relevant file +(show/tree etc) so notmuch-read-query just needs to choose which one +to call. + +Best wishes + +Mark + + + + emacs/notmuch-show.el | 9 +++++++++ + emacs/notmuch-tree.el | 9 +++++++++ + emacs/notmuch.el | 10 +++++++++- + 3 files changed, 27 insertions(+), 1 deletion(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index df10d4b..313952f 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -1186,6 +1186,15 @@ (defun notmuch-show-capture-state () + - the current message." + (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages))) + ++(defun notmuch-show-get-query () ++ "Return the current query in this show buffer" ++ (if notmuch-show-query-context ++ (concat notmuch-show-thread-id ++ " and (" ++ notmuch-show-query-context ++ ")") ++ notmuch-show-thread-id)) ++ + (defun notmuch-show-apply-state (state) + "Apply STATE to the current buffer. + +diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el +index 7d5f475..e9249da 100644 +--- a/emacs/notmuch-tree.el ++++ b/emacs/notmuch-tree.el +@@ -897,6 +897,15 @@ (defun notmuch-tree-worker (basic-query &optional query-context target open-targ + (set-process-filter proc 'notmuch-tree-process-filter) + (set-process-query-on-exit-flag proc nil)))) + ++(defun notmuch-tree-get-query () ++ "Return the current query in this tree buffer" ++ (if notmuch-tree-query-context ++ (concat notmuch-tree-basic-query ++ " and (" ++ notmuch-tree-query-context ++ ")") ++ notmuch-tree-basic-query)) ++ + (defun notmuch-tree (&optional query query-context target buffer-name open-target) + "Display threads matching QUERY in Tree View. + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 6c0bc1b..5339a64 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -860,6 +860,10 @@ (defun notmuch-read-query (prompt) + (concat "tag:" (notmuch-escape-boolean-term tag))) + (process-lines notmuch-command "search" "--output=tags" "*"))))) + (let ((keymap (copy-keymap minibuffer-local-map)) ++ (current-query (case major-mode ++ (notmuch-search-mode (notmuch-search-get-query)) ++ (notmuch-show-mode (notmuch-show-get-query)) ++ (notmuch-tree-mode (notmuch-tree-get-query)))) + (minibuffer-completion-table + (completion-table-dynamic + (lambda (string) +@@ -877,7 +881,11 @@ (defun notmuch-read-query (prompt) + (define-key keymap (kbd "TAB") 'minibuffer-complete) + (let ((history-delete-duplicates t)) + (read-from-minibuffer prompt nil keymap nil +- 'notmuch-search-history nil nil))))) ++ 'notmuch-search-history current-query nil))))) ++ ++(defun notmuch-search-get-query () ++ "Return the current query in this search buffer" ++ notmuch-search-query-string) + + ;;;###autoload + (put 'notmuch-search 'notmuch-doc "Search for messages.") +-- +1.7.10.4 + -- 2.26.2