From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 YEoxH0jdH2MIJAEAbAwnHQ (envelope-from ) for ; Tue, 13 Sep 2022 03:30:48 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id MHcWH0jdH2N/cwAAauVa8A (envelope-from ) for ; Tue, 13 Sep 2022 03:30:48 +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 D609C25AC1 for ; Tue, 13 Sep 2022 03:30:47 +0200 (CEST) Received: from localhost ([::1]:48988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXulC-0005fF-PW for larch@yhetil.org; Mon, 12 Sep 2022 21:30:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXujz-0005f2-3i for emacs-orgmode@gnu.org; Mon, 12 Sep 2022 21:29:31 -0400 Received: from [2409:8a28:6039:e940:52d2:f5ff:fe16:c591] (port=61957 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXujw-000885-EB for emacs-orgmode@gnu.org; Mon, 12 Sep 2022 21:29:30 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id 8C84F63406B3; Tue, 13 Sep 2022 09:29:19 +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 2] New: auto display inline images under subtree when `org-cycle'. Date: Tue, 13 Sep 2022 09:09:08 +0800 In-reply-to: <87y1uovp9w.fsf@localhost> 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 2409:8a28:6039:e940:52d2:f5ff:fe16:c591 (deferred) Received-SPF: softfail client-ip=2409:8a28:6039:e940:52d2:f5ff:fe16:c591; envelope-from=numbchild@gmail.com; helo=Mac-mini.local X-Spam_score_int: 36 X-Spam_score: 3.6 X-Spam_bar: +++ X-Spam_report: (3.6 / 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, 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: 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: , 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=1663032648; 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=JzrTEfqWOSLIKHK6hqCKB9wpW3PSvzPmfd1vtYfR174=; b=creApZNqg002ADPJ++gFhhdr0llG1w4bWO6Okgz9rlg/1ToV5yNIy/q8lpltB1UQ8VEvsi xcy9l6bKJK6bkkG3HLuz+/xHfcfyf1ZSfyoocBDD41WwfoGv0vYf7F0t3NWnGXICvh7Qbe 2qTBhCOS9vtApny7l+aiOI2b7yFD1d6b0jaC4vBpUONHAcfJvknJ5hTOFTqBWC6RE53J1w 4XZ6zibnEDOHGaqsKGL0rzEBeoz1nS4TB6lHGRLZ9cyPHm3x75HPPDMvaHXsPj3qY6bIkQ O62A0oa3qpz1zXqPi6lDNsdWv6gQlVJYXDhUsUgpaaIuwDh88nS2RL9r8vCi3g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663032648; a=rsa-sha256; cv=none; b=c3brPdTu+i2jDOXQowXw51RbrKIy1V63j/CZ4omJn6ZWTliyogOao6nL07lvMQ0LDWjZqW 0sC0JGHT95hDdW7Mwqya1fY3SW/9vZzrFhXnHYoZZTCxUOH3Bo5irLKB/BmJVf3a4jPq7S s7JKlGZdfc1kYIzFfx+le96OZJGn+B/Dx8yuItVFjWyeHbv4+x5x7lH5lS2a24LL1LljOv lpAc7wEIB4QvncokJp6FCugi+GCsnNYEBirYulkRUKCqnoRj8dU5qqhhgIsHGcqGDUwkt5 9PKKg7NnGhrHZNXUCCa5vPi1aXti0eeaHeVwzt44OVyHYIMgK1hRynWnjGvuzw== 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.79 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: D609C25AC1 X-Spam-Score: 2.79 X-Migadu-Scanner: scn1.migadu.com X-TUID: XPsgSmWVuQGd --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Ihor Radchenko writes: > "Christopher M. Miles" writes: > >> Ihor Radchenko writes: >> >>> "Christopher M. Miles" writes: >>> >>>>> When I put it on beginning of org document, then preview inline images, but those global attributes >>>>> not affected. The inline images still display in actual image size. I want to specify image size >>>>> under headline properties. Is it possible to do this? >>>> >>>> I implemented this feature by written a hook. Hope this can be helpful >>>> for someone who also has this needs. Here is the code: >>> >>> This looks useful. >>> Would you be interested to write a patch? >> >> The is the new patch which updated the defcustom variable docstring has correct description. > > Thanks for the patch! > Before extending org-cycle functionality, let's first try to sort out > subtree-level setting of the image size. This is implemented by retrieve subtree-level property value in function ~~org-display-inline-image--width~~. I submitted two separated patches. > > In the patch, you are suggesting to use INLINE-IMAGE-WIDTH property. > However, if we apply the patch as is, this property will only be useful > when calling a single function - > `org-display-subtree-with-inline-images'. > It is not ideal. The patch's purpose is auto display inline images when [TAB] (~org-cycle~) expanding heading or subtrees. Not for global ~org-toggle-inline-images~. Also, introduce a new extra argument "~state~" for ~org-display-inline-images~ like bellowing is not ideal. I think should separate the ~org-cycle~ logic instead of put in ~org-display-inline-images~. In global scope, ~org-toggle-inline-images~ already respect the updated function ~org-display-inline-image--width~, it should respect the subtree property width. #+begin_src emacs-lisp ;; V ;; ----- (defun org-display-inline-images (&optional state include-linked refresh beg end) ...) #+end_src *NOTE*: Because ~org-cycle-hook~ will pass a ~state~ variable to hook function. > > If we introduce subtree-level setting for inline image size, it should > also work when displaying inline images by other existing means > (org-toggle-inline-images). This is implemented by retrieve subtree-level property value in function ~~org-display-inline-image--width~~. > > Instead of working around the existing code of > `org-display-inline-images' and setting a custom > `org-image-actual-width' variable in buffer, it is much better to change > `org-display-inline-images' directly. At the end, the patch is not bound > to your personal config - feel free to alter the existing Org functions. This is implemented by retrieve subtree-level property value in function ~~org-display-inline-image--width~~. > > Similarly, you do not need to do > (add-to-list 'org-default-properties "INLINE-IMAGE-WIDTH") > Simply change the default value of `org-default-properties'. Updated > > Finally, it will be more consistent to name the property closer to the > variable name: ORG-IMAGE-ACTUAL-WIDTH. Updated --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Support-subtree-level-image-width-specificati.patch Content-Transfer-Encoding: quoted-printable Content-Description: subtree-level property width support From=20cc322145c2248e95bc76fee7e6d33f575d93e79f 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 6e6c437d5..70333c609 100644 =2D-- a/lisp/org.el +++ b/lisp/org.el @@ -12199,7 +12199,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 @@ -16241,14 +16242,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 Content-Description: org-cycle-hook function support From=2098babf12b2d9dbc38250186e0284fad6d937e3f3 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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 70333c609..30716c04e 100644 =2D-- a/lisp/org.el +++ b/lisp/org.el @@ -1108,6 +1108,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 @@ -16216,6 +16223,38 @@ 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 + (org-narrow-to-subtree) + (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----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmMf3OsACgkQG13xyVro msPELwf/dffE9jH20vMKWLTeSnY9fA/gA86ZEjiqGQITTy5pDdtXkyirwb61BRAq 5T3dOjwB38XGzMCY88sYHYjJeMhfSYJsYfLSndd5iD3aDGXGbxLyetyvqJV07dvZ taMaYxA7/NEKzTyui6IncCJFJHlX1CxwTh34aVOV4yU32yrQGJdW3Hlc/tDA9If5 BgmdG5PbelpUZCQsjq2uakVls8fRT28Oy3AoLOmkqbLrFPmkLBjQDOrzooNALaNw z9PJ3utX70A/gzhvsbIhMp1bXbYZ11brItI7566zTs/IytjytplHc8L01PvCbKdm Isp1C+XS+48oSmmiuEYIDVI1rGFAPg== =NVwo -----END PGP SIGNATURE----- --==-=-=--