all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Po Lu <luangruo@yahoo.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: move_it_vertically_backward question
Date: Tue, 14 Dec 2021 08:53:35 +0800	[thread overview]
Message-ID: <874k7cuhv4.fsf@yahoo.com> (raw)
In-Reply-To: <837dc8mue3.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 13 Dec 2021 16:50:12 +0200")

Eli Zaretskii <eliz@gnu.org> writes:

> I'm not sure this is the way to go, judging by what you told on
> help-gnu-emacs.  The main reason is that window-text-pixel-size, which
> you said doesn't do what you want, uses exactly the same technique as
> you are trying to do in this new primitive, and so whatever problems
> you have with window-text-pixel-size, you will bump into them (or
> similar problems) with your new primitive as well.  This stuff is
> always extremely tricky when advanced display features are used, like
> display and overlay strings with embedded newlines, line-prefix, line
> numbers, etc.  There's no easy way around this complexity.

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.

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.

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

> The commentary to the function doesn't tell the whole story.  In fact,
> it always undershoots first, because of this:
>
>   /* Estimate how many newlines we must move back.  */
>   nlines = max (1, dy / default_line_pixel_height (it->w));
>
> This is integer division, so it truncates the number of lines.  E.g.,
> in your case, with DY between 17 and 33 you get 1 line, not more.
> Then it moves back by that number of physical lines, which is why you
> get the line before window-start.
>
> And then it can move farther back, but only if the undershoot is
> "large enough":
>
>       /* If we did not reach target_y, try to move further backward if
> 	 we can.  If we moved too far backward, try to move forward.  */
>       if (target_y < it->current_y
> 	  /* This is heuristic.  In a window that's 3 lines high, with
> 	     a line height of 13 pixels each, recentering with point
> 	     on the bottom line will try to move -39/2 = 19 pixels
> 	     backward.  Try to avoid moving into the first line.  */
> 	  && (it->current_y - target_y
> 	      > min (window_box_height (it->w), line_height * 2 / 3))
> 	  && IT_CHARPOS (*it) > BEGV)
> 	{
> 	  move_trace ("  not far enough -> move_vert %d\n",
> 		      target_y - it->current_y);
> 	  dy = it->current_y - target_y;
> 	  goto move_further_back;
> 	}

> That "2/3rd of line height" threshold heuristic is the reason why it
> not always moves one more line back.  On my system, the default pixel
> height of a line is 16, so it moves to the second line before
> window-start for DY >= 27, since 2/3rd of 16 is 10.

Hmm.  Is it legal to pass a negative Y argument to `move_it_to'?
Perhaps that can be used instead.

Thanks.



  reply	other threads:[~2021-12-14  0:53 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87lf0pw78r.fsf.ref@yahoo.com>
2021-12-13  2:47 ` move_it_vertically_backward question Po Lu
2021-12-13 14:50   ` Eli Zaretskii
2021-12-14  0:53     ` Po Lu [this message]
2021-12-14 12:52       ` Eli Zaretskii
2021-12-14 13:28         ` Po Lu
2021-12-14 13:45           ` Eli Zaretskii
2021-12-15  1:18             ` Po Lu
2021-12-15  3:27               ` Eli Zaretskii
2021-12-15  3:30                 ` Po Lu
2021-12-15 13:27                   ` Eli Zaretskii
2021-12-15 13:39                     ` Po Lu
2021-12-15  2:13             ` Po Lu
2021-12-15 10:28               ` Po Lu
2021-12-15 13:56                 ` Eli Zaretskii
2021-12-15 13:25               ` Eli Zaretskii
2021-12-15 13:38                 ` Po Lu
2021-12-15 14:50                   ` Eli Zaretskii
2021-12-16  0:41                     ` Po Lu
2021-12-16  8:29                       ` Eli Zaretskii
2021-12-16  9:25                         ` Po Lu
2021-12-16 10:04                           ` Eli Zaretskii
2021-12-16 10:27                             ` Po Lu
2021-12-16 12:17                               ` Po Lu
2021-12-16 13:27                                 ` Eli Zaretskii
2021-12-16 13:34                                   ` Po Lu
2021-12-16 13:59                                     ` Eli Zaretskii
2021-12-17  1:45                                       ` Po Lu
2021-12-18 10:28                                         ` Eli Zaretskii
2021-12-18 10:49                                           ` Po Lu
2021-12-18 11:03                                             ` Eli Zaretskii
2021-12-18 11:18                                               ` Po Lu
2021-12-18 11:29                                                 ` Eli Zaretskii
2021-12-18 11:31                                                   ` Po Lu
2021-12-18 11:35                                                     ` Eli Zaretskii
2021-12-18 11:39                                                       ` Po Lu
2021-12-19  0:54                                           ` Po Lu
2021-12-19  8:29                                             ` Eli Zaretskii
2021-12-19  9:16                                               ` Po Lu
2021-12-19  9:27                                                 ` Eli Zaretskii
2021-12-19 10:25                                                   ` Po Lu
2021-12-19 18:07                                                     ` Eli Zaretskii
2021-12-20  1:05                                                       ` Po Lu
2021-12-21 12:58                                                         ` Po Lu
2021-12-21 17:07                                                           ` Eli Zaretskii
2021-12-22  0:49                                                             ` Po Lu
2021-12-22 14:59                                                               ` Eli Zaretskii
2021-12-23  1:30                                                               ` Po Lu
2021-12-23  9:49                                                                 ` Eli Zaretskii
2021-12-23 10:29                                                                   ` Po Lu
2021-12-23 10:39                                                                     ` Eli Zaretskii
2021-12-23 10:42                                                                       ` Po Lu
2021-12-23 10:50                                                                         ` Eli Zaretskii
2021-12-23 10:55                                                                           ` Po Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874k7cuhv4.fsf@yahoo.com \
    --to=luangruo@yahoo.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.