]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-tag.el
emacs: add notmuch-tag-undo
[notmuch] / emacs / notmuch-tag.el
index 4c974679944871aec3dd8301ea9e820b0b43807c..959778819617f9cd23498818b2344103fb008c12 100644 (file)
@@ -278,6 +278,7 @@ This can be used with `notmuch-tag-format-image-data'."
 ;;; track history of tag operations
 (defvar-local notmuch-tag-history nil
   "Buffer local history of `notmuch-tag' function.")
+(put 'notmuch-tag-history 'permanent-local t)
 
 ;;; Format Handling
 
@@ -502,6 +503,19 @@ notmuch-after-tag-hook will be run."
                 (query query))
     (run-hooks 'notmuch-after-tag-hook)))
 
+(defun notmuch-tag-undo ()
+  "Undo the previous tagging operation in the current buffer. Uses
+buffer local variable `notmuch-tag-history' to determine what
+that operation was."
+  (interactive)
+  (when (null notmuch-tag-history)
+    (error "no further notmuch undo information"))
+  (let* ((action (pop notmuch-tag-history))
+        (query (plist-get action :query))
+        (changes (notmuch-tag-change-list (plist-get action :tag-changes) t)))
+    (notmuch-tag query changes t))
+  (notmuch-refresh-this-buffer))
+
 (defun notmuch-tag-change-list (tags &optional reverse)
   "Convert TAGS into a list of tag changes.