From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id EAUEI8MVjWfd9AAAqHPOHw:P1 (envelope-from ) for ; Sun, 19 Jan 2025 15:09:55 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id EAUEI8MVjWfd9AAAqHPOHw (envelope-from ) for ; Sun, 19 Jan 2025 16:09:55 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=thaodan.de header.s=mail header.b=uJ96lhjS; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=quarantine) header.from=thaodan.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1737299365; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature:autocrypt:autocrypt; bh=hqSMz5+O0F45ikRg6qculCCEvddkKwSWuBaO0APQ8CU=; b=m+Z+CKFIe9onrP03aQd3lIj7MxeP+AdfG9HHnSXnD0TPSm9lPTPKVuN/ubNmCO3RyDQAzM LaJDrrtnhjImcmyUJidLmEZoWQubC6b5ge/09b5vx02buB5fmdQ08h67MDLTBpFhEvqDA1 fi7GYxirlEVOVFkFYDI9Al6Jco90LvTNofx0GW8195mDY2a5iqeBVjIii/Ym8G2WKrRv4N W1c778sz1MNavviwUElZwjXudJMABhNPIjbeRb3GVG0PEwcSdg3C9CRMPqcrfivFN4BeqP sBRTx0xmo5W5r39NmxVEA/p5MmfXRwHNAe46nfrYXEardyHyzvLXHHFJzryVxQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=thaodan.de header.s=mail header.b=uJ96lhjS; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=quarantine) header.from=thaodan.de ARC-Seal: i=1; s=key1; d=yhetil.org; t=1737299365; a=rsa-sha256; cv=none; b=qUnUirhqUF0tqVQHaoL3Oe0AqQLMHHQvegTyvi/tI25y5r/dkPWjg1ebJIfLGmkOdDzhGl RK74XsAWRjDyuOJKMoncu4EmAz8TxcWntbcSFjszFVBFoGihneE+7RBfu6qm0BJDN4lrNW P5Lpb8uUhxvVXNf9mYAAZBH0uUnQ4DG+LchYlNa9wifyPP/o2xtO+FrGTqAL/kQrdOVmxn 9aypBnrhoy1z+pnRpFjw3kcKZUv4lLLEnVVfiGl9h+hDqvxzgPthOLAnbgIH7fTPj1s4pd f3uXea1C1e6XVkp51zo69ZtEaXMPq30xsiGEuQ5qbQyHeQAzyNQ9NLuNT2QMKQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 79A147D04E for ; Sun, 19 Jan 2025 16:09:24 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tZWuk-0006UZ-8k; Sun, 19 Jan 2025 10:08:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tZWuh-0006UC-UG for emacs-orgmode@gnu.org; Sun, 19 Jan 2025 10:08:35 -0500 Received: from thaodan.de ([2a03:4000:4f:f15::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tZWue-00024b-2f for emacs-orgmode@gnu.org; Sun, 19 Jan 2025 10:08:35 -0500 Received: from odin (dsl-trebng12-50dc7b-49.dhcp.inet.fi [80.220.123.49]) by thaodan.de (Postfix) with ESMTPSA id B9D38D0009B; Sun, 19 Jan 2025 17:08:27 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thaodan.de; s=mail; t=1737299307; bh=0UW1lZPCqhNMYkeXYzN9Z4fqlnqLERNZLIJy01+iSZc=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=uJ96lhjS6CRb3/9L08M5c2K898cQWsBjaC1D6AEfi4c9xZPW33W+Dqg/+FKSqOcKc CzKI9a7TT380veQNK8TvY0bGc9JpFT/T1hRDyUUWuByVo4UWFkHUsXsfF+rBvXFL27 MfFMJpRIO9aE6Na2OpAYrl3JL/qe4kyATY3swk5fwb8oyVXmzm2z3+J8MU5nbZLaAw K+Cx4XlB27OSgfRhhB7Zr2VSAScEa8Bxn0t9NbPeg8zynaOFS6UWA0cUypStCk3qb6 /VG5uzz4twUUc4zRgY87Iszm7pBrjunBvJKBjiwOMSThlGO6EcfsKlfuUFL61Umtcg tUiuhCiP9BiLyKsu4yNp/prIKdle6NgN40og7dMkOm44/Hr0cmbVgSnBPHaMXaUhcp zKf8xAsbsINi6vPU59keFnLJ7DH+CKQny1LFu8RXq2DKXogzMIT2vnIhyKHZWncwQ3 qcVuSiIYzbb5wS3JsTyxOh0VPHvbfupkL3fFXhdjZDxJZt6UzK+7hNxjXlUnhNBzHa jUWBkENSSI1kQK6DQuUn8TaMkovUBr2ZmKEtsn1Esd+awwIc56md6J9C/UDhao5Ukv g0FD/re1666mkAnKI0fmRGjFCwd+5J60bJDEFtREsn0ghOgAmcVMGJ4k6b3dJDwi78 mr28Kt7LqKYv+vLANUmUovxI= From: =?utf-8?Q?Bj=C3=B6rn?= Bidar To: Ihor Radchenko Cc: Karthik Chikmagalur , emacs-orgmode@gnu.org Subject: Re: Link preview generation with new link preview property In-Reply-To: <87h65wdv0i.fsf@localhost> (Ihor Radchenko's message of "Sat, 18 Jan 2025 15:03:25 +0000") References: <6755f138.0c0a0220.40388.51fbSMTPIN_ADDED_BROKEN@mx.google.com> <874j382kue.fsf@gmail.com> <87pllug2y4.fsf@localhost> <87ldwfnff4.fsf@gmail.com> <874j328aym.fsf@localhost> <6764aa79.050a0220.23273b.09a5SMTPIN_ADDED_BROKEN@mx.google.com> <87y102mgdx.fsf@gmail.com> <87msgd2j9k.fsf@localhost> <877c7afz2y.fsf@localhost> <87h65wdv0i.fsf@localhost> Autocrypt: addr=bjorn.bidar@thaodan.de; prefer-encrypt=nopreference; keydata= mDMEZNfpPhYJKwYBBAHaRw8BAQdACBEmr+0xwIIHZfIDlZmm7sa+lHHSb0g9FZrN6qE6ru60JUJq w7ZybiBCaWRhciA8Ympvcm4uYmlkYXJAdGhhb2Rhbi5kZT6IlgQTFgoAPgIbAwULCQgHAgIiAgYV CgkICwIEFgIDAQIeBwIXgBYhBFHxdut1RzAepymoq1wbdKFlHF9oBQJk1/YmAhkBAAoJEFwbdKFl HF9oB9cBAJoIIGQKXm4cpap+Flxc/EGnYl0123lcEyzuduqvlDT0AQC3OlFKm/OiqJ8IMTrzJRZ8 phFssTkSrrFXnM2jm5PYDoiTBBMWCgA7FiEEUfF263VHMB6nKairXBt0oWUcX2gFAmTX6T4CGwMF CwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQXBt0oWUcX2hbCQEAtru7kvM8hi8zo6z9ux2h K+B5xViKuo7Z8K3IXuK5ugwA+wUfKzomzdBPhfxDsqLcEziGRxoyx0Q3ld9aermBUccHtBxCasO2 cm4gQmlkYXIgPG1lQHRoYW9kYW4uZGU+iJMEExYKADsCGwMFCwkIBwICI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kph.fsf@> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a03:4000:4f:f15::1; envelope-from=bjorn.bidar@thaodan.de; helo=thaodan.de X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, INVALID_MSGID=0.568, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -2.97 X-Spam-Score: -2.97 X-Migadu-Queue-Id: 79A147D04E X-TUID: M4wpR0LtogJL --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > Bj=C3=B6rn Bidar writes: > >>> IMHO, it would be best to pass image file name/raw image data to >>> `org-link-preview-image-data', not an image object and call >>> `org--create-inline-image' from inside `org-link-preview-image-data'. >>> That way, we can automatically obey Org customization wrt image >>> alignment, image width, and image max width. >> >> For that case using org-link-preview-file should be sufficient?=20 > > Sorry, I am lost. > AFAIU, your original motivation was: > > >> Would it be possible to also handle image data in the function or > >> refactor the org-link-preview-file function in a way that the geome= try > >> handling is done in a helper function which can be reused by other > >> handlers. > > Did it change? It didn't but if the handler which would the uses a raw (temporary) file it= could have used org-link-preview-file, which essentially meant that the handler which uses org-link-preview file is a proxy for it. The thing that confused me, but I think I wasn't aware of not getting it yesterday was that org--create-inline-image creates the actual image object. I was thinking that the image object would have been created in the handler and then passed to the helper function. I think what also confused me that org--create-inline-image talks about files not image-data. Do I understand correctly that for image-data the handling of files in line 1035 is just skipped? Another that I just came to mind what is better for such a use case the use of a buffer or a variable to store the image data? Url (and eww) for ex= ample usually uses buffers. I updated my patch with the recommended changes and updated the docstring accordingly. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-link-Split-link-preview-into-two-functions.patch >From ee0d30fac48d1f3ee86a653fe537badde5e3174d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= 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 raw image according to the correct alignment and with for the link to be previewed. Passing the link can be skipped if alignment and with are given. --- lisp/ol.el | 57 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index 032610bad..ebfe926a1 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -2177,27 +2177,46 @@ (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 &optional link align width) + "Display raw image data IMAGE-DATA in overlay OV for LINK. + +If not given ALIGN and WIDTH is derived from LINK. +If LINK was not passed ALIGN and WIDTH have to be given. + +An image object is created from IMAGE-DATA to be displayed in overlay. + +This intended to be used by functions which provide the :preview link property +of links such as in `org-link-preview-file'" + (if (or (and align width) + link) + (let* ((align (or align + (org-image--align link))) + (width (or width + (org-display-inline-image--width link))) + (image-object (org--create-inline-image image-data width))) + ;; See bug#59902. We cannot rely + ;; on Emacs to update image if the file + ;; has changed. + (image-flush image-object) + (overlay-put ov 'display image-object) + (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)))))))) + (error "Either align and width or link have to be passed"))) + ;;;; "help" link type (defun org-link--open-help (path _) "Open a \"help\" type link. -- 2.45.2 --=-=-=--