From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id aI6ALhUn02aD4gAA62LTzQ:P1 (envelope-from ) for ; Sat, 31 Aug 2024 14:22:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id aI6ALhUn02aD4gAA62LTzQ (envelope-from ) for ; Sat, 31 Aug 2024 16:22:13 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=CdzWxnL3; 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=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1725114133; 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; bh=IRL3qvFSftoknt8oQyJmK5kvIdZfj/LWK37oEvOhkJA=; b=a/+zDGun8suF2m54IMC6Ip9tNjVJUOoj2/YmOh+fIoB3p4nzJ6w+2iX5a/blyrQkrU24zC V+EzdWgblLu5vQTeBpf6ziofkOUbV5NgiRp27JI8Lxr1Qb0LKjXXJwQt8OcEKeUx54l7eM yIXgk8A7kltuEYq3XxW/tygdFRR/tSA1BAgDPgKnJXXZbliatbSOEhsaesjYVDitFfrmC4 cUebp0tlrlOoJyVBtMTI/7CR183WY5FsxphVJbrgthEv3Q1Fa8T/0ZcIWiuxB9VkBc0KEn 7D0g+Cn9aunoLEDULY7qiN6LvQCqhFqj0MLXq7sqlzme5dT1wotbD4L0TYGYCw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=CdzWxnL3; 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=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1725114133; a=rsa-sha256; cv=none; b=L3Q2IzFPHAwrJ6+yqJMMPrTrj7/qKDVGxotzsIGucPY20Yec5FCoaMMueqeKntq8VDCx9t N0p+sW66OMumVSUxWtMsN2npJSFie7mCPpwmDdGK761VjVP65le1RnVYYPYfnTPa6XdraJ R2Gt9Z8wUze+fanPTsi3BUoNQ+ao5v0bu5YBTHR2B8Z7zevwab0r8QErumcxWqrtS85Gj8 HsSpuWUhj3wtHoESoWeAre80fXRbVEN1oma6xXGZn4LOE5ZgRGdPoDuy+jd34koeB1gKGA KVMhhY6MQsMhuHoDyNLgIrRtR7depWkRUNZm+pw3ZEjBroJiuK18Bjf/tSi2dQ== 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 8D65E68D32 for ; Sat, 31 Aug 2024 16:22:13 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1skOyi-0004aw-O6; Sat, 31 Aug 2024 10:21:24 -0400 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 1skOyg-0004aj-MB for emacs-orgmode@gnu.org; Sat, 31 Aug 2024 10:21:23 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1skOyd-0000O5-Ot for emacs-orgmode@gnu.org; Sat, 31 Aug 2024 10:21:22 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id D48C6240103 for ; Sat, 31 Aug 2024 16:21:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725114077; bh=jfSsKefB8yzw+gS6J14mhiDAOlJVxLdONEghgSQ0ZUM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=CdzWxnL363DNJK2O1MytFQYhAcwmsf0USKfjHgYnP57OMIbp3qfhIj9wd9b2z7hse CcHKXeVNchlCeBShy/xx1GPkfO789CsZkax33LaDxkDviG4I0P5W5CLHZOxbCDIzU5 Zymq2InyJH2XddyJ0uD1RJhxgf1UXe6ItElLgPuEE92jKxf39W/evS+aaLKpSJBNl0 YJ6WfjgMMQMup3viEocFtx89LCnD9Sw3zOrCpyZoRtyzJxenOhBu92XWsggVhW+zLf cEKjhEyj8iIGtqbTMy2cISz9mkQB7/oTdmK4GoBzt60Ggr3pu5UqBxtPof3adxQbs1 lMFZnZD/gbpkw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Wwxyh6Fhxz9rxF; Sat, 31 Aug 2024 16:21:16 +0200 (CEST) From: Ihor Radchenko To: Karthik Chikmagalur Cc: stardiviner , Org mode Subject: Re: [PATCH v1] Inline image display as part of a new org-link-preview system In-Reply-To: <875xrqg6cb.fsf@gmail.com> References: <6461a84b.a70a0220.b6d36.5d00@mx.google.com> <646379fc.620a0220.c0ae4.9fb2@mx.google.com> <87zg3l1rgb.fsf@localhost> <64c8a313.a70a0220.93ee0.14fb@mx.google.com> <87il9zgpdp.fsf@localhost> <64c905d7.170a0220.f434a.fddb@mx.google.com> <87o7jpoqfl.fsf@localhost> <64cc9b8a.170a0220.dfa99.2e18@mx.google.com> <87msz7kym0.fsf@localhost> <669882e5.050a0220.8ff6d.33c6@mx.google.com> <871q3logb9.fsf@localhost> <66a8b73b.170a0220.383476.996e@mx.google.com> <87o75yhwnu.fsf@localhost> <87v7zyyvm3.fsf@localhost> <87frr07xz8.fsf@gmail.com> <87cym38aj8.fsf@gmail.com> <87r0ajawgj.fsf@localhost> <87a5h77zb1.fsf@gmail.com> <87msl4wv8d.fsf@localhost> <875xrqg6cb.fsf@gmail.com> Date: Sat, 31 Aug 2024 14:22:42 +0000 Message-ID: <874j70n559.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 8D65E68D32 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -9.71 X-Spam-Score: -9.71 X-TUID: L+sWuY5+Xp7k Karthik Chikmagalur writes: >> Spin out will be easier when for my rebase :) > > Please find attached the draft of a patch implementing a general > link-preview system. Thanks! > Not yet handled or final: > > - Link abbreviations: I'm using org-link-any-re to find links, and this > appears to be handling link abbreviations fine. So there is no > special code to handle link abbreviations. But I'm not sure. > - The calling convention for the :preview function is not final. Right > now it is given the overlay, the link type and the link path. But > other link details can be required -- for example, image links need to > read the org keywords for the image width and alignment, so I end up > calling (org-element-context) again inside the :preview function. We may simply pass the link object to :preview function. > Subject: [PATCH 2/2] org-link: Move inline image display to org-link Is there [PATCH 1/2]? > * lisp/org-keys.el: Bind `C-c C-x C-v' to new command > `org-link-preview', which has the same prefix arg behaviors as > `org-latex-preview'. Didn't we discuss changes to the behavior? > +`:preview' > + > + Function to run when generating an in-buffer preview for the > + link. It must accept three arguments: > + - an overlay placed from the start to the end of the link. > + - the link type, as a string. > + - the path, as a string. Maybe we can ask the function to return non-nil when the preview is going to happen. The current approach with "overlay deleted then no preview" is not ideal. > +(defun org-link-preview--get-overlays (&optional beg end) > + "Return link preview overlays between BEG and END." > + (let* ((beg (or beg (point-min))) > + (end (or end (point-max))) > + (overlays (overlays-in beg end)) > + result) > + (dolist (ov overlays result) > + (when (memq ov org-link-preview-overlays) > + (push ov result))))) I know that this is a copy-paste, but we may utilize 'org-image-overlay + `org-find-overlays' here. > +(defun org-link-preview--remove-overlay (ov after _beg _end &optional _len) > + "Remove link-preview overlay OV if a corresponding region is modified. > + > +AFTER is true when this function is called post-change." > + (when (and ov after) > + (setq org-link-preview-overlays (delete ov org-link-preview-overlays)) > + ;; Clear image from cache to avoid image not updating upon > + ;; changing on disk. See Emacs bug#59902. > + (when (overlay-get ov 'org-image-overlay) > + (image-flush (overlay-get ov 'display))) > + (delete-overlay ov))) It implies that every :preview function _must_ put an image as 'display property. If it does not, we will run into errors. But should it? Also, when if preview is asynchronous, and we run this function when the image is not yet assigned to the overlay? > + (cond > + ((not (display-graphic-p)) > + (message "Your Emacs does not support displaying images!")) May some third-party previews not require graphic? > +(defun org-link-preview-clear (&optional beg end) > + "Clear link previews in region BEG to END." > + (interactive (and (use-region-p) (list (region-beginning) (region-end)))) > + (let* ((beg (or beg (point-min))) > + (end (or end (point-max))) > + (overlays (overlays-in beg end))) > + (dolist (ov overlays) > + (when (memq ov org-link-preview-overlays) > + (when-let ((image (overlay-get ov 'display)) > + ((imagep image))) > + (image-flush image)) > + (setq org-link-preview-overlays (delq ov org-link-preview-overlays)) > + (delete-overlay ov))) In asynchronous previews, some overlays may be deleted already. We should be careful with this. > +(defun org-link-preview-file (ov linktype path) > + "Display image file PATH in overlay OV. > + > +LINKTYPE is the Org link type used to preview PATH, either > +\"file\" or \"attachment\". > + > +Equip each image with the keymap `image-map'. > + > +This is intended to be used as the `:preview' link property of > +file links, see `org-link-parameters'." > + (if-let ((file-full > + (if (equal "attachment" linktype) > + (progn > + (require 'org-attach) > + (ignore-errors (org-attach-expand path))) > + (expand-file-name path))) I'd rather put this part into org-attach, as a separate function that calls `org-link-preview-file'. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at