Function: org-set-tags-command

org-set-tags-command is an interactive and byte-compiled function defined in org.el.gz.

Signature

(org-set-tags-command &optional ARG)

Documentation

Set the tags for the current visible entry.

When called with C-u (universal-argument) prefix argument ARG, realign all tags in the current buffer.

When called with C-u (universal-argument) C-u (universal-argument) prefix argument, unconditionally do not offer the fast tag selection interface.

If a region is active, set tags in the region according to the setting of org-loop-over-headlines-in-active-region.

This function is for interactive use only; in Lisp code use org-set-tags instead.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-set-tags-command (&optional arg)
  "Set the tags for the current visible entry.

When called with `\\[universal-argument]' prefix argument ARG, \
realign all tags
in the current buffer.

When called with `\\[universal-argument] \\[universal-argument]' prefix argument, \
unconditionally do not
offer the fast tag selection interface.

If a region is active, set tags in the region according to the
setting of `org-loop-over-headlines-in-active-region'.

This function is for interactive use only;
in Lisp code use `org-set-tags' instead."
  (interactive "P")
  (let ((org-use-fast-tag-selection
	 (unless (equal '(16) arg) org-use-fast-tag-selection)))
    (cond
     ((equal '(4) arg) (org-align-tags t))
     ((and (org-region-active-p) org-loop-over-headlines-in-active-region)
      (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
		    'region-start-level 'region))
            org-loop-over-headlines-in-active-region) ;  hint: infinite recursion.
	(org-map-entries
	 #'org-set-tags-command
	 nil cl
	 (lambda () (when (org-invisible-p) (org-end-of-subtree nil t))))))
     (t
      (save-excursion
        ;; FIXME: We need to add support setting #+FILETAGS.
        (when (org-before-first-heading-p)
          (user-error "Setting file tags is not supported yet"))
	(org-back-to-heading)
	(let* ((all-tags (org-get-tags))
               (local-table (or org-current-tag-alist (org-get-buffer-tags)))
	       (table (setq org-last-tags-completion-table
                            (append
                             ;; Put local tags in front.
                             local-table
                             (cl-set-difference
			      (org--tag-add-to-alist
			       (and org-complete-tags-always-offer-all-agenda-tags
				    (org-global-tags-completion-table
				     (org-agenda-files)))
			       local-table)
                              local-table))))
	       (current-tags
		(cl-remove-if (lambda (tag) (get-text-property 0 'inherited tag))
			      all-tags))
	       (inherited-tags
		(cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited tag))
				  all-tags))
	       (tags
		(replace-regexp-in-string
		 ;; Ignore all forbidden characters in tags.
		 "[^[:alnum:]_@#%]+" ":"
		 (if (or (eq t org-use-fast-tag-selection)
			 (and org-use-fast-tag-selection
			      (delq nil (mapcar #'cdr table))))
		     (org-fast-tag-selection
		      current-tags
		      inherited-tags
		      table
		      (and org-fast-tag-selection-include-todo org-todo-key-alist))
		   (let ((org-add-colon-after-tag-completion (< 1 (length table)))
                         (crm-separator "[ \t]*:[ \t]*"))
		     (mapconcat #'identity
                                (completing-read-multiple
                                 "Tags: "
                                 org-last-tags-completion-table
                                 nil nil (org-make-tag-string current-tags)
                                 'org-tags-history)
                                ":"))))))
	  (org-set-tags tags)))))
    ;; `save-excursion' may not replace the point at the right
    ;; position.
    (when (and (save-excursion (skip-chars-backward "*") (bolp))
	       (looking-at-p " "))
      (forward-char))))