[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Link preview generation with new link preview property
From: |
Björn Bidar |
Subject: |
Re: Link preview generation with new link preview property |
Date: |
Fri, 20 Dec 2024 01:20:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Ihor Radchenko <yantar92@posteo.net> writes:
> Karthik Chikmagalur <karthikchikmagalur@gmail.com> writes:
>
>> ...
>> Considering this, it might be better to just split
>> `org-link-preview-file' into two public functions, where the "inside"
>> function accepts an image instead of a file.
>
> Agree.
> Would you be interested to create a patch?
Did you think of something like this?
>From a3c682a7d730b0ae9492407d080ba8549a19e02d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bidar@thaodan.de>
Date: Fri, 20 Dec 2024 01:00:46 +0200
Subject: [PATCH] org-link: Split link preview into two functions
* lisp/ol.el (org-link-preview-file,
org-link-preview-image-data): Split up the actual preview part into
a separate function. The new preview function can be called by
:preview handler to display the image according to the correct alignment
for the link to be previewed.
---
lisp/ol.el | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index 032610bad..dd6b07152 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -2177,27 +2177,34 @@ (defun org-link-preview-file (ov path link)
((string-match-p (image-file-name-regexp) file))
((file-exists-p file)))
(let* ((width (org-display-inline-image--width link))
- (align (org-image--align link))
- (image (org--create-inline-image file width)))
- (when image ; Add image to overlay
- ;; See bug#59902. We cannot rely
- ;; on Emacs to update image if the file
- ;; has changed.
- (image-flush image)
- (overlay-put ov 'display image)
- (overlay-put ov 'face 'default)
- (overlay-put ov 'keymap image-map)
- (when align
- (overlay-put
- ov 'before-string
- (propertize
- " " 'face 'default
- 'display
- (pcase align
- ("center" `(space :align-to (- center (0.5 . ,image))))
- ("right" `(space :align-to (- right ,image)))))))
+ (image-data (org--create-inline-image file width)))
+ (when image-data
+ (org-link-preview-image-data ov image-data link)
t)))))
+(defun org-link-preview-image-data (ov image-data link)
+ "Display image data IMAGE-DATA in overlay OV for link.
+
+This intended to be used by functions which provide the :preview link property
+of links such as in `org-link-preview-file'"
+ (let ((align (org-image--align link)))
+ ;; See bug#59902. We cannot rely
+ ;; on Emacs to update image if the file
+ ;; has changed.
+ (image-flush image-data)
+ (overlay-put ov 'display image-data)
+ (overlay-put ov 'face 'default)
+ (overlay-put ov 'keymap image-map)
+ (when align
+ (overlay-put
+ ov 'before-string
+ (propertize
+ " " 'face 'default
+ 'display
+ (pcase align
+ ("center" `(space :align-to (- center (0.5 . ,image-data))))
+ ("right" `(space :align-to (- right ,image-data)))))))))
+
;;;; "help" link type
(defun org-link--open-help (path _)
"Open a \"help\" type link.
--
2.45.2
- Link preview generation with new link preview property, Björn Bidar, 2024/12/08
- Re: Link preview generation with new link preview property, Karthik Chikmagalur, 2024/12/13
- Re: Link preview generation with new link preview property, Björn Bidar, 2024/12/13
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/14
- Re: Link preview generation with new link preview property, Björn Bidar, 2024/12/16
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/17
- Re: Link preview generation with new link preview property, Björn Bidar, 2024/12/19
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/21
- Re: Link preview generation with new link preview property, Karthik Chikmagalur, 2024/12/16
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/17
- Re: Link preview generation with new link preview property,
Björn Bidar <=
- Re: Link preview generation with new link preview property, Karthik Chikmagalur, 2024/12/19
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/21
- Re: Link preview generation with new link preview property, Björn Bidar, 2024/12/23
- Message not available
- Re: Link preview generation with new link preview property, Karthik Chikmagalur, 2024/12/26
- Re: Link preview generation with new link preview property, Björn Bidar, 2024/12/29
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/30
- Re: Link preview generation with new link preview property, stardiviner, 2024/12/18
- Re: Link preview generation with new link preview property, Karthik Chikmagalur, 2024/12/18
- Re: Link preview generation with new link preview property, Björn Bidar, 2024/12/19
- Re: Link preview generation with new link preview property, Ihor Radchenko, 2024/12/21