2

Is there a way to read tags with completion from the user in the same way read-number or read-string allows?

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 org-ql-search query.

  • Tags are strings, are they not? – NickD May 8 at 15:23
  • yes, but then you don't get the tag completion. You would have to guess/remember which tags are available. – AEmacs May 8 at 15:33
  • You should put that requirement in the question. – NickD May 8 at 15:56
3

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)))
| improve this answer | |
  • Perfect, thanks! – AEmacs May 9 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.