help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: are there hooks for text becoming visible or hidden in a given windo


From: Stefan Monnier
Subject: Re: are there hooks for text becoming visible or hidden in a given window?
Date: Thu, 24 Feb 2022 19:10:39 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> Is there a way to mark a region of text in a buffer, so that when that text
> becomes visible in any window, or when it stops being visible, a hook is
> called and provided the location of the text in the buffer, and the window
> in which its visibility has changed?

To detect when a chunk of buffer is visible, you can use jit-lock.
It's not exact (it will sometimes trigger even if the chunk is not
actually visible), but it's probably the closest we have (especially if
you want it to be efficient even where there are thousands of such
buffer-chunks to "monitor").

> but disappear from the second window if the link is deleted or
> scrolled outside of the window.

We don't have anything for that, no.  I'd suggest you use
a post-command-hook that monitors which of those thingies is
still visible.

I have been known to propose the introduction of
a `post-redisplay-function` which would work like
`pre-redispay-function` except it's run after the redisplay.
I think I have a patch for that lying around (IIRC originally written
to try and improve the display of "tofu" by adding a `help-echo`
property to those characters).

I guess you could use such a thing as well (and potentially for both
uses).  Changing a buffer in response to changes to the display of
another window isn't well supported by the redisplay (because it means
you need a redisplay cycle right after a redisplay cycle), so you'd need
to force a new redisplay "by hand".

There might also be some questions about what "visible" means.
E.g. is a chunk of buffer "visible" if it's between `window-start` and
`window-end` but is covered by an `invisible` property?  Or if it's
(horizontally) scrolled out of view?


        Stefan




reply via email to

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