Function: org-tags-completion-function

org-tags-completion-function is a byte-compiled function defined in org.el.gz.

Signature

(org-tags-completion-function STRING PREDICATE &optional FLAG)

Documentation

Complete tag STRING.

The format for tag string is described in the Info node (org) Matching tags and properties.

FLAG specifies the type of completion operation to perform. This function is passed as a collection function to completing-read, which see.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-tags-completion-function (string _predicate &optional flag)
  "Complete tag STRING.

The format for tag string is described in the
Info node `(org) Matching tags and properties'.

FLAG specifies the type of completion operation to perform.  This
function is passed as a collection function to `completing-read',
which see."
  ;; FIXME: This function is used to complete a tag string which can
  ;; include properties but does not know anything about properties
  (let ((completion-ignore-case nil)	;tags are case-sensitive
	(confirm (lambda (x) (stringp (car x))))
	(prefix "")
        begin)
    (when (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
      (setq prefix (match-string 1 string))
      (setq begin (match-beginning 2))
      (setq string (match-string 2 string)))
    (pcase flag
      (`t (all-completions string org-last-tags-completion-table confirm))
      (`lambda (assoc string org-last-tags-completion-table)) ;exact match?
      (`(boundaries . ,suffix)
       (let ((end (if (string-match "[-+:&,|]" suffix)
                      (match-beginning 0)
                    (length suffix))))
         `(boundaries ,(or begin 0) . ,end)))
      (`nil
       (pcase (try-completion string org-last-tags-completion-table confirm)
	 ((and completion (pred stringp))
	  (concat prefix
		  completion
		  (if (and org-add-colon-after-tag-completion
			   (assoc completion org-last-tags-completion-table))
		      ":"
		    "")))
	 (completion completion)))
      (_ nil))))