From: "Christopher M. Miles" <numbchild@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: numbchild@gmail.com, Org mode <emacs-orgmode@gnu.org>
Subject: [PATCH v2] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer
Date: Mon, 15 May 2023 22:00:02 +0800 [thread overview]
Message-ID: <64623c09.170a0220.52bf9.9437@mx.google.com> (raw)
In-Reply-To: <87sfbxhmxe.fsf@localhost>
[-- 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 --]
next prev parent reply other threads:[~2023-05-15 14:06 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Christopher M. Miles [this message]
2023-05-16 9:17 ` [PATCH v2] " 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
2023-08-05 5:28 ` [PATCH v3.2] " Christopher M. Miles
2024-07-22 10:46 ` Ihor Radchenko
2024-08-01 22:58 ` [PATCH v4.0] " stardiviner
[not found] ` <66a8b73b.170a0220.383476.996e@mx.google.com>
2024-08-12 10:18 ` Ihor Radchenko
2024-08-14 2:04 ` stardiviner
2024-08-18 10:27 ` Ihor Radchenko
2024-08-20 2:02 ` Karthik Chikmagalur
2024-08-20 15:43 ` Karthik Chikmagalur
2024-08-20 18:19 ` Ihor Radchenko
2024-08-20 19:46 ` Karthik Chikmagalur
2024-08-22 13:19 ` Ihor Radchenko
2024-08-23 6:04 ` Karthik Chikmagalur
2024-08-23 23:36 ` [PATCH v1] Inline image display as part of a new org-link-preview system Karthik Chikmagalur
2024-08-24 1:00 ` Karthik Chikmagalur
2024-08-31 14:22 ` Ihor Radchenko
2024-08-31 16:41 ` Karthik Chikmagalur
2024-08-31 16:53 ` Ihor Radchenko
2024-08-31 22:37 ` [PATCH v2] " Karthik Chikmagalur
2024-09-01 13:06 ` Ihor Radchenko
2024-09-02 20:13 ` [PATCH v3] " Karthik Chikmagalur
2024-09-08 7:43 ` Ihor Radchenko
2024-09-09 3:21 ` Karthik Chikmagalur
2024-09-09 6:06 ` Ihor Radchenko
2024-09-09 6:30 ` Karthik Chikmagalur
2024-09-09 16:47 ` Ihor Radchenko
2024-09-09 19:14 ` Karthik Chikmagalur
2024-09-10 16:57 ` Ihor Radchenko
2024-09-10 19:53 ` Karthik Chikmagalur
2024-09-15 7:51 ` Ihor Radchenko
2024-09-09 21:45 ` Karthik Chikmagalur
2024-09-10 16:58 ` Ihor Radchenko
2024-09-10 17:38 ` Karthik Chikmagalur
2024-09-10 18:34 ` Ihor Radchenko
2024-09-10 19:43 ` Karthik Chikmagalur
2024-09-15 8:12 ` Ihor Radchenko
2024-09-15 20:50 ` Karthik Chikmagalur
2024-09-15 21:57 ` [PATCH v4] " Karthik Chikmagalur
2024-09-17 18:16 ` Ihor Radchenko
2024-09-18 1:44 ` [PATCH v5] " Karthik Chikmagalur
2024-09-21 10:11 ` Ihor Radchenko
2024-09-22 22:00 ` [PATCH v6] " Karthik Chikmagalur
2024-10-03 17:03 ` Ihor Radchenko
2024-10-08 0:07 ` [PATCH v7] " Karthik Chikmagalur
2024-10-10 17:15 ` Ihor Radchenko
2024-10-10 21:23 ` Karthik Chikmagalur
2024-10-12 8:15 ` Ihor Radchenko
2024-10-28 6:13 ` [PATCH v8] " Karthik Chikmagalur
2024-10-28 18:16 ` Ihor Radchenko
2024-10-28 21:53 ` [PATCH v9] " Karthik Chikmagalur
2024-10-29 18:46 ` Ihor Radchenko
2024-10-29 20:45 ` [PATCH v10] " Karthik Chikmagalur
2024-10-30 17:32 ` Ihor Radchenko
2024-10-30 19:50 ` Karthik Chikmagalur
2024-10-31 18:16 ` Ihor Radchenko
2024-11-14 5:43 ` Karthik Chikmagalur
2024-11-14 17:14 ` Ihor Radchenko
2024-11-14 22:10 ` Karthik Chikmagalur
2024-08-18 10:34 ` [FR] Automatically display images in resutls of evaluation (was: [PATCH v4.0] Re: [PATCH] add a function to only refresh inline images under current headline instead of global buffer) Ihor Radchenko
[not found] ` <66c54dfc.a70a0220.3c823a.2899@mx.google.com>
2024-08-22 13:06 ` [FR] Automatically display images in resutls of evaluation Ihor Radchenko
[not found] ` <66c89411.170a0220.3255c1.0cd5@mx.google.com>
[not found] ` <87zfor7b04.fsf@localhost>
[not found] ` <CAL1eYuLOsaS43ahueN4uWiCn+Ykp=p_-t9dzAypKdy1en_53BQ@mail.gmail.com>
2024-09-15 13:33 ` [PATCH v3] " Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=64623c09.170a0220.52bf9.9437@mx.google.com \
--to=numbchild@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.