Subject: bug#78106: [Feature Request] EGLOT: Optionally make code action indications use mouse clicks

From: Elijah Gabe Pérez <[email-masked]>
Date: Fri, 02 May 2025 19:54:44 -0600

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

>> I used `substitute-command-keys' only for get the mouse-1/2/3 button for
>> margin, but since i see this is problematic, I've changed it to only
>> display `mouse-2'.
>
> Yes, this is a problem.  Maybe we should just let the hardcoded mouse-2
> be there, or maybe there is a better way.  Anyway, please proceed from
> the simpler patch after my sig.

> I noticed the 'tooltip' (sans "1") variable wasn't being used for
> anything.

It's used only for nearby and margin options:

>>                 (goto-char (car bounds))
>> -               (let ((ov (make-overlay (car bounds) (cadr bounds))))
>> +               (let ((ov (make-overlay (car bounds) (cadr bounds)))
>> +                     (tooltip-1 (propertize
>> +                                 tooltip
>> +                                 'help-echo
>> +                                 (concat
>> +                                  blurb
>> +                                  ",\nmouse-2: execute code actions at point"))))
>>                   (overlay-put ov 'eglot--actions actions)
>>                   (overlay-put ov 'eglot--suggestion-tooltip tooltip)
>>                   (overlay-put
>>                    ov
>>                    'before-string
>>                    (cond ((memq 'nearby eglot-code-action-indications)
>> -                         tooltip)
>> +                         tooltip-1)
                                    ^
>>                          ((memq 'margin eglot-code-action-indications)
>>                           (propertize "⚡"
>>                                       'display
>>                                       `((margin left-margin)
>> -                                       ,tooltip)))))
>> +                                       ,tooltip-1)))))
                                                   ^
>>                   (setq eglot--suggestion-overlay ov)))))

Thus, Eldoc will not display "mouse-2: execute code actions at point",
which can be confusing.

> I think that -- ideally, at least on Emacs master -- there should be a
> way to tell substitute-command-keys which parts of the Emacs layout to
> consider when constructing its strings.  Feel free to ask about this on
> emacs-devel and then bring any results back to Eglot.  If we can't find
> anything better I'll commit some version of your patch.

For now i think that the hardcoded mouse-2 would be the best choice,
also I've seen in other packages (including built-in) that they does the
same.

> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index d796c9fc802..8d2934391d6 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -2531,7 +2531,11 @@ eglot-mode-line-action-suggestion
>    '(:eval
>      (when (and (memq 'mode-line eglot-code-action-indications)
>                 (overlay-buffer eglot--suggestion-overlay))
> -      (overlay-get eglot--suggestion-overlay 'eglot--suggestion-tooltip)))
> +      (eglot--mode-line-props
> +       eglot-code-action-indicator 'eglot-code-action-indicator-face
> +       `((mouse-1
> +          eglot-code-actions-at-mouse
> +          "execute code actions at point")))))
>    "Eglot mode line construct for at-point code actions.")

No problem with this.

>  (add-to-list
> @@ -4146,14 +4150,13 @@ eglot-code-action-suggestion
>               (setq tooltip
>                     (propertize eglot-code-action-indicator
>                                 'face 'eglot-code-action-indicator-face
> -                               'help-echo blurb
> +                               'help-echo "mouse-2: execute code actions at point"

"mouse-2: execute code actions at point" will appear also in ElDoc.

>                                 'mouse-face 'highlight
>                                 'keymap eglot-diagnostics-map))
>               (save-excursion
>                 (goto-char (car bounds))
>                 (let ((ov (make-overlay (car bounds) (cadr bounds))))
>                   (overlay-put ov 'eglot--actions actions)
> -                 (overlay-put ov 'eglot--suggestion-tooltip tooltip)

What was 'eglot--suggestion-tooltip' used for? Are you sure it should be
removed?

>                   (overlay-put
>                    ov
>                    'before-string

-- 
                                          - E.G via GNU Emacs and Org.