On Thu, May 11, 2023 at 8:42 AM Tim Visher <tim.vis...@gmail.com> wrote:

> On Wed, May 10, 2023 at 5:04 PM Tim Visher <tim.vis...@gmail.com> wrote:
>
>> Can `org-capture` templates be made to result in a sub-heading of the
>> current heading?
>>
>> So
>>
>> ```
>> * This Week
>> ** TODO A TODO Item
>>
>>    [2023-05-05 Fri 10:47]
>>
>>    A description <point's here>
>> ```
>>
>> and I whack my capture keychord and get
>>
>> ```
>> * This Week
>> ** TODO A TODO Item
>>
>>    [2023-05-05 Fri 10:47]
>>
>>    A description
>> *** [2023-05-10 Wed 17:02]
>>
>>     [2023-05-10 Wed 17:02]
>>
>>     <point's here>
>> ```
>>
>
> It's worth noting that with a capture template like
>
> ```
> ("twj" "TODO Work TODO Journal" entry
>  (file+headline "~/Documents/todo.org" "Inbox")
>  "* %U
>
>    %U
>
>    %?")
> ```
>
> If I do the usual `M-0 M-x org-capture` with point in the original spot it
> behaves exactly as I want it to. My goal is to get it to behave that way
> just by invoking the capture template.
>

OK after poking around in `org-capture-set-target-location` I think I have
this sorted. Please let me know if I'm doing something obviously silly. :)

```
(defun timvisher--org-capture-sub-heading-insertion-point
    ()
  (insert "\n")
  (forward-char)
  (org-capture-put :exact-position (point) :insert-here t))

;; Embedded in the capture templates list
("twj" "TODO Work TODO Journal" entry
 (function timvisher--org-capture-sub-heading-insertion-point)
 "* %U

  %U

  %?")
```

The key was finding that it wasn't enough to merely move point to the
proper location. I _also_ needed to call `org-capture-put`. The docs on
this subject are a little misleading, IMHO.

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


Empirically it seems like you have to visit the file, move point to the
right location, _and_ call `org-capture-put`.

-- Tim Visher

Reply via email to