From 3c396f9e91d04e2648e98c574c346341cfd0ae46 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Mon, 9 Aug 2021 15:28:24 +0800 Subject: [PATCH] (fix)replace-link-at-point: preserve description (#1753) Preserve descriptions (if any) when replacing `roam:` links. Fixes #1737. --- org-roam-node.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org-roam-node.el b/org-roam-node.el index ee0380e..00e6fd4 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -610,6 +610,11 @@ Assumes that the cursor was put where the link is." (let* ((link (or link (org-element-context))) (type (org-element-property :type link)) (path (org-element-property :path link)) + (desc (and (org-element-property :contents-begin link) + (org-element-property :contents-end link) + (buffer-substring-no-properties + (org-element-property :contents-begin link) + (org-element-property :contents-end link)))) node) (goto-char (org-element-property :begin link)) (when (and (org-in-regexp org-link-any-re 1) @@ -617,7 +622,7 @@ Assumes that the cursor was put where the link is." (setq node (org-roam-node-from-title-or-alias path))) (replace-match (org-link-make-string (concat "id:" (org-roam-node-id node)) - path))))))) + (or desc path)))))))) (defun org-roam-link-replace-all () "Replace all \"roam:\" links in buffer with \"id:\" links."