From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id MOAOE+PhH2NydQEAbAwnHQ (envelope-from ) for ; Tue, 13 Sep 2022 03:50:27 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id yJArEuPhH2MorgAAG6o9tA (envelope-from ) for ; Tue, 13 Sep 2022 03:50:27 +0200 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 D0E1226385 for ; Tue, 13 Sep 2022 03:50:26 +0200 (CEST) Received: from localhost ([::1]:57870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXv4C-0004zI-IP for larch@yhetil.org; Mon, 12 Sep 2022 21:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXv3n-0004yw-D9 for emacs-orgmode@gnu.org; Mon, 12 Sep 2022 21:49:59 -0400 Received: from [39.171.215.24] (port=6084 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXv3k-0002oC-Qq for emacs-orgmode@gnu.org; Mon, 12 Sep 2022 21:49:59 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id 27D39634128D; Tue, 13 Sep 2022 09:49:44 +0800 (CST) References: <631d472b.c80a0220.2b4b2.bf86SMTPIN_ADDED_BROKEN@mx.google.com> <87h71ew0m0.fsf@localhost> <631e92ee.050a0220.f9c18.92f5SMTPIN_ADDED_BROKEN@mx.google.com> <87y1uovp9w.fsf@localhost> User-agent: mu4e 1.8.9; emacs 29.0.50 From: "Christopher M. Miles" To: Ihor Radchenko Cc: "Christopher M. Miles" , emacs-orgmode@gnu.org Subject: [PATCH 3] New: auto display inline images under subtree when `org-cycle'. Date: Tue, 13 Sep 2022 09:48:00 +0800 In-reply-to: Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Host-Lookup-Failed: Reverse DNS lookup failed for 39.171.215.24 (deferred) Received-SPF: softfail client-ip=39.171.215.24; envelope-from=numbchild@gmail.com; helo=Mac-mini.local X-Spam_score_int: 69 X-Spam_score: 6.9 X-Spam_bar: ++++++ X-Spam_report: (6.9 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FROM=0.001, MSGID_MULTIPLE_AT=1, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_PBL=3.335, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, SPOOFED_FREEMAIL_NO_RDNS=1.119, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: reject 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: , Reply-To: numbchild@gmail.com Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1663033826; h=from:from:sender:sender:reply-to: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; bh=zsRdOdhQ3RNZs5zmjdC4fcIOE+TiJzfHVQndRsCt5J0=; b=onLVqHWz4tXxLs4U9CtHjJeATvWydehTjpYdrjishAD++yD4JFL2d5il8G/VothPMSkKFU 4/Kc3d2+CESeStv1kyljSeMmhn6LkljYI1JRTxG46+3rlKbJN13VamviwA2ApZ3lDOmYUP 4ooiejTULSopjdbuFoWmZnOwdppCNkDZ1724AMCKHEVRKIAJ2xeYIoSjxnQJZ3LOH7RBlk 1iXyB7hs/ulNfAGhUJSa6BYM/20MMLegUWKOt8ZstZK3lj5S8iwMhnPvuIH1lu2pdW/fBR 3qQqZOKx4MzACSOX8stCY06ynqhI3qE7EFB7qN74jc3CyXk4y9ygez474btFew== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663033826; a=rsa-sha256; cv=none; b=c/VXthlPxg1spfCgB1948KxQEIKPmQJWBdug+wVj/bzRtdZ9+wEQhxbvzGrg9dyYBcDrgx DaqPVbKY67Namzm1ExUlUGv1wBJNDa0TqNIBXUJi326FEjs9DXVw7zPXOAjMD/Q7KTA6Ni KkjWi6XBoiQl3KFXVYwL+dU0DuT2RhAYKzYCOhDZWgMoTyvL9SMKeKw9j/rY/n3E2fGHMi FFuzgsdUYKH9i/gDhd+2hRmTbUZMqcY4evbYBAo4h1o3GRxuWlcMAZf2K45SSIw0HDpyac YldESVpxcbOXmOBYjDM0oPXV7NHmEyTxIzsvzVPR7jSMiTyOeyXV8n1Hm2t5mg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 2.80 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: D0E1226385 X-Spam-Score: 2.80 X-Migadu-Scanner: scn1.migadu.com X-TUID: vPUs99Rs5mmy --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain "Christopher M. Miles" writes: Ihor, My new patch still have some issue in the 'fold state which I added "FIXME" marker. Hope can get some solution from you. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Support-subtree-level-image-width-specificati.patch Content-Transfer-Encoding: quoted-printable From=204a56ec6b09e09d92a81e3aa72f4197d716d0ca87 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Mon, 12 Sep 2022 09:45:09 +0800 Subject: [PATCH 1/2] org.el: Support subtree-level image width specification * lisp/org.el (org-display-inline-image--width): Detect subtree-level property "ORG-IMAGE-ACTUAL-WIDTH" value as image width before fallback. =2D-- lisp/org.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 4eef56f45..07c86229b 100644 =2D-- a/lisp/org.el +++ b/lisp/org.el @@ -12128,7 +12128,8 @@ but in some other way.") "EXPORT_OPTIONS" "EXPORT_TEXT" "EXPORT_FILE_NAME" "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE" "UNNUMBERED" "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STAT= E" =2D "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS") + "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS" + "ORG-IMAGE-ACTUAL-WIDTH") "Some properties that are used by Org mode for various purposes. Being in this list makes sure that they are offered for completion.") =20 @@ -16164,14 +16165,19 @@ buffer boundaries with possible narrowing." (org-element-property :begin par) (re-search-forward attr-re par-end t))) (match-string 1))) + ;; support subtree-level property "ORG-IMAGE-ACTUAL-WIDTH" spec= ified width. + (subtree-property-width + (ignore-errors (org-property-or-variable-value 'ORG-IMAGE-ACTU= AL-WIDTH))) (width (cond ;; Treat :width t as if `org-image-actual-width' were t. ((string=3D attr-width "t") nil) =2D ;; Fallback to `org-image-actual-width' if no interprable w= idth is given. ((or (null attr-width) (string-match-p "\\`[^0-9]" attr-width)) =2D (car org-image-actual-width)) + ;; Try to use subtree-level width before fallback. + (or subtree-property-width + ;; Fallback to `org-image-actual-width' if no interprabl= e width is given. + (car org-image-actual-width))) ;; Convert numeric widths to numbers, converting percentages. ((string-match-p "\\`[0-9.]+%" attr-width) (/ (string-to-number attr-width) 100.0)) =2D-=20 2.37.2 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-org.el-Add-hook-function-to-auto-display-inline-imag.patch Content-Transfer-Encoding: quoted-printable From=202fc76c4581b60c6631186bfdc489732075432c26 Mon Sep 17 00:00:00 2001 From: stardiviner Date: Tue, 13 Sep 2022 09:04:03 +0800 Subject: [PATCH 2/2] org.el: Add hook function to auto display inline images of subtree * lisp/org.el (org-display-subtree-with-inline-images): Add an option and hook function to auto display of inline images under current expanded visible subtree. =2D-- lisp/org.el | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 07c86229b..0bd942e07 100644 =2D-- a/lisp/org.el +++ b/lisp/org.el @@ -1104,6 +1104,13 @@ the following lines anywhere in the buffer: :version "24.1" :type 'boolean) =20 +(defcustom org-cycle-display-inline-images nil + "Non-nil means auto display inline images under subtree when `org-cycle' +by the function `org-display-subtree-with-inline-images' on hook `org-cycl= e-hook'." + :group 'org-startup + :version "24.1" + :type 'boolean) + (defcustom org-startup-with-latex-preview nil "Non-nil means preview LaTeX fragments when loading a new Org file. =20 @@ -16139,6 +16146,42 @@ buffer boundaries with possible narrowing." (overlay-put ov 'keymap image-map)) (push ov org-inline-image-overlays)))))))))))))))) =20 +(defun org-display-subtree-inline-images (&optional state) + "Toggle the display of inline images under current expanded visible subt= ree. +This hook function will auto display or hide inline images after `org-cycl= e'. +It is used to hook on `org-cycle-hook'. +The function behavior is controlled by `org-cycle-display-inline-images'." + (interactive) + (when (and org-cycle-display-inline-images + ;; not global state change from `org-cycle-global'. + (not (memq state '(overview contents all)))) + (pcase state + ('children + (save-excursion + (save-restriction + (org-narrow-to-subtree) + ;; If has nested headlines, beg,end only from parent headling + ;; to first child headline which reference to upper let-binding + ;; `org-next-visible-heading'. + (org-display-inline-images t t (point-min) (progn (org-next-vis= ible-heading 1) (point)))))) + ('subtree + (save-excursion + (save-restriction + (org-narrow-to-subtree) + ;; If has nested headlines, also display inline images under al= l subtrees. + (org-display-inline-images t t (point-min) (point-max))))) + ('folded + ;; (save-excursion + ;; (save-restriction + ;; (org-narrow-to-subtree) + ;; ;; FIXME: this will auto expand heading caused `org-cycle' f= olded failed. + ;; (mapc #'delete-overlay (overlays-in (point-min) (point-max))= ))) + ) + ('nil (funcall 'org-toggle-inline-images)) + (t nil)))) + +(add-hook 'org-cycle-hook #'org-display-subtree-inline-images) + (defvar visual-fill-column-width) ; Silence compiler warning (defun org-display-inline-image--width (link) "Determine the display width of the image LINK, in pixels. =2D-=20 2.37.2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 [ stardiviner ] I try to make every word tell the meaning that I want to express without mi= sunderstanding. Blog: https://stardiviner.github.io/ IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmMf4bgACgkQG13xyVro msNTigf/RejJ6hsRqQ72qi4m5ImXz3MiYTJX4IdjwxZoxsbivZ5Weqfd+qAzhsMg ZXcO8nWBYjHUoVCP1ke/VFvFl87/AlE+GEx0uz/UHo1QKbKS4TrNvKuWxOVzpIFg PidixapLOSjrYuZlcRH0JSEcRZOHmS6UWkvWJ98NPSfy1MbUR7FfYbKb/vrlC1Jy miNkNksJVNwAGQLKbGNGcJ7a/7Q2TIMH7o58oiAOX3+JFXewwp11ZNKu6NlBdjwh R5YcFl8bZ3JEZnTOEYfUp0v637KvWLITnGus9s6mZIPgtvK5p/pPlLr+J+2DkrMq T8+adUyCoMtEAfFHm0kp3yisFhue0g== =89MP -----END PGP SIGNATURE----- --==-=-=--