On Fri, May 12, 2023 at 8:05 AM Ihor Radchenko <yantar92@posteo.net> wrote:
Tim Visher <tim.visher@gmail.com> writes:
> Can `org-capture` templates be made to result in a sub-heading of the
> current heading?

Just use target `here' (as symbol).

Thanks for the suggestion, Ihor.

Do you have an example of this actually working? I'm on `Org mode version 9.6.5` which looks to be the latest available from GNU ELPA and there seems to be a dispute between `org-capture-set-target-location` which understands that the result of `(org-capture-get :target)` can return a symbol rather than a list vs. `org-capture` itself which assumes that target will _always_ be a list.

My testing code:

```
(timvisher--comment
 ;; Context
 (defmacro timvisher--comment
     (&rest _)
   nil)

 (defmacro wcb (buffer &rest body)
   `(with-current-buffer ,buffer
      ,@body))

 ;; Demo code
 (setq org-capture-templates
       '(("1" "1" entry here "* 1")
         ("2" "2" entry (here) "* 2")))

 ;; Fails with `Capture template ‘1’: Wrong type argument: listp, here`
 ;; because of `… (car (org-capture-get :target)) …`
 (wcb "todo.org"
      (org-capture nil "1"))

 ;; Fails with `Invalid capture target specification: (here)` because
 ;; `(pcase (or target (org-capture-get :target)) …)` doesn't have a case
 ;; for `(here)`
 (wcb "todo.org"
      (org-capture nil "2"))
 )

```