branch: externals/org
commit 3362773397df1e05fb2cc31b9cd944ca83ab6792
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    Fix previews of links inside description
    
    * lisp/ol.el (org-link-preview-region): Add special handling of links
    inside description.  It was present in the past but was lost in the
    new preview system.
    
    Reported-by: Max Nikulin <[email protected]>
    Link: 
https://list.orgmode.org/orgmode/[email protected]/
---
 lisp/ol.el | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index a903870fb0..9b5b07b7fb 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -50,6 +50,9 @@
 (declare-function org-before-first-heading-p "org" ())
 (declare-function org-do-occur "org" (regexp &optional cleanup))
 (declare-function org-element-at-point "org-element" (&optional pom 
cached-only))
+(declare-function org-element-parse-secondary-string "org-element"
+                  (string restriction &optional parent))
+(declare-function org-element-restriction "org-element" (element))
 (declare-function org-element-cache-refresh "org-element" (pos))
 (declare-function org-element-cache-reset "org-element" (&optional all 
no-persistence))
 (declare-function org-element-context "org-element" (&optional element))
@@ -2173,11 +2176,26 @@ buffer boundaries with possible narrowing."
         (forward-char -1)               ;ensure we are on the link
         (when-let*
             ((link (org-element-lineage (org-element-context) 'link t))
+             (path (or
+                    ;; Link without description or link with description
+                    ;; that is requested to be previewed anyway.
+                    (and (or include-linked
+                             (not (org-element-contents-begin link)))
+                         (org-element-property :path link))
+                    ;; Special case: link with description where
+                    ;; description is itself a sole link
+                    (and (org-element-contents-begin link)
+                         (setq link
+                               (org-with-point-at (org-element-contents-begin 
link)
+                                 (org-element-put-property
+                                  (org-element-link-parser) :parent link)))
+                         (org-element-type-p link 'link)
+                         (equal (org-element-end link)
+                                (org-element-contents-end
+                                 (org-element-parent link)))
+                         (org-element-property :path link))))
              (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))))
+             (preview-func (org-link-get-parameter linktype :preview)))
           ;; Create an overlay to hold the preview
           (let ((ov (or (cdr-safe (get-char-property-and-overlay
                                    (org-element-begin link) 
'org-image-overlay))

Reply via email to