emacs: Use interactive specifications for tag changes in show

This modifies all tagging operations in show to call
`notmuch-read-tag-changes' in their interactive specification to input
tag changes, rather than depending on lower-level functions to prompt
for tag changes regardless of their calling context.

Besides being more Elispy and providing a more consistent programmatic
API, this enables callers to provide two call site-specific pieces of
information: an appropriate prompt, and the set of visible tags.  The
prompt lets us differentiate * from +/-.  Providing visible tags
enables a more consistent user experience than retrieving the
(potentially different) tags from the database, and avoids a
round-trip to the CLI and database.
This commit is contained in:
Austin Clements 2013-10-22 20:21:56 -04:00 committed by David Bremner
parent 0f8d5b6b0e
commit 47792533b3

View file

@ -1782,23 +1782,28 @@ TAG-CHANGES is a list of tag operations for `notmuch-tag'."
(notmuch-tag (notmuch-show-get-message-id) tag-changes)
(notmuch-show-set-tags new-tags))))
(defun notmuch-show-tag (&optional tag-changes)
(defun notmuch-show-tag (tag-changes)
"Change tags for the current message.
See `notmuch-tag' for information on the format of TAG-CHANGES."
(interactive)
(let* ((tag-changes (notmuch-tag (notmuch-show-get-message-id) tag-changes))
(current-tags (notmuch-show-get-tags))
(interactive (list (notmuch-read-tag-changes (notmuch-show-get-tags)
"Tag message")))
(notmuch-tag (notmuch-show-get-message-id) tag-changes)
(let* ((current-tags (notmuch-show-get-tags))
(new-tags (notmuch-update-tags current-tags tag-changes)))
(unless (equal current-tags new-tags)
(notmuch-show-set-tags new-tags))))
(defun notmuch-show-tag-all (&optional tag-changes)
(defun notmuch-show-tag-all (tag-changes)
"Change tags for all messages in the current show buffer.
See `notmuch-tag' for information on the format of TAG-CHANGES."
(interactive)
(setq tag-changes (notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes))
(interactive
(list (let (tags)
(notmuch-show-mapc
(lambda () (setq tags (append (notmuch-show-get-tags) tags))))
(notmuch-read-tag-changes tags "Tag thread"))))
(notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes)
(notmuch-show-mapc
(lambda ()
(let* ((current-tags (notmuch-show-get-tags))
@ -1806,19 +1811,21 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
(unless (equal current-tags new-tags)
(notmuch-show-set-tags new-tags))))))
(defun notmuch-show-add-tag ()
(defun notmuch-show-add-tag (tag-changes)
"Change tags for the current message (defaulting to add).
Same as `notmuch-show-tag' but sets initial input to '+'."
(interactive)
(notmuch-show-tag "+"))
(interactive
(list (notmuch-read-tag-changes (notmuch-show-get-tags) "Tag message" "+")))
(notmuch-show-tag tag-changes))
(defun notmuch-show-remove-tag ()
(defun notmuch-show-remove-tag (tag-changes)
"Change tags for the current message (defaulting to remove).
Same as `notmuch-show-tag' but sets initial input to '-'."
(interactive)
(notmuch-show-tag "-"))
(interactive
(list (notmuch-read-tag-changes (notmuch-show-get-tags) "Tag message" "-")))
(notmuch-show-tag tag-changes))
(defun notmuch-show-toggle-visibility-headers ()
"Toggle the visibility of the current message headers."