mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat): support more ref links (#900)
This adds support for all sorts of ref links (http, https, and any custom link types). If the ref is not a file or org-ref citation link, the full link path is used. Closes #744.
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
- [#851](https://github.com/org-roam/org-roam/pull/851) Add `'first-directory'` option for `org-roam-tag-sources`
|
||||
- [#863](https://github.com/org-roam/org-roam/pull/863) Display outline hierarchy in backlinks buffer
|
||||
- [#898](https://github.com/org-roam/org-roam/pull/898) Add `org-roam-random-note` to browse a random note.
|
||||
- [#900](https://github.com/org-roam/org-roam/pull/900) Support and index all valid org links
|
||||
|
||||
### Bugfixes
|
||||
|
||||
|
@ -84,7 +84,7 @@ Has an effect if and only if `org-roam-buffer-position' is `top' or `bottom'."
|
||||
|
||||
(defcustom org-roam-buffer-prepare-hook '(org-roam-buffer--insert-title
|
||||
org-roam-buffer--insert-backlinks
|
||||
org-roam-buffer--insert-citelinks)
|
||||
org-roam-buffer--insert-ref-links)
|
||||
"Hook run in the `org-roam-buffer' before it is displayed."
|
||||
:type 'hook
|
||||
:group 'org-roam)
|
||||
@ -123,10 +123,9 @@ For example: (setq org-roam-buffer-window-parameters '((no-other-window . t)))"
|
||||
,wrong-type))))))
|
||||
(concat string (when (> l 1) "s"))))
|
||||
|
||||
(defun org-roam-buffer--insert-citelinks ()
|
||||
"Insert citation backlinks for the current buffer."
|
||||
(when-let ((org-ref-p (require 'org-ref nil t)) ;; Ensure that org-ref is present
|
||||
(ref (cdr (with-temp-buffer
|
||||
(defun org-roam-buffer--insert-ref-links ()
|
||||
"Insert ref backlinks for the current buffer."
|
||||
(when-let ((ref (cdr (with-temp-buffer
|
||||
(insert-buffer-substring org-roam-buffer--current)
|
||||
(org-roam--extract-ref)))))
|
||||
(if-let* ((key-backlinks (org-roam--get-backlinks ref))
|
||||
@ -134,7 +133,7 @@ For example: (setq org-roam-buffer-window-parameters '((no-other-window . t)))"
|
||||
(progn
|
||||
(insert (let ((l (length key-backlinks)))
|
||||
(format "\n\n* %d %s\n"
|
||||
l (org-roam-buffer--pluralize "Cite backlink" l))))
|
||||
l (org-roam-buffer--pluralize "Ref Backlink" l))))
|
||||
(dolist (group grouped-backlinks)
|
||||
(let ((file-from (car group))
|
||||
(bls (cdr group)))
|
||||
@ -150,7 +149,7 @@ For example: (setq org-roam-buffer-window-parameters '((no-other-window . t)))"
|
||||
'file-from file-from
|
||||
'file-from-point (plist-get props :point)))
|
||||
(insert "\n\n"))))))
|
||||
(insert "\n\n* No cite backlinks!"))))
|
||||
(insert "\n\n* No ref backlinks!"))))
|
||||
|
||||
(defun org-roam-buffer--insert-backlinks ()
|
||||
"Insert the org-roam-buffer backlinks string for the current buffer."
|
||||
|
36
org-roam.el
36
org-roam.el
@ -556,6 +556,7 @@ This is the format that emacsql expects when inserting into the database.
|
||||
FILE-FROM is typically the buffer file path, but this may not exist, for example
|
||||
in temp buffers. In cases where this occurs, we do know the file path, and pass
|
||||
it as FILE-PATH."
|
||||
(require 'org-ref nil t)
|
||||
(let ((file-path (or file-path
|
||||
(file-truename (buffer-file-name))))
|
||||
links)
|
||||
@ -563,22 +564,9 @@ it as FILE-PATH."
|
||||
(lambda (link)
|
||||
(let* ((type (org-element-property :type link))
|
||||
(path (org-element-property :path link))
|
||||
(start (org-element-property :begin link))
|
||||
(id-data (org-roam-id-find path))
|
||||
(link-type (cond ((and (string= type "file")
|
||||
(org-roam--org-file-p path))
|
||||
"file")
|
||||
((and (string= type "id")
|
||||
id-data)
|
||||
"id")
|
||||
((and
|
||||
(require 'org-ref nil t)
|
||||
(-contains? org-ref-cite-types type))
|
||||
"cite")
|
||||
(t nil))))
|
||||
(when link-type
|
||||
(goto-char start)
|
||||
(let* ((element (org-element-at-point))
|
||||
(start (org-element-property :begin link)))
|
||||
(goto-char start)
|
||||
(let* ((element (org-element-at-point))
|
||||
(begin (or (org-element-property :content-begin element)
|
||||
(org-element-property :begin element)))
|
||||
(content (or (org-element-property :raw-value element)
|
||||
@ -594,20 +582,24 @@ it as FILE-PATH."
|
||||
(org-roam--get-outline-path))
|
||||
:content content
|
||||
:point begin))
|
||||
(names (pcase link-type
|
||||
(names (pcase type
|
||||
("file"
|
||||
(list (file-truename (expand-file-name path (file-name-directory file-path)))))
|
||||
("id"
|
||||
(list (car id-data)))
|
||||
("cite"
|
||||
(org-ref-split-and-strip-string path)))))
|
||||
(list (car (org-roam-id-find path))))
|
||||
((pred (lambda (typ)
|
||||
(and (boundp 'org-ref-cite-types)
|
||||
(-contains? org-ref-cite-types typ))))
|
||||
(setq type "cite")
|
||||
(org-ref-split-and-strip-string path))
|
||||
(_ (list (org-element-property :raw-link link))))))
|
||||
(seq-do (lambda (name)
|
||||
(push (vector file-path
|
||||
name
|
||||
link-type
|
||||
type
|
||||
properties)
|
||||
links))
|
||||
names)))))))
|
||||
names))))))
|
||||
links))
|
||||
|
||||
(defun org-roam--extract-headlines (&optional file-path)
|
||||
|
Reference in New Issue
Block a user