(fix): fix backlink-to-current-p killing buffers (#1263)

Change `org-roam--backlink-to-current-p` to only perform a DB query.
This commit is contained in:
Jethro Kuan
2020-11-12 16:11:35 +08:00
committed by GitHub
parent d4c875b53b
commit a86d82b20e

View File

@ -1015,24 +1015,18 @@ Return nil if the file does not exist."
(and (boundp org-roam-backlinks-mode)
org-roam-backlinks-mode))
(defun org-roam--retrieve-link-destination (&optional pom)
"Retrieve the destination of the link at POM.
The point-or-marker POM can either be a position in the current
buffer or a marker."
(let ((pom (or pom (point))))
(org-with-point-at pom
(defun org-roam--backlink-to-current-p ()
"Return t if the link at point is to the current Org-roam file."
(save-match-data
(let ((current-file (buffer-file-name org-roam-buffer--current))
(backlink-dest (save-excursion
(let* ((context (org-element-context))
(type (org-element-property :type context))
(dest (org-element-property :path context)))
(pcase type
("id" (car (org-roam-id-find dest)))
("id" (org-roam-id-get-file dest))
(_ dest))))))
(defun org-roam--backlink-to-current-p ()
"Return t if backlink is to the current Org-roam file."
(let ((current (buffer-file-name org-roam-buffer--current))
(backlink-dest (org-roam--retrieve-link-destination)))
(string= current backlink-dest)))
(string= current-file backlink-dest))))
(defun org-roam-open-at-point ()
"Open an Org-roam link or visit the text previewed at point.