Subject: bug#46552: 27.1; image-mode should not move current point

From: Eli Zaretskii <[email-masked]>
Date: Tue, 16 Feb 2021 18:32:26 +0200

> From: Lars Ingebrigtsen <[email-masked]>
> Date: Tue, 16 Feb 2021 13:36:18 +0100
> Cc: [email-masked]
> 
> This is most puzzling.  I can reproduce this problem in Emacs 28 without
> a problem.  But:
> 
> C-c C-c runs the command image-toggle-display (found in
> image-minor-mode-map), which is an interactive Lisp closure in
> ‘image-mode.el’.
> 
> If I instead say `M-: (image-toggle-display) RET' or even
> `M-: (call-interactively 'image-toggle-display) RET', I can't.
> 
> And `C-c C-c' should be totally equivalent to the latter, right?
> 
> So what's moving point?

It's the "point-adjustment" feature, which moves point out of
invisible/intangible/display-property/etc text, where we don't want
the user to see point, ever.  Try setting
global-disable-point-adjustment non-nil, and you will see what happens
when this is disabled.

> It must be some...  hook function or something that reacts
> differently to the two things...  but looking through the
> image-mode.el code, it's not obvious what that could be.

It's not in image-mode.el, it's a general feature of Emacs not
directly related to images.

> Anybody got any ideas here?

The point adjustment needs to decide whether to move point before or
after the display property.  Its logic is based on heuristics that can
break/change behavior depending on how the command was invoked,
because it's based on the previous value of point (if point moved
forward, the logic prefers to adjust point in the forward direction,
and vice versa).