Subject: bug#73863: 30.0.91; Unexpected cursor movement with flymake-show-diagnostics-at-end-of-line

From: João Távora <[email-masked]>
Date: Sun, 20 Oct 2024 10:28:50 +0100

Flymake queries should be directed to Spencer Baugh

But if this fixes the user's problem and doesn't hurt anyone who does
have wide enough windows and on top of that sufficient testing is done,
I don't object to this solution.  I don't know what that problem is.  Does
the user want their cursor to show at the end of the intangible overlay?
If so, that's odd: I designed this feature to be as little intrusive as possible
i.e. so that turning it on has no other effect than some text appearing
at the end of line -- and only at the end of line.  If there is little space, I
would say the right thing to do is to truncate, not wrap to the next line

To try and answer your question,  I don't think it is used by other Flymake
parts (the function name hints at it: flymake--eol- means "end of line").
However, I advise to give it testing (with multiple diagnostics on one
line, for example). I remember trying many variations on these things
and each had its drawbacks.  But possibly (probably?) I didn't test
this one.  Anyway, do test this out with other flymake eol users and
consider the impact to users with wide enough windows: if there's no
impact I don't see why this wouldn't be acceptable. But that is for
Spencer or you to decide.

João

On Sun, Oct 20, 2024 at 8:25 AM Eli Zaretskii <[email-masked]> wrote:
>
> > From: Romain Ouabdelkader <[email-masked]>
> > Date: Sat, 19 Oct 2024 15:41:05 +0200
> > Cc: [email-masked]
> >
> >  So this problem only happens when the window is not wide enough, and
> >  the diagnostic wraps to the next screen line?
> >
> > Yes that's correct, this happens to me quite often when I have two windows open side by side.
>
> This is actually what flymake.el requests the display engine to do: it
> asks it to show the cursor on the first character of the diagnostic's
> before-string:
>
>    (put-text-property 0 1 'cursor t summary)
>
> So when you use C-n, Emacs moves point to the end of the
> before-string, but the 'cursor' property tells it to show the cursor
> on the first character of the before-string, which is on a previous
> screen line.  So the display engine obeys and shows the cursor there.
>
> The following simple patch seems to give much better results.  João,
> is the code in question used by any Flymake feature other than this
> new flymake-show-diagnostics-at-end-of-line option?  If so, we'll
> probably need some condition to move the 'cursor' property to end of
> string (assuming you don't object to this solution).
>
> diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
> index 9a6b62c..0ef1ed0 100644
> --- a/lisp/progmodes/flymake.el
> +++ b/lisp/progmodes/flymake.el
> @@ -835,8 +835,12 @@ flymake--eol-overlay-summary
>                                                 (1- (length diags)))
>                                         'face 'flymake-eol-information-face)))))
>                     (t
> -                    (mapconcat #'summarize diags " "))))))
> -      (put-text-property 0 1 'cursor t summary)
> +                    (mapconcat #'summarize diags " ")))))
> +           (last-pos (1- (length summary))))
> +      ;; Put the 'cursor' property on the last character of the summary,
> +      ;; so that vertical-motion produces the expected results when the
> +      ;; summary wraps to next screen lines.
> +      (put-text-property last-pos (1+ last-pos) 'cursor t summary)
>        summary)))
>
>  (defun flymake--update-eol-overlays ()

-- 
João Távora