emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] add a function to only refresh inline images under current headline instead of global buffer
@ 2023-05-15  3:28 Christopher M. Miles
  2023-05-15 11:08 ` Ihor Radchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2023-05-15  3:28 UTC (permalink / raw)
  To: Org mode

[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]


I found a lot of third-part Emacs packages refresh Org source block image result using the API function like this:

#+begin_src emacs-lisp
;; Automatically refresh inline images.
  (add-hook 'org-babel-after-execute-hook
            (defun ob-dall-e--refresh-inline-images ()
              (when org-inline-image-overlays
                (org-redisplay-inline-images))))
#+end_src

The `org-redisplay-inline-images' will refresh whole buffer inline
images. When the buffer is a big Org file, and not all inline images are
display already by default (still image file links under fold status).
Invoking `org-redisplay-inline-images' will cause Emacs suspend a long
time.

So I suggest to add an variant local function of
`org-redisplay-inline-images' which named
`org-redisplay-inline-images-under-headline' that only redisplay inline
images under current headline to solve the issue.

Here is the diff code prototype, Ihor, can you review it? If it's ok, I
will send patch update then.

#+begin_src diff
 (defun org-redisplay-inline-images ()
-  "Assure display of inline images and refresh them."
+  "Assure display of global all inline images in buffer and refresh them.
+
+NOTE: This function will refresh whole buffer inline images, if
+you only want to refresh inline images under headline, suggest to
+use `org-redisplay-inline-images-under-headline' in your hook or advice."
   (interactive)
   (org-toggle-inline-images)
   (unless org-inline-image-overlays
     (org-toggle-inline-images)))
 
+(defun org-redisplay-inline-images-under-headline ()
+  "Assure display of images under current headline and refresh them.
+This function is the suggested to be used in hook or advice."
+  (interactive)
+  (org-with-wide-buffer
+   (org-narrow-to-subtree)
+   ;; If has nested headlines, beg,end only from parent headline
+   ;; to first child headline which reference to upper
+   ;; let-binding `org-next-visible-heading'.
+   (org-display-inline-images
+    nil nil
+    (point-min) (progn (org-next-visible-heading 1) (point)))))
+
#+end_src

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-05-15  3:28 [PATCH] add a function to only refresh inline images under current headline instead of global buffer Christopher M. Miles
@ 2023-05-15 11:08 ` Ihor Radchenko
  2023-05-15 13:01   ` Christopher M. Miles
  2023-05-15 14:00   ` [PATCH v2] " Christopher M. Miles
  0 siblings, 2 replies; 18+ messages in thread
From: Ihor Radchenko @ 2023-05-15 11:08 UTC (permalink / raw)
  To: numbchild; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

> The `org-redisplay-inline-images' will refresh whole buffer inline
> images. When the buffer is a big Org file, and not all inline images are
> display already by default (still image file links under fold status).
> Invoking `org-redisplay-inline-images' will cause Emacs suspend a long
> time.
>
> So I suggest to add an variant local function of
> `org-redisplay-inline-images' which named
> `org-redisplay-inline-images-under-headline' that only redisplay inline
> images under current headline to solve the issue.
>
> Here is the diff code prototype, Ihor, can you review it? If it's ok, I
> will send patch update then.

I'd prefer something more closely resembling `org-latex-preview'
approach with prefix arguments:

    Toggle preview of the LaTeX fragment at point.
    
    If the cursor is on a LaTeX fragment, create the image and
    overlay it over the source code, if there is none.  Remove it
    otherwise.  If there is no fragment at point, display images for
    all fragments in the current section.  With an active region,
    display images for all fragments in the region.
    
    With a C-u prefix argument ARG, clear images for all fragments
    in the current section.
    
    With a C-u C-u prefix argument ARG, display image for all
    fragments in the buffer.
    
    With a C-u C-u C-u prefix argument ARG, clear image for all
    fragments in the buffer.

`org-toggle-inline-images' should also be changed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-05-15 11:08 ` Ihor Radchenko
@ 2023-05-15 13:01   ` Christopher M. Miles
  2023-05-15 14:00   ` [PATCH v2] " Christopher M. Miles
  1 sibling, 0 replies; 18+ messages in thread
From: Christopher M. Miles @ 2023-05-15 13:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: numbchild, Org mode

[-- Attachment #1: Type: text/plain, Size: 2019 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> The `org-redisplay-inline-images' will refresh whole buffer inline
>> images. When the buffer is a big Org file, and not all inline images are
>> display already by default (still image file links under fold status).
>> Invoking `org-redisplay-inline-images' will cause Emacs suspend a long
>> time.
>>
>> So I suggest to add an variant local function of
>> `org-redisplay-inline-images' which named
>> `org-redisplay-inline-images-under-headline' that only redisplay inline
>> images under current headline to solve the issue.
>>
>> Here is the diff code prototype, Ihor, can you review it? If it's ok, I
>> will send patch update then.
>
> I'd prefer something more closely resembling `org-latex-preview'
> approach with prefix arguments:
>
>     Toggle preview of the LaTeX fragment at point.
>     
>     If the cursor is on a LaTeX fragment, create the image and
>     overlay it over the source code, if there is none.  Remove it
>     otherwise.  If there is no fragment at point, display images for
>     all fragments in the current section.  With an active region,
>     display images for all fragments in the region.
>     
>     With a C-u prefix argument ARG, clear images for all fragments
>     in the current section.
>     
>     With a C-u C-u prefix argument ARG, display image for all
>     fragments in the buffer.
>     
>     With a C-u C-u C-u prefix argument ARG, clear image for all
>     fragments in the buffer.
>
> `org-toggle-inline-images' should also be changed.

I agree this solution. I will check out latex fragment preview source
code whether I can implement this.

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-05-15 11:08 ` Ihor Radchenko
  2023-05-15 13:01   ` Christopher M. Miles
@ 2023-05-15 14:00   ` Christopher M. Miles
  2023-05-16  9:17     ` Ihor Radchenko
  1 sibling, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2023-05-15 14:00 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: numbchild, Org mode

[-- Attachment #1: Type: text/plain, Size: 5505 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> The `org-redisplay-inline-images' will refresh whole buffer inline
>> images. When the buffer is a big Org file, and not all inline images are
>> display already by default (still image file links under fold status).
>> Invoking `org-redisplay-inline-images' will cause Emacs suspend a long
>> time.
>>
>> So I suggest to add an variant local function of
>> `org-redisplay-inline-images' which named
>> `org-redisplay-inline-images-under-headline' that only redisplay inline
>> images under current headline to solve the issue.
>>
>> Here is the diff code prototype, Ihor, can you review it? If it's ok, I
>> will send patch update then.
>
> I'd prefer something more closely resembling `org-latex-preview'
> approach with prefix arguments:
>
>     Toggle preview of the LaTeX fragment at point.
>     
>     If the cursor is on a LaTeX fragment, create the image and
>     overlay it over the source code, if there is none.  Remove it
>     otherwise.  If there is no fragment at point, display images for
>     all fragments in the current section.  With an active region,
>     display images for all fragments in the region.
>     
>     With a C-u prefix argument ARG, clear images for all fragments
>     in the current section.
>     
>     With a C-u C-u prefix argument ARG, display image for all
>     fragments in the buffer.
>     
>     With a C-u C-u C-u prefix argument ARG, clear image for all
>     fragments in the buffer.
>
> `org-toggle-inline-images' should also be changed.

Here is the source code of `org-toggle-inline-images'. I implement this
by reference `org-latex-preview'. I have not write testing, but only
manually tested with Edebug and on actual Org buffer displaying and
disable inline images. The command works fine. Ihor, can you review the code?

#+begin_src emacs-lisp
(defun org-toggle-inline-images (&optional arg include-linked beg end)
  "Toggle the display of inline images at point.
INCLUDE-LINKED is passed to `org-display-inline-images'.

If cursor is on an inline image link, display the inline image.
If there is none, remove it otherwise.
If there is no inline image link at point, display all inline images in the current section.
With an active region, display inline images in the region.

With a `\\[universal-argument]' prefix argument ARG, clear inline
images in the current section.

With a `\\[universal-argument] \\[universal-argument]' prefix
 argument ARG, display all inline images in the buffer.

With a `\\[universal-argument] \\[universal-argument] \
\\[universal-argument]' prefix argument ARG, clear all inline
images in the buffer."
  (interactive "P")
  (cond
   ((not (display-graphic-p)) nil)
   ;; Clear whole buffer inline images.
   ((equal arg '(64))
    (org-remove-inline-images (point-min) (point-max))
    (message "Inline images preview disabled in buffer."))
   ;; Display whole buffer inline images.
   ((equal arg '(16))
    (message "Displaying all inline images in buffer...")
    (org-display-inline-images include-linked nil (point-min) (point-max))
    (message "Displaying all inline images in buffer... done."))
   ;; Clear current section.
   ((equal arg '(4))
    (let* ((beg (if (use-region-p)
                    (region-beginning)
                  (if (org-before-first-heading-p) (point-min)
                    (save-excursion
	              (org-with-limited-levels (org-back-to-heading t) (point))))))
           (end (if (use-region-p)
                    (region-end)
                  (org-with-limited-levels (org-entry-end-position))))
           (inline-images (org--inline-image-overlays beg end)))
      (org-remove-inline-images beg end)
      (message "%d inline images display removed." (length inline-images))))
   ;; Display region selected inline images.
   ((use-region-p)
    (message "Displaying inline images in region...")
    (org-display-inline-images include-linked t (region-beginning) (region-end))
    (message "Displaying inline images in region... done."))
   ;; Toggle display of inline image link at point.
   ((let ((context (org-element-context)))
      (and (memq (org-element-type context) '(link))
	   (let ((beg (org-element-property :begin context))
		 (end (org-element-property :end context)))
	     (if (org--inline-image-overlays beg end)
                 (progn
                   (org-remove-inline-images beg end)
	           (message "Display inline image at point removed."))
	       (org-display-inline-images include-linked t beg end)
	       (message "Displaying inline image at point ... done."))
	     t))))
   ;; Display inline images under current section.
   (t
    (let ((beg (if (org-before-first-heading-p) (point-min)
		 (save-excursion
		   (org-with-limited-levels (org-back-to-heading t) (point)))))
	  (end (org-with-limited-levels (org-entry-end-position))))
      (message "Displaying inline images in section...")
      (org-display-inline-images include-linked t beg end)
      (message "Displaying inline images in section... done.")))))
#+end_src

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-05-15 14:00   ` [PATCH v2] " Christopher M. Miles
@ 2023-05-16  9:17     ` Ihor Radchenko
  2023-05-16 12:18       ` Christopher M. Miles
  0 siblings, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2023-05-16  9:17 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

>> I'd prefer something more closely resembling `org-latex-preview'
>> approach with prefix arguments:
>> ...
>> `org-toggle-inline-images' should also be changed.
>
> Here is the source code of `org-toggle-inline-images'. I implement this
> by reference `org-latex-preview'. I have not write testing, but only
> manually tested with Edebug and on actual Org buffer displaying and
> disable inline images. The command works fine. Ihor, can you review the code?

Unlike `org-latex-preview', here we need to (1) respect active region;
(2) keep the backward compatibility for INCLUDE-LINKED.

For (1), for example, it would make sense to respect region when prefix
argument is C-u and clear images only there. For (2), we need to at
least allow toggling images with description using some prefix argument
(previously, any prefix argument would do).

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-05-16  9:17     ` Ihor Radchenko
@ 2023-05-16 12:18       ` Christopher M. Miles
  2023-07-24 11:25         ` Ihor Radchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2023-05-16 12:18 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode

[-- Attachment #1: Type: text/plain, Size: 3125 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>> I'd prefer something more closely resembling `org-latex-preview'
>>> approach with prefix arguments:
>>> ...
>>> `org-toggle-inline-images' should also be changed.
>>
>> Here is the source code of `org-toggle-inline-images'. I implement this
>> by reference `org-latex-preview'. I have not write testing, but only
>> manually tested with Edebug and on actual Org buffer displaying and
>> disable inline images. The command works fine. Ihor, can you review the code?
>
> Unlike `org-latex-preview', here we need to (1) respect active region;
> (2) keep the backward compatibility for INCLUDE-LINKED.
>
> For (1), for example, it would make sense to respect region when prefix
> argument is C-u and clear images only there. For (2), we need to at
> least allow toggling images with description using some prefix argument
> (previously, any prefix argument would do).

I indeed implemented all same behavior like `org-latex-preview' in new
`org-toggle-inline-images'.

For (1), org-latex-preview has a `cond' logic to toggle preview in
region. Here is the code from `org-latex-preview'.

((use-region-p)
    (message "Creating LaTeX previews in region...")
    (org--latex-preview-region (region-beginning) (region-end))
    (message "Creating LaTeX previews in region... done."))

+

;; Clear current section.
   ((equal arg '(4))
    (org-clear-latex-preview
     (if (use-region-p)
         (region-beginning)
       (if (org-before-first-heading-p) (point-min)
         (save-excursion
	   (org-with-limited-levels (org-back-to-heading t) (point)))))
     (if (use-region-p)
         (region-end)
       (org-with-limited-levels (org-entry-end-position)))))

And I also implement the toggle inline images in region logic in
`org-toggle-inline-images' as bellowing:

;; Display region selected inline images.
   ((use-region-p)
    (message "Displaying inline images in region...")
    (org-display-inline-images include-linked t (region-beginning) (region-end))
    (message "Displaying inline images in region... done."))

+

;; Clear current section.
   ((equal arg '(4))
    (org-clear-latex-preview
     (if (use-region-p)
         (region-beginning)
       (if (org-before-first-heading-p) (point-min)
         (save-excursion
	   (org-with-limited-levels (org-back-to-heading t) (point)))))
     (if (use-region-p)
         (region-end)
       (org-with-limited-levels (org-entry-end-position)))))

------------------------------------------------------------------------

For (2), It's working. The code passed the parameter `include-linked' to
`org-display-inline-images'. So they works in any case of [C-u] prefix.

Maybe you want to eval the patch code to test.

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-05-16 12:18       ` Christopher M. Miles
@ 2023-07-24 11:25         ` Ihor Radchenko
  2023-08-01  4:40           ` [PATCH v3] " Christopher M. Miles
  0 siblings, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2023-07-24 11:25 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

>> Unlike `org-latex-preview', here we need to (1) respect active region;
>> (2) keep the backward compatibility for INCLUDE-LINKED.
>>
>> For (1), for example, it would make sense to respect region when prefix
>> argument is C-u and clear images only there. For (2), we need to at
>> least allow toggling images with description using some prefix argument
>> (previously, any prefix argument would do).
>
> I indeed implemented all same behavior like `org-latex-preview' in new
> `org-toggle-inline-images'.
>
> ...
> And I also implement the toggle inline images in region logic in
> `org-toggle-inline-images' as bellowing:
>
> ;; Display region selected inline images.
>    ((use-region-p)
>     (message "Displaying inline images in region...")
>     (org-display-inline-images include-linked t (region-beginning) (region-end))
>     (message "Displaying inline images in region... done."))

This is not a toggle. This is unconditional refresh.

> For (2), It's working. The code passed the parameter `include-linked' to
> `org-display-inline-images'. So they works in any case of [C-u] prefix.

My concern is that previously C-u M-x org-toggle-inline-images would
"display links with a text description part". With your patch, it is no
longer the case because INCLUDE-LINKED is not affected by the prefix
argument.

And there is no clean way to allow INCLUDE-LINKED while keeping
consistency with latex preview commands.

What we might do here is making a new defcustom that will control
whether linked images should be displayed. Then, something like C-1
org-toggle-inline-images could toggle that defcustom and refresh all the
image previews in buffer (if any).

WDYT?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-07-24 11:25         ` Ihor Radchenko
@ 2023-08-01  4:40           ` Christopher M. Miles
  2023-08-01  8:04             ` Ihor Radchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2023-08-01  4:40 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode


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


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>> Unlike `org-latex-preview', here we need to (1) respect active region;
>>> (2) keep the backward compatibility for INCLUDE-LINKED.
>>>
>>> For (1), for example, it would make sense to respect region when prefix
>>> argument is C-u and clear images only there. For (2), we need to at
>>> least allow toggling images with description using some prefix argument
>>> (previously, any prefix argument would do).
>>
>> I indeed implemented all same behavior like `org-latex-preview' in new
>> `org-toggle-inline-images'.
>>
>> ...
>> And I also implement the toggle inline images in region logic in
>> `org-toggle-inline-images' as bellowing:
>>
>> ;; Display region selected inline images.
>>    ((use-region-p)
>>     (message "Displaying inline images in region...")
>>     (org-display-inline-images include-linked t (region-beginning) (region-end))
>>     (message "Displaying inline images in region... done."))
>
> This is not a toggle. This is unconditional refresh.
>
Yes, indeed it's a unconditional refresh. It does not match the meaning of word "toggle".

Seems need to detect whether has image overlays in region. I added this
detection in new patch. Like bellowing:

#+begin_src emacs-lisp
...
((use-region-p)
    (if (seq-contains-p
         (mapcar
          (lambda (ov)
            (plist-get (overlay-properties ov) 'org-image-overlay))
          (overlays-in beg end))
         t)
        (progn
          (org-remove-inline-images beg end)
          (message "Inline images in region removed."))
      (message "Displaying inline images in region...")
      (org-display-inline-images include-linked nil (region-beginning) (region-end))
      (message "Displaying inline images in region... done.")))
....
#+end_src

>> For (2), It's working. The code passed the parameter `include-linked' to
>> `org-display-inline-images'. So they works in any case of [C-u] prefix.
>
> My concern is that previously C-u M-x org-toggle-inline-images would
> "display links with a text description part". With your patch, it is no
> longer the case because INCLUDE-LINKED is not affected by the prefix
> argument.
>
> And there is no clean way to allow INCLUDE-LINKED while keeping
> consistency with latex preview commands.

About the INCLUDE-LINKED argument, I don't know how to process it. In
theory, it should be handled by function org-display-inline-images
instead of org-toggle-inline-images. If you have improvements on it, can
you add code on my patch?

>
> What we might do here is making a new defcustom that will control
> whether linked images should be displayed. Then, something like C-1
> org-toggle-inline-images could toggle that defcustom and refresh all the
> image previews in buffer (if any).
>
> WDYT?

Refreshing all image previews in buffer is same as old behavior. My
patch's purpose is to improve function org-toggle-inline-images behavior
which refresh only in current level scope instead of whole buffer with
lot of inline images especially heavy and suspend Emacs. Because
function org-toggle-inline-images is used in of lot Emacs ob-* related
packages on after babel execution hook. Old behavior caused execute one
source block need to refresh whole buffer all images. Instead of only
current headline images, or just results image.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-Improve-inline-images-displaying-like-LaTeX-prev.patch --]
[-- Type: text/x-patch, Size: 5252 bytes --]

From 635624cb8446791b9e39f2803077ac9fa6d17225 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Mon, 22 May 2023 16:25:33 +0800
Subject: [PATCH] org: Improve inline images displaying like LaTeX previewing

* lisp/org.el (org-toggle-inline-images): Implement LaTeX previewing
same logic in inline images toggle displaying.
---
 lisp/org.el | 92 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 77 insertions(+), 15 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index e72cf056a..f847a42e7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16160,22 +16160,84 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
       (when (memq ov org-inline-image-overlays)
         (push ov result)))))
 
-(defun org-toggle-inline-images (&optional include-linked beg end)
-  "Toggle the display of inline images.
-INCLUDE-LINKED is passed to `org-display-inline-images'."
+(defun org-toggle-inline-images (&optional arg include-linked beg end)
+  "Toggle the display of inline images at point.
+INCLUDE-LINKED is passed to `org-display-inline-images'.
+
+If cursor is on an inline image link, display the inline image.
+If there is none, remove it otherwise.
+If there is no inline image link at point, display all inline images in the current section.
+With an active region, display inline images in the region.
+
+With a `\\[universal-argument]' prefix argument ARG, clear inline
+images in the current section.
+
+With a `\\[universal-argument] \\[universal-argument]' prefix
+ argument ARG, display all inline images in the buffer.
+
+With a `\\[universal-argument] \\[universal-argument] \
+\\[universal-argument]' prefix argument ARG, clear all inline
+images in the buffer."
   (interactive "P")
-  (if (org--inline-image-overlays beg end)
-      (progn
-        (org-remove-inline-images beg end)
-        (when (called-interactively-p 'interactive)
-	  (message "Inline image display turned off")))
-    (org-display-inline-images include-linked nil beg end)
-    (when (called-interactively-p 'interactive)
-      (let ((new (org--inline-image-overlays beg end)))
-        (message (if new
-		     (format "%d images displayed inline"
-			     (length new))
-		   "No images to display inline"))))))
+  (cond
+   ((not (display-graphic-p)) nil)
+   ;; Clear whole buffer inline images.
+   ((equal arg '(64))
+    (org-remove-inline-images (point-min) (point-max))
+    (message "Inline images preview disabled in buffer."))
+   ;; Display whole buffer inline images.
+   ((equal arg '(16))
+    (message "Displaying all inline images in buffer...")
+    (org-display-inline-images include-linked nil (point-min) (point-max))
+    (message "Displaying all inline images in buffer... done."))
+   ;; Clear current section.
+   ((equal arg '(4))
+    (let* ((beg (if (use-region-p)
+                    (region-beginning)
+                  (if (org-before-first-heading-p) (point-min)
+                    (save-excursion
+	              (org-with-limited-levels (org-back-to-heading t) (point))))))
+           (end (if (use-region-p)
+                    (region-end)
+                  (org-with-limited-levels (org-entry-end-position))))
+           (inline-images (org--inline-image-overlays beg end)))
+      (org-remove-inline-images beg end)
+      (message "%d inline images display removed." (length inline-images))))
+   ;; Display region selected inline images.
+   ((use-region-p)
+    (if (seq-contains-p
+         (mapcar
+          (lambda (ov)
+            (plist-get (overlay-properties ov) 'org-image-overlay))
+          (overlays-in beg end))
+         t)
+        (progn
+          (org-remove-inline-images beg end)
+          (message "Inline images in region removed."))
+      (message "Displaying inline images in region...")
+      (org-display-inline-images include-linked nil (region-beginning) (region-end))
+      (message "Displaying inline images in region... done.")))
+   ;; Toggle display of inline image link at point.
+   ((let ((context (org-element-context)))
+      (and (memq (org-element-type context) '(link))
+	   (let ((beg (org-element-property :begin context))
+		 (end (org-element-property :end context)))
+	     (if (org--inline-image-overlays beg end)
+                 (progn
+                   (org-remove-inline-images beg end)
+	           (message "Display inline image at point removed."))
+	       (org-display-inline-images include-linked t beg end)
+	       (message "Displaying inline image at point ... done."))
+	     t))))
+   ;; Display inline images under current section.
+   (t
+    (let ((beg (if (org-before-first-heading-p) (point-min)
+		 (save-excursion
+		   (org-with-limited-levels (org-back-to-heading t) (point)))))
+	  (end (org-with-limited-levels (org-entry-end-position))))
+      (message "Displaying inline images in section...")
+      (org-display-inline-images include-linked t beg end)
+      (message "Displaying inline images in section... done.")))))
 
 (defun org-redisplay-inline-images ()
   "Assure display of inline images and refresh them."
-- 
2.39.2 (Apple Git-143)


[-- 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 --]

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01  4:40           ` [PATCH v3] " Christopher M. Miles
@ 2023-08-01  8:04             ` Ihor Radchenko
  2023-08-01 12:17               ` [PATCH v3.1] " Christopher M. Miles
  0 siblings, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2023-08-01  8:04 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

>> This is not a toggle. This is unconditional refresh.
>>
> Yes, indeed it's a unconditional refresh. It does not match the meaning of word "toggle".
>
> Seems need to detect whether has image overlays in region. I added this
> detection in new patch. Like bellowing:
>
> #+begin_src emacs-lisp
> ...
> ((use-region-p)
>     (if (seq-contains-p
>          (mapcar
>           (lambda (ov)
>             (plist-get (overlay-properties ov) 'org-image-overlay))
>           (overlays-in beg end))
>          t)

You can just use `org--inline-image-overlays'.

>> And there is no clean way to allow INCLUDE-LINKED while keeping
>> consistency with latex preview commands.
>
> About the INCLUDE-LINKED argument, I don't know how to process it. In
> theory, it should be handled by function org-display-inline-images
> instead of org-toggle-inline-images. If you have improvements on it, can
> you add code on my patch?

The problem here is backwards compatibility. `org-toggle-inline-images'
is bound to C-c C-x C-v and people may be used to C-u C-c C-x C-v
displaying linked images like

[[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]

I will need to think more how to approach this.

>> What we might do here is making a new defcustom that will control
>> whether linked images should be displayed. Then, something like C-1
>> org-toggle-inline-images could toggle that defcustom and refresh all the
>> image previews in buffer (if any).
>>
>> WDYT?
>
> Refreshing all image previews in buffer is same as old behavior.

Sure. But the idea of this specific C-1 prefix argument is to toggle the
hypothetical defcustom `org-inline-images-include-linked'. If we flip it
we may need to remove/add linked image previews or otherwise risk users
being confused by the defcustom not taking effect.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01  8:04             ` Ihor Radchenko
@ 2023-08-01 12:17               ` Christopher M. Miles
  2023-08-01 14:09                 ` Ihor Radchenko
  2023-08-02  7:26                 ` Ihor Radchenko
  0 siblings, 2 replies; 18+ messages in thread
From: Christopher M. Miles @ 2023-08-01 12:17 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode


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


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>> This is not a toggle. This is unconditional refresh.
>>>
>> Yes, indeed it's a unconditional refresh. It does not match the meaning of word "toggle".
>>
>> Seems need to detect whether has image overlays in region. I added this
>> detection in new patch. Like bellowing:
>>
>> #+begin_src emacs-lisp
>> ...
>> ((use-region-p)
>>     (if (seq-contains-p
>>          (mapcar
>>           (lambda (ov)
>>             (plist-get (overlay-properties ov) 'org-image-overlay))
>>           (overlays-in beg end))
>>          t)
>
> You can just use `org--inline-image-overlays'.
>

Aha, I forget this API function, I applied in new patch.

>>> And there is no clean way to allow INCLUDE-LINKED while keeping
>>> consistency with latex preview commands.
>>
>> About the INCLUDE-LINKED argument, I don't know how to process it. In
>> theory, it should be handled by function org-display-inline-images
>> instead of org-toggle-inline-images. If you have improvements on it, can
>> you add code on my patch?
>
> The problem here is backwards compatibility. `org-toggle-inline-images'
> is bound to C-c C-x C-v and people may be used to C-u C-c C-x C-v
> displaying linked images like
>
> [[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]
>
> I will need to think more how to approach this.
>

Indeed.

>>> What we might do here is making a new defcustom that will control
>>> whether linked images should be displayed. Then, something like C-1
>>> org-toggle-inline-images could toggle that defcustom and refresh all the
>>> image previews in buffer (if any).
>>>
>>> WDYT?
>>
>> Refreshing all image previews in buffer is same as old behavior.
>
> Sure. But the idea of this specific C-1 prefix argument is to toggle the
> hypothetical defcustom `org-inline-images-include-linked'. If we flip it
> we may need to remove/add linked image previews or otherwise risk users
> being confused by the defcustom not taking effect.

I checked source code, don't know where to insert this functionality.
Is it be in `org-display-inline-images` or somewhere else?
I will find time to checking code whether can add this in another patch.
If you have plan for this, let me know.

I think current patch is ready for merging now. WDYT?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-Improve-inline-images-displaying-like-LaTeX-prev.patch --]
[-- Type: text/x-patch, Size: 5168 bytes --]

From 2f68f0172dc5e452c05a9d254eab8ae797bcd15b Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Mon, 22 May 2023 16:25:33 +0800
Subject: [PATCH] org: Improve inline images displaying like LaTeX previewing

* lisp/org.el (org-toggle-inline-images): Implement LaTeX previewing
same logic in inline images toggle displaying.
---
 lisp/org.el | 89 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 74 insertions(+), 15 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index e72cf056a..04f713d26 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16160,22 +16160,81 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
       (when (memq ov org-inline-image-overlays)
         (push ov result)))))
 
-(defun org-toggle-inline-images (&optional include-linked beg end)
-  "Toggle the display of inline images.
-INCLUDE-LINKED is passed to `org-display-inline-images'."
+(defun org-toggle-inline-images (&optional arg include-linked beg end)
+  "Toggle the display of inline images at point.
+INCLUDE-LINKED is passed to `org-display-inline-images'.
+
+If cursor is on an inline image link, display the inline image.
+If there is none, remove it otherwise.
+If there is no inline image link at point, display all inline images in the current section.
+With an active region, display inline images in the region.
+
+With a `\\[universal-argument]' prefix argument ARG, clear inline
+images in the current section.
+
+With a `\\[universal-argument] \\[universal-argument]' prefix
+ argument ARG, display all inline images in the buffer.
+
+With a `\\[universal-argument] \\[universal-argument] \
+\\[universal-argument]' prefix argument ARG, clear all inline
+images in the buffer."
   (interactive "P")
-  (if (org--inline-image-overlays beg end)
-      (progn
-        (org-remove-inline-images beg end)
-        (when (called-interactively-p 'interactive)
-	  (message "Inline image display turned off")))
-    (org-display-inline-images include-linked nil beg end)
-    (when (called-interactively-p 'interactive)
-      (let ((new (org--inline-image-overlays beg end)))
-        (message (if new
-		     (format "%d images displayed inline"
-			     (length new))
-		   "No images to display inline"))))))
+  (cond
+   ((not (display-graphic-p)) nil)
+   ;; Clear whole buffer inline images.
+   ((equal arg '(64))
+    (org-remove-inline-images (point-min) (point-max))
+    (message "Inline images preview disabled in buffer."))
+   ;; Display whole buffer inline images.
+   ((equal arg '(16))
+    (message "Displaying all inline images in buffer...")
+    (org-display-inline-images include-linked nil (point-min) (point-max))
+    (message "Displaying all inline images in buffer... done."))
+   ;; Clear current section.
+   ((equal arg '(4))
+    (let* ((beg (if (use-region-p)
+                    (region-beginning)
+                  (if (org-before-first-heading-p) (point-min)
+                    (save-excursion
+	              (org-with-limited-levels (org-back-to-heading t) (point))))))
+           (end (if (use-region-p)
+                    (region-end)
+                  (org-with-limited-levels (org-entry-end-position))))
+           (inline-images (org--inline-image-overlays beg end)))
+      (org-remove-inline-images beg end)
+      (message "%d inline images display removed." (length inline-images))))
+   ;; Display region selected inline images.
+   ((use-region-p)
+    (let ((beg (region-beginning))
+          (end (region-end)))
+      (if (org--inline-image-overlays beg end)
+          (progn
+            (org-remove-inline-images beg end)
+            (message "Inline images in region removed."))
+        (message "Displaying inline images in region...")
+        (org-display-inline-images include-linked t beg end)
+        (message "Displaying inline images in region... done."))))
+   ;; Toggle display of inline image link at point.
+   ((let ((context (org-element-context)))
+      (and (memq (org-element-type context) '(link))
+	   (let ((beg (org-element-property :begin context))
+		 (end (org-element-property :end context)))
+	     (if (org--inline-image-overlays beg end)
+                 (progn
+                   (org-remove-inline-images beg end)
+	           (message "Display inline image at point removed."))
+	       (org-display-inline-images include-linked t beg end)
+	       (message "Displaying inline image at point ... done."))
+	     t))))
+   ;; Display inline images under current section.
+   (t
+    (let ((beg (if (org-before-first-heading-p) (point-min)
+		 (save-excursion
+		   (org-with-limited-levels (org-back-to-heading t) (point)))))
+	  (end (org-with-limited-levels (org-entry-end-position))))
+      (message "Displaying inline images in section...")
+      (org-display-inline-images include-linked t beg end)
+      (message "Displaying inline images in section... done.")))))
 
 (defun org-redisplay-inline-images ()
   "Assure display of inline images and refresh them."
-- 
2.39.2 (Apple Git-143)


[-- 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 --]

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01 12:17               ` [PATCH v3.1] " Christopher M. Miles
@ 2023-08-01 14:09                 ` Ihor Radchenko
  2023-08-01 15:22                   ` Christopher M. Miles
  2023-08-01 15:46                   ` Christopher M. Miles
  2023-08-02  7:26                 ` Ihor Radchenko
  1 sibling, 2 replies; 18+ messages in thread
From: Ihor Radchenko @ 2023-08-01 14:09 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

> I think current patch is ready for merging now. WDYT?

No, unfortunately.
With your patch, it will become impossible to display linked images
using interactive command.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01 14:09                 ` Ihor Radchenko
@ 2023-08-01 15:22                   ` Christopher M. Miles
  2023-08-01 15:46                   ` Christopher M. Miles
  1 sibling, 0 replies; 18+ messages in thread
From: Christopher M. Miles @ 2023-08-01 15:22 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> I think current patch is ready for merging now. WDYT?
>
> No, unfortunately.
> With your patch, it will become impossible to display linked images
> using interactive command.

I still need time to study how to add support for this. Most likely I
can't implement it by myself. Would you modify my patch to add support
for this?

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01 14:09                 ` Ihor Radchenko
  2023-08-01 15:22                   ` Christopher M. Miles
@ 2023-08-01 15:46                   ` Christopher M. Miles
  2023-08-02 16:08                     ` Ihor Radchenko
  1 sibling, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2023-08-01 15:46 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> I think current patch is ready for merging now. WDYT?
>
> No, unfortunately.
> With your patch, it will become impossible to display linked images
> using interactive command.

Does this code match the needs?

#+begin_src emacs-lisp
   ;; [M-1] / [C-1] argument for linked images like:
   ;; [[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]
   ((equal arg 1)
    (setq org-inline-images-include-linked (not org-inline-images-include-linked))
    (let ((current-prefix-arg nil))
      (org-toggle-inline-images nil org-inline-images-include-linked)))
#+end_src

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01 12:17               ` [PATCH v3.1] " Christopher M. Miles
  2023-08-01 14:09                 ` Ihor Radchenko
@ 2023-08-02  7:26                 ` Ihor Radchenko
  2023-08-02 15:44                   ` Christopher M. Miles
  1 sibling, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2023-08-02  7:26 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

>> The problem here is backwards compatibility. `org-toggle-inline-images'
>> is bound to C-c C-x C-v and people may be used to C-u C-c C-x C-v
>> displaying linked images like
>>
>> [[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]
>>
>> I will need to think more how to approach this.
>>
>
> Indeed.

Another problem with your change is that the order of arguments changed.
If there is some Elisp doing something like
(org-toggle-inline-images INCLUDE-LINKED), your patch will break the
code.

I think that instead of changing the existing function, we can convert
your patch into a new function `org-toggle-inline-images-command' that
will be free to alter the argument order. We can then re-bind that
function in org-keys to make it used by default, but only interactively.

As for displaying linked images, what about something like


C-1 C-c C-x C-v being equivalent of
C-c C-x C-v + INCLUDE-LINKED=t
(display in current section/region, with linked)

and

C-11 C-c C-x C-v being equivalent of
C-u C-u C-c C-x C-v + INCLUDE-LINKED=t
(display in the whole buffer, with linked)

> +(defun org-toggle-inline-images (&optional arg include-linked beg end)
> +  "Toggle the display of inline images at point.
> +INCLUDE-LINKED is passed to `org-display-inline-images'.
> +
> +If cursor is on an inline image link, display the inline image.
> +If there is none, remove it otherwise.

I do not quite understand what the last line is trying to say.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-02  7:26                 ` Ihor Radchenko
@ 2023-08-02 15:44                   ` Christopher M. Miles
  2023-08-04  8:20                     ` Ihor Radchenko
  0 siblings, 1 reply; 18+ messages in thread
From: Christopher M. Miles @ 2023-08-02 15:44 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode

[-- Attachment #1: Type: text/plain, Size: 2590 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>> The problem here is backwards compatibility. `org-toggle-inline-images'
>>> is bound to C-c C-x C-v and people may be used to C-u C-c C-x C-v
>>> displaying linked images like
>>>
>>> [[https://orgmode.org/resources/img/org-mode-unicorn.svg][description]]
>>>
>>> I will need to think more how to approach this.
>>>
>>
>> Indeed.
>
> Another problem with your change is that the order of arguments changed.
> If there is some Elisp doing something like
> (org-toggle-inline-images INCLUDE-LINKED), your patch will break the
> code.
>
> I think that instead of changing the existing function, we can convert
> your patch into a new function `org-toggle-inline-images-command' that
> will be free to alter the argument order. We can then re-bind that
> function in org-keys to make it used by default, but only interactively.
>

I don't think so, the patch main purpose is for improve image refreshing
after babel result image displaying. Because the function is hooked by
other ob-* packages. Another purpose is headline level images displaying.
So modifying this function is the only way.

> As for displaying linked images, what about something like
>
>
> C-1 C-c C-x C-v being equivalent of
> C-c C-x C-v + INCLUDE-LINKED=t
> (display in current section/region, with linked)
>
> and
>
> C-11 C-c C-x C-v being equivalent of
> C-u C-u C-c C-x C-v + INCLUDE-LINKED=t
> (display in the whole buffer, with linked)
>

Don't know, I have not use it this way. I think INCLUDE-LINKED is just a
option argument for function org-display-inline-images. No need to be
available for toggle in interactive command. An option like
org-inline-images-include-linked is enough.

>> +(defun org-toggle-inline-images (&optional arg include-linked beg end)
>> +  "Toggle the display of inline images at point.
>> +INCLUDE-LINKED is passed to `org-display-inline-images'.
>> +
>> +If cursor is on an inline image link, display the inline image.
>> +If there is none, remove it otherwise.
>
> I do not quite understand what the last line is trying to say.

Emmm, I forget the meaning of it. I read the docstring again, seems it
can be deleted. I will delete it in my patch.

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-01 15:46                   ` Christopher M. Miles
@ 2023-08-02 16:08                     ` Ihor Radchenko
  2023-08-04  6:30                       ` Christopher M. Miles
  0 siblings, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2023-08-02 16:08 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

>> With your patch, it will become impossible to display linked images
>> using interactive command.
>
> Does this code match the needs?

Please check my latest reply (https://list.orgmode.org/87o7jpoqfl.fsf@localhost/T/#m25fbb254635512a7bf86d368bf93a24a1c2fb3f1).
I think we may go away without introducing an extra defcustom.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-02 16:08                     ` Ihor Radchenko
@ 2023-08-04  6:30                       ` Christopher M. Miles
  0 siblings, 0 replies; 18+ messages in thread
From: Christopher M. Miles @ 2023-08-04  6:30 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Christopher M. Miles, Org mode

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>>> With your patch, it will become impossible to display linked images
>>> using interactive command.
>>
>> Does this code match the needs?
>
> Please check my latest reply (https://list.orgmode.org/87o7jpoqfl.fsf@localhost/T/#m25fbb254635512a7bf86d368bf93a24a1c2fb3f1).
> I think we may go away without introducing an extra defcustom.

After yesterday night studying source code, I still can't figure out
solution. So I pass this patch to you. Wait you to finish the unfinished
part of path.

-- 

[ 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 --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3.1] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
  2023-08-02 15:44                   ` Christopher M. Miles
@ 2023-08-04  8:20                     ` Ihor Radchenko
  0 siblings, 0 replies; 18+ messages in thread
From: Ihor Radchenko @ 2023-08-04  8:20 UTC (permalink / raw)
  To: Christopher M. Miles; +Cc: Org mode

"Christopher M. Miles" <numbchild@gmail.com> writes:

>> I think that instead of changing the existing function, we can convert
>> your patch into a new function `org-toggle-inline-images-command' that
>> will be free to alter the argument order. We can then re-bind that
>> function in org-keys to make it used by default, but only interactively.
>>
> I don't think so, the patch main purpose is for improve image refreshing
> after babel result image displaying. Because the function is hooked by
> other ob-* packages. Another purpose is headline level images displaying.
> So modifying this function is the only way.

Fair point.
Then, for backward compatibility, we may treat any non-nil, non-list
(like '(4), '(16), '(64)), non-number (like 1, 11) value as
INCLUDE-LINKED. This way, the existing calls like
(org-toggle-inline-images t) will not be broken.

Also, the signature should be

(defun org-toggle-inline-images (&optional arg beg end include-linked)

So that the meaning of the second and third argument is unchanged.

>> As for displaying linked images, what about something like
>>
>>
>> C-1 C-c C-x C-v being equivalent of
>> C-c C-x C-v + INCLUDE-LINKED=t
>> (display in current section/region, with linked)
>>
>> and
>>
>> C-11 C-c C-x C-v being equivalent of
>> C-u C-u C-c C-x C-v + INCLUDE-LINKED=t
>> (display in the whole buffer, with linked)
>>
> Don't know, I have not use it this way. I think INCLUDE-LINKED is just a
> option argument for function org-display-inline-images. No need to be
> available for toggle in interactive command. An option like
> org-inline-images-include-linked is enough.

Sorry, but ignoring backwards compatibility is not an option.
If you personally haven't used some feature, it does not mean that
others also didn't.

We can make limited compromises, but should try our best not to break
things that were working before.
See https://bzg.fr/en/the-software-maintainers-pledge/

>>> +If cursor is on an inline image link, display the inline image.
>>> +If there is none, remove it otherwise.
>>
>> I do not quite understand what the last line is trying to say.
>
> Emmm, I forget the meaning of it. I read the docstring again, seems it
> can be deleted. I will delete it in my patch.

> After yesterday night studying source code, I still can't figure out
> solution. So I pass this patch to you. Wait you to finish the unfinished
> part of path.

I hope that now you have enough information to update the patch.
Let me know if not.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-08-04  8:21 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15  3:28 [PATCH] add a function to only refresh inline images under current headline instead of global buffer Christopher M. Miles
2023-05-15 11:08 ` Ihor Radchenko
2023-05-15 13:01   ` Christopher M. Miles
2023-05-15 14:00   ` [PATCH v2] " Christopher M. Miles
2023-05-16  9:17     ` Ihor Radchenko
2023-05-16 12:18       ` Christopher M. Miles
2023-07-24 11:25         ` Ihor Radchenko
2023-08-01  4:40           ` [PATCH v3] " Christopher M. Miles
2023-08-01  8:04             ` Ihor Radchenko
2023-08-01 12:17               ` [PATCH v3.1] " Christopher M. Miles
2023-08-01 14:09                 ` Ihor Radchenko
2023-08-01 15:22                   ` Christopher M. Miles
2023-08-01 15:46                   ` Christopher M. Miles
2023-08-02 16:08                     ` Ihor Radchenko
2023-08-04  6:30                       ` Christopher M. Miles
2023-08-02  7:26                 ` Ihor Radchenko
2023-08-02 15:44                   ` Christopher M. Miles
2023-08-04  8:20                     ` Ihor Radchenko

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).