Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-25 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> Sure. Can you please send the final version of the patch and the working
>> tests?
>
> I separated code patch and test into two patches. You can apply selectively.

Sorry, I was not very clear.
I meant to remove that patch that fails due to noninteractive and leave
the rest.

>  doc/org-manual.org|   6 +++
>  etc/ORG-NEWS  |   7 
>  lisp/org-cycle.el |  38 +-
>  lisp/org-keys.el  |   2 +-
>  lisp/org.el   |  21 ++
>  .../images/Org mode logo mono-color.png   | Bin 0 -> 7523 bytes

The image should belong to the test patch.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-23 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> Whether can this patch be merged at first, put the test in future to
> finish? In recent days, I still have not figured out this image overlays
> test.

Sure. Can you please send the final version of the patch and the working
tests?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-23 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> Whether can this patch be merged at first, put the test in future to
>> finish? In recent days, I still have not figured out this image overlays
>> test.
>
> Sure. Can you please send the final version of the patch and the working
> tests?

I separated code patch and test into two patches. You can apply selectively.

From 2beacea9082e7eddd5db426cd180ea42ebb46656 Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Tue, 4 Oct 2022 12:36:32 +0800
Subject: [PATCH 1/2] org.el: Support auto display inline images when cycling

* lisp/org.el (org-toggle-inline-images): Support region.
(org-display-inline-images): Fix refresh argument logic.
(org-remove-inline-images): Support region.

* lisp/org-keys.el (org-toggle-inline-images): Update arguments.

* lisp/org-cycle.el (org-cycle-inline-images-display): Add new option to
control whether auto display inline images when cycling.
(org-cycle-display-inline-images): Add new hook function to auto display
inline images when cycling.
(org-cycle-hook): Add `org-cycle-display-inline-images' into cycling
hook by default.

* doc/org-manual.org (Exporting):
* etc/ORG-NEWS: Document the new option.
---
 doc/org-manual.org|   6 +++
 etc/ORG-NEWS  |   7 
 lisp/org-cycle.el |  38 +-
 lisp/org-keys.el  |   2 +-
 lisp/org.el   |  21 ++
 .../images/Org mode logo mono-color.png   | Bin 0 -> 7523 bytes
 6 files changed, 63 insertions(+), 11 deletions(-)
 create mode 100755 testing/examples/images/Org mode logo mono-color.png

diff --git a/doc/org-manual.org b/doc/org-manual.org
index ad584d7a5..18a050069 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -11489,6 +11489,12 @@ command:
   - When set to nil, try to get the width from an =#+ATTR.*= keyword
 and fall back on the original width if none is found.
 
+
+#+vindex: org-cycle-inline-images-display
+Inline images can also be displayed when cycling the folding state.
+When custom option ~org-cycle-inline-images-display~ is set, the
+visible inline images under subtree will be displayed automatically.
+
 ** Captions
 :PROPERTIES:
 :DESCRIPTION: Describe tables, images...
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c18c03725..d87b49bd3 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -307,6 +307,13 @@ to pass the contents of a named code block as a string argument.
 The new property =ORG-IMAGE-ACTUAL-WIDTH= can override the global
 variable ~org-image-actual-width~ value for inline images display width.
 
+*** Outline cycling can now include inline image visibility
+
+New ~org-cycle-hook~ function ~org-cycle-display-inline-images~ for
+auto-displaying inline images in the visible parts of the subtree.
+This behavior is controlled by new custom option
+~org-cycle-inline-images-display~.
+
 *** New ~org-babel-tangle-finished-hook~ hook run at the very end of ~org-babel-tangle~
 
 This provides a proper counterpart to ~org-babel-pre-tangle-hook~, as
diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el
index c1caa3fdc..14388caaf 100644
--- a/lisp/org-cycle.el
+++ b/lisp/org-cycle.el
@@ -208,8 +208,9 @@ the values `folded', `children', or `subtree'."
   :type 'hook)
 
 (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
-		   org-cycle-show-empty-lines
-		   org-cycle-optimize-window-after-visibility-change)
+org-cycle-show-empty-lines
+org-cycle-optimize-window-after-visibility-change
+org-cycle-display-inline-images)
   "Hook that is run after `org-cycle' has changed the buffer visibility.
 The function(s) in this hook must accept a single argument which indicates
 the new state that was set by the most recent `org-cycle' command.  The
@@ -229,6 +230,13 @@ normal outline commands like `show-all', but not with the cycling commands."
   :group 'org-cycle
   :type 'boolean)
 
+(defcustom org-cycle-inline-images-display nil
+  "Non-nil means auto display inline images under subtree when cycling."
+  :group 'org-startup
+  :group 'org-cycle
+  :package-version '(Org . "9.6")
+  :type 'boolean)
+
 (defvar org-cycle-tab-first-hook nil
   "Hook for functions to attach themselves to TAB.
 See `org-ctrl-c-ctrl-c-hook' for more information.
@@ -775,6 +783,32 @@ STATE should be one of the symbols listed in the docstring of
 		   "Subtree is archived and stays closed.  Use \
 `\\[org-cycle-force-archived]' to cycle it anyway."))
 
+(defun org-cycle-display-inline-images (state)
+  "Auto display inline images under subtree when cycling.
+It works when `org-cycle-inline-images-display' is non-nil."
+  (when org-cycle-inline-images-display
+(pcase state
+  ('children
+   (org-with-wide-buffer
+(org-narrow-to-subtree)
+;; If has nested headlines, beg,end only from parent 

Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-21 Thread Christopher M. Miles

Whether can this patch be merged at first, put the test in future to
finish? In recent days, I still have not figured out this image overlays
test.

"Christopher M. Miles"  writes:

> [[PGP Signed Part:Undecided]]
>
> Ihor Radchenko  writes:
>
>> "Christopher M. Miles"  writes:
>>
 I think that the best we can do in this situation is mocking
 `create-image' in batch mode to return non-nil using `cl-letf'.
>>>
>>> I checked the `create-image' in image.el source code, don't know how to
>>> mocking this. I have no experience and idea about this. I also searched
>>> org testing. Have not found similar situations.
>>>
>>> If you have idea how to write this test, I suggest pass this word to
>>> you. What do you think?
>>
>> I imagine something like
>>
>> ;; Mock `create-image' to work noninteractively.
>> (cl-letf (((symbol-function 'create-image)
>> (lambda ( _)
>>   `(image :type "dummy" :data "dummy"
>>   )
>
> After wrapped your cl-letf redefining function binding. Still failed on test.
>
> Here is the new test code:
>
> #+begin_src emacs-lisp
> (ert-deftest test-org-fold/org-fold-display-inline-images ()
>   "Test inline images displaying when cycling."
>   ;; Mock `create-image' to work noninteractively.
>   (cl-letf (((symbol-function 'create-image)
>(lambda ( _) `(image :type "dummy" :data "dummy"
> (let* ((org-cycle-inline-images-display t)
>(images-dir (expand-file-name "examples/images/" org-test-dir))
>(org-logo-image (expand-file-name "Org mode logo mono-color.png" 
> images-dir)))
>   ;; `org-cycle' -(state)-> `'children' display child inline images.
>   (org-test-with-temp-text
>(format "* Heading 1
> [[file:%s]]
> " org-logo-image)
>(org-overview)
>;; (org-cycle)
>;; (org-cycle-internal-local)
>;; (org-cycle-display-inline-images 'children)
>(org-fold-show-children)
>(run-hook-with-args 'org-cycle-hook 'children)
>(org-next-link)
>(should org-inline-image-overlays)
>(should (overlays-at (point)))
>(org-toggle-inline-images)
>(should-not (overlays-at (point
>   
>   ;; `org-cycle' -(state)-> `'subtree' display subtrees inline images.
>   (org-test-with-temp-text
>(format "* Heading 1
> [[file:%s]]
> ** Subheading 1
> [[file:%s]]
> ** Subheading 2
> [[file:%s]]" org-logo-image org-logo-image org-logo-image)
>(org-overview)
>;; (org-cycle)
>;; (org-cycle)
>;; (org-cycle-internal-global)
>(org-fold-show-subtree)
>(run-hook-with-args 'org-cycle-hook 'subtree)
>(org-next-link)
>(org-next-link)
>;; (should org-inline-image-overlays)
>(should (overlays-at (point)))
>(org-toggle-inline-images)
>(should-not (overlays-at (point
>   
>   ;; `org-cycle' -(state)-> `'folded' remove inline image overlays.
>   (org-test-with-temp-text
>(format "* Heading 1
> [[file:%s]]
> ** Subheading 1
> [[file:%s]]
> ** Subheading 2
> [[file:%s]]" org-logo-image org-logo-image org-logo-image)
>(org-overview)
>(org-show-subtree)
>(org-fold-subtree t)
>(run-hook-with-args 'org-cycle-hook 'folded)
>(should (null org-inline-image-overlays))
>(should (null (overlays-in (point-min) (point-max
>(org-show-subtree)
>(should-not org-inline-image-overlays)
>(should-not (overlays-in (point-min) (point-max)))
> #+end_src
>
>
> And failed after command:
>
> #+begin_src shell
> make BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty 
> #+end_src
>
>
> Here is the output:
>
> #+begin_example
> ~/Code/Emacs/org-mode:main*:1 λ make 
> BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty  
> install -m 755 -d 
> /var/folders/ym/f3v5_yk1279g5ls70x3hzblhgn/T//tmp-orgtest
> TMPDIR=/var/folders/ym/f3v5_yk1279g5ls70x3hzblhgn/T//tmp-orgtest emacs  
> -Q -batch --eval '(setq vc-handled-backends nil org-startup-folded nil 
> org-element-cache-persistent nil)'  --eval '(add-to-list '"'"'load-path 
> (concat default-directory "lisp"))' --eval '(add-to-list '"'"'load-path 
> (concat default-directory "testing"))'  -l org-batch-test-init --eval '(setq 
> org-batch-test t org-babel-load-languages (quote ( (awk . t)  (C . t)  
> (fortran . t)  (maxima . t)  (lilypond . t)  (octave . t)  (perl . t)  
> (python . t)  (emacs-lisp . t)  (shell . t)  (org . t))) org-test-select-re 
> "test-org-fold/org-fold-display-inline-images" )' -l org-loaddefs.el -l cl -l 
> testing/org-test.el -l ert -l org -l ox -l ol  --eval 
> '(org-test-run-batch-tests org-test-select-re)'
> Package cl is deprecated
> Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/org.el' newer than 
> byte-compiled file; using older file
> Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/org-compat.el' newer 
> than byte-compiled file; using older file

Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-10 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> I think that the best we can do in this situation is mocking
>>> `create-image' in batch mode to return non-nil using `cl-letf'.
>>
>> I checked the `create-image' in image.el source code, don't know how to
>> mocking this. I have no experience and idea about this. I also searched
>> org testing. Have not found similar situations.
>>
>> If you have idea how to write this test, I suggest pass this word to
>> you. What do you think?
>
> I imagine something like
>
> ;; Mock `create-image' to work noninteractively.
> (cl-letf (((symbol-function 'create-image)
>  (lambda ( _)
>`(image :type "dummy" :data "dummy"
>   )

After wrapped your cl-letf redefining function binding. Still failed on test.

Here is the new test code:

#+begin_src emacs-lisp
(ert-deftest test-org-fold/org-fold-display-inline-images ()
  "Test inline images displaying when cycling."
  ;; Mock `create-image' to work noninteractively.
  (cl-letf (((symbol-function 'create-image)
 (lambda ( _) `(image :type "dummy" :data "dummy"
(let* ((org-cycle-inline-images-display t)
   (images-dir (expand-file-name "examples/images/" org-test-dir))
   (org-logo-image (expand-file-name "Org mode logo mono-color.png" 
images-dir)))
  ;; `org-cycle' -(state)-> `'children' display child inline images.
  (org-test-with-temp-text
   (format "* Heading 1
[[file:%s]]
" org-logo-image)
   (org-overview)
   ;; (org-cycle)
   ;; (org-cycle-internal-local)
   ;; (org-cycle-display-inline-images 'children)
   (org-fold-show-children)
   (run-hook-with-args 'org-cycle-hook 'children)
   (org-next-link)
   (should org-inline-image-overlays)
   (should (overlays-at (point)))
   (org-toggle-inline-images)
   (should-not (overlays-at (point
  
  ;; `org-cycle' -(state)-> `'subtree' display subtrees inline images.
  (org-test-with-temp-text
   (format "* Heading 1
[[file:%s]]
** Subheading 1
[[file:%s]]
** Subheading 2
[[file:%s]]" org-logo-image org-logo-image org-logo-image)
   (org-overview)
   ;; (org-cycle)
   ;; (org-cycle)
   ;; (org-cycle-internal-global)
   (org-fold-show-subtree)
   (run-hook-with-args 'org-cycle-hook 'subtree)
   (org-next-link)
   (org-next-link)
   ;; (should org-inline-image-overlays)
   (should (overlays-at (point)))
   (org-toggle-inline-images)
   (should-not (overlays-at (point
  
  ;; `org-cycle' -(state)-> `'folded' remove inline image overlays.
  (org-test-with-temp-text
   (format "* Heading 1
[[file:%s]]
** Subheading 1
[[file:%s]]
** Subheading 2
[[file:%s]]" org-logo-image org-logo-image org-logo-image)
   (org-overview)
   (org-show-subtree)
   (org-fold-subtree t)
   (run-hook-with-args 'org-cycle-hook 'folded)
   (should (null org-inline-image-overlays))
   (should (null (overlays-in (point-min) (point-max
   (org-show-subtree)
   (should-not org-inline-image-overlays)
   (should-not (overlays-in (point-min) (point-max)))
#+end_src

And failed after command:

#+begin_src shell
make BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty 
#+end_src

Here is the output:

#+begin_example
~/Code/Emacs/org-mode:main*:1 λ make 
BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty  
install -m 755 -d /var/folders/ym/f3v5_yk1279g5ls70x3hzblhgn/T//tmp-orgtest
TMPDIR=/var/folders/ym/f3v5_yk1279g5ls70x3hzblhgn/T//tmp-orgtest emacs  -Q 
-batch --eval '(setq vc-handled-backends nil org-startup-folded nil 
org-element-cache-persistent nil)'  --eval '(add-to-list '"'"'load-path (concat 
default-directory "lisp"))' --eval '(add-to-list '"'"'load-path (concat 
default-directory "testing"))'  -l org-batch-test-init --eval '(setq 
org-batch-test t org-babel-load-languages (quote ( (awk . t)  (C . t)  (fortran 
. t)  (maxima . t)  (lilypond . t)  (octave . t)  (perl . t)  (python . t)  
(emacs-lisp . t)  (shell . t)  (org . t))) org-test-select-re 
"test-org-fold/org-fold-display-inline-images" )' -l org-loaddefs.el -l cl -l 
testing/org-test.el -l ert -l org -l ox -l ol  --eval 
'(org-test-run-batch-tests org-test-select-re)'
Package cl is deprecated
Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/org.el' newer than 
byte-compiled file; using older file
Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/org-compat.el' newer 
than byte-compiled file; using older file
Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/org-macs.el' newer 
than byte-compiled file; using older file
Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/org-keys.el' newer 
than byte-compiled file; using older file
Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/oc.el' newer than 
byte-compiled file; using older file
Source file `/Users/stardiviner/Code/Emacs/org-mode/lisp/ol.el' newer than 

Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-09 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> I think that the best we can do in this situation is mocking
>> `create-image' in batch mode to return non-nil using `cl-letf'.
>
> I checked the `create-image' in image.el source code, don't know how to
> mocking this. I have no experience and idea about this. I also searched
> org testing. Have not found similar situations.
>
> If you have idea how to write this test, I suggest pass this word to
> you. What do you think?

I imagine something like

;; Mock `create-image' to work noninteractively.
(cl-letf (((symbol-function 'create-image)
   (lambda ( _)
 `(image :type "dummy" :data "dummy"
  )

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-08 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>>> However, upon testing your patch, tests are still failing on my side.
>>> Can you please investigate?
>>
>> But If I use [M-x ert] to run the test 
>> "test-org-fold/org-fold-display-inline-images" is passed.
>> Here is the steps:
>> 1. [M-x load-file RET /path/to/org-mode/testing/org-test.el RET]
>> 2. [C-M-x] to evaluate the target test
>> 3. [M-x ert RET test-org-fold/org-fold-display-inline-images RET] to run 
>> this test
>>
>> I attached the uploaded screencast video link to prove it passed.
>>
>> https://share.cleanshot.com/tvUUoQ
>>
>> I tried many different other API functions to cycle or fold/unfold, but none
>> of them works under command "make test" or command
>> "make BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty".
>>
>> I have nothing brain to think for this test now. Really can't figure out
>> why this image is not displayed as overlay. Can you help me to fix this test?
>
> The problem is with batch mode. `create-image' will return nil in batch
> mode and hence no overlays are ever created even though
> `org-display-inline-images' does get called.

I see, no wonder that failed for command "make test" but success in "[M-x ert]".

> I think that the best we can do in this situation is mocking
> `create-image' in batch mode to return non-nil using `cl-letf'.

I checked the `create-image' in image.el source code, don't know how to
mocking this. I have no experience and idea about this. I also searched
org testing. Have not found similar situations.

If you have idea how to write this test, I suggest pass this word to
you. What do you think?

-- 

[ 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 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-08 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

>> However, upon testing your patch, tests are still failing on my side.
>> Can you please investigate?
>
> But If I use [M-x ert] to run the test 
> "test-org-fold/org-fold-display-inline-images" is passed.
> Here is the steps:
> 1. [M-x load-file RET /path/to/org-mode/testing/org-test.el RET]
> 2. [C-M-x] to evaluate the target test
> 3. [M-x ert RET test-org-fold/org-fold-display-inline-images RET] to run this 
> test
>
> I attached the uploaded screencast video link to prove it passed.
>
> https://share.cleanshot.com/tvUUoQ
>
> I tried many different other API functions to cycle or fold/unfold, but none
> of them works under command "make test" or command
> "make BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty".
>
> I have nothing brain to think for this test now. Really can't figure out
> why this image is not displayed as overlay. Can you help me to fix this test?

The problem is with batch mode. `create-image' will return nil in batch
mode and hence no overlays are ever created even though
`org-display-inline-images' does get called.

I think that the best we can do in this situation is mocking
`create-image' in batch mode to return non-nil using `cl-letf'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-04 Thread Christopher M. Miles

Ihor Radchenko  writes:

> "Christopher M. Miles"  writes:
>
>> I think the patch is finished. Please review, Ihor. Thanks for helping.
>
> Thanks for the update!
> I have cleaned the manual and ORG-NEWS wordings.
>
> Upon reading the exported version of the manual, I realized that the
> part in 2.2.1 Global and local cycling section sounds very awkward and
> that we do not mention other cycle hooks like hiding archived
> subtrees there. So, I decided to remove it.
>
> I also rewrote the other part in a bit more direct tone and moved the
> index entry.
>
> (In general, it is useful to try reading the exported version of the
> manual with the additions to check if things are still coherent - manual
> is not just a collection of independent statements; we need to make sure
> that it is not confusing the new readers).
>
> I also updated the commit message adding the CHANGELOG entries about the
> manual and ORG-NEWS.
>

It's OK.

> I am attaching the updated version of the patch with my amendments.

Applied your updated patch.

> However, upon testing your patch, tests are still failing on my side.
> Can you please investigate?

But If I use [M-x ert] to run the test 
"test-org-fold/org-fold-display-inline-images" is passed.
Here is the steps:
1. [M-x load-file RET /path/to/org-mode/testing/org-test.el RET]
2. [C-M-x] to evaluate the target test
3. [M-x ert RET test-org-fold/org-fold-display-inline-images RET] to run this 
test

I attached the uploaded screencast video link to prove it passed.

https://share.cleanshot.com/tvUUoQ

I tried many different other API functions to cycle or fold/unfold, but none
of them works under command "make test" or command
"make BTEST_RE="test-org-fold/org-fold-display-inline-images" test-dirty".

I have nothing brain to think for this test now. Really can't figure out
why this image is not displayed as overlay. Can you help me to fix this test?

#+begin_src emacs-lisp
(ert-deftest test-org-fold/org-fold-display-inline-images ()
  "Test inline images displaying when cycling."
  (let* ((org-cycle-inline-images-display t)
 (images-dir (expand-file-name "examples/images/" org-test-dir))
 (org-logo-image (expand-file-name "Org mode logo mono-color.png" 
images-dir)))
;; `org-cycle' -(state)-> `'children' display child inline images.
(org-test-with-temp-text
(format "* Heading 1
[[file:%s]]
" org-logo-image)
  (org-overview)
  (org-cycle)
  ;; (org-cycle-internal-local)
  ;; (run-hook-with-args 'org-cycle-hook 'children)
  ;; (org-cycle-display-inline-images 'children)
  (org-next-link)
  ;; (should org-inline-image-overlays)
  (should (overlays-at (point)))
  (org-toggle-inline-images)
  (should-not (overlays-at (point

;; `org-cycle' -(state)-> `'subtree' display subtrees inline images.
(org-test-with-temp-text
(format "* Heading 1
[[file:%s]]
** Subheading 1
[[file:%s]]
** Subheading 2
[[file:%s]]" org-logo-image org-logo-image org-logo-image)
  (org-overview)
  (org-cycle)
  (org-cycle)
  ;; (org-cycle-internal-global)
  ;; (run-hook-with-args 'org-cycle-hook 'subtree)
  (org-next-link)
  (org-next-link)
  ;; (should org-inline-image-overlays)
  (should (overlays-at (point)))
  (org-toggle-inline-images)
  (should-not (overlays-at (point

;; `org-cycle' -(state)-> `'folded' remove inline image overlays.
(org-test-with-temp-text
(format "* Heading 1
[[file:%s]]
** Subheading 1
[[file:%s]]
** Subheading 2
[[file:%s]]" org-logo-image org-logo-image org-logo-image)
  (org-overview)
  (org-show-subtree)
  (org-fold-subtree t)
  (run-hook-with-args 'org-cycle-hook 'folded)
  (should (null org-inline-image-overlays))
  (should (null (overlays-in (point-min) (point-max
  (org-show-subtree)
  (should-not org-inline-image-overlays)
  (should-not (overlays-in (point-min) (point-max))
#+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


signature.asc
Description: PGP signature


Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-03 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> I think the patch is finished. Please review, Ihor. Thanks for helping.

Thanks for the update!
I have cleaned the manual and ORG-NEWS wordings.

Upon reading the exported version of the manual, I realized that the
part in 2.2.1 Global and local cycling section sounds very awkward and
that we do not mention other cycle hooks like hiding archived
subtrees there. So, I decided to remove it.

I also rewrote the other part in a bit more direct tone and moved the
index entry.

(In general, it is useful to try reading the exported version of the
manual with the additions to check if things are still coherent - manual
is not just a collection of independent statements; we need to make sure
that it is not confusing the new readers).

I also updated the commit message adding the CHANGELOG entries about the
manual and ORG-NEWS.

However, upon testing your patch, tests are still failing on my side.
Can you please investigate?

I am attaching the updated version of the patch with my amendments.

Best,
Ihor

>From ab303eb5c007822d045f5e6ba3f00779c0abf1bc Mon Sep 17 00:00:00 2001
Message-Id: 
From: stardiviner 
Date: Wed, 28 Sep 2022 20:46:52 +0800
Subject: [PATCH] org.el: Support auto display inline images when cycling

* lisp/org.el (org-toggle-inline-images): Support region.
(org-display-inline-images): Fix refresh argument logic.
(org-remove-inline-images): Support region.

* lisp/org-keys.el (org-toggle-inline-images): Update arguments.

* lisp/org-cycle.el (org-cycle-inline-images-display): Add new option to
control whether auto display inline images when cycling.
(org-cycle-display-inline-images): Add new hook function to auto display
inline images when cycling.
(org-cycle-hook): Add `org-cycle-display-inline-images' into cycling
hook by default.

* testing/lisp/test-org-fold.el (test-org-fold/org-fold-display-inline-images):
Add test for inline image displaying when cycling.

* doc/org-manual.org (Exporting):
* etc/ORG-NEWS: Document the new option.
---
 doc/org-manual.org|   6 ++
 etc/ORG-NEWS  |   7 +++
 lisp/org-cycle.el |  38 -
 lisp/org-keys.el  |   2 +-
 lisp/org.el   |  21 ---
 .../images/Org mode logo mono-color.png   | Bin 0 -> 7523 bytes
 testing/lisp/test-org-fold.el |  52 ++
 7 files changed, 115 insertions(+), 11 deletions(-)
 create mode 100755 testing/examples/images/Org mode logo mono-color.png

diff --git a/doc/org-manual.org b/doc/org-manual.org
index a5fec8cf9..ec838df97 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -11470,6 +11470,12 @@ ** Images
   - When set to nil, try to get the width from an =#+ATTR.*= keyword
 and fall back on the original width if none is found.
 
+
+#+vindex: org-cycle-inline-images-display
+Inline images can also be displayed when cycling the folding state.
+When custom option ~org-cycle-inline-images-display~ is set, the
+visible inline images under subtree will be displayed automatically.
+
 ** Captions
 :PROPERTIES:
 :DESCRIPTION: Describe tables, images...
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4728528f8..75a77378a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -307,6 +307,13 @@ to pass the contents of a named code block as a string argument.
 The new property =ORG-IMAGE-ACTUAL-WIDTH= can override the global
 variable ~org-image-actual-width~ value for inline images display width.
 
+*** Outline cycling can now include inline image visibility
+
+New ~org-cycle-hook~ function ~org-cycle-display-inline-images~ for
+auto-displaying inline images in the visible parts of the subtree.
+This behavior is controlled by new custom option
+~org-cycle-inline-images-display~.
+
 *** New ~org-babel-tangle-finished-hook~ hook run at the very end of ~org-babel-tangle~
 
 This provides a proper counterpart to ~org-babel-pre-tangle-hook~, as
diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el
index 656ca83f2..212d25a44 100644
--- a/lisp/org-cycle.el
+++ b/lisp/org-cycle.el
@@ -208,8 +208,9 @@ (defcustom org-cycle-pre-hook nil
   :type 'hook)
 
 (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
-		   org-cycle-show-empty-lines
-		   org-cycle-optimize-window-after-visibility-change)
+org-cycle-show-empty-lines
+org-cycle-optimize-window-after-visibility-change
+org-cycle-display-inline-images)
   "Hook that is run after `org-cycle' has changed the buffer visibility.
 The function(s) in this hook must accept a single argument which indicates
 the new state that was set by the most recent `org-cycle' command.  The
@@ -229,6 +230,13 @@ (defcustom org-cycle-open-archived-trees nil
   :group 'org-cycle
   :type 'boolean)
 
+(defcustom org-cycle-inline-images-display nil
+  "Non-nil means auto display inline images under subtree when 

Re: [PATCH 2-v4] New: auto display inline images under subtree when `org-cycle'.

2022-10-02 Thread Christopher M. Miles

Finally finished and passed the test. Here I attached the new patch.

From c36122f818289cbd26026ae75ce480b03e03f61a Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Wed, 28 Sep 2022 20:46:52 +0800
Subject: [PATCH] org.el: Support auto display inline images when cycling

* lisp/org.el (org-toggle-inline-images): Support region.
(org-display-inline-images): Fix refresh argument logic.
(org-remove-inline-images): Support region.

* lisp/org-keys.el (org-toggle-inline-images): Update arguments.

* lisp/org-cycle.el (org-cycle-inline-images-display): Add new option to
control whether auto display inline images when cycling.
(org-cycle-display-inline-images): Add new hook function to auto display
inline images when cycling.
(org-cycle-hook): Add `org-cycle-display-inline-images' into cycling
hook by default.

* testing/lisp/test-org-fold.el (test-org-fold/org-fold-display-inline-images):
Add test for inline image displaying when cycling.
---
 doc/org-manual.org|  12 
 etc/ORG-NEWS  |   5 ++
 lisp/org-cycle.el |  38 -
 lisp/org-keys.el  |   2 +-
 lisp/org.el   |  21 ---
 .../images/Org mode logo mono-color.png   | Bin 0 -> 7523 bytes
 testing/lisp/test-org-fold.el |  52 ++
 7 files changed, 119 insertions(+), 11 deletions(-)
 create mode 100755 testing/examples/images/Org mode logo mono-color.png

diff --git a/doc/org-manual.org b/doc/org-manual.org
index ab8a295e5..ec5b729be 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -475,6 +475,13 @@ Org uses just two commands, bound to {{{kbd(TAB)}}} and
   #+vindex: org-cycle-emulate-tab
   Point must be on a headline for this to work[fn:4].
 
+  #+vindex: org-cycle-inline-images-display
+  Outline cycling can now include inline image visibility. You can
+  enable this behavior by setting custom option
+  ~org-cycle-inline-images-display~ to non-~nil~. After enabled, when
+  you pressed {{{kbd(TAB)}}} on headline, the inline images under
+  subtree will be displayed automatically based on the ~org-cycle~ state.
+
 - {{{kbd(S-TAB)}}} (~org-global-cycle~), {{{kbd(C-u TAB)}}} ::
 
   #+cindex: global visibility states
@@ -11332,6 +11339,11 @@ command:
   - When set to nil, try to get the width from an =#+ATTR.*= keyword
 and fall back on the original width if none is found.
 
+Inline images under subtree can be auto displayed by enabling custom
+option ~org-cycle-inline-images-display~. After enabled, when you
+pressed {{{kbd(TAB)}}} on headline, the inline images under subtree
+will be displayed automatically based on the ~org-cycle~ state.
+
 ** Captions
 :PROPERTIES:
 :DESCRIPTION: Describe tables, images...
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index cab64317f..8832a5beb 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -307,6 +307,11 @@ to pass the contents of a named code block as a string argument.
 The new property =ORG-IMAGE-ACTUAL-WIDTH= can override the global
 variable ~org-image-actual-width~ value for inline images display width.
 
+*** New ~org-cycle-hook~ function ~org-cycle-display-inline-images~ for auto displaying subtree inline images
+
+Outline cycling can now include inline image visibility. This behavior
+is controlled by custom option ~org-cycle-inline-images-display~.
+
 *** New ~org-babel-tangle-finished-hook~ hook run at the very end of ~org-babel-tangle~
 
 This provides a proper counterpart to ~org-babel-pre-tangle-hook~, as
diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el
index 656ca83f2..212d25a44 100644
--- a/lisp/org-cycle.el
+++ b/lisp/org-cycle.el
@@ -208,8 +208,9 @@ the values `folded', `children', or `subtree'."
   :type 'hook)
 
 (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
-		   org-cycle-show-empty-lines
-		   org-cycle-optimize-window-after-visibility-change)
+org-cycle-show-empty-lines
+org-cycle-optimize-window-after-visibility-change
+org-cycle-display-inline-images)
   "Hook that is run after `org-cycle' has changed the buffer visibility.
 The function(s) in this hook must accept a single argument which indicates
 the new state that was set by the most recent `org-cycle' command.  The
@@ -229,6 +230,13 @@ normal outline commands like `show-all', but not with the cycling commands."
   :group 'org-cycle
   :type 'boolean)
 
+(defcustom org-cycle-inline-images-display nil
+  "Non-nil means auto display inline images under subtree when cycling."
+  :group 'org-startup
+  :group 'org-cycle
+  :package-version '(Org . "9.6")
+  :type 'boolean)
+
 (defvar org-cycle-tab-first-hook nil
   "Hook for functions to attach themselves to TAB.
 See `org-ctrl-c-ctrl-c-hook' for more information.
@@ -776,6 +784,32 @@ STATE should be one of the symbols listed in the docstring of
 		   "Subtree is archived and stays closed.