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

ROAM_REFS is being inserted into file top PROPERTIES when capturing ref as an entry #1937

Open
AloisJanicek opened this issue Nov 2, 2021 · 3 comments
Projects

Comments

@AloisJanicek
Copy link
Contributor

AloisJanicek commented Nov 2, 2021

Description

When I attempt to capture some ref from browser as entry (as level 1 heading inside org-roam file node), the ROAM_REFS gets inserted into its file-top :PROPERTIES: drawer in addition to correct expansion from the capture template itself.

I tracked down this behavior to org-roam-protocol--insert-captured-ref-h and its invocation in org-roam-capture--prepare-buffer through (run-hooks 'org-roam-capture-new-node-hook)

Steps to Reproduce

  1. Have some org-roam file node of title "Some title"
  2. Set following ref capture template:
(setq
 org-roam-capture-ref-templates
 `(("r" "ref" entry (function
                     (lambda ()
                       (format
                        "* ${title} :ref:\n:PROPERTIES:\n:ID: %s\n:ROAM_REFS: ${ref}\n:END:"
                        (org-id-uuid))))
    :target (node "Some title")
    :unnarrowed t
    :immediate-finish t)))
  1. Capture url/title from browser via usual bookmarklet using template "r"

Backtrace

Expected Results

ROAM_REFS gets added only to the newly created level 1 org entry in accordance with capture template "r"

Actual Results

ROAM_REFS gets added to the file top PROPERTIES drawer in addition to expansion of template "r"

Environment

latest org-roam commit, up-to-date doom-emacs, emacs 28.60 native-comp

@project-bot project-bot bot added this to Backlog in Org-roam Nov 2, 2021
@sg-qwt
Copy link

sg-qwt commented Mar 25, 2023

I hit the exact issue today. All my roam_refs are essentially duplicated by this. Do you find a way to not automatically insert ROAM_REFS at file level?

@sg-qwt
Copy link

sg-qwt commented Mar 25, 2023

(add-hook 'org-roam-capture-new-node-hook #'org-roam-capture--insert-captured-ref-h)

This hook is automatically added for capture which caused the problem. I worked around by setting org-roam-capture-new-node-hook to nil.

Some relevant discussion here

@martyone
Copy link

For me this change fixed the behavior for file+olp and file+head+olp targets:

diff --git a/org-roam-capture.el b/org-roam-capture.el
index 8ec9170..4c9b328 100644
--- a/org-roam-capture.el
+++ b/org-roam-capture.el
@@ -495,9 +495,8 @@ Return the ID of the location."
              new-file-p (org-roam-capture--new-file-p path))
        (when new-file-p (org-roam-capture--put :new-file path))
        (set-buffer (org-capture-target-buffer path))
-       (setq p (point-min))
        (let ((m (org-roam-capture-find-or-create-olp olp)))
-         (goto-char m))
+         (setq p (goto-char m)))
        (widen))
       (`(file+head ,path ,head)
        (setq path (org-roam-capture--target-truepath path)
@@ -516,9 +515,8 @@ Return the ID of the location."
        (when new-file-p
          (org-roam-capture--put :new-file path)
          (insert (org-roam-capture--fill-template head 'ensure-newline)))
-       (setq p (point-min))
        (let ((m (org-roam-capture-find-or-create-olp olp)))
-         (goto-char m)))
+         (setq p (goto-char m))))
       (`(file+datetree ,path ,tree-type)
        (setq path (org-roam-capture--target-truepath path))
        (require 'org-datetree)

Used with this template:

(setq org-roam-capture-ref-templates
      '(("r" "reference" plain "%?"
         :target (file+olp "references.org" ("${title}"))
         :unnarrowed t)))

martyone added a commit to martyone/org-roam that referenced this issue Feb 12, 2024
Suitable for maintaining a list of references in a single specific file,
possibly in cooperation with org-bibtex.

Related to issue org-roam#1937.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Org-roam
Backlog
Development

No branches or pull requests

3 participants