From: Ihor Radchenko <yantar92@posteo.net>
To: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Cc: stardiviner <numbchild@gmail.com>, Org mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH v3] Inline image display as part of a new org-link-preview system
Date: Sun, 08 Sep 2024 07:43:52 +0000 [thread overview]
Message-ID: <87o74ypp3b.fsf@localhost> (raw)
In-Reply-To: <878qw9ak6a.fsf@gmail.com>
Karthik Chikmagalur <karthikchikmagalur@gmail.com> writes:
>>> +BEG and END define the considered part. They default to the
>>> +buffer boundaries with possible narrowing."
>>> + (interactive "P")
>>> + (when (display-graphic-p)
>>
>> Do we need it here? You check graphics both here and later in the
>> preview function. We may probably drop the check herein.
>
> I moved the `refresh' clause out of the display-graphic-p check, but I
> think it's needed. Otherwise this line will run once per previewed
> image instead of once per call to `org-link-preview':
>
> (when (fboundp 'clear-image-cache) (clear-image-cache))
>
> clearing newly placed previews (within the same run) from the cache.
Sorry, I was not clear. I only referred to `display-graphic-p' check. I
did not mean `clear-image-cache'.
> That said, I have a question about `clear-image-cache' here. Why does
> Org clear the Emacs frame's entire image cache every time
> `org-link-preview-region' (or the previous `org-display-inline-images')
> is called? This seems overreaching. There are many situations even
> within Org mode where we want to avoid the extra file access that
> clearing the image cache will cause, like in a buffer with hundreds of
> LaTeX previews. Images in unrelated buffers/major-modes are also
> affected.
Here is the original code:
(when refresh
(org-remove-inline-images beg end)
(when (fboundp 'clear-image-cache) (clear-image-cache)))
Image cache is cleared _only_ with REFRESH argument.
I think that makes sense, right?
>>> + (let* ((width (org-display-inline-image--width link))
>>> + (align (org-image--align link))
>>> + (image (org--create-inline-image file width)))
>>
>> I am wondering why you left these functions in org.el. Why not moving
>> them here?
>
> They seemed out of place in ol.el, so my plan was the following:
> 1. This patch: Implement org-link-preview.
> 2. Another patch: Move image creation/manipulation/geometry functions
> from org into an org-image (or org-image-utils) library. Require it in
> ol.
>
> However, I can move them wherever you want, let me know.
I'd rather see them moved.
You can later send another patch moving them into the new utils library,
if you want.
I am asking because you may or may not have time to create that followup
patch. So, better have things sorted out at every step rather than
relying upon followups that may or may not happen (e.g. for reasons you
cannot control)
>>> + (when image ; Add image to overlay
>>> ...
>>> + (overlay-put ov 'org-image-overlay t)
>>
>> This is redundant, isn't it?
>
> I don't know how create-image can fail. Suppose a .jpg file exists but
> is corrupted or does not have image/jpeg data. Then create-image
> returns nil, as does `org--create-inline-image'. This check guards
> against trying to preview an "image" that's nil.
Let me elaborate.
In `org-link-preview-region', you set org-image-overlay property:
+ (overlay-put ov 'org-image-overlay t)
+ (overlay-put ov 'modification-hooks
+ (list 'org-link-preview--remove-overlay))
+ ;; call preview function for link type
+ (if (funcall preview-func ov path link)
+ (when (overlay-buffer ov)
Then, you do it yet again in `org-link-preview-file', when the property
is already there - this part is redundant.
I do not see how `org--create-inline-image' affects the above.
>>> + (when (boundp 'image-map)
>>
>> What if not bound? Why not simply (require 'image)?
>
> Just unmodified old code. I've require'd image in ol now, let me know
> if I should do it differently.
Let's not require it on top level. Maybe better do it within the preview
function.
>> I am wondering whether asynchronicity should be implemented on high
>> level rather than inside individual link preview functions.
>> We may, for example, first create the necessary overlays and indicate
>> that they are "processing..." first, and then call the actual preview
>> functions asynchronously.
>>
>> If we leave asynchronous handling to individual previews, they will have
>> no way to handle queuing large number of link previews, and we may arrive
>> at the common situation with network processes when they schedule and
>> finish around the same time, hanging Emacs while it is handling
>> a bunch of process sentinels.
>
> I'm not sure how to solve this problem. Here's what I'm picturing --
> note that this doesn't actually avoid the process sentinel pile-up:
>
> The preview provider should return its callback function to Org so Org
> can run it at its convenience.
>
> Org runs (funcall #'preview-func ov path link)
>
> preview-func returns either
> 1. t, if preview is synchronous and successful,
> 2. nil, if preview is synchronous but failed,
> 3. A callback-func, if preview is asynchronous. In this case the
> preview-func starts the network request or async job.
>
> Org adds callback-func to the queue of callback-funcs for this run, and
> runs them spaced out on a timer or something. Preview success depends
> on whether the callback-func returns t or nil.
>
> Implementing something like this should be easy with org-async, included
> in the LaTeX preview patchset.
>
> But the process sentinels will run independent of Org's callback queue.
> The callbacks only place the resulting image (or other metadata) on the
> overlays. The bottleneck here is not the display engine, so this
> doesn't solve the problem.
>
> Can you give me some more details of what you have in mind?
I mostly meant calling preview-func asynchronously, while idle, spaced
out, spending not longer than a fraction of second to call several
preview-funcs.
Spacing might then be controlled by the users.
We might go further, and let the preview functions return a
process. Then, we may explicitly control running sentinels just for that
process via `accept-process-output'. But I am not sure if we need to go
that far.
--
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>
next prev parent reply other threads:[~2024-09-08 7:43 UTC|newest]
Thread overview: 79+ 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 ` [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
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 [this message]
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-11-21 3:46 ` 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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o74ypp3b.fsf@localhost \
--to=yantar92@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=karthikchikmagalur@gmail.com \
--cc=numbchild@gmail.com \
/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 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).