From c520141562a4af4fc89c15cd19c37f7c7548da19 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Tue, 22 Apr 2014 21:11:48 +0100 Subject: [PATCH] [WIP PATCH 2/4] emacs: search: add a marked thread variable and add to relevant functions --- 7d/6fcec662c4fb864bd7b89f6a4c0df10dd512a5 | 251 ++++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 7d/6fcec662c4fb864bd7b89f6a4c0df10dd512a5 diff --git a/7d/6fcec662c4fb864bd7b89f6a4c0df10dd512a5 b/7d/6fcec662c4fb864bd7b89f6a4c0df10dd512a5 new file mode 100644 index 000000000..d72fa0270 --- /dev/null +++ b/7d/6fcec662c4fb864bd7b89f6a4c0df10dd512a5 @@ -0,0 +1,251 @@ +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 1785E431FC2 + for ; Tue, 22 Apr 2014 13:12:15 -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 e6pOaAATsk7h for ; + Tue, 22 Apr 2014 13:12:11 -0700 (PDT) +Received: from mail-we0-f175.google.com (mail-we0-f175.google.com + [74.125.82.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id CB391431FC0 + for ; Tue, 22 Apr 2014 13:12:08 -0700 (PDT) +Received: by mail-we0-f175.google.com with SMTP id q58so5386031wes.6 + for ; Tue, 22 Apr 2014 13:12:07 -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=sdOSw48NlKn58XcRkyvgYWg0Cvs0tiX6J93UPY4P8fQ=; + b=sQggZF54V2YGczbd+YPbtNcTEYZQn53xB57+sc/f8MkET+DrhnNRBR1+nlW2oWl4ly + wM07alRy7IdbKkysHowTIyXkp0DAlge0aL53O9A/X8rT7biZLQEepQ3HXKph/Lqk733Y + KpZXjawhckT5e6MsS5+NwfgoTjUFc6HRreF5DWZH1iNMa/yKr4Pdtj7bVzfqRT3BdK/z + LJMB6LrnOCW4lJR9L2gT3eSENiQyzUtisz71WEmD3hulr82kue6aZZFHpTlUgR2SpUGZ + IJ5p5v0sJXPQXN9lqmEJLVIjOHaS2ydWn2rbl6rySq3ygx6ofoAdrbNCtB8FFT2WwrPS + 4uCA== +X-Received: by 10.180.78.225 with SMTP id e1mr20532843wix.17.1398197527525; + Tue, 22 Apr 2014 13:12:07 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id + lj15sm24552802wic.13.2014.04.22.13.12.06 for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Tue, 22 Apr 2014 13:12:07 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [WIP PATCH 2/4] emacs: search: add a marked thread variable and add + to relevant functions +Date: Tue, 22 Apr 2014 21:11:48 +0100 +Message-Id: <1398197510-28224-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com> +References: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com> +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: Tue, 22 Apr 2014 20:12:15 -0000 + +Add a marked thread variable containing a list of thread ids of marked +threads and make it be passed through all relevant functions. This +ends up being quite large as there are quite a few callers. + +Alternatively we could overload beg rather than adding a thread-list +variable. This would make a much smaller patch but might be more +confusing. +--- + emacs/notmuch.el | 66 +++++++++++++++++++++++++++++++----------------------- + 1 file changed, 38 insertions(+), 28 deletions(-) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index cb7c006..7b06458 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -100,6 +100,11 @@ (defcustom notmuch-init-file (locate-user-emacs-file "notmuch-config") + (defvar notmuch-query-history nil + "Variable to store minibuffer history for notmuch queries") + ++(defvar notmuch-search-marked-threads nil ++ "Buffer local list of marked threads") ++(make-variable-buffer-local 'notmuch-search-marked-threads) ++(put 'notmuch-search-marked-threads 'permanent-local t) ++ + (defun notmuch-foreach-mime-part (function mm-handle) + (cond ((stringp (car mm-handle)) + (dolist (part (cdr mm-handle)) +@@ -375,7 +380,7 @@ (defun notmuch-search-result-end (&optional pos) + (next-single-property-change (or pos (point)) 'notmuch-search-result + nil (point-max)))) + +-(defun notmuch-search-foreach-result (beg end function) ++(defun notmuch-search-foreach-result (beg end thread-list function) + "Invoke FUNCTION for each result between BEG and END. + + FUNCTION should take no arguments. It will be applied at the +@@ -400,9 +405,9 @@ (defun notmuch-search-foreach-result (beg end function) + ;; the indentation of callers doesn't get out of hand. + (put 'notmuch-search-foreach-result 'lisp-indent-function 2) + +-(defun notmuch-search-properties-in-region (property beg end) ++(defun notmuch-search-properties-in-region (property beg end &optional thread-list) + (let (output) +- (notmuch-search-foreach-result beg end ++ (notmuch-search-foreach-result beg end thread-list + (lambda () + (push (plist-get (notmuch-search-get-result) property) output))) + output)) +@@ -421,13 +426,13 @@ (defun notmuch-search-find-stable-query () + matched and unmatched messages in the current thread." + (plist-get (notmuch-search-get-result) :query)) + +-(defun notmuch-search-find-stable-query-region (beg end &optional only-matched) ++(defun notmuch-search-find-stable-query-region (beg end &optional only-matched thread-list) + "Return the stable query for the current region. + + If ONLY-MATCHED is non-nil, include only matched messages. If it + is nil, include both matched and unmatched messages." + (let ((query-list nil) (all (not only-matched))) +- (dolist (queries (notmuch-search-properties-in-region :query beg end)) ++ (dolist (queries (notmuch-search-properties-in-region :query beg end thread-list)) + (when (first queries) + (push (first queries) query-list)) + (when (and all (second queries)) +@@ -438,17 +443,17 @@ (defun notmuch-search-find-authors () + "Return the authors for the current thread" + (plist-get (notmuch-search-get-result) :authors)) + +-(defun notmuch-search-find-authors-region (beg end) ++(defun notmuch-search-find-authors-region (beg end &optional thread-list) + "Return a list of authors for the current region" +- (notmuch-search-properties-in-region :authors beg end)) ++ (notmuch-search-properties-in-region :authors beg end thread-list)) + + (defun notmuch-search-find-subject () + "Return the subject for the current thread" + (plist-get (notmuch-search-get-result) :subject)) + +-(defun notmuch-search-find-subject-region (beg end) ++(defun notmuch-search-find-subject-region (beg end &optional thread-list) + "Return a list of authors for the current region" +- (notmuch-search-properties-in-region :subject beg end)) ++ (notmuch-search-properties-in-region :subject beg end thread-list)) + + (defun notmuch-search-show-thread (&optional elide-toggle) + "Display the currently selected thread." +@@ -497,9 +502,9 @@ (defun notmuch-search-set-tags (tags &optional pos) + (defun notmuch-search-get-tags (&optional pos) + (plist-get (notmuch-search-get-result pos) :tags)) + +-(defun notmuch-search-get-tags-region (beg end) ++(defun notmuch-search-get-tags-region (beg end &optional thread-list) + (let (output) +- (notmuch-search-foreach-result beg end ++ (notmuch-search-foreach-result beg end thread-list + (lambda () + (setq output (append output (notmuch-search-get-tags))))) + output)) +@@ -507,24 +512,29 @@ (defun notmuch-search-get-tags-region (beg end) + (defun notmuch-search-interactive-region () + "Return the bounds of the current interactive region. + +-This returns (BEG END), where BEG and END are the bounds of the +-region if the region is active, or both `point' otherwise." ++This returns (BEG END THREAD-LIST), where BEG and END are the ++bounds of the region if the region is active, or both `point' ++otherwise and THREAD-LIST is a list of the marked threads (if ++any)." + (if (region-active-p) +- (list (region-beginning) (region-end)) +- (list (point) (point)))) ++ (list (region-beginning) (region-end) notmuch-search-marked-threads) ++ (list (point) (point) notmuch-search-marked-threads))) + + (defun notmuch-search-interactive-tag-changes (&optional initial-input) +- "Prompt for tag changes for the current thread or region. ++ "Prompt for tag changes for the current thread, marked threads or region. + +-Returns (TAG-CHANGES REGION-BEGIN REGION-END)." ++Returns (TAG-CHANGES REGION-BEGIN REGION-END THREAD-LIST)." + (let* ((region (notmuch-search-interactive-region)) + (beg (first region)) (end (second region)) +- (prompt (if (= beg end) "Tag thread" "Tag region"))) ++ (thread-list (third region)) ++ (prompt (if thread-list ++ "Tag marked threads" ++ (if (= beg end) "Tag thread" "Tag region")))) + (cons (notmuch-read-tag-changes +- (notmuch-search-get-tags-region beg end) prompt initial-input) ++ (notmuch-search-get-tags-region beg end thread-list) prompt initial-input) + region))) + +-(defun notmuch-search-tag (tag-changes &optional beg end only-matched) ++(defun notmuch-search-tag (tag-changes &optional beg end only-matched thread-list) + "Change tags for the currently selected thread or region. + + See `notmuch-tag' for information on the format of TAG-CHANGES. +@@ -537,30 +547,30 @@ (defun notmuch-search-tag (tag-changes &optional beg end only-matched) + (interactive (notmuch-search-interactive-tag-changes)) + (unless (and beg end) (setq beg (point) end (point))) + (let ((search-string (notmuch-search-find-stable-query-region +- beg end only-matched))) ++ beg end only-matched thread-list))) + (notmuch-tag search-string tag-changes) +- (notmuch-search-foreach-result beg end ++ (notmuch-search-foreach-result beg end thread-list + (lambda () + (notmuch-search-set-tags + (notmuch-update-tags (notmuch-search-get-tags) tag-changes)))))) + +-(defun notmuch-search-add-tag (tag-changes &optional beg end) ++(defun notmuch-search-add-tag (tag-changes &optional beg end thread-list) + "Change tags for the current thread or region (defaulting to add). + + Same as `notmuch-search-tag' but sets initial input to '+'." + (interactive (notmuch-search-interactive-tag-changes "+")) +- (notmuch-search-tag tag-changes beg end)) ++ (notmuch-search-tag tag-changes beg end nil thread-list)) + +-(defun notmuch-search-remove-tag (tag-changes &optional beg end) ++(defun notmuch-search-remove-tag (tag-changes &optional beg end thread-list) + "Change tags for the current thread or region (defaulting to remove). + + Same as `notmuch-search-tag' but sets initial input to '-'." + (interactive (notmuch-search-interactive-tag-changes "-")) +- (notmuch-search-tag tag-changes beg end)) ++ (notmuch-search-tag tag-changes beg end nil thread-list)) + + (put 'notmuch-search-archive-thread 'notmuch-prefix-doc + "Un-archive the currently selected thread.") +-(defun notmuch-search-archive-thread (&optional unarchive beg end) ++(defun notmuch-search-archive-thread (&optional unarchive beg end thread-list) + "Archive the currently selected thread or region. + + Archive each message in the currently selected thread by applying +@@ -573,7 +583,7 @@ (defun notmuch-search-archive-thread (&optional unarchive beg end) + (interactive (cons current-prefix-arg (notmuch-search-interactive-region))) + (when notmuch-archive-tags + (notmuch-search-tag +- (notmuch-tag-change-list notmuch-archive-tags unarchive) beg end)) ++ (notmuch-tag-change-list notmuch-archive-tags unarchive) beg end thread-list)) + (notmuch-search-next-thread)) + + (defun notmuch-search-update-result (result &optional pos) +-- +1.7.10.4 + -- 2.26.2