I use the browser button described somewhere as roam-refs, which when I click on it in Chrome, opens a new buffer on a new org-roam node for which the capture template looks like this:
:PROPERTIES:
:ID: 220416_145107
:ROAM_REFS: https://en.wikipedia.org/wiki/Foobar
:END:
#+title: Foobar - Wikipedia
Is there already a keystroke or function for opening the thing referred to by the ROAM_REFS property, from wherever in the org document point is?
If not, what approach would people suggest for the implementation of such a function?
I’m thinking it would be nice to open the ROAM_REFS destination as if you navigated to it and then did C-c C-o for org-open-at-point.
I think it would be simple if you can guarantee for your use:
You only have file nodes; no headline nodes
You only have one value in roam_refs prop (you could have multiple in theory)
save-excursion (to keep current point)
widen (in case you are narrowing the current buffer
when org-get-enty (or similar func name) to get roam_refs, returns value
org-open-link url (use the value as string)
Something like this?
The last steps to open url might need some tweaks depending on availability of functions — e.g. it might be easier to move to your point to the property and call c-c c-o.
I believe there is also an org macro to do the first two steps in one (called org-with-point or something)
—
If you can’t guarantee the first two conditions, you’d need to generalize this for any nodes:
get the current node where the point is (I think org-roam has this fun, used to update the org-roam buffer as you move to a different node)
Get the values of prop roam_refs (perhaps use the roam’s method for the instance of node to get the value for the current node)
Iterate the values to check any is URL (there should be a func built in with prefix “url”)
Thank you for your ideas @nobiot. Based on them, I’ve written this up, which is simple and does the trick:
(defun gpc/open-node-roam-ref-url ()
"Open the URL in this node's ROAM_REFS property, if one exists"
(interactive)
(when-let ((ref-url (org-entry-get-with-inheritance "ROAM_REFS")))
(browse-url ref-url)))
I bound it to a keystroke under my roam prefix in Doom, and am happy now
This is a really nice idea, which I took and adapted for users of org-roam v1.
(defun lt/open-roam_key-ref-url ()
"Open the URL in this note's ROAM_KEY property, if one exists"
(interactive)
(when-let ((ref-url (org-roam--extract-global-props '("ROAM_KEY"))))
(browse-url (cdar ref-url))))
It is rather simple but I learned a lot by writing this.