emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Christopher M. Miles" <numbchild@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: "Christopher M. Miles" <numbchild@gmail.com>, 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	[thread overview]
Message-ID: <m2mtb1q82y.fsf@numbchild@gmail.com> (raw)
In-Reply-To: <87y1uluir1.fsf@localhost>


[-- Attachment #1.1: Type: text/plain, Size: 2414 bytes --]


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 <yantar92@gmail.com> writes:

> "Christopher M. Miles" <numbchild@gmail.com> 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 <TAB> 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 <TAB> 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



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org.el-Support-subtree-level-org-image-actual-width-.patch --]
[-- Type: text/x-patch, Size: 8384 bytes --]

From 1bc3224220ec71292e08ebc6b25e0064f7243f2e Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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'.
---
 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
--- 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].
 
+  #+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
+    =#+ATTR.*= 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 =#+ATTR.*= 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 >= 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
+  "=ORG-IMAGE-ACTUAL-WIDTH=".
+
 ** Captions
 :PROPERTIES:
 :DESCRIPTION: Describe tables, images...
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index a7f32671e..f30809973 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -296,6 +296,10 @@ headings in HTML export.
 Use the header argument =:var x=code-block[]= or
 : #+CALL: fn(x=code-block[])
 to pass the contents of a named code block as a string argument.
+*** New property =ORG-IMAGE-ACTUAL-WIDTH= for overriding global ~org-image-actual-width~
+
+The new property "=ORG-IMAGE-ACTUAL-WIDTH=" can override the global
+variable ~org-image-actual-width~ value for inline images display width.
 
 ** New options
 *** New custom settings =org-icalendar-scheduled-summary-prefix= and =org-icalendar-deadline-summary-prefix=
diff --git a/lisp/org.el b/lisp/org.el
index 6e6c437d5..d2d66038d 100644
--- 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_STATE"
-    "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.")
 
@@ -16228,48 +16229,50 @@ buffer boundaries with possible narrowing."
   If the value is a float between 0 and 2, it interpreted as that proportion
   of the text width in the buffer."
   ;; Apply `org-image-actual-width' specifications.
-  (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= attr-width "t") nil)
-             ;; Fallback to `org-image-actual-width' if no interprable width is given.
-             ((or (null attr-width)
-                  (string-match-p "\\`[^0-9]" attr-width))
-              (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))
-             (t (string-to-number attr-width)))))
-      (if (and (floatp width) (<= 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 like
-          ;; #+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 upper
-          ;; bound as cases such as 1.2\linewidth are feasible.
-          (round (* width
-                    (window-pixel-width)
-                    (/ (or (and (bound-and-true-p visual-fill-column-mode)
-                                (or visual-fill-column-width auto-fill-function))
-                           (when auto-fill-function fill-column)
-                           (- (window-text-width) (line-number-display-width)))
-                       (float (window-total-width)))))
-        width)))
-   ((numberp org-image-actual-width)
-    org-image-actual-width)
-   (t nil)))
+  ;; support subtree-level property "ORG-IMAGE-ACTUAL-WIDTH" specified width.
+  (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= attr-width "t") nil)
+               ;; Fallback to `org-image-actual-width' if no interprable width is given.
+               ((or (null attr-width)
+                    (string-match-p "\\`[^0-9]" attr-width))
+                (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))
+               (t (string-to-number attr-width)))))
+        (if (and (floatp width) (<= 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 like
+            ;; #+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 upper
+            ;; bound as cases such as 1.2\linewidth are feasible.
+            (round (* width
+                      (window-pixel-width)
+                      (/ (or (and (bound-and-true-p visual-fill-column-mode)
+                                  (or visual-fill-column-width auto-fill-function))
+                             (when auto-fill-function fill-column)
+                             (- (window-text-width) (line-number-display-width)))
+                         (float (window-total-width)))))
+          width)))
+     ((numberp org-image-actual-width)
+      org-image-actual-width)
+     (t nil))))
 
 (defun org-display-inline-remove-overlay (ov after _beg _end &optional _len)
   "Remove inline-display overlay if a corresponding region is modified."
-- 
2.37.2


[-- Attachment #1.3: Type: text/plain, Size: 267 bytes --]


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  reply	other threads:[~2022-09-15  9:55 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22  6:34 [QUESTION] How to specific image size attributes under headline scope? Christopher M. Miles
2021-11-22 18:31 ` Timothy
2022-08-18 12:44   ` Christopher M. Miles
     [not found]   ` <m2o7whra7j.fsf@numbchild>
2022-08-22 17:10     ` Timothy
2022-08-23  0:24       ` Christopher M. Miles
2022-09-11  2:20 ` [SOLVED] " Christopher M. Miles
2022-09-11  2:25 ` Christopher M. Miles
     [not found] ` <631d472b.c80a0220.2b4b2.bf86SMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-11 12:34   ` Ihor Radchenko
2022-09-12  1:54     ` [PATCH] " Christopher M. Miles
2022-09-12  1:59     ` [PATCH] New: auto display inline images under subtree when `org-cycle' Christopher M. Miles
     [not found]     ` <m2wna9bbc2.fsf@numbchild>
2022-09-12  6:03       ` [ISSUE] " Christopher M. Miles
     [not found]     ` <631e92ee.050a0220.f9c18.92f5SMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-12 10:51       ` Ihor Radchenko
2022-09-13  1:09         ` [PATCH 2] " Christopher M. Miles
     [not found]         ` <m2leqogiz8.fsf@numbchild>
2022-09-13  1:48           ` [PATCH 3] " Christopher M. Miles
     [not found]           ` <631fe1c9.050a0220.3ab2b.3f52SMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-15  3:27             ` Ihor Radchenko
2022-09-15  4:53               ` [PATCH 4] " Christopher M. Miles
     [not found]               ` <6322b0a8.050a0220.59bb8.6923SMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-15  8:47                 ` Ihor Radchenko
2022-09-15  9:43                   ` Christopher M. Miles [this message]
     [not found]                   ` <6322f5ad.c80a0220.5e936.823eSMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-20  7:01                     ` [PATCH v6] Re: [PATCH 5] " Ihor Radchenko
2022-09-20 11:32                       ` [PATCH v6] " Christopher M. Miles
     [not found]                       ` <6329c8b0.050a0220.412d.0a6cSMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-21  7:54                         ` Ihor Radchenko
2022-09-28 12:55                           ` [PATCH 2-v1] " Christopher M. Miles
     [not found]                           ` <633454e3.050a0220.7278b.1fa5SMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-29  3:05                             ` Ihor Radchenko
2022-09-29  6:06                               ` Christopher M. Miles
2022-09-29  6:57                               ` [PATCH 2-v1 (test v1)] " Christopher M. Miles
     [not found]                               ` <63353c69.370a0220.67788.e8a1SMTPIN_ADDED_BROKEN@mx.google.com>
2022-09-30  3:19                                 ` [PATCH 2-v1] " Ihor Radchenko
2022-09-30  8:27                                   ` [PATCH 2-v2] " Christopher M. Miles
     [not found]                                   ` <6336a955.050a0220.4e72e.2b23SMTPIN_ADDED_BROKEN@mx.google.com>
2022-10-01  3:16                                     ` Ihor Radchenko
2022-10-01  9:51                                       ` [PATCH 2-v3] " Christopher M. Miles
     [not found]                                       ` <63380f57.370a0220.a9d9a.dee8SMTPIN_ADDED_BROKEN@mx.google.com>
2022-10-03  3:21                                         ` Ihor Radchenko
2022-10-03  4:37                                           ` [PATCH 2-v4] " Christopher M. Miles
     [not found]                                           ` <633a67d8.050a0220.733e8.e57dSMTPIN_ADDED_BROKEN@mx.google.com>
2022-10-04  4:36                                             ` Ihor Radchenko
2022-10-04  7:27                                               ` Christopher M. Miles
     [not found]                                               ` <633be6d3.370a0220.4060.bacdSMTPIN_ADDED_BROKEN@mx.google.com>
2022-10-08  7:53                                                 ` Ihor Radchenko
2022-10-08  9:50                                                   ` Christopher M. Miles
     [not found]                                                   ` <634149f4.c80a0220.1376.e564SMTPIN_ADDED_BROKEN@mx.google.com>
2022-10-09  7:21                                                     ` Ihor Radchenko
2022-10-10  8:40                                                       ` Christopher M. Miles
     [not found]                                                       ` <m2v8os5aqy.fsf@numbchild>
2022-10-22  1:29                                                         ` Christopher M. Miles
2022-10-23  4:33                                                           ` Ihor Radchenko
2022-10-23  7:14                                                             ` Christopher M. Miles
2022-10-25  7:23                                                               ` Ihor Radchenko
2022-10-25 14:22                                                                 ` [PATCH v3] " Christopher M. Miles
2022-10-26  4:50                                                                   ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2mtb1q82y.fsf@numbchild@gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).