From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gCLaFHX2ImOpVAAAbAwnHQ (envelope-from ) for ; Thu, 15 Sep 2022 11:55:01 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id mGviFHX2ImMJ0QAAauVa8A (envelope-from ) for ; Thu, 15 Sep 2022 11:55:01 +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 D3B3F2E6C9 for ; Thu, 15 Sep 2022 11:55:00 +0200 (CEST) Received: from localhost ([::1]:47280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYlaF-0008K1-Rk for larch@yhetil.org; Thu, 15 Sep 2022 05:54:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYlWv-0008HS-V7 for emacs-orgmode@gnu.org; Thu, 15 Sep 2022 05:51:34 -0400 Received: from [39.171.215.24] (port=6101 helo=Mac-mini.local) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYlWs-00021G-Vi for emacs-orgmode@gnu.org; Thu, 15 Sep 2022 05:51:33 -0400 Received: by Mac-mini.local (Postfix, from userid 501) id A85B2644576A; Thu, 15 Sep 2022 17:51:21 +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> <6322b0a8.050a0220.59bb8.6923SMTPIN_ADDED_BROKEN@mx.google.com> <87y1uluir1.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 5] New: auto display inline images under subtree when `org-cycle'. Date: Thu, 15 Sep 2022 17:43:19 +0800 In-reply-to: <87y1uluir1.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 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=1663235700; 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=7HhIFKRy5MjXnG5GzUCZzVgqDk/d/HmzlR6bpHOtmCM=; b=lZHmNR+JrnFWps/3KZ7kL7Nw2BJyFmOtSrvG+VAmV4Jrsb+9uC9J1QNvc2Ej2uXBz/dxn/ al/182xTRZ9wPAAZJIT0Sv7S2C/c17+dWv4GUV0RdZeHXeqnmz2agK9EkGRHPbOii7EPCB +BszcQtAr5xyVgNVoV3eTKDBQiAGkdFp6NxZAhbcdtt8P4AHLLmRXRZcKtHtgC8BNYBZNv /o7QThwwnxLe9ozoW6Z9Phb6qllq83sDKEjO3ovKAA5xHeXaXhVQSqTu9x7nQpsnHnPXRf sXcz8fy7VJvrgcywSAMbVygUg82lLbYQ3PhaKReg7/jiifwhTaQS+RPhV1QZZg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663235700; a=rsa-sha256; cv=none; b=gNmPnqFb8M/MQXP1qbCMEAIMqY/9dOtUKANwP42eBESgMSOI0Cwt6avtulLp+bse2ggSB0 T4FNE8J7Hx7i/1M2emc5sFXUsvbnDWH7PSnhvpuPnXHBEcIE6pVKCsa6umaD+A1WXFe7Bd reNejFWyN510dhcNHoHluI8f6IixtNnnGtfksQsFSJqRmywVPcQWMCNFfEt+c/a97bW/Lw vXPAK2FBtcJ36GLaC+k8Xq0zxMZT8/apEiht+55V879FJ4JxAeB7ZY+b2F5TfvNXDykAUo NsPL5Ve+Vn0IxYHM3yqDwpH4ZEKFLT94LfvwlLN2a0wANeLZRcrgeRjQtJO+dQ== 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: 0.97 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: D3B3F2E6C9 X-Spam-Score: 0.97 X-Migadu-Scanner: scn0.migadu.com X-TUID: O8NHZBJIqNQt --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Sorry for this hard work on this patch. And thanks for your carefully code reviewing. I have not contribute to org-mode for a long time, already forgot most guidelines. Regards Ihor Radchenko writes: > "Christopher M. Miles" writes: > >>> 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....) > > I meant doc/org-manual.org > Note doc/Documentation_Standards.org for the conventions we use in the > manual. Your patch does not follow those conventions (double space > between sentences). Done > >> P.S: I merged two commits into one for clear. > > Let's not do it. They are two distinct changes and I will have > significant comments regarding subtree cycling. (I had plans to > implement cycling at point for images, and we may as well take this > chance to create some generic infrastructure for showing/hiding the > inline images). > > For now, lets sort out the ORG-IMAGE-ACTUAL-WIDTH property and get it > merges. Then, we can move ahead to the subtree cycling feature. > Ok, I will submit the first patch of new property at first. If you're going to implement this cycling inline image display feature, that's great! >> * lisp/org.el (org-display-inline-image--width): support subtree-level > ^S > >> +If you want to override global variable ~org-image-actual-width~ of >> +inline image display width, you can specify property >> +"=ORG-IMAGE-ACTUAL-WIDTH=" in subtree level. It will only affect >> +inline images under the specified subtree. > > Could you also add a paragraph describing what org-image-actual-width > does? Done in doc/org-manual.org > >> +*** New default property =ORG-IMAGE-ACTUAL-WIDTH= for overriding global ~org-image-actual-width~ > > I think that people may be confused by "default property" here. Just say > "new property". Done > >> +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. > > It is not necessarily subtree-level. You can as well set it in > document-wide property drawer. Just say "The new property ... > overrides ...". Done --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Support-subtree-level-org-image-actual-width-.patch Content-Transfer-Encoding: quoted-printable From=201bc3224220ec71292e08ebc6b25e0064f7243f2e Mon Sep 17 00:00:00 2001 From: stardiviner Date: Thu, 15 Sep 2022 17:25:13 +0800 Subject: [PATCH] org.el: Support subtree-level org-image-actual-width overriding * lisp/org.el (org-display-inline-image--width): Support new property "ORG-IMAGE-ACTUAL-WIDTH" overriding global variable `org-image-actual-width'. =2D-- doc/org-manual.org | 21 +++++++++++ etc/ORG-NEWS | 4 +++ lisp/org.el | 89 ++++++++++++++++++++++++---------------------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index a37b8390c..2d2b93694 100644 =2D-- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -11314,6 +11314,27 @@ command: startup by configuring the variable ~org-startup-with-inline-images~[fn:119]. =20 + #+vindex: org-image-actual-width + Control the display size of inline images. + The value can be bellowing formats: + - When non-nil, use the actual width of images when inlining them. + - When set to a number, use imagemagick (when available) to set the + image's width to this value. + - When set to a number in a list, try to get the width from any + =3D#+ATTR.*=3D keyword if it matches a width specification like: + #+ATTR_HTML: :width 300px + and fall back on that number if none is found. + - When set to nil, try to get the width from an =3D#+ATTR.*=3D keyword + and fall back on the original width if none is found. + - When set to any other non-nil value, always use the image width. + + This requires Emacs >=3D 24.1, built with imagemagick support. + + #+cindex: @samp{NOBLOCKING}, property + If you want to override the global variable ~org-image-actual-width~ + of inline image display width, you can specify property + "=3DORG-IMAGE-ACTUAL-WIDTH=3D". + ** Captions :PROPERTIES: :DESCRIPTION: Describe tables, images... diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a7f32671e..f30809973 100644 =2D-- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -296,6 +296,10 @@ 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 property =3DORG-IMAGE-ACTUAL-WIDTH=3D for overriding global ~org-i= mage-actual-width~ + +The new property "=3DORG-IMAGE-ACTUAL-WIDTH=3D" can override the global +variable ~org-image-actual-width~ value for inline images display width. =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..d2d66038d 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 @@ -16228,48 +16229,50 @@ 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) + ;; Fallback to `org-image-actual-width' if no interprable w= idth is given. + ((or (null attr-width) + (string-match-p "\\`[^0-9]" attr-width)) + (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----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmMi9ZUACgkQG13xyVro msPQqwgAy63i2h0wQ8BU1HRBpoMrx3a4n2O3cJ9bUdWUIamSiz7ZrQsxLfhVf/g7 aWJpwl5h7igEIVWIs/QoMVp0CxKO6/b3n699upfk8mL9psd/n2PmTiJFWMEQ6zWm pNPkVMmIC+yX6WG2huMyTzwmRUILsYuaPSoEC7hnR6S9C/d//nEqmddwu+qlwXP9 KGlEkt2L8cH/57ojgGlom45jq4M9glIDxSMBUFaETTM002XbNHKZSRa3DVQnll37 3wGgGR+4bP8lVVuB1tloJ2SMCR2RTt3edEm9mkJzDEfEg88bqpvOrixCkblbY4xX D0HfJXdOrVsRG9HE6KJMaaT2CMkDcw== =7uHq -----END PGP SIGNATURE----- --==-=-=--