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

From: Ergus <[email-masked]>
Date: Tue, 28 Jan 2025 13:59:22 +0100

On Mon, Jan 27, 2025 at 09:00:45PM +0200, Juri Linkov wrote:
>>>> 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 ;)
>
It depends ;)

>> +(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".
>
This works the same way. The previous code didn't support dynamically
change the flymake-fringe-indicator-position. We can try to solve it,
but we go back to the same issue tan in my first patch. We cannot change
the map.

>> +      (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.
>
I haven't seen this, please tell me how to reproduce it.

>> +(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'.

I will include these in the next patch. When I fix the
with-selected-window issue you mention before.

Best,
Ergus