emacs-devel
[Top][All Lists]
Advanced

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

Re: move_it_vertically_backward question


From: Eli Zaretskii
Subject: Re: move_it_vertically_backward question
Date: Tue, 14 Dec 2021 14:52:10 +0200

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Tue, 14 Dec 2021 08:53:35 +0800
> 
> Yes, I understand that much.  This primitive is supposed to solve a
> performance problem though: right now, we go through quite a few hoops
> to find such a position and return its height, and I've been getting
> complaints that the speed of that is unacceptable.

Extending an existing primitive will give you the same performance as
a new primitive.  But it will also save you from reinventing the wheel
and from having to deal with all the subtleties of primitives that
simulate display to find some place or measure of the text as it will
be on display.

> Since there seems to be no faster way to do what I'm trying to,
> introducing a new primitive seems to be the way to go.

I'm saying that extending an existing primitive to cover your use case
might be a better way forward.

> > Instead, we should understand better why window-text-pixel-size
> > doesn't fit your bill, and then extend it so that it does what you
> > want in your use cases.
> 
> While the performance of `window-text-pixel-size' itself is ample,
> finding the target window start is not: we have to find the beginning of
> the visual line, then (vertical-motion -1) in a loop calculating the
> height with `window-text-pixel-size' until it reaches an appropriate
> value.

Which might mean that window-text-pixel-size should support a
specification of FROM and TO that is not just buffer position, but
something like "beginning of previous line".

> Hmm.  Is it legal to pass a negative Y argument to `move_it_to'?

"Legal", as in "no against the law"?  Yes.  "Valid"? no.  The
move_to_* functions can generally only move forward, because they use
the normal "iteration through buffer text" infrastructure, and that
examines characters in the order of increasing buffer positions.  We
don't have algorithms that can perform layout calculations while going
back in the buffer.

So to move back, you need first go far enough back (e.g., with
move_it_vertically_backward), then move forward to find the place
where you wanted to find yourself wrt the starting point.  Se an
example in move_it_by_lines.



reply via email to

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