From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: move_it_vertically_backward question Date: Tue, 14 Dec 2021 08:53:35 +0800 Message-ID: <874k7cuhv4.fsf@yahoo.com> References: <87lf0pw78r.fsf.ref@yahoo.com> <87lf0pw78r.fsf@yahoo.com> <837dc8mue3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36827"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 14 01:54:36 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mww5T-0009Pn-D3 for ged-emacs-devel@m.gmane-mx.org; Tue, 14 Dec 2021 01:54:35 +0100 Original-Received: from localhost ([::1]:44510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mww5Q-0006Dc-QW for ged-emacs-devel@m.gmane-mx.org; Mon, 13 Dec 2021 19:54:32 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mww4n-0005Xg-5Q for emacs-devel@gnu.org; Mon, 13 Dec 2021 19:53:53 -0500 Original-Received: from sonic314-21.consmr.mail.ne1.yahoo.com ([66.163.189.147]:39458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mww4k-0000Ln-Oj for emacs-devel@gnu.org; Mon, 13 Dec 2021 19:53:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1639443226; bh=BuoJHgwu1HbrYGUu3fOyzk/QDv5MhzQNSQWZ+qnMyvA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=OCt4Z/7PSFW6HFG0mEosed/3Yv7l4KodjUMvhZzWONkJFHSptHNzSVb/iEiTNRygjF/LTuomhGGjVWdPzrcwoayMrDi2DxvNYhwRgox7au0NCmUy9UNmdl9U+c2iyY6A8EXnpiMf9DH48r7inkLTRouiedYpe9r6aScPxmTsbozhAoAMd1ZYI14A5oeK80E6CjnQqqgFhahB7lgZcRbgQXnEf6IhZq6LtCCEZyLkgJcL0pF4BcKxqN2pxaAmTzlnOiK6nSlfsfZYTGB1S1zstp5+x844JrDfR2OTKXQlInrzaEt0x8FMfmlQUjYWXW+ZnzVa0eDtQ9aNIrCf0M+Qlg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1639443226; bh=Z4LkO3wic2XkIZ2mit8VFDET2DCyiA5gvBZQw0V1U8Y=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Qg07fbbxulmGPp2fR6dJtJK+y5ZMN8NbyNuKEFBNUG91j0ABkUiU8CeL6cZzTZaxorbbcDKf4iDovFhN8LFY2wcLO3VJR14K6IBm8uqHAz9fF3ju9ffLuulIzpYhu2+tJ0n0RuUDzdXMmMdWRYli8NIJEafw5dN6wWXDx/FH2jPfiClzQX9SH9zMqzfzhCrrbbIIoEvkUYBOu9k6wv4BGvXQdwbWxt9+eE6X5fY13k1hoU/EM0F+5ZUJu6JSZuo4wHMZG0qtviK3WmRXckzOt4pKsdegG6vcTT3giowSbShNHYdbCcjvDKkh/r89OTDtzIJB2fCTUM86AGg4w905Xg== X-YMail-OSG: ZwnGYqwVM1ncopHeHV9Te_u0MNP25L.W.UvObqvA0veieYFsaaMQZ9rUrAaPwdJ lqo4FjyQKIoQAU4adALRfC3VWNWndm3AsTDZ_EwhbnNZ_y.VIdSIRZ2.fzPCSJO2ijftY3G2uOf2 uK6Oh7Lve.3fViqJMZpr6dvk2Qz4_1WWXezT3lCm2bbMG5gW94entM8PpdP3L3STBk3VBbW2T8rp erytV7NeyvZgrfJZCLIJZaIYFQ9q65L84F2UiU4OWtu9NlrEaULjHah9IgZiKteo.g3TbO7Zk5x. u_IJ6bnwp_EkRRtSr.QVfUdtK_X1Vhx__DSWB2no8m1hBTPLcOEe.LWugNGXNoPQP_.EVPUPwysf z7Ay.1Jj1755fz0s5MsrPxWRIcbRRCqH5xFithNjkTWUlbKxy4q08nHXCQuRnnxIHuQJjHhO3lpN qLAgKUy6Y4BDWU38sHq5Mmjt2NOb0siLswnTpOM2Yx.2A009iuUs4VSTZ32Qz3KSj4tkPBOM_CHF apCD1_qI6_gHc0eK3dOP7vz1n5CnGerm5GaS5bkq.zXTPZEvqhwJwUMu.6Eg3GhvV1nbhysKJXZi A6aZUJ3M5JOmKyHxiTTrIlrL7LDZHyY51_hA0b03rGMz_2TnnvYrHGUaUBlQNRDUGwYz8jN.ibir c_TftsBtwdrLC0FMvfwll.MMU12uLLO4etK4sr.0_RlZE0shjNRAzy3b75PftIn3tozyagtjd9b4 wylQZKv87Jp4sbIVxG5tiJPBkxbEeY71Wa1CbJ5rsSTUro8FRxEKbrSG3a3EN8EiPtAtm3vyIqr. 3X40rA.h3DEr5RryYgGsO6JH0S1qvZ3kWPEVhU9VO8 X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Tue, 14 Dec 2021 00:53:46 +0000 Original-Received: by kubenode519.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 2afb8fdc3b7749a7edd828a46d1b9d95; Tue, 14 Dec 2021 00:53:40 +0000 (UTC) In-Reply-To: <837dc8mue3.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 13 Dec 2021 16:50:12 +0200") X-Mailer: WebService/1.1.19415 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.189.147; envelope-from=luangruo@yahoo.com; helo=sonic314-21.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:281869 Archived-At: Eli Zaretskii 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.