diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index d8773e6..57ff72e 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -1054,11 +1054,35 @@ argument, hide all of the messages." (interactive) (backward-button 1)) +(defun notmuch-is-user-tag (tag) + ;; Returns true if tag is not one of + ;; inbox, deleted, replied, draft, + (not (member tag '("inbox" "replied" "draft" "deleted" + "attachment" "unread")))) + (defun notmuch-show-archive-thread-internal (show-next) ;; Remove the tag from the current set of messages. (goto-char (point-min)) - (loop do (notmuch-show-remove-tag "inbox") - until (not (notmuch-show-goto-message-next))) + (let ((has-empty-tags)) + ;; 1st pass: try to see if adding a tag is necessary. + (loop do (let ((user-tags (remove-if-not #'notmuch-is-user-tag + (notmuch-show-get-tags)))) + (setq has-empty-tags + (or has-empty-tags (eq user-tags nil)))) + until (not (notmuch-show-goto-message-next))) + ;; Only ask for a tag to add if has-empty-tags is non-nil. Use + ;; tags-to-apply to propose a default value. + (let ((tags-to-add '())) + (if has-empty-tags + (setq tags-to-add (list (notmuch-select-tag-with-completion + "Some messages in the thread have no user tags. Add: ")))) + ;; 2nd pass: tag all the messages with the user-selected tag, + ;; and remove the "inbox" tag + (goto-char (point-min)) + (loop do (progn + (apply #'notmuch-show-add-tag tags-to-add) + (notmuch-show-remove-tag "inbox")) + until (not (notmuch-show-goto-message-next))))) ;; Move to the next item in the search results, if any. (let ((parent-buffer notmuch-show-parent-buffer)) (notmuch-kill-this-buffer) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 5933747..eeff18c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -560,7 +560,9 @@ thread or threads in the current region." This function advances the next thread when finished." (interactive) - (notmuch-search-remove-tag-thread "inbox") + (save-excursion + (notmuch-search-show-thread) + (notmuch-show-archive-thread-internal nil)) (forward-line)) (defun notmuch-search-process-sentinel (proc msg)