[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two questions about overlays

From: dalanicolai
Subject: Re: Two questions about overlays
Date: Tue, 21 Feb 2023 15:52:06 +0100

Okay, finally, (I should have done this immediately), here is the best
and most brief explanation: So load the code of the attached UPDATED
scrap-mode.el. Then do `M-x scrap-expand-overlays`. It will print 1000, but
I expect it to print the number of overlays you are actually seeing on
screen, because the function calls

(print (length (overlays-in (window-start) (window-end)))))

after adding the 'space' display properties/expanding the overlays. So
although the display properties have been added, they seem to not have
taken effect at the time

(print (length (overlays-in (window-start) (window-end)))))

is evaluated. If you uncomment the `sit-for` in
`scrap-expand-overlays`, then you will see it prints a different
(i.e. the correct/expected) number.

Another way to get the expected number, is to now do

M-: (length (overlays-in (window-start) (window-end)))

On Tue, 21 Feb 2023 at 14:57, dalanicolai <dalanicolai@gmail.com> wrote:
B.t.w. I am using Emacs 29 (and 30), and the overlay-recenter is still there.
Maybe it would be handy to remove it then?

On Tue, 21 Feb 2023 at 14:50, dalanicolai <dalanicolai@gmail.com> wrote:
Let me, additionally, very briefly explain what the code is doing, and
what I am expecting (as an attempt to make it immediately clear what I

So the code is first simply creating (for my dir) 108 overlays.  Then
in 'scrap-dir-images' are made to display the images from the
directory. Immediately, after the
'(seq-do-indexed (lambda (im n) (overlay-put ... 'display ...)'
the function print the value of '(overlays-in (window-start) (window-end))',
which return 108. However, I expect it to print 2, as the overlays should
have the size of the images now (and I see only two images simultaneously on
screen). Indeed when doing 'M-: (overlays-in (window-start) (window-end))'
immediately after creating the 'image gallery', it returns 2.

On Tue, 21 Feb 2023 at 14:39, dalanicolai <dalanicolai@gmail.com> wrote:
In this example code, I am simply displaying all images at once,
because I am assuming that the images in the directory are not too
many and that they are small (which is not a very reasonable
assumption, but this is just my personal 'test' function).

Indeed, the example does not call sit-for, because it should show that
the printed number of overlays, is the number of all images in the
directory (instead of only the number of images currently on the
screen, i.e. within '(overlays-in (window-start) (window-end))' ).

For example, I have a directory with 108 images, when I run 'M-x
scrap-dir-images' it print 108, although it should print the number of
images on screen i.e. by '(overlays-in (window-start) (window-end))',
which value is what 'scrap-dir-images' prints.  However, the images
are normal 'foto' size, so that I only see two images on screen, and
indeed doing 'M-: (overlays-in (window-start) (window-end))' manually
now prints 2.  If I had added the '(sit-for)' in the example
code, then I would have 'fixed' the problem, and 'scrap-dir-images'
would have printed 2 immediately because the display property
('expansion of the overlays') got enough time to take effect.

I hope this clears things up, but of course I would be happy to try
another explanation (e.g. sending by adding an animated gif).

But this function is a no-op in Emacs 29 and later, since the overlays
were reimplemented in a way that makes it unnecessary to "center" the
list of overlays.  So you can forget about that and ignore this

Thanks, that is indeed handy to know.

On Tue, 21 Feb 2023 at 14:21, Eli Zaretskii <eliz@gnu.org> wrote:
> From: dalanicolai <dalanicolai@gmail.com>
> Date: Tue, 21 Feb 2023 13:46:56 +0100
> So now here are the questions:
> - when displaying multiple pages in columns, I would like to use the
> overlays-in function to determine which overlays should display
> images.  So I am creating a full 'book roll' by giving the overlays a
> size via the 'space' display property, after which I use overlays-in
> to determine which overlays are actually visible. However, after it
> takes some time for the 'space' display property to take effect, so I
> am manuall adding a 'sit-for' with some reasonable delay
> time. However, I would like to ask if there is someone has an idea for
> a 'better' mechanism to wait until/detect if the 'overlay expansion'
> has finished.
> If the explanation is not clear then please load the following file
> and do 'M-x scrap-dir-images' on a directory that contains enough
> images to not fit all on a single screen. It will print the number of
> overlays found via 'overlays-in' directly after 'displaying the
> images' (here by assigning the image as display property instead of
> space). You will find it prints all overlays in the buffer (instead of
> only the ones on screen). To find what I expect it to print now
> (again) do 'M-: (overlays-in (window-start) (window-end))'.

I did all that, and I still don't understand the question.  In
particular, your code doesn't call sit-for, so I'm unsure what exactly
is the problem you are asking about here.

> My second question is about the function 'overlay-recenter' I don't
> really understand its docstring. What kind of 'overlay lookup' would
> go faster? What is 'overlay-lookup' anyway?

Looking up overlays that are relevant to a particular buffer position.

But this function is a no-op in Emacs 29 and later, since the overlays
were reimplemented in a way that makes it unnecessary to "center" the
list of overlays.  So you can forget about that and ignore this

Attachment: scrap-mode.el
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]