emacs-devel
[Top][All Lists]
Advanced

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

Re: Use cases for post-redisplay hooks


From: Keith David Bershatsky
Subject: Re: Use cases for post-redisplay hooks
Date: Mon, 04 Jul 2016 15:50:42 -0700

The implementation of the `window-start-end-hook` is probably easier to explain 
with a diff, which is attached.  I haven't worked much on the hook since March 
11, 2016, so it applies to the master branch on or about that date.  [I think I 
made a few very minor changes after that, but don't have a diff ready at this 
time.]

Each command loop, I place the following overlays on just the visible window:

* [Maybe] draw a vertical line that tracks the cursor position, which is 
compatible with `word-wrap` enabled.  Sometimes I force it to draw immediately, 
but most of the time it is on an idle timer.  The line stretches from the top 
of the window to the bottom of the window.

* Place line numbers to the left of the left-fringe.

* Place pilcrows at the end of each line.  [The `buffer-display-table` can't be 
used for this because those pilcrows are not compatible with the vertical line, 
which also adds pilcrows.]

* Draw a horizontal line underneath where the cursor is located.  The line 
stretches from the left-fringe to the right-fringe, and sometimes some I add 
bitmaps in the fringe.

* If there is a region active, then the region is colored appropriately to work 
with the cross-hairs (describe-above).

* I also run some other stuff at the tail end, which is not really that 
important to the use case -- e.g., parentheses highlighting, and flyspell.

The reason I mentioned the `window-scroll-functions` hook was an assumption (on 
my part) that Clément had initially categorized my potential usage of the 
proposed `post-redisplay-hook` as only relating to scrolling.  I just wanted to 
clarify / differentiate my proposed use case as needing `window-start` and 
`window-end` each command loop.

With respect to the hook running more than once each command loop, it is only a 
problem for me because my calculations are costly time-wise (e.g., 
`vertical-motion').  So, I only want to do it one time each command loop.  The 
`window-start-end-hook` only fires completely when point is fully visible and 
when the values for `window-start` and `window-end` are correct (at least in so 
far as my testing has shown).  Someone who uses a simple function attached to a 
hook that runs multiple times each command loop would not likely be bothered if 
there is a little waste.  I suffer from a little O.C.D., so just the thought of 
a function running for no reason at all bothers me.  :)

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

At Mon, 04 Jul 2016 18:06:33 -0400,
Stefan Monnier wrote:
> 
> > I am using a slightly modified version of Emacs that has what
> > I call a `window-start-end-hook`, which lets me draw overlays on just the
> > visible window every command loop.  I needs more work, but that is the
> > general idea of the modification.
> 
> Could you clarify what you use it for?
> 
> Also is it run after redisplay?  If so, how does it work?  I mean how do
> you add overlays *after* redisplay?  Do you trigger a second redisplay
> right after the first, or is it simply that your overlays don't affect
> the display?
> 
> > There are certain movements of point that are not covered by the
> > `window-scroll-functions` hook, so that hook cannot be used reliably for the
> > above-mentioned purpose.
> 
> Not sure what point has to do with window-start-end-hook.
> 
> > And, the hook *may* run more than once each command loop, leading to
> > potentially wasted time spent running an overlay function that will
> > need to run again anyway before the display cycle finishes.
> 
> Is that a problem in practice?
> 
> 
>         Stefan

Attachment: window_start_end_hook.diff
Description: application/diff


reply via email to

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