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: Po Lu
Subject: Re: move_it_vertically_backward question
Date: Tue, 14 Dec 2021 21:28:44 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

> 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.

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

I don't know of any existing primitive that may make sense to extend in
this manner though.

> 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".

Yes, but that would still entail having to repetitively loop in Lisp
until the desired position is found, assuming the delta by which we are
scrolling is larger than the height of the previous screen line, while
this primitive looks for a line that is at least a specified amount of
pixels above the window start, which lets us avoid the extra looping in
Lisp if the line is not tall enough.

Also, for the result to be useful, `window-text-pixel-size' would also
have to return the buffer position of the measured line's start, which
doesn't make sense for a function that is only intended to measure size.

> 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.

Thanks.  Something like this seems to work:

  while (-it.current_y < pix)
    {
      last_y = it.current_y;
      move_it_by_lines (&it, -1);
    }

But I have a few questions: what is TRT if `move_it_by_lines' can't move
further back?  And also, does `move_it_by_lines' (or for that matter,
the move_it_* functions in general) only move within the accessible
portion of the buffer, or does narrowing have to be handled in some
specific manner?

Thanks.


reply via email to

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