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

> 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
>
>   %?")
> ```
>

Minor correction. I need to both insert a newline _and *leave*_ point where
it was or I don't get a sub-heading at the proper level (the current level
of the previous journal entry). If I don't insert the newline then
cancelling the entry also pulls the next heading up into the text of the
current heading.

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

-- Tim Visher

Reply via email to