emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tim Visher <tim.visher@gmail.com>
To: Emacs Org Mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Can `org-capture` templates be made to result in a sub-heading of the current heading?
Date: Thu, 11 May 2023 09:05:44 -0400	[thread overview]
Message-ID: <CAHa53uwZDB83t+XOB7wH62JytWPbBVDstPo5_BS2foGok0rRrA@mail.gmail.com> (raw)
In-Reply-To: <CAHa53uxPpQAEzTGdX8J1JcNV=2ca+6srTarccE4S93u2Po1LXA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2073 bytes --]

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

> On Wed, May 10, 2023 at 5:04 PM Tim Visher <tim.visher@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

[-- Attachment #2: Type: text/html, Size: 4025 bytes --]

  reply	other threads:[~2023-05-11 13:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10 21:04 Can `org-capture` templates be made to result in a sub-heading of the current heading? Tim Visher
2023-05-11 12:42 ` Tim Visher
2023-05-11 13:05   ` Tim Visher [this message]
2023-05-11 13:10     ` Tim Visher
2023-05-12 12:08 ` Ihor Radchenko
2023-05-12 14:24   ` Tim Visher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHa53uwZDB83t+XOB7wH62JytWPbBVDstPo5_BS2foGok0rRrA@mail.gmail.com \
    --to=tim.visher@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).