GNU bug report logs - #58793
28.1.90; Emacs tries to recenter / rescroll when it hits hidden org emphasis

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Wed, 26 Oct 2022 07:59:02 UTC

Severity: normal

Found in version 28.1.90

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 58793 in the body.
You can then email your comments to 58793 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Wed, 26 Oct 2022 07:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ihor Radchenko <yantar92 <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 26 Oct 2022 07:59:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.1.90; Emacs tries to recenter / rescroll when it hits hidden org
 emphasis
Date: Wed, 26 Oct 2022 07:59:14 +0000
Hello,

I am forwarding the following bug report from Org mailing list
(https://orgmode.org/list/CA+FzMhahT16w5KPi3hgq8Gn7wnb+PjcNuS_ULk_jroGLHBVBaw <at> mail.gmail.com)
It appears to be related to Emacs.
I can also reproduce on my side and I have seen similar scrolling quirks
myself in the daily usage.

-------------

To reproduce this:
1. Load the repro emacs settings.
2. Scroll down in a buffer, such that top of buffer is not visible on
screen.
3. Create an emphasized word at the beginning of the 2nd visual-line in a
visually-wrapped line.
4. Move your point to the start of that emphasized word

It's a little difficult to describe, so I'll give an example. Assume
that the visual-line wrapping is happening at the place indicated by
"$".

```
So, if this were one long line, then this is the first visual line,$
/whereas/ this is the second visual line in the paragraph, and you'd place$
point on the italicized "w" in the word "whereas". That triggers the bug.
```

What happens next is that emacs thinks the point is no longer on screen
and tries to scroll to fix that. Under vanilla emacs, it will just
recenter the point. This still is misbehaving but not terribly. However,
with
smooth-scrolling as mentioned above, the behavior is worse. The window
scrolls up and point jumps to the top of the window.

Reproed this with the following: emacs -Q
with the following:
```
(setq org-hide-emphasis-markers t)

(org-mode)
(visual-line-mode 1)

;; Without this, emacs will still show bug by calling recenter, but the
effect is particularly egregious with these settings (i.e. smooth scrolling)
(setq scroll-conservatively 101
      scroll-preserve-screen-position t
      scroll-margin 0)
```

Best,
Ihor

In GNU Emacs 28.1.90 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.16.0)
 of 2022-07-17 built on localhost
Repository revision: f5218385c064aa959650bfe49ca32795270851eb
Repository branch: emacs-28
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Gentoo Linux


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Wed, 26 Oct 2022 16:37:02 GMT) Full text and rfc822 format available.

Message #8 received at 58793 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 58793 <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90;
 Emacs tries to recenter / rescroll when it hits hidden org emphasis
Date: Wed, 26 Oct 2022 19:35:30 +0300
> From: Ihor Radchenko <yantar92 <at> posteo.net>
> Date: Wed, 26 Oct 2022 07:59:14 +0000
> 
> So, if this were one long line, then this is the first visual line,$
> /whereas/ this is the second visual line in the paragraph, and you'd place$
> point on the italicized "w" in the word "whereas". That triggers the bug.

But you are not on the italicized "w", are you?  Try "C-x =", and you
will see.

The question is why.  Hmm...




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Thu, 27 Oct 2022 04:24:01 GMT) Full text and rfc822 format available.

Message #11 received at 58793 <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 58793 <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90; Emacs tries to recenter / rescroll when it
 hits hidden org emphasis
Date: Thu, 27 Oct 2022 04:24:17 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> So, if this were one long line, then this is the first visual line,$
>> /whereas/ this is the second visual line in the paragraph, and you'd place$
>> point on the italicized "w" in the word "whereas". That triggers the bug.
>
> But you are not on the italicized "w", are you?  Try "C-x =", and you
> will see.

(I assume that you have managed to confirm the bug; I can provide a more
detailed recipe if necessary)

Yes, C-x = reports invisible "/".

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Thu, 27 Oct 2022 06:03:02 GMT) Full text and rfc822 format available.

Message #14 received at 58793 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 58793 <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90; Emacs tries to recenter / rescroll when it
 hits hidden org emphasis
Date: Thu, 27 Oct 2022 09:02:29 +0300
> From: Ihor Radchenko <yantar92 <at> posteo.net>
> Cc: 58793 <at> debbugs.gnu.org
> Date: Thu, 27 Oct 2022 04:24:17 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> So, if this were one long line, then this is the first visual line,$
> >> /whereas/ this is the second visual line in the paragraph, and you'd place$
> >> point on the italicized "w" in the word "whereas". That triggers the bug.
> >
> > But you are not on the italicized "w", are you?  Try "C-x =", and you
> > will see.
> 
> (I assume that you have managed to confirm the bug; I can provide a more
> detailed recipe if necessary)

Yes, I see the recentering scroll.  I will look into that shortly.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Thu, 27 Oct 2022 13:14:02 GMT) Full text and rfc822 format available.

Message #17 received at 58793 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 58793 <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90;
 Emacs tries to recenter / rescroll when it hits hidden org emphasis
Date: Thu, 27 Oct 2022 16:13:07 +0300
> From: Ihor Radchenko <yantar92 <at> posteo.net>
> Date: Wed, 26 Oct 2022 07:59:14 +0000
> 
> 1. Load the repro emacs settings.
> 2. Scroll down in a buffer, such that top of buffer is not visible on
> screen.
> 3. Create an emphasized word at the beginning of the 2nd visual-line in a
> visually-wrapped line.
> 4. Move your point to the start of that emphasized word
> 
> It's a little difficult to describe, so I'll give an example. Assume
> that the visual-line wrapping is happening at the place indicated by
> "$".
> 
> ```
> So, if this were one long line, then this is the first visual line,$
> /whereas/ this is the second visual line in the paragraph, and you'd place$
> point on the italicized "w" in the word "whereas". That triggers the bug.
> ```
> 
> What happens next is that emacs thinks the point is no longer on screen
> and tries to scroll to fix that. Under vanilla emacs, it will just
> recenter the point. This still is misbehaving but not terribly. However,
> with
> smooth-scrolling as mentioned above, the behavior is worse. The window
> scrolls up and point jumps to the top of the window.
> 
> Reproed this with the following: emacs -Q
> with the following:
> ```
> (setq org-hide-emphasis-markers t)
> 
> (org-mode)
> (visual-line-mode 1)
> 
> ;; Without this, emacs will still show bug by calling recenter, but the
> effect is particularly egregious with these settings (i.e. smooth scrolling)
> (setq scroll-conservatively 101
>       scroll-preserve-screen-position t
>       scroll-margin 0)
> ```

Thanks, I hope I fixed this now.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Fri, 28 Oct 2022 04:07:01 GMT) Full text and rfc822 format available.

Message #20 received at 58793 <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 58793 <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90; Emacs tries to recenter / rescroll when it
 hits hidden org emphasis
Date: Fri, 28 Oct 2022 04:07:33 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

> Thanks, I hope I fixed this now.

I confirm the fix.
Thanks!

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Fri, 28 Oct 2022 06:37:02 GMT) Full text and rfc822 format available.

Notification sent to Ihor Radchenko <yantar92 <at> posteo.net>:
bug acknowledged by developer. (Fri, 28 Oct 2022 06:37:02 GMT) Full text and rfc822 format available.

Message #25 received at 58793-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 58793-done <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90; Emacs tries to recenter / rescroll when it
 hits hidden org emphasis
Date: Fri, 28 Oct 2022 09:36:43 +0300
> From: Ihor Radchenko <yantar92 <at> posteo.net>
> Cc: 58793 <at> debbugs.gnu.org
> Date: Fri, 28 Oct 2022 04:07:33 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Thanks, I hope I fixed this now.
> 
> I confirm the fix.
> Thanks!

Thanks for testing, I'm therefore closing the bug.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Fri, 28 Oct 2022 06:51:02 GMT) Full text and rfc822 format available.

Message #28 received at 58793-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 58793-done <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90; Emacs tries to recenter / rescroll when it
 hits hidden org emphasis
Date: Fri, 28 Oct 2022 09:50:34 +0300
> From: Ihor Radchenko <yantar92 <at> posteo.net>
> Cc: 58793 <at> debbugs.gnu.org
> Date: Fri, 28 Oct 2022 04:07:33 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Thanks, I hope I fixed this now.
> 
> I confirm the fix.
> Thanks!

Thanks for testing, I'm therefore closing the bug.

Btw, you wrote to the Org list that this issue has nothing to do with
Org, but that is inaccurate.  The bug was triggered by the fact that a
screen line started with invisible text, and point was inside that
invisible text.  Emacs display code assumes in a lot of places that
the position of point is somewhere between the positions of the first
and the last glyph of a screen line which displays the cursor.
Invisible text at the beginning or end of a screen line violates that
assumption, if point is inside invisible text, because invisible text
doesn't produce glyphs on the screen.  Violating that assumption
delivers a fatal blow to many redisplay optimizations that reuse
previous display (instead of redrawing everything anew); one of such
optimizations is for the situation when nothing's changed on display
except that point moved.  The display engine is still capable of
dealing with such unusual situations, but it is likely to recenter the
window in these cases, something that you find jarring.

So by using invisible text too much, Org does risk triggering such
situations more frequently.  Since the result is not fatally wrong,
just aesthetically annoying, I could say "wontfix", because fixing
this is notoriously complicated, and risks introducing new exciting
bugs (I hope I didn't introduce any this time).  In this case I was
lucky to be able to find a reasonable solution, but I cannot guarantee
that for any similar issue in the future.  After all, arguably Emacs
just copes with the unusual situation by falling back on the only
fail-safe redisplay mechanism we have.  So it is not a bug, strictly
speaking, just unusual and unexpected behavior.

Please keep this in mind as you introduce features into Org and
elsewhere which use invisible text.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#58793; Package emacs. (Sat, 29 Oct 2022 02:42:02 GMT) Full text and rfc822 format available.

Message #31 received at 58793-done <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 58793-done <at> debbugs.gnu.org
Subject: Re: bug#58793: 28.1.90; Emacs tries to recenter / rescroll when it
 hits hidden org emphasis
Date: Sat, 29 Oct 2022 02:42:13 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

> Btw, you wrote to the Org list that this issue has nothing to do with
> Org, but that is inaccurate.  The bug was triggered by the fact that a
> screen line started with invisible text, and point was inside that
> invisible text.  Emacs display code assumes in a lot of places that
> the position of point is somewhere between the positions of the first
> and the last glyph of a screen line which displays the cursor.
> Invisible text at the beginning or end of a screen line violates that
> assumption, if point is inside invisible text, because invisible text
> doesn't produce glyphs on the screen.  Violating that assumption
> delivers a fatal blow to many redisplay optimizations that reuse
> previous display (instead of redrawing everything anew); one of such
> optimizations is for the situation when nothing's changed on display
> except that point moved.  The display engine is still capable of
> dealing with such unusual situations, but it is likely to recenter the
> window in these cases, something that you find jarring.

Thanks for the explanation!
AFAIU, there is no way to avoid this and also use invisible text
somewhere not at bol/eol. The best we can do is minimizing the chance
to trigger this redisplay behaviour.

> So by using invisible text too much, Org does risk triggering such
> situations more frequently.  Since the result is not fatally wrong,
> just aesthetically annoying, I could say "wontfix", because fixing
> this is notoriously complicated, and risks introducing new exciting
> bugs (I hope I didn't introduce any this time).  In this case I was
> lucky to be able to find a reasonable solution, but I cannot guarantee
> that for any similar issue in the future.  After all, arguably Emacs
> just copes with the unusual situation by falling back on the only
> fail-safe redisplay mechanism we have.  So it is not a bug, strictly
> speaking, just unusual and unexpected behavior.

> Please keep this in mind as you introduce features into Org and
> elsewhere which use invisible text.

Noted. Though I feel that we really need to have A LOT of invisible text
to hit the issue frequently. (here, I was just digging through old bug
reports in Org mailing list; it is not something people often complain
about)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 26 Nov 2022 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 209 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.