Skip to content

(fix)capture: always trigger :if-new template for existing nodes#1807

Merged
jethrokuan merged 3 commits intomasterfrom
fix/capture-if-new
Aug 26, 2021
Merged

(fix)capture: always trigger :if-new template for existing nodes#1807
jethrokuan merged 3 commits intomasterfrom
fix/capture-if-new

Conversation

@Wetlize
Copy link
Contributor

@Wetlize Wetlize commented Aug 26, 2021

Previously, if org-roam-capture- would be triggered for an existing node
it would just move the point to the beginning of the node, ignoring the
target from the :if-new part of the template.

This patch will now also run the :if-new part of the template for
existing nodes, just like it does right now in case of daily
templates (which happened to be never recognized as existing nodes
during the capture process).

Previously, if org-roam-capture- would be triggered for an existing node
it would just move the point to the beginning of the node, ignoring the
target from the :if-new part of the template.

This patch will now also run the :if-new part of the template for
existing nodes, just like it does right now in case of daily
templates (which happened to be never recognized as existing nodes
during the capture process).
@Wetlize
Copy link
Contributor Author

Wetlize commented Aug 26, 2021

@jethrokuan This is already existing behavior for dailies, but I didn't realize that it doesn't work with the normal capture templates, so it fixes that. So for example, given the next template:

("pt" "Project note" entry
           "* TODO %?"
           :if-new (file+head+olp "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}" ("Tasks"))
           :unnarrowed t)

and a similar template for daily, a daily template would properly keep create new TODO entry for existing "Tasks" heading given the same daily date, while in case of the normal capture it would do the next for a new node:

* Tasks
** TODO This is my task

And then running the same template for the same node would yield:

* Tasks
** TODO This is my task
* TODO bar baz

I didn't notice any regression, but just in case would like to pass through your review.

@Wetlize Wetlize requested a review from jethrokuan August 26, 2021 02:59
@jethrokuan
Copy link
Member

I was a little confused when you said "always trigger :if-new on existing nodes" because it sounds like the opposite of what :if-new is supposed to do, but I tried it out and understand what is meant here. I think for clarity later on we may need to rename/remove the :if-new key.

@Wetlize
Copy link
Contributor Author

Wetlize commented Aug 26, 2021

I was a little confused when you said "always trigger :if-new on existing nodes"
I think for clarity later on we may need to rename/remove the :if-new key.

Oh, I agree with all that. I think #1804 provides perfect opportunity to pull the trigger for the rename. My preference would be s/:if-new/:target, which would be also semantically (given org-capture) correct way to name it.

@jethrokuan jethrokuan merged commit 4c4b024 into master Aug 26, 2021
@jethrokuan jethrokuan deleted the fix/capture-if-new branch August 26, 2021 11:04
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants