>> When headline cycle expanding on STATE is `subtree` in function >> `org-cycle-display-link-previews`, assume I have org-mode content like >> bellowing: >> ... >> The first two links will be previewed twice. (I use package >> "org-link-beautify.el" which display icon on link. Then it will link >> previewing with two icons.) > > Karthik, may you please take a look?
Attached a patch to fix this. Please let me know if this strategy is acceptable. Stardiviner, under these changes this logic in your org-link-beautify package is incorrect: --8<---------------cut here---------------start------------->8--- (unless (overlay-get ov 'org-image-overlay) (overlay-put ov 'display ...) (overlay-put ov 'after-string ...) (overlay-put ov 'keymap org-link-beautify-keymap)))) --8<---------------cut here---------------end--------------->8--- Your beautify-* functions return nil if there is already an image overlay. This will mean that the overlays are removed. If you want your function to do nothing you should return t. See this part of the docstring for org-link-parameters: --8<---------------cut here---------------start------------->8--- ‘:preview’ Function to run to generate an in-buffer preview for the link. It must accept three arguments... THIS FUNCTION MUST RETURN A NON-NIL VALUE TO INDICATE SUCCESS. A return value of nil implies that the preview failed, and the overlay placed on the link will be removed. --8<---------------cut here---------------end--------------->8--- Karthik
>From 4c5a6f9ea5cdccc158ecbd67a94e82a01a3bd130 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Date: Fri, 28 Mar 2025 15:37:53 -0700 Subject: [PATCH] ol: Reuse existing overlay when previewing links * lisp/ol.el (org-link-preview-region): If a preview overlay exists on a link region when previewing that link, reuse it instead of placing a second one. --- lisp/ol.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index 9e46b43a5..c08bfe67b 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -2069,13 +2069,15 @@ (defun org-link-preview-region (&optional include-linked refresh beg end) (not (org-element-contents-begin link))) (org-element-property :path link)))) ;; Create an overlay to hold the preview - (let ((ov (make-overlay - (org-element-begin link) - (progn - (goto-char - (org-element-end link)) - (unless (eolp) (skip-chars-backward " \t")) - (point))))) + (let ((ov (or (cdr-safe (get-char-property-and-overlay + (org-element-begin link) 'org-image-overlay)) + (make-overlay + (org-element-begin link) + (progn + (goto-char + (org-element-end link)) + (unless (eolp) (skip-chars-backward " \t")) + (point)))))) (overlay-put ov 'modification-hooks (list 'org-link-preview--remove-overlay)) (push ov org-link-preview-overlays) -- 2.47.2