I've got the following function:
(defun my/org-roam-capture-to-link ()
"In org-roam files, capture to node linked at point."
(interactive)
(when-let ((_ (org-roam-file-p)) ;; Only act in org-roam files
(link-start (car (org-in-regexp org-link-bracket-re 1)))
(link (save-excursion
(goto-char link-start)
(org-element-link-parser)))
(id (plist-get (cadr link) :path))
;; This will fail if there is no node
(node (org-roam-node-from-id id)))
;; If there /is/ a node, capture to it.
(org-roam-capture- :node node)))
This should capture to the org-roam node at the id linked at point, but only if point is at a link to such a node, and I'm in an org-roam file's buffer.
Normally when I just run `org-roam-capture` and select an already existing node, *no* new text is added, and I just add whatever I need to and press `C-c C-c`.
Now, If I'm on a link to an org-roam node, and run `my/org-roam-capture-to-link` interactively with `M-x`, it does exactly that: nothing new is added, exactly what I want.
But I wanted to run it from `org-metareturn`. I added the symbol for the function to `org-metareturn-hook`. Now if I press `M-RET` on an appropriate link, I *do* get an org-roam capture, but it adds an empty heading on a newline (that is, it adds "\\n* |", with the cursor at |).
What's going on? How can I make the meta-return version work like the M-x version?
Thanks!