Skip to content

Conversation

@bgro
Copy link
Contributor

@bgro bgro commented Aug 18, 2025

This is a proposal to make capturing using org-capture a bit more flexible such that some use-cases that org-roam-capture allows can also be handled without extending org-capture.

One such use-case is the ability to provide a directory in which a new file is to be generated per template. Currently, org-node works around this by allowing the user to configure whether she should be asked for the folder when a new file is created ... but it would be nicer if one could set specific folders for specific templates.

This pull-request adds the possibility to provide a plist with parameters to org-node-capture-template for
influencing the path for a new file. For usage in a capture template, In the result has to be wrapped in a nullary lambda function in the capture template:

(function (lambda () (org-node-capture-target '(:path "~/org/articles"))))

(the change is backward compatible, i.e., (function org-node-capture-target) still works.)

The following parameters exist:

  • :path: Provide the path of the directory in which the new file will be created
  • :ask_path Always ask for the path, even if org-node-file-directory-ask is configured otherwise

Possibly, a few more use-cases could be tackled with this approach.

@meedstrom
Copy link
Owner

Thank you, I’ll look at this soon!

@bgro
Copy link
Contributor Author

bgro commented Sep 2, 2025

I have been going a bit further on this, but don't want to add more changes before I know whether the direction is palatable to you. Please let me know whether I should update the PR with the following:

  • :path can also be a function -- if it is a function, then the function is called to determine the folder in which the new note is created

  • Additional configuration parameter :node-id, which allows the user to specify the id of a node under which the newly created content is to be added. I use it for the following use-case:

    ("P" "contact person" entry (function (lambda () (org-node-capture-target
      	       '(:node-id "249506ab-d89c-4419-aecd-70d7c314ce36"))))
    "* %(org-capture-get :title)\n:PROPERTIES:\n:ID: %(org-capture-get :id)\n:EMAIL:\n:PHONE:\n:ALIAS:\n:NICKNAME:\\n:NOTE:\n:ADDRESS:\n:BIRTHDAY:\n:END:\n"
    )

    where the node-id points to the file id of my contact-person-file.

    Or maybe I am missing something entirely and am over-complicating things: is there another way to create a new org-node node /within an existing file/ using a template that has access to the title that was entered after executing org-node-find?

@meedstrom
Copy link
Owner

meedstrom commented Sep 13, 2025

These are good ideas.

(I'd also like to look at changing org-node-guess-or-ask-dir so that it prompts for the full file name and not just directory, but I guess that can wait.)

I agree about letting it be a function too.

I am not sure yet if the design with an optional plist suits my tastes. But it occurs to me you could put any property-value pair in the capture template's main plist, like this:

(setq org-capture-templates
      '(("p" "Capture plain text into ID node" plain #'org-node-capture-target nil
         :path "~/foo/bar")))

Then inside org-node-capture-target, you can eval (org-capture-get :path) to get "~/foo/bar".

As for :node-id, yes, I've wanted that for a while! Only applies if it's new, so it's instead of creating a new file, right? Maybe :parent-id or :parent-id-if-new?

Here's your code with some changes to make use of org-capture-plist, but untested: main...dev2 (there's also a possibly unnecessary feature of being able to put lambdas for :title and :id in the template) Does it appeal to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants