Function: org-roam-node-from-ref

org-roam-node-from-ref is a byte-compiled function defined in org-roam-node.el.

Signature

(org-roam-node-from-ref REF)

Documentation

Return an org-roam-node from REF reference.

Return nil if there's no node with such REF.

Source Code

;; Defined in ~/.emacs.d/elpa/org-roam-20260224.1637/org-roam-node.el
(defun org-roam-node-from-ref (ref)
  "Return an `org-roam-node' from REF reference.
Return nil if there's no node with such REF."
  (save-match-data
    (let (type path)
      (cond
       ((string-match org-link-plain-re ref)
        (setq type (match-string 1 ref)
              path (match-string 2 ref)))
       ((string-prefix-p "@" ref)
        (setq type "cite"
              path (substring ref 1))))
      (when (and type path)
        (when-let* ((id (caar (org-roam-db-query
                               [:select [nodes:id]
                                :from refs
                                :left-join nodes
                                :on (= refs:node-id nodes:id)
                                :where (= refs:type $s1)
                                :and (= refs:ref $s2)
                                :limit 1]
                               type path))))
          (org-roam-populate (org-roam-node-create :id id)))))))