From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.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 uBZYM5wHkGe2JgAA62LTzQ:P1 (envelope-from ) for ; Tue, 21 Jan 2025 20:46:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id uBZYM5wHkGe2JgAA62LTzQ (envelope-from ) for ; Tue, 21 Jan 2025 21:46:20 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=thaodan.de header.s=mail header.b="ViHGB/Tm"; 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=1737492379; 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=opB0G8CR5GWfsgMxEqkCGfI/s6MZ3kj4gnMnbWbQwLQ=; b=Jwsfgzx/NGEDCZboErK2sYopiq6dSQaUM/iN4ly/NrZzSa3feR/J9sU+DW+Y+488a7+jYI m+X/rFb//lZ24dMvC5CeKxUXVMXN3Hz0+Ji/d1XY5lzCjEVMiMLUw5+7ntSBs9JwSaSznj J65DZOrmxXWT9Y69JOqBazBAayRjp+OEKo9bAbimH0EoLSmBCqt8VghEKzn/vhMMI9OOEl g3gqSmTDW9NNTeR+JwSc0Yse3ZAQ0wQK92cjNFz5iM27JnidWYjDqVHok9A7+JLxbSYYM7 o7ASYEZ415a4JvkuDD6Xbs32lmggmZF26vUojAzEF7PdzSlkRRDhq5c2FFOEiA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=thaodan.de header.s=mail header.b="ViHGB/Tm"; 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=1737492379; a=rsa-sha256; cv=none; b=JsZZFVwF4GkrzttOtXfxP6tijWqfc/YgvgXMP4jxjonQX08S8fFyiin4gQcaMyL6xHRK9h wKId0ewiJEFzzXOzYYtqqM3oWLcgGY8o1hOw/VC5StBL6z+Tu8snG1mz5cQHZvEteGwDkS OftcbD1FN9q1YWMu0wlHLCIQ9M4PFI9nZnA1ZUqxzKTNASTVW8SeYZrSq8s54aKAX0ZPjf yBBSNfgSPaJbgJ54r28j2SMFpWokDepckA35g35UQKyfQdeMlEKueCc08pigRnMOsxtu4v /iDZA9d2lPwFsk+y9Fl4xOXGR+3WDmwqfTEsqVlKJikwjtuSN/rxQArf4d9Sgw== 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 A70F082D02 for ; Tue, 21 Jan 2025 21:46:19 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1taL7t-0008LL-Tc; Tue, 21 Jan 2025 15:45:34 -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 1taL7p-0008GP-4g for emacs-orgmode@gnu.org; Tue, 21 Jan 2025 15:45:29 -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 1taL7i-0005YC-Ox for emacs-orgmode@gnu.org; Tue, 21 Jan 2025 15:45:28 -0500 Received: from odin (dsl-trebng12-50dc7b-49.dhcp.inet.fi [80.220.123.49]) by thaodan.de (Postfix) with ESMTPSA id AE7A6D00043; Tue, 21 Jan 2025 22:45:17 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thaodan.de; s=mail; t=1737492317; bh=VjnAI1FeJs+wfPDacgL9VT6UEb02bovFh7gMo2TkWX0=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=ViHGB/TmJi4FGX8jctG4a7EnHL24FhgvXKWsz952UTGjVV0fWFoLBYHiPq/sHg25y 3s7CmEGiZfT1CigBHxfQDWBB2iq0y79E6VhKak8U+NP9FhAicQ3tTEvXbpvE3UJLAr GlXgaI5h2dMUzn25GkNXxY3R93wfDeF/eRBzuRVejFNJfGsF/7IDCm2OeAPxVEP8HZ U09VLNlaDYdIwWZ7/Nrb8iGQVdkTwFWR1MwU/dXvP8UTn/MfIP0svvNH465i5lr2GR vABVHMxq4xgymQxA0/TiLa8d9DCIuYdUGCLMY2gZvSEYGL2F2NVMJr18viOsa5Xq3l eYaJzyfo9Pb28tyNdsjNReIQAqLTB2NBuQYBJMW6pOPOfE1EPNYXBwF4+yQ4STN2Vz fn0Th56xxeig2djfOiSq3sPFesIhCL2Z7gwardLTXWPNKTr6R2Fr16v7DFis3x4Q/B 2bM2MT0fN5NRQEJmTcLja0EJqZ4ZCYAjOy/aK0mmGu7a3Zb8p5PgDfnZF6/eeHMfE+ gkeDjUC3kI5mPeL4oB42BVvn3IZnaLwPWz2+Kep3x3wItC6Nw+Lqbq8IQQWBgLf9Jh piELSjI1tLcSKI3qAfnSK/6mcuASobljfjnKR5pKtGdM+beGxStG6M+4vb1J4R253W gl0G3/BDagfDrMiFC+u8xgyg= 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: <87cyggq8eg.fsf@localhost> (Ihor Radchenko's message of "Tue, 21 Jan 2025 19:22:31 +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> <87cyggq8eg.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 cm4gQmlkYXIgPG1lQH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Tue, 21 Jan 2025 22:45:16 +0200 Message-ID: <877c6nuc9v.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.95 X-Spam-Score: -2.95 X-Migadu-Queue-Id: A70F082D02 X-TUID: 5z/mqOpc78fp --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > Bj=C3=B6rn Bidar writes: > >> 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. > > Feel free to improve the docstring. > I do agree that it may be confusing. create-image uses the term file-or-data instead of file would that be bette= r? >> 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? > > May you please elaborate? I do not quite get your question (or maybe > have something else on that line number). I'm talking about the pcase, if the image is data the pcase largely doesn't apply. >> 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= example >> usually uses buffers. > > I do not think that there is much difference. Unless we have a huge numbe= r of images (in which case we may create performance problems by > increasing the number of buffers - some Emacs operations scale with the > number of buffers). > ok >> +(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 ALIGN and/or WIDTH are not given, they are derived from LINK object > (ast node). > >> +If LINK was not passed ALIGN and WIDTH have to be given. > > If LINK is nil, ... > I fixed the docstrings and move the require image to the helper function. > Also, we need to explain the possible values of ALIGN and WIDTH. > Maybe even provide some defaults (maybe even via cl-defun) Would it make sense to provide defaults for ALIGN and WIDTH when they have to be supplied or be derived from link? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-link-Split-link-preview-into-two-functions.patch >From 51d94bf20b043be635af3719464dccd0cc589f93 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 | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/lisp/ol.el b/lisp/ol.el index 43fac7433..0429e257c 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -2178,23 +2178,39 @@ (defun org-link-preview-file (ov path link) This is intended to be used as the `:preview' link property of file links, see `org-link-parameters'." - (when (display-graphic-p) - (require 'image) (when-let* ((file-full (expand-file-name path)) (file (substitute-in-file-name file-full)) ((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 + (org-link-preview-image-data ov file link))) + +(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 ALIGN and/or WIDTH are not given, they are derived from LINK object +\(ast node\). +If LINK is nil, 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) + (when (display-graphic-p) + (require 'image) + (when-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) - (overlay-put ov 'display image) - (overlay-put ov 'face 'default) - (overlay-put ov 'keymap image-map) + (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 @@ -2202,9 +2218,9 @@ (defun org-link-preview-file (ov path link) " " 'face 'default 'display (pcase align - ("center" `(space :align-to (- center (0.5 . ,image)))) - ("right" `(space :align-to (- right ,image))))))) - t))))) + ("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 _) -- 2.45.2 --=-=-=--