Subject: bug#75841: [PATCH] [UPDATE3] Fix mouse click on flymake

From: Juri Linkov <[email-masked]>
Date: Mon, 27 Jan 2025 21:00:45 +0200

>>> Please find attached the patch with the fix + the new feature.
>>
>>Your previous patch worked at least for margins, but new one doesn't work.
>>
> Try it now please. I actually detected the issue just now and was
> planning to submit a new patch. when I saw your message

Thanks for the patch.  I tested it, and now it works.
Please see some comments below.

> I actually prefer to create a branch and so on, but I thought that this
> patch would be just a couple of lines (like in my first message). But
> things are never as simple as I would like ;)

Too many troubles with the branch because it requires recompilation
every time after switching the branch.  The patch is much simpler ;)

> +(defvar-keymap flymake-mode-map
> +               :doc "Keymap for `flymake-mode'."
> +               (format "<%s> <mouse-1>" flymake-fringe-indicator-position)
> +               #'flymake-show-buffer-diagnostics-at-event-line)

This dependency on 'flymake-fringe-indicator-position' can break
in the case when the user customizes the value
of 'flymake-fringe-indicator-position' to 'right-fringe'.
Then clicking will fail with "<right-fringe> <mouse-1> is undefined".

> +      (with-selected-window (posn-window posn)
> +	(with-current-buffer (window-buffer)
> +	  (goto-char pos)
> +          (if full-line
> +              (flymake-diagnostics (line-beginning-position) (line-end-position))
> +            (flymake-diagnostics pos (1+ pos))))))))

I don't know if '(with-selected-window (posn-window posn)' was intended
to handle this case, but clicking on the fringe still raises the error
"Flymake mode is not enabled in the current buffer" when clicking
from the diagnostics buffer.

> +(defcustom flymake-after-jump-hook '(pulse-momentary-highlight-one-line)
> +  "Hook called after jumping to a diagnostic line.
> +
> +This hooks are called when `flymake-show-buffer-diagnostics' receives an
> +the optional `diagnostic' argument and it matches an entry in the
> +diagnostic's buffer."
> +  :type 'hook
> +  :version "31.0")

Please note that this is not direct equivalent to xref-after-jump-hook.
xref-after-jump-hook is more like flymake-show-diagnostic and
flymake-goto-diagnostic that jumps from the diagnostic buffer to the
source buffer.  But this hook is about showing the diagnostic buffer.
So a less ambiguous name would be 'flymake-after-show-buffer-diagnostics-hook'.

Then 'pulse-momentary-highlight-one-line' works nicely.
For consistency it could use the same face 'highlight'
as 'pulse-momentary-highlight-region' in 'flymake-show-diagnostic'.