When headline cycle expanding on STATE is `subtree` in function `org-cycle-display-link-previews`, assume I have org-mode content like bellowing:
#+begin_src org
#+end_src
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.)
So checked source code in `org-link-preview-region`. It should check whether already has org-mode link preview overlay.
For example, adding a condition outside of the `while-let*` binding code.
#+begin_src diff
modified lisp/ol.el
@@ -2056,25 +2056,26 @@ buffer boundaries with possible narrowing."
;; Collect links to preview
(while (re-search-forward org-link-any-re end t)
(forward-char -1) ;ensure we are on the link
- (when-let*
- ((link (org-element-lineage (org-element-context) 'link t))
- (linktype (org-element-property :type link))
- (preview-func (org-link-get-parameter linktype :preview))
- (path (and (or include-linked
- (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)))))
- (overlay-put ov 'modification-hooks
- (list 'org-link-preview--remove-overlay))
- (push ov org-link-preview-overlays)
- (push (list preview-func ov path link) preview-queue))))
+ (unless (overlays-at (point)) ;; <-------------- Added condition here. (I think the condition can be more explicit detect on org-mode link preview property detection)
+ (when-let*
+ ((link (org-element-lineage (org-element-context) 'link t))
+ (linktype (org-element-property :type link))
+ (preview-func (org-link-get-parameter linktype :preview))
+ (path (and (or include-linked
+ (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)))))
+ (overlay-put ov 'modification-hooks
+ (list 'org-link-preview--remove-overlay))
+ (push ov org-link-preview-overlays)
+ (push (list preview-func ov path link) preview-queue)))))
;; Collect previews in buffer-local LIFO preview queue
(setq org-link-preview--queue
(nconc (nreverse preview-queue) org-link-preview--queue))
#+end_src