From b6856b9a24c72a5c1a3062fdacc18004859ea2f3 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Mon, 20 Aug 2012 18:52:48 +1700 Subject: [PATCH] [PATCH 09/11] emacs: add ability to show recipients instead of author in search --- 00/1918349983966dd8ff969c0a0acf1a2385579e | 209 ++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 00/1918349983966dd8ff969c0a0acf1a2385579e diff --git a/00/1918349983966dd8ff969c0a0acf1a2385579e b/00/1918349983966dd8ff969c0a0acf1a2385579e new file mode 100644 index 000000000..0cba2ec96 --- /dev/null +++ b/00/1918349983966dd8ff969c0a0acf1a2385579e @@ -0,0 +1,209 @@ +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 410F2431FBD + for ; Sun, 19 Aug 2012 18:53:14 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] 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 7IKskeKAT7Qm for ; + Sun, 19 Aug 2012 18:53:12 -0700 (PDT) +Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu + [131.215.239.19]) + by olra.theworths.org (Postfix) with ESMTP id 87F16431FC3 + for ; Sun, 19 Aug 2012 18:53:08 -0700 (PDT) +Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1]) + by fire-doxen-postvirus (Postfix) with ESMTP id C0E81328018 + for ; Sun, 19 Aug 2012 18:53:07 -0700 (PDT) +X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new +Received: from finestructure.net (unknown [76.89.192.57]) + (Authenticated sender: jrollins) + by fire-doxen-submit (Postfix) with ESMTP id B89122E50D82 + for ; Sun, 19 Aug 2012 18:53:05 -0700 (PDT) +Received: by finestructure.net (Postfix, from userid 1000) + id E312BCF3; Sun, 19 Aug 2012 18:53:03 -0700 (PDT) +From: Jameson Graef Rollins +To: Notmuch Mail +Subject: [PATCH 09/11] emacs: add ability to show recipients instead of author + in search +Date: Sun, 19 Aug 2012 18:52:48 -0700 +Message-Id: <1345427570-26518-10-git-send-email-jrollins@finestructure.net> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1345427570-26518-9-git-send-email-jrollins@finestructure.net> +References: <1345427570-26518-1-git-send-email-jrollins@finestructure.net> + <1345427570-26518-2-git-send-email-jrollins@finestructure.net> + <1345427570-26518-3-git-send-email-jrollins@finestructure.net> + <1345427570-26518-4-git-send-email-jrollins@finestructure.net> + <1345427570-26518-5-git-send-email-jrollins@finestructure.net> + <1345427570-26518-6-git-send-email-jrollins@finestructure.net> + <1345427570-26518-7-git-send-email-jrollins@finestructure.net> + <1345427570-26518-8-git-send-email-jrollins@finestructure.net> + <1345427570-26518-9-git-send-email-jrollins@finestructure.net> +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, 20 Aug 2012 01:53:14 -0000 + +A new boolean argument is added to notmuch-search to control whether +thread authors or recipients are shown in the 'authors' field. +--- + emacs/notmuch-hello.el | 6 +++--- + emacs/notmuch.el | 40 +++++++++++++++++++++++++++++----------- + 2 files changed, 32 insertions(+), 14 deletions(-) + +diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el +index 684bedc..4615cf6 100644 +--- a/emacs/notmuch-hello.el ++++ b/emacs/notmuch-hello.el +@@ -26,7 +26,7 @@ + (require 'notmuch-lib) + (require 'notmuch-mua) + +-(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation)) ++(declare-function notmuch-search "notmuch" (query &optional oldest-first show-recipients target-thread target-line continuation)) + (declare-function notmuch-poll "notmuch" ()) + + (defcustom notmuch-hello-recent-searches-max 10 +@@ -280,7 +280,7 @@ afterwards.") + (setq search (notmuch-hello-trim search)) + (let ((history-delete-duplicates t)) + (add-to-history 'notmuch-search-history search))) +- (notmuch-search search notmuch-search-oldest-first nil nil ++ (notmuch-search search notmuch-search-oldest-first nil nil nil + #'notmuch-hello-search-continuation)) + + (defun notmuch-hello-add-saved-search (widget) +@@ -331,7 +331,7 @@ diagonal." + (notmuch-search (widget-get widget + :notmuch-search-terms) + notmuch-search-oldest-first +- nil nil #'notmuch-hello-search-continuation)) ++ nil nil nil #'notmuch-hello-search-continuation)) + + (defun notmuch-saved-search-count (search) + (car (process-lines notmuch-command "count" search))) +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index 7b61e9b..d05b1e8 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -254,6 +254,7 @@ For a mouse binding, return nil." + (notmuch-common-do-stash (notmuch-search-find-thread-id))) + + (defvar notmuch-search-query-string) ++(defvar notmuch-search-show-recipients) + (defvar notmuch-search-target-thread) + (defvar notmuch-search-target-line) + (defvar notmuch-search-continuation) +@@ -405,6 +406,7 @@ Complete list of currently available key bindings: + (make-local-variable 'notmuch-search-oldest-first) + (make-local-variable 'notmuch-search-target-thread) + (make-local-variable 'notmuch-search-target-line) ++ (make-local-variable 'notmuch-search-show-recipients) + (set (make-local-variable 'notmuch-search-continuation) nil) + (set (make-local-variable 'scroll-preserve-screen-position) t) + (add-to-invisibility-spec (cons 'ellipsis t)) +@@ -781,7 +783,10 @@ non-authors is found, assume that all of the authors match." + 'face 'notmuch-search-subject))) + + ((string-equal field "authors") +- (notmuch-search-insert-authors format-string (plist-get result :authors))) ++ (notmuch-search-insert-authors format-string ++ (if notmuch-search-show-recipients ++ (plist-get result :recipients) ++ (plist-get result :authors)))) + + ((string-equal field "tags") + (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) +@@ -931,13 +936,16 @@ PROMPT is the string to prompt with." + 'notmuch-search-history nil nil))))) + + ;;;###autoload +-(defun notmuch-search (&optional query oldest-first target-thread target-line continuation) ++(defun notmuch-search (&optional query oldest-first show-recipients target-thread target-line continuation) + "Run \"notmuch search\" with the given `query' and display results. + + If `query' is nil, it is read interactively from the minibuffer. + Other optional parameters are used as follows: + + oldest-first: A Boolean controlling the sort order of returned threads ++ show-recipients: A Boolean controlling whether or not thread ++ recipients instead of authors are shown in the ++ 'authors' field. + target-thread: A thread ID (without the thread: prefix) that will be made + current if it appears in the search results. + target-line: The line number to move to if the target thread does not +@@ -952,25 +960,34 @@ Other optional parameters are used as follows: + (set 'buffer-undo-list t) + (set 'notmuch-search-query-string query) + (set 'notmuch-search-oldest-first oldest-first) ++ (set 'notmuch-search-show-recipients show-recipients) + (set 'notmuch-search-target-thread target-thread) + (set 'notmuch-search-target-line target-line) + (set 'notmuch-search-continuation continuation) + (let ((proc (get-buffer-process (current-buffer))) ++ (proc-args (list ++ "notmuch-search" buffer ++ notmuch-command "search" ++ "--format=json" ++ (if oldest-first ++ "--sort=oldest-first" ++ "--sort=newest-first"))) + (inhibit-read-only t)) ++ (if show-recipients ++ (setq proc-args (append proc-args '("--include-recipients")))) + (if proc + (error "notmuch search process already running for query `%s'" query) + ) + (erase-buffer) + (goto-char (point-min)) + (save-excursion +- (let ((proc (start-process +- "notmuch-search" buffer +- notmuch-command "search" +- "--format=json" +- (if oldest-first +- "--sort=oldest-first" +- "--sort=newest-first") +- query)) ++ (let ( ++ ;; start-process insists on non-nil string arguments. ++ ;; This is annoying for variable length argument lists. ++ ;; We use apply here so that we can construct the ++ ;; start-process argument list ahead of time (instead of ++ ;; at invocation) to avoid nils. ++ (proc (apply 'start-process (append proc-args (list query)))) + ;; Use a scratch buffer to accumulate partial output. + ;; This buffer will be killed by the sentinel, which + ;; should be called no matter how the process dies. +@@ -995,11 +1012,12 @@ same relative position within the new buffer." + (interactive) + (let ((target-line (line-number-at-pos)) + (oldest-first notmuch-search-oldest-first) ++ (show-recipients notmuch-search-show-recipients) + (target-thread (notmuch-search-find-thread-id 'bare)) + (query notmuch-search-query-string) + (continuation notmuch-search-continuation)) + (notmuch-kill-this-buffer) +- (notmuch-search query oldest-first target-thread target-line continuation) ++ (notmuch-search query oldest-first show-recipients target-thread target-line continuation) + (goto-char (point-min)))) + + (defcustom notmuch-poll-script nil +-- +1.7.10.4 + -- 2.26.2