Re: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer

2023-07-24 Thread Ihor Radchenko
"Christopher M. Miles"  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 .
Support Org development at ,
or support my work at 



Re: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer

2023-05-16 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  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


signature.asc
Description: PGP signature


Re: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer

2023-05-16 Thread Ihor Radchenko
"Christopher M. Miles"  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 .
Support Org development at ,
or support my work at