+(defun notmuch-search-get-tags-region (beg end)
+ (save-excursion
+ (let ((output nil)
+ (last-line (line-number-at-pos end)))
+ (goto-char beg)
+ (while (<= (line-number-at-pos) last-line)
+ (setq output (append output (notmuch-search-get-tags)))
+ (forward-line 1))
+ output)))
+
+(defun notmuch-search-add-tag-thread (tag)
+ (notmuch-call-notmuch-process "tag" (concat "+" tag) (notmuch-search-find-thread-id))
+ (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<))))
+
+(defun notmuch-search-add-tag-region (tag beg end)
+ (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
+ (notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string)
+ (save-excursion
+ (let ((last-line (line-number-at-pos end)))
+ (goto-char beg)
+ (while (<= (line-number-at-pos) last-line)
+ (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<)))
+ (forward-line))))))
+
+(defun notmuch-search-remove-tag-thread (tag)
+ (notmuch-call-notmuch-process "tag" (concat "-" tag) (notmuch-search-find-thread-id))
+ (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))))
+
+(defun notmuch-search-remove-tag-region (tag beg end)
+ (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
+ (notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string)
+ (save-excursion
+ (let ((last-line (line-number-at-pos end)))
+ (goto-char beg)
+ (while (<= (line-number-at-pos) last-line)
+ (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
+ (forward-line))))))
+