GNU bug report logs - #45319
28.0.50; Redisplay: `forward-char' moves backwards into invisible text

Previous Next

Package: emacs;

Reported by: Michael Heerdegen <michael_heerdegen <at> web.de>

Date: Sat, 19 Dec 2020 06:12:01 UTC

Severity: normal

Found in version 28.0.50

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 45319 in the body.
You can then email your comments to 45319 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#45319; Package emacs. (Sat, 19 Dec 2020 06:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 19 Dec 2020 06:12:02 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: bug-gnu-emacs <at> gnu.org
Cc: Jonas Bernoulli <jonas <at> bernoul.li>
Subject: 28.0.50; Redisplay: `forward-char' moves backwards into invisible text
Date: Sat, 19 Dec 2020 07:10:53 +0100
[Message part 1 (text/plain, inline)]
Hello,

I have found a strange problem I encountered in the Magit Log buffer,
but it is reproducible in any buffer in emacs -Q.  CC'ing Jonas
Bernoulli, maintainer of Magit, for information.

I insert something like this into e.g. *scratch* (looks a bit like a
Magit log buffer):

[test.txt (text/plain, inline)]
11111
  a
  b
  c
22222
  x
  y
  z
33333
  f
  g
  h
44444
  i
  j
  k
[Message part 3 (text/plain, inline)]
Lets do this:

  (add-hook 'post-command-hook (lambda () (message "%s" (point))))

to see the value of point when we move around in the buffer.

I want to hide lines that start with whitespace, so I do this:

  (defvar my-magit-log-show-only-hash-lines-mode-keywords
    `((,(rx (and bol space (* any) eol))
       (0 (let ((beg (match-beginning 0))
                (end (1+ (match-end 0))))
            (add-text-properties beg end
                                 (list 'invisible 'my-magit-log-show-only-hash-lines))
            nil)))))

  (define-minor-mode my-magit-log-show-only-hash-lines-mode
    "..." nil nil nil
    (if (not my-magit-log-show-only-hash-lines-mode)
        (remove-from-invisibility-spec 'my-magit-log-show-only-hash-lines)
      (font-lock-add-keywords nil my-magit-log-show-only-hash-lines-mode-keywords)
      (add-to-invisibility-spec 'my-magit-log-show-only-hash-lines)))

Now enable that mode in the buffer and M-x font-lock-fontify-buffer.

When I now move around in the buffer with the arrow keys, it often
happens that when point is at the beginning of a visible line, and I hit
<right>, the echo area shows that point actually has moved backwards into
the invisible area somewhere before that line, but the cursor is placed
at the expected position.  Further movement behaves as expected from the
drawn cursor position, just the value of `point' sometimes is
inconsistent, and that can cause trouble (like incorrect section
highlighting in the Magit Log buffer).


TIA,

Michael.



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 09:12:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50;
 Redisplay: `forward-char' moves backwards into invisible text
Date: Sat, 19 Dec 2020 11:10:48 +0200
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Date: Sat, 19 Dec 2020 07:10:53 +0100
> Cc: Jonas Bernoulli <jonas <at> bernoul.li>
> 
>   (defvar my-magit-log-show-only-hash-lines-mode-keywords
>     `((,(rx (and bol space (* any) eol))
>        (0 (let ((beg (match-beginning 0))
>                 (end (1+ (match-end 0))))
>             (add-text-properties beg end
>                                  (list 'invisible 'my-magit-log-show-only-hash-lines))
>             nil)))))
> 
>   (define-minor-mode my-magit-log-show-only-hash-lines-mode
>     "..." nil nil nil
>     (if (not my-magit-log-show-only-hash-lines-mode)
>         (remove-from-invisibility-spec 'my-magit-log-show-only-hash-lines)
>       (font-lock-add-keywords nil my-magit-log-show-only-hash-lines-mode-keywords)
>       (add-to-invisibility-spec 'my-magit-log-show-only-hash-lines)))
> 
> Now enable that mode in the buffer and M-x font-lock-fontify-buffer.
> 
> When I now move around in the buffer with the arrow keys, it often
> happens that when point is at the beginning of a visible line, and I hit
> <right>, the echo area shows that point actually has moved backwards into
> the invisible area somewhere before that line, but the cursor is placed
> at the expected position.  Further movement behaves as expected from the
> drawn cursor position, just the value of `point' sometimes is
> inconsistent, and that can cause trouble (like incorrect section
> highlighting in the Magit Log buffer).

Does setting global-disable-point-adjustment non-nil and repeating
your experiment explain what happens?

It isn't a redisplay problem.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 11:22:02 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sat, 19 Dec 2020 12:21:27 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> Does setting global-disable-point-adjustment non-nil and repeating
> your experiment explain what happens?

I currently can't try because I'm eating ATM (yeah, shouldn't read mails
while eating...) but in the Magit buffer that was the first thing I had
tried and it didn't have an effect.

> It isn't a redisplay problem.

Point is moved from a visible into an invisible area - that should not
happen, no?  Even with point-adjustment enabled.

Regards,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 11:27:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sat, 19 Dec 2020 13:26:01 +0200
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 45319 <at> debbugs.gnu.org,  jonas <at> bernoul.li
> Date: Sat, 19 Dec 2020 12:21:27 +0100
> 
> > Does setting global-disable-point-adjustment non-nil and repeating
> > your experiment explain what happens?
> 
> I currently can't try because I'm eating ATM (yeah, shouldn't read mails
> while eating...) but in the Magit buffer that was the first thing I had
> tried and it didn't have an effect.

then maybe your recipe is not a complete demonstration what happens in
Magit buffers.

> > It isn't a redisplay problem.
> 
> Point is moved from a visible into an invisible area - that should not
> happen, no?  Even with point-adjustment enabled.

Why not?  "Invisible" means it is not displayed, but it doesn't mean
point cannot be there.  We have point-adjustment to avoid confusing
users because otherwise when point enters invisible text, cursor
movement commands would seem to have no effect, but that doesn't mean
point cannot enter invisible text.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 12:10:02 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sat, 19 Dec 2020 13:09:49 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> Why not?  "Invisible" means it is not displayed, but it doesn't mean
> point cannot be there.  We have point-adjustment to avoid confusing
> users because otherwise when point enters invisible text, cursor
> movement commands would seem to have no effect, but that doesn't mean
> point cannot enter invisible text.

But in the situation I described, I have been starting at a visible
position, `forward-char' should move point to the next char which is
also a visible, instead Emacs moves point some characters backwards into
an unrelated invisible position, that makes no sense to me.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 12:21:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sat, 19 Dec 2020 14:19:43 +0200
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 45319 <at> debbugs.gnu.org,  jonas <at> bernoul.li
> Date: Sat, 19 Dec 2020 13:09:49 +0100
> 
> But in the situation I described, I have been starting at a visible
> position, `forward-char' should move point to the next char which is
> also a visible, instead Emacs moves point some characters backwards into
> an unrelated invisible position, that makes no sense to me.

You judge what Emacs does with point by a report from a
post-command-hook.  But that's not necessarily what Emacs does with
point: the latter is what is shown by "C-x =".  Does that ever show
moving back?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 12:45:01 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sat, 19 Dec 2020 13:44:05 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> You judge what Emacs does with point by a report from a
> post-command-hook.  But that's not necessarily what Emacs does with
> point: the latter is what is shown by "C-x =".  Does that ever show
> moving back?

Magit's section highlighting is performed in post-command-hook, so it
highlights the wrong section in this case based on that value.  Do you
have a solution for this kind of problem?  hl-line-mode has the same
problem btw.

Ok, have tried now with (setq global-disable-point-adjustment t) and it
avoids the problem in my test case, yes.  However it's not what I want
to do in this buffer (or generally in this kind of situation, most of
the time).

Thanks,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sat, 19 Dec 2020 13:06:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sat, 19 Dec 2020 15:05:25 +0200
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 45319 <at> debbugs.gnu.org,  jonas <at> bernoul.li
> Date: Sat, 19 Dec 2020 13:44:05 +0100
> 
> Magit's section highlighting is performed in post-command-hook, so it
> highlights the wrong section in this case based on that value.  Do you
> have a solution for this kind of problem?

I don't think I understand the problem well enough yet to answer that
question, especially since you say that your simplified recipe behaves
differently.

What exactly is the problem in the magit case? does it use the value
of point in some way, and if so, how?  IOW, what is "section
highlighting" in magit?

> Ok, have tried now with (setq global-disable-point-adjustment t) and it
> avoids the problem in my test case, yes.  However it's not what I want
> to do in this buffer (or generally in this kind of situation, most of
> the time).

A stab in the dark: there's disable-point-adjustment, which could be
set temporarily, perhaps that could help?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sun, 20 Dec 2020 02:16:02 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sun, 20 Dec 2020 03:15:46 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> I don't think I understand the problem well enough yet to answer that
> question, especially since you say that your simplified recipe behaves
> differently.
>
> What exactly is the problem in the magit case? does it use the value
> of point in some way, and if so, how?  IOW, what is "section
> highlighting" in magit?

Let me ask a question first, for my better understanding, I'm curious:
what's your opinion about the (in my eyes) wrong value of point present
when `post-command-hook' is run?  Is it (1) expected and totally makes
sense, should be like that, or more like (2) not relevant, should not be
relied on, or (3) makes not much sense and is not so good but hard to
get to grips?

> A stab in the dark: there's disable-point-adjustment, which could be
> set temporarily, perhaps that could help?

Would that help to fix the behavior of `hl-line-mode' marking the wrong
line?

The Magit case is not much different.  Here a "section" is simply not a
line but a set of consecutive lines denoting a commit (headline + diff,
for example).  As with hl-line-mode, the wrong section is highlighted
when moving.  But since some commands depend on the currently
highlighted section, the consequence is that these commands then operate
on the wrong section.


Regards,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sun, 20 Dec 2020 03:33:02 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sun, 20 Dec 2020 04:32:04 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> A stab in the dark: there's disable-point-adjustment, which could be
> set temporarily, perhaps that could help?

I see now that I once already had filed a bug report concerning a
similar thing, and one thing Stefan mentioned there is relevant in this
case: with point "at" the beginning of a visible line, after invisible
lines,

  (get-pos-property (point) 'invisible) ==> t

so I'm trying with

  (setf (alist-get 'invisible text-property-default-nonsticky) t)

now.  Seems it helps (for my minor mode at least).


Thanks,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45319; Package emacs. (Sun, 20 Dec 2020 08:03:02 GMT) Full text and rfc822 format available.

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

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jonas <at> bernoul.li, 45319 <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sun, 20 Dec 2020 09:01:52 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> What exactly is the problem in the magit case?

I see now that that problem has been discussed in Bug#23079.  If you
think that everything is alright with my test case you might close this
bug and probably merge with that one.

Thanks,

Michael.




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sun, 20 Dec 2020 15:39:01 GMT) Full text and rfc822 format available.

Notification sent to Michael Heerdegen <michael_heerdegen <at> web.de>:
bug acknowledged by developer. (Sun, 20 Dec 2020 15:39:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: jonas <at> bernoul.li, 45319-done <at> debbugs.gnu.org
Subject: Re: bug#45319: 28.0.50; Redisplay: `forward-char' moves backwards
 into invisible text
Date: Sun, 20 Dec 2020 17:38:26 +0200
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: 45319 <at> debbugs.gnu.org,  jonas <at> bernoul.li
> Date: Sun, 20 Dec 2020 09:01:52 +0100
> 
> I see now that that problem has been discussed in Bug#23079.  If you
> think that everything is alright with my test case you might close this
> bug and probably merge with that one.

I closed this one.  Merging them is too much of a hassle with
debbugs's unhelpful defaults for archived bugs.

The only other thing I could say, which may or may not be helpful for
your use case, is that Lisp programs shouldn't assume they will always
find point outside of invisible portion of the text, and instead
actively look for the first visible position after point.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 18 Jan 2021 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 148 days ago.

Previous Next


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