* [PATCH] The function `org-link-preview-region` should detect whether already has overlay.
@ 2025-01-29 9:55 stardiviner
0 siblings, 0 replies; only message in thread
From: stardiviner @ 2025-01-29 9:55 UTC (permalink / raw)
To: Org-mode
[-- Attachment #1: Type: text/plain, Size: 3645 bytes --]
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
** TODO iamtxt.com
DEADLINE: <2025-01-17 Fri>
:LOGBOOK:
- State "TODO" from [2025-01-17 Fri 00:19]
:END:
https://www.iamtxt.com/book/47744.html
https://www.iamtxt.com/book/47681.html
*** kk
https://www.iamtxt.com/book/41334.html
https://www.iamtxt.com/book/42259.html
#+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
[stardiviner] <Hack this world!> GPG key ID: 47C32433
IRC(freeenode): stardiviner Twitter: @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/
[-- Attachment #2: Type: text/html, Size: 6046 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-01-29 9:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-29 9:55 [PATCH] The function `org-link-preview-region` should detect whether already has overlay stardiviner
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).