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

From: Juri Linkov <[email-masked]>
Date: Tue, 28 Jan 2025 20:17:51 +0200

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

Do you see a problem with binding both initially:
'left-fringe' and 'right-fringe'?

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

The previous code didn't support this case, so no need to handle this.
I just thought why with-selected-window can't handle the case
when the selected window was the diagnostics buffer, and then
can't click the fringe in the source 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'.
>
> I will include these in the next patch. When I fix the
> with-selected-window issue you mention before.

Thanks.