简体   繁体   中英

Org Capture: prompt for information when determining the target file

I'm looking to build a capture template that, when run, prompts the user for more information to determine the path of the target file.

I have a few pieces already.

A function which asks the user for data and returns a string:

(defun my/get-121-orgfile ()
  "Ask the user for the name of the participant so that we can build"
  (interactive)
  (read-string "Participant Name: ")
)

An org-capture-template which will run the prompt successfully when emacs loads:

(setq org-capture-templates
    `(
      ("m1" "1-1 meetings")
      ("m1b" "prep for a 1-1 meeting" entry
       (file ,(concat "~/org/meetings/1-2-1/" (my/get-121-orgfile) ".org"))
       (file "~/org/templates/meeting-121-prep.org")
       :clock-in t)
))

I took the back quote and comma pattern from this SO answer , but I haven't been able to figure out how to scope this behaviour to when I select the template: I want the prompt to pop up each time I hit <org-capture>m1b .

The backquote-comma pattern will not help here: it will call the function at the time that org-capture-template is set. What you are trying to do is to call the function when the capture is executed.

The only way I know to do that would to use the (function foo) target mechanism of org-capture-templates . The doc string says:

 (function function-finding-location) Most general way: write your own function which both visits the file and moves point to the right location

So you would not be able to use the (file...) target as you do above. Instead you have to write a function that gets all the information you want and then visit the target file at the target location and add the filled-out template.

This is not a complete answer but it was too long for a comment, but maybe it helps to point you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM