I would like to write a function that prompts the user to enter a refile location (with completion, like when you call org-refile). When the user chooses a refile location, I would like to return the filename and title of the chosen subheading (so I can do things with that data in the rest of the function).

Is this possible? Apologies if the question is unclear, I'm struggling to think of the right terminology.

I am using Ivy, in case this matters.

1 Answer 1


Maybe you can use org-refile-get-location. The doc string says: " ...Prompt the user for a refile location, using PROMPT..." . The return value is not documented AFAICT, but an experiment shows that it returns a list, the first two elements of which are the headline to refile under and the pathname of the file to refile into:

("Misc (tabs.org)" "/home/nick/lib/org/tabs.org" "^\\(\\*+\\)\\(?: +\\(DONE\\|TODO\\)\\)?\\(?: +\\(\\[#.\\]\\)\\)?\\(?: +\\(?:\\[[0-9%/]+\\] *\\)*\\(Misc\\)\\(?: *\\[[0-9%/]+\\]\\)*\\)\\(?:[  ]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[    ]*$" 3)

The reason it says "Misc (tabs.org)" above, is that in my case, I have two possible "Misc" headlines in two different files. I did not pursue it far enough to be able to tell you what the third and fourth elements of the list represent.

You can get the doc string of the function with C-h f org-refile-get-location. Note that it is not a command, so you can' use M-x org-refile-get-location: you can use ESC ESC : (org-refile-get-location "My Prompt") RET or you can wrap it in a command:

(defun my/org-refile-get-location-command ()
   (org-refile-get-location "My Prompt"))
  • That's exactly what I'm looking for - thanks so much. :)
    – randouser
    Commented Oct 22, 2021 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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