Subject: Re: bug#62157: More control over the mouse behaviour in eglot
From: Stefan Kangas <[email-masked]>
To: João Távora <[email-masked]>
Cc: [email-masked], Pedro Andres Aranda Gutierrez <[email-masked]>
Date: Mon, 11 Sep 2023 17:22:41 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

João Távora <[email-masked]> writes:

> On Mon, Mar 13, 2023 at 7:22 AM Pedro Andres Aranda Gutierrez
> <[email-masked]> wrote:
>>
>> When I edit Python with eglot,  mouse-1-down opens the eglot code
>> actions menu when over a place where there is a possible action. I'd
>> like to be able to define the mouse event to open the menu myself. In
>> the same line, I'd like to control the items on the code actions mouse
>> menu.
>
> These are two separate requests.  I'll focus on the first one,
> as the second one is obscure.  It probablyneeds its own separate
> issue describing a reproducible observable example of what "item
> control" is desired.
>
> So, having mouse-1 for the binding to get code actions in diagnostics
> is indeed not good, because it prevents point from being put on
> a certain character using mouse-1, which should really nothappen.
>
> Currently, to configure it, the user must place a certain property on
> the symbols eglot-note eglot-warning eglot-error, which is not
> easy at all.
>
> Can you try this patch?  It also changes the default binding to
> [mouse-2].
>
> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index 2491c86ea5b..256b4cd93ba 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -2084,15 +2084,18 @@ eglot--mode-line-format
>  (defalias 'eglot--make-diag 'flymake-make-diagnostic)
>  (defalias 'eglot--diag-data 'flymake-diagnostic-data)
>
> +(defvar eglot-diagnostics-map
> +  "Map active in Eglot-backed Flymake diagnostic overlays."
> +  (let ((map (make-sparse-keymap)))
> +    (define-key map [mouse-1] 'eglot-code-actions-at-mouse)
> +    map))
> +
>  (cl-loop for i from 1
>           for type in '(eglot-note eglot-warning eglot-error)
>           do (put type 'flymake-overlay-control
>                   `((mouse-face . highlight)
>                     (priority . ,(+ 50 i))
> -                   (keymap . ,(let ((map (make-sparse-keymap)))
> -                                (define-key map [mouse-1]
> -                                            (eglot--mouse-call
> 'eglot-code-actions))
> -                                map)))))
> +                   (keymap . ,eglot-diagnostics-map))))
>
>
>  ;;; Protocol implementation (Requests, notifications, etc)
> @@ -3335,6 +3338,9 @@ eglot-code-actions
>          (eglot--read-execute-code-action actions server action-kind)
>        actions)))
>
> +(defalias 'eglot-code-actions-at-mouse (eglot--mouse-call 'eglot-code-actions)
> +  "Like `eglot-code-actions', but intended for mouse events.")
> +
>  (defun eglot--read-execute-code-action (actions server &optional action-kind)
>    "Helper for interactive calls to `eglot-code-actions'."
>    (let* ((menu-items
>
> João

It seems like the fix was the patch above, which IIUC has been
installed.  I'm therefore closing this bug report.

If this conclusion is incorrect and this is still an issue, please reply
to this email (use "Reply to all" in your email client) and we can
reopen the bug report.