From c2b12346164cf099888a729268416fc31b75ed15 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Thu, 17 Apr 2014 06:43:24 +0100 Subject: [PATCH] [PATCH] emacs: search: edit current query --- f3/de36b2e1fb2513f14ab1e9627370dc315f8741 | 145 ++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 f3/de36b2e1fb2513f14ab1e9627370dc315f8741 diff --git a/f3/de36b2e1fb2513f14ab1e9627370dc315f8741 b/f3/de36b2e1fb2513f14ab1e9627370dc315f8741 new file mode 100644 index 000000000..620bf64f9 --- /dev/null +++ b/f3/de36b2e1fb2513f14ab1e9627370dc315f8741 @@ -0,0 +1,145 @@ +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 D54B6431FBD + for ; Wed, 16 Apr 2014 22:43:47 -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 dUpC53z9soyC for ; + Wed, 16 Apr 2014 22:43:42 -0700 (PDT) +Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com + [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + EFB21431FAE for ; Wed, 16 Apr 2014 22:43:41 -0700 + (PDT) +Received: by mail-ee0-f53.google.com with SMTP id b57so181881eek.12 + for ; Wed, 16 Apr 2014 22:43:39 -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; + bh=M/KzWWvPUNFru8WybAZAzsQknx9Hdretw7w6Qoihn/I=; + b=BFfvmYI+c7vIui8C9FeUles0euINikApww7RxpCywWBBbyMfdszozSgiZcx5uomf6r + KrKOI3tuAjgMQ/BfXzMSj64r2QMGISBQN14Si3rJKiFHCcjP3aSzdiR5ji/jGD2eBgTR + S+/AWlThvrtkExVKXepDlWxS69BX4lPqsUlMvuVIb739UeUfDtxhBYt96GkrzPnP3499 + gDGTftg98W9BQ87csGADoXDGkR+ebLLJEtYMktucze4snDx+YUxIPU1JRPclvDvaamb3 + YRlqUh1x7nEnFPXba1pd7nPv9ucyCz+03dtgY8b4tm/ePmptgqOatKEc7oS0VgVwWPJX + Ml5Q== +X-Received: by 10.14.105.4 with SMTP id j4mr11204617eeg.41.1397713419529; + Wed, 16 Apr 2014 22:43:39 -0700 (PDT) +Received: from localhost ([217.17.137.178]) by mx.google.com with ESMTPSA id + x45sm64077345eef.15.2014.04.16.22.43.38 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Wed, 16 Apr 2014 22:43:38 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH] emacs: search: edit current query +Date: Thu, 17 Apr 2014 06:43:24 +0100 +Message-Id: <1397713404-3089-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +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, 17 Apr 2014 05:43:48 -0000 + +This adds an option to edit the current query. It is bound to +prefix-key f as it is a sort of inverse operation to filtering. +--- +rlb asked for the option to modify the existing search query on +irc. This implements that for the search view. + +Best wishes + +Mark + + + + + + emacs/notmuch.el | 37 ++++++++++++++++++++++++++----------- + 1 file changed, 26 insertions(+), 11 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 6c0bc1b..b4408f1 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -848,7 +848,7 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." + (concat "*notmuch-search-" query "*")) + ))) + +-(defun notmuch-read-query (prompt) ++(defun notmuch-read-query (prompt &optional initial-contents) + "Read a notmuch-query from the minibuffer with completion. + + PROMPT is the string to prompt with." +@@ -876,7 +876,7 @@ PROMPT is the string to prompt with." + ;; this was simpler than convincing completing-read to accept spaces: + (define-key keymap (kbd "TAB") 'minibuffer-complete) + (let ((history-delete-duplicates t)) +- (read-from-minibuffer prompt nil keymap nil ++ (read-from-minibuffer prompt initial-contents keymap nil + 'notmuch-search-history nil nil))))) + + ;;;###autoload +@@ -963,18 +963,33 @@ default sort order is defined by `notmuch-search-oldest-first'." + (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first)) + (notmuch-search-refresh-view)) + +-(defun notmuch-search-filter (query) ++(put 'notmuch-search-filter 'notmuch-doc ++ "Filter the current search results based on an additional query string.") ++(put 'notmuch-search-filter 'notmuch-prefix-doc ++ "Edit the current search query.") ++(defun notmuch-search-filter (modify query) + "Filter the current search results based on an additional query string. + + Runs a new search matching only messages that match both the +-current search results AND the additional query string provided." +- (interactive (list (notmuch-read-query "Filter search: "))) +- (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query) +- (concat "( " query " )") +- query))) +- (notmuch-search (if (string= notmuch-search-query-string "*") +- grouped-query +- (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first))) ++current search results AND the additional query string provided. ++ ++If called with a prefix-arg then present the user with the ++existing query string to allow the user to edit it." ++ (interactive (let ((query-string (if current-prefix-arg ++ "Modify Search: " ++ "Filter Search: ")) ++ (initial-contents (if current-prefix-arg ++ notmuch-search-query-string ++ nil))) ++ (list current-prefix-arg (notmuch-read-query query-string initial-contents)))) ++ (if modify ++ (notmuch-search query notmuch-search-oldest-first) ++ (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query) ++ (concat "( " query " )") ++ query))) ++ (notmuch-search (if (string= notmuch-search-query-string "*") ++ grouped-query ++ (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))) + + (defun notmuch-search-filter-by-tag (tag) + "Filter the current search results based on a single tag. +-- +1.7.10.4 + -- 2.26.2