Function: org-change-tag-in-region
org-change-tag-in-region is an interactive and byte-compiled function
defined in org.el.gz.
Signature
(org-change-tag-in-region BEG END TAG OFF)
Documentation
Add or remove TAG for each entry in the region.
This works in the agenda, and also in an Org buffer.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-change-tag-in-region (beg end tag off)
"Add or remove TAG for each entry in the region.
This works in the agenda, and also in an Org buffer."
(interactive
(list (region-beginning) (region-end)
(let ((org-last-tags-completion-table
(if (derived-mode-p 'org-mode)
(org--tag-add-to-alist
(org-get-buffer-tags)
(org-global-tags-completion-table))
(org-global-tags-completion-table))))
(completing-read
"Tag: " org-last-tags-completion-table nil nil nil
'org-tags-history))
(progn
(message "[s]et or [r]emove? ")
(equal (read-char-exclusive) ?r))))
(deactivate-mark)
(let ((agendap (equal major-mode 'org-agenda-mode))
l1 l2 m buf pos newhead (cnt 0))
(goto-char end)
(setq l2 (1- (org-current-line)))
(goto-char beg)
(setq l1 (org-current-line))
(cl-loop for l from l1 to l2 do
(org-goto-line l)
(setq m (get-text-property (point) 'org-hd-marker))
(when (or (and (derived-mode-p 'org-mode) (org-at-heading-p))
(and agendap m))
(setq buf (if agendap (marker-buffer m) (current-buffer))
pos (if agendap m (point)))
(with-current-buffer buf
(save-excursion
(save-restriction
(goto-char pos)
(setq cnt (1+ cnt))
(org-toggle-tag tag (if off 'off 'on))
(setq newhead (org-get-heading)))))
(and agendap (org-agenda-change-all-lines newhead m))))
(message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))