Is there a way to read tags with completion from the user in the same way
I would like to have a custom function defined where I ask the user for a tag (or list of tags) and use that in a
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
You can get all the buffer tags by calling
org-get-buffer-tags. You can then combine that with
completing-read whose doc string reads as follows:
completing-read is a built-in function in ‘C source code’.
(completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD)
Read a string in the minibuffer, with completion. PROMPT is a string to prompt with; normally it ends in a colon and a space. COLLECTION can be a list of strings, an alist, an obarray or a hash table. COLLECTION can also be a function to do the completion itself...
So here's a function to do what you want:
(defun my-read-tag-with-completion () (interactive) (completing-read "Enter a tag: " (org-get-buffer-tags)))