There are several ways to choose where a captured entry will go.
You can always use org-refile
(C-c C-w
) in the capture buffer to move the capture. This will also finalize the capture.
If you want to encode the target headline in the capture template, use file+headline
as the target, thusly:
("t" "Todo" entry
(file+headline "/path/to/file.org" "Target Headline")
"* TODO %?"
)
Another solution is to use file+function
as the target for your capture template. First define a function that prompts for a headline and jumps to it.
(defun org-get-target-headline (&optional prompt)
"Prompt for a location in an org file and jump to it.
This is for promping for refile targets when doing captures."
(let* ((target (save-excursion
(org-refile-get-location prompt nil nil t)))
(file (nth 1 target))
(pos (nth 3 target))
)
(with-current-buffer (find-file-noselect file)
(goto-char pos)
(org-end-of-subtree)
(org-return)
)))
Then add a capture template using this function to get the target:
'("t" "Todo" entry
(file+function "/path/to/file.org" org-get-target-headline)
"* TODO %?")
You will be prompted for the target before being dropped into the capture buffer. This is most useful when the template has :immediate-finish t
and you never get a capture buffer to refile from.
And that's not all! There are a number of other ways for a template to select it's target, see the manual for org-capture-templates for a list of them.
The most general version is to use function
as the target, which lets you give an arbitrary function for both the target file and headline.
EDIT:
As of org-mode
9 the above function no longer works. Instead use
(defun org-get-target-headline (&optional targets prompt)
"Prompt for a location in an org file and jump to it.
This is for promping for refile targets when doing captures.
Targets are selected from `org-refile-targets'. If TARGETS is
given it temporarily overrides `org-refile-targets'. PROMPT will
replace the default prompt message.
If CAPTURE-LOC is is given, capture to that location instead of
prompting."
(let ((org-refile-targets (or targets org-refile-targets))
(prompt (or prompt "Capture Location")))
(org-refile t nil nil prompt)))
which does the same thing, but also allows you to restrict the set of possible targets.
C-c C-w
instead ofC-c C-c
.