emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: stardiviner <numbchild@gmail.com>
To: Org-mode <emacs-orgmode@gnu.org>
Subject: [PATCH] The function `org-link-preview-region` should detect whether already has overlay.
Date: Wed, 29 Jan 2025 17:55:23 +0800	[thread overview]
Message-ID: <CAL1eYu+PeoBhPAtHH1uw9oMhbLQ9L7oFLoCK01Fjp4w_cB2qYw@mail.gmail.com> (raw)

[-- 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 --]

                 reply	other threads:[~2025-01-29  9:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAL1eYu+PeoBhPAtHH1uw9oMhbLQ9L7oFLoCK01Fjp4w_cB2qYw@mail.gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).