Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added error checking org-roam-capture--setup-target-location #2413

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dmgerman
Copy link

@dmgerman dmgerman commented Feb 3, 2024

If a template is invalid org-roam-capture--setup-target-location does not set any target. Then (goto) fails due to lack of buffer.

For example, this template:

 (setq org-roam-capture-templates
    '(
      ("m"
       "movie" plain
       "*** ${title}\n :PROPERTIES:\n :RATING:\n:END:\n%t\n"
       :target (file+olp+datetree "Weekly.org" "abc")
       ))))

generates the error:

save-excursion: Wrong type argument: integer-or-marker-p, nil

which is not very helpful

This patch adds an error message in such a case. It will report instead:

Invalid org-roam capture specification (file+olp+datetree "Weekly.org" "abc")

Motivation for this change

If a template is invalid org-roam-capture--setup-target-location does not set
any target. Then (goto) fails due to lack of buffer.

For example, this template:

     (setq org-roam-capture-templates
        '(
          ("m"
           "movie" plain
           "*** ${title}\n :PROPERTIES:\n :RATING:\n:END:\n%t\n"
           :target (file+olp+datetree "Weekly.org" "abc")
           ))))

generates the error:

    save-excursion: Wrong type argument: integer-or-marker-p, nil

which is not very helpful

This patch adds an error message in such a case. It will report instead:

   Invalid org-roam capture specification (file+olp+datetree "Weekly.org" "abc")
@dmgerman
Copy link
Author

dmgerman commented Feb 3, 2024

One extra comment. I am not sure if this is an error or on purpose. The documentation of org-mode says that the destionation is file+olp+datetree, but that destination is not handled by org-roam. Instead, file+datetree is used. It might be worthwhile to document this discrepancy

Org-roam templates are used for two purposes:

- when calling org-roam-capture, and
- when visiting a node that does not exist.

This means that the name of the destination is always being queried, even if it not used
in the template.

This patch does several things:

1. When doing org-roam-capture, it asks for the destination  only
   if the template requests it.

2. If visiting a node that does not exist, a node is created and passed to the templates.

Perhaps more importantly, the code has been refactored and the processing of the templates has
less cloned code. It hopefully makes it easier to maintain.

Some things to note:

- org-roam-capture--node was incorrectly described as only not-nil during a template creation.
  That was not true. This variable is not re-entrant.

- when visiting a node that does not exist, the user is asked for a template. The template
  might never use this node (e.g. if the destination is node)
This allows for templates that work on existing nodes only and helps
add the new content exactly at a given location.
Templates should be of two types:

1. those that create files, and
2. those that do not create files.

This option allows to check the intent of the template.

It has two values:

yes -> only allow the template to create a new file
no  -> template will only operate on files that exist, it will not create it

if the option is not available, the template can be used for both.

Note that this option only applies to "file" type templates.
All node templates require the node to exist.
If the node title/node-id is not provided, as for a node.
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.

None yet

2 participants