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 iFPiHt+wImOsRgEAbAwnHQ (envelope-from ) for ; Thu, 15 Sep 2022 06:58:07 +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 0A8VH9+wImOzSQAAauVa8A (envelope-from ) for ; Thu, 15 Sep 2022 06:58:07 +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 DB3971C2DF for ; Thu, 15 Sep 2022 06:58:06 +0200 (CEST) Received: from localhost ([::1]:44764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYgwv-0004en-Nu for larch@yhetil.org; Thu, 15 Sep 2022 00:58:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYgw0-0004ec-Np for emacs-orgmode@gnu.org; Thu, 15 Sep 2022 00:57:08 -0400 Received: from [2409:8a28:6039:e940:52d2:f5ff:fe16:c591] (port=62124 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYgvx-0005Q3-Ei for emacs-orgmode@gnu.org; Thu, 15 Sep 2022 00:57:08 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id E40C5643706B; Thu, 15 Sep 2022 12:56:54 +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> <631fe1c9.050a0220.3ab2b.3f52SMTPIN_ADDED_BROKEN@mx.google.com> <87bkrhwc42.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 4] New: auto display inline images under subtree when `org-cycle'. Date: Thu, 15 Sep 2022 12:53:06 +0800 In-reply-to: <87bkrhwc42.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=1663217887; 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=q1+Eeas4n83HctU0pXQTFe2XoUbHvq44GaJUcNNyWao=; b=M0fCoGzw3c4rnf0+u6nuCMpq2ABQIZcG/INjku7G2ZnhB3A9zgKr7FkeIrEOEKVSol1ZGp 1w2swpypPFcVdl8/+sbncDtSsHFDN4mKsxz7j8kV8srP8MAFjFGFsRC3W/GnvAdGOaelcR tTCkIOh/7eKv07VLyp7IhnRP7Cco4tCQJEQmt08t6mYlkDyvNHAWoZxPVU+2MQT8M//zig hrFU7GQaxB7kj80hPNbDmiuQzmn+x4CHl2RGrrbKFPQ59ctw0z6KZLAR8nwDTVvK11USDD b2dPB+UGr9mQYLSIZSEd+Xdbp0JQmKtKyQT0c0rEZdOJ3mC/a7R5bnfVCjd5jA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663217887; a=rsa-sha256; cv=none; b=QyWLuvfTb5tdUHmiUw+4q+aUGQwBJqpJagfsWjEcGVYWDSJFHZ3VnMX4YH+VBYU1BxOtTY DEq1aw11sDv9JA6JHeXEs1M9gKkG2beyx8yWgA3x80sSvBw0IgL+MyDn6k6rzuhR09Pnv0 NAxHVwk5qcer//8d9Ktm42NhxaircKexw1Np//RH5jd0ujDK4z4GCaBi1PJ0L1mZ2FdVfZ DIOlX2YIiCy9gEzx4LhCMyw8hiKuyk45//Mi+eu4AOBlbYtMqfSW4FwtMVYj4TlYEuJ3Xd C6xmg2cYmEuq0bOSlFOTtcoh0oi3jY54O9sBnh85GL1EQlSNckTQt70C6kyTPg== 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: 1.78 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: DB3971C2DF X-Spam-Score: 1.78 X-Migadu-Scanner: scn1.migadu.com X-TUID: R8cVYJwceeUQ --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Ihor Radchenko writes: > "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. > > I will comment only on the first patch for now. > >> "EXPORT_OPTIONS" "EXPORT_TEXT" "EXPORT_FILE_NAME" >> "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE" "UNNUMBERED" >> "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_S= TATE" >> - "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS") >> + "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS" >> + "ORG-IMAGE-ACTUAL-WIDTH") > > This change should also be mentioned in the commit message. Done > >> @@ -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" s= pecified width. >> + (subtree-property-width >> + (ignore-errors (org-property-or-variable-value 'ORG-IMAGE-A= CTUAL-WIDTH))) > > You are checking the property too late. I suggest to let-bind > org-image-actual-width around the whole `cond' instead. > > That way, subtree-local value of ORG-IMAGE-ACTUAL-WIDTH will have an > effect of setting `org-image-actual-width' value. Done > > Also, is there any particular reason why you wrap > `org-property-or-variable-value' into `ignore-errors'? Remove, I originally use another property keyword instead of ORG-IMAGE-ACTUAL-WIDTH, so ~org-property-or-variable-value~ will raise error if property does not exist. SO I added ~ignore-errors~. Now removed. > > Finally, you can simply do > > (org-property-or-variable-value 'org-image-actual-width)=20 > > It will return the property value _or_ org-image-actual-width value. > Done >> - (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 interpr= able width is given. >> + (car org-image-actual-width))) > > With my last suggestion, this code will not be needed. Done > > Also, this change should be documented in etc/NEWS and also in > "12.7 Images" section of the manual. Done. (the manual, you mean org-manual.org right? I found too many documents under doc/ folder, confused for a while....) P.S: I merged two commits into one for clear. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Add-hook-function-to-auto-display-inline-imag.patch Content-Transfer-Encoding: quoted-printable From=204ba9bb3063bde50511457b1d30f1299a85e3ffaf Mon Sep 17 00:00:00 2001 From: stardiviner Date: Mon, 12 Sep 2022 09:45:09 +0800 Subject: [PATCH] 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. * lisp/org.el (org-display-inline-image--width): support subtree-level property "ORG-IMAGE-ACTUAL-WIDTH" specified width. * lisp/org.el (org-default-properties): Add a new property in to override global org-image-actual-width subtree level. =2D-- doc/org-manual.org | 5 ++ etc/ORG-NEWS | 5 ++ lisp/org.el | 133 ++++++++++++++++++++++++++++++--------------- 3 files changed, 100 insertions(+), 43 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index a37b8390c..77274e250 100644 =2D-- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -11314,6 +11314,11 @@ command: startup by configuring the variable ~org-startup-with-inline-images~[fn:119]. =20 +If you want to override global variable ~org-image-actual-width~ of +inline image display width, you can specify property +"=3DORG-IMAGE-ACTUAL-WIDTH=3D" in subtree level. It will only affect +inline images under the specified subtree. + ** Captions :PROPERTIES: :DESCRIPTION: Describe tables, images... diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a7f32671e..42e7e4292 100644 =2D-- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -296,6 +296,11 @@ headings in HTML export. Use the header argument =3D:var x=3Dcode-block[]=3D or : #+CALL: fn(x=3Dcode-block[]) to pass the contents of a named code block as a string argument. +*** New default property =3DORG-IMAGE-ACTUAL-WIDTH=3D for overriding globa= l ~org-image-actual-width~ + +The subtree-level property "ORG-IMAGE-ACTUAL-WIDTH" can override the +global variable ~org-image-actual-width~ settings for inline images +width under current property specified subtree. =20 ** New options *** New custom settings =3Dorg-icalendar-scheduled-summary-prefix=3D and = =3Dorg-icalendar-deadline-summary-prefix=3D diff --git a/lisp/org.el b/lisp/org.el index 6e6c437d5..98cac1c1c 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 @@ -12199,7 +12206,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 @@ -16215,6 +16223,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)) + (_ 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. @@ -16228,48 +16272,51 @@ buffer boundaries with possible narrowing." If the value is a float between 0 and 2, it interpreted as that proporti= on of the text width in the buffer." ;; Apply `org-image-actual-width' specifications. =2D (cond =2D ((eq org-image-actual-width t) nil) =2D ((listp org-image-actual-width) =2D (let* ((case-fold-search t) =2D (par (org-element-lineage link '(paragraph))) =2D (attr-re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)") =2D (par-end (org-element-property :post-affiliated par)) =2D ;; Try to find an attribute providing a :width. =2D (attr-width =2D (when (and par (org-with-point-at =2D (org-element-property :begin par) =2D (re-search-forward attr-re par-end t))) =2D (match-string 1))) =2D (width =2D (cond =2D ;; Treat :width t as if `org-image-actual-width' were t. =2D ((string=3D attr-width "t") nil) =2D ;; Fallback to `org-image-actual-width' if no interprable w= idth is given. =2D ((or (null attr-width) =2D (string-match-p "\\`[^0-9]" attr-width)) =2D (car org-image-actual-width)) =2D ;; Convert numeric widths to numbers, converting percentage= s. =2D ((string-match-p "\\`[0-9.]+%" attr-width) =2D (/ (string-to-number attr-width) 100.0)) =2D (t (string-to-number attr-width))))) =2D (if (and (floatp width) (<=3D 0.0 width 2.0)) =2D ;; A float in [0,2] should be interpereted as this portion of =2D ;; the text width in the window. This works well with cases l= ike =2D ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width, =2D ;; as the "0.X" is pulled out as a float. We use 2 as the upp= er =2D ;; bound as cases such as 1.2\linewidth are feasible. =2D (round (* width =2D (window-pixel-width) =2D (/ (or (and (bound-and-true-p visual-fill-column-mod= e) =2D (or visual-fill-column-width auto-fill-f= unction)) =2D (when auto-fill-function fill-column) =2D (- (window-text-width) (line-number-display-w= idth))) =2D (float (window-total-width))))) =2D width))) =2D ((numberp org-image-actual-width) =2D org-image-actual-width) =2D (t nil))) + ;; support subtree-level property "ORG-IMAGE-ACTUAL-WIDTH" specified wid= th. + (let ((org-image-actual-width (org-property-or-variable-value 'org-image= -actual-width))) + (cond + ((eq org-image-actual-width t) nil) + ((listp org-image-actual-width) + (let* ((case-fold-search t) + (par (org-element-lineage link '(paragraph))) + (attr-re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)") + (par-end (org-element-property :post-affiliated par)) + ;; Try to find an attribute providing a :width. + (attr-width + (when (and par (org-with-point-at + (org-element-property :begin par) + (re-search-forward attr-re par-end t))) + (match-string 1))) + (width + (cond + ;; Treat :width t as if `org-image-actual-width' were t. + ((string=3D attr-width "t") nil) + ((or (null attr-width) + (string-match-p "\\`[^0-9]" attr-width)) + ;; Try to use subtree-level width before fallback. + ;; Fallback to `org-image-actual-width' if no interprable = width is given. + (car org-image-actual-width)) + ;; Convert numeric widths to numbers, converting percentage= s. + ((string-match-p "\\`[0-9.]+%" attr-width) + (/ (string-to-number attr-width) 100.0)) + (t (string-to-number attr-width))))) + (if (and (floatp width) (<=3D 0.0 width 2.0)) + ;; A float in [0,2] should be interpereted as this portion of + ;; the text width in the window. This works well with cases l= ike + ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width, + ;; as the "0.X" is pulled out as a float. We use 2 as the upp= er + ;; bound as cases such as 1.2\linewidth are feasible. + (round (* width + (window-pixel-width) + (/ (or (and (bound-and-true-p visual-fill-column-mod= e) + (or visual-fill-column-width auto-fill-f= unction)) + (when auto-fill-function fill-column) + (- (window-text-width) (line-number-display-w= idth))) + (float (window-total-width))))) + width))) + ((numberp org-image-actual-width) + org-image-actual-width) + (t nil)))) =20 (defun org-display-inline-remove-overlay (ov after _beg _end &optional _le= n) "Remove inline-display overlay if a corresponding region is modified." =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----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmMisJMACgkQG13xyVro msM29wgAxqxjh3ZA4EJqy1FKrU+nj2KNSx7CpYkM51a1or0+P33tWs3y39xBGZqr Yi/FQPWFPTdtfjNDC5r5mBRRBqDvyj2cuSL+knHvNUhphiHqKV9SoW53qitjXgC+ DWTBFC5mwdheGktcTinnI4Yr1YsF/b+/tKYgvbLLKvwNBLO1rEMyZeCXJplm4Jke kggevUIDzIOQ6H2Xmrah1qdjvwODEBjBF6m/KIh7o9JqvnQ4pYclMJpef90SWxu0 59rF4Qamzkp0baaZIgUDTwltX+M++Z2fIkBtgG9i71/uF2NWzVIOzb3Ya9tQ7T9e K/ObZwYM/DXxQ5Yd/z9joR02uO7CVg== =TLHc -----END PGP SIGNATURE----- --==-=-=--