Ihor Radchenko writes: > "Christopher M. Miles" 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