Subject: Re: bug#69259: 30.0.50; (get-pos-property 9483 'cursor-intangible) gives args-out-of-range error in folded magit buffer

From: Eli Zaretskii <[email-masked]>
Date: Wed, 21 Feb 2024 14:31:21 +0200

> From: StrawberryTea <[email-masked]>
> Cc: [email-masked]
> Date: Tue, 20 Feb 2024 09:42:36 -0600
> 
> Hi Eli. I inserted a print function into magit-post-command-hook:
> 
> (defadvice! cae-magit-section-post-command-hook-a (oldfun)
>   :around #’magit-section-post-command-hook
>   (condition-case e
>       (funcall oldfun)
>     (error
>      (+log “magit-post-command-hook error:”
>            (current-buffer) (selected-window) (buffer-narrowed-p) (point-min)
>   (point-max) (buffer-size)))))
> 
> and it outputted this:
> Values: magit-post-command-hook error:, magit: emacs, #<window 156 on
> *Messages*>, nil, 1, 20993, 20992 Eli Zaretskii <[email-masked]>
> 
> So basically, the situation is that the (current-buffer) is magit: emacs whereas
> the window is on \*Messages\* and so when we call (get-pos-property pos
> ’cursor-intangible), it uses a point value from magit: emacs on the messages
> buffer.
> 
> Why exactly are the window-buffer and the current-buffer different? I think this
> has to do with persp-mode. My guess is that when it sets the new window
> configuration, the current-buffer is not updated to the new window’s buffer
> immediately.

It is more likely that the post-command-hook was somehow invoked
inside with-selected-window or save-window-excursion or something like
that.

I think cursor-sensor is written under the assumption that the
selected window's buffer is also the current buffer, and if so,
magit-post-command-hook should abide by that protocol.  Stefan, am I
right?