[WIP PATCH 2/4] emacs: search: add a marked thread variable and add to relevant functions
Mark Walters
markwalters1009 at gmail.com
Tue Apr 22 13:11:48 PDT 2014
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
More information about the notmuch
mailing list