From a86d82b20efc69139cf29135d81ddc38eba87b51 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Thu, 12 Nov 2020 16:11:35 +0800 Subject: [PATCH] (fix): fix backlink-to-current-p killing buffers (#1263) Change `org-roam--backlink-to-current-p` to only perform a DB query. --- org-roam.el | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/org-roam.el b/org-roam.el index 144092a..41e1f2b 100644 --- a/org-roam.el +++ b/org-roam.el @@ -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 - (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))) - (_ 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))) + "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" (org-roam-id-get-file dest)) + (_ dest)))))) + (string= current-file backlink-dest)))) (defun org-roam-open-at-point () "Open an Org-roam link or visit the text previewed at point.