Subject: Re: bug#53910: [External] : bug#53910: 29.0.50; context-menu-mode breaks help in read-only buffers

From: Juri Linkov <[email-masked]>
Date: Fri, 18 Feb 2022 09:44:14 +0200

>>>>  (defvar context-menu-entry
>>>>    `(menu-item ,(purecopy "Context Menu") ,(make-sparse-keymap)
>>>> -              :filter ,(lambda (_) (context-menu-map)))
>>>> +              :filter ,(lambda (_) (unless help-buffer-under-preparation
>>>> +                                     ;; No need to build menu to describe keys
>>>> +                                     (context-menu-map))))
>>>>    "Menu item that creates the context menu and can be bound to a mouse key.")
>>> FWIW, I find this hideous.  `mouse.el` should not depend on `help-*` variables.
>> I know, but there are too many problems when help functions are trying
>> to build the context menu in a non-displayed buffer.
>
> Those are bugs in the context-menu functions that need to be fixed
> because they'll bite us sooner or later in other cases anyway.
> In a sense, we should be happy to have such an easy way to trigger those
> bugs ;-)

If `context-menu-mode` is intended to work only on displayed buffers,
is it really important to ensure that it also doesn't fail on
non-window buffers?  I think the bug is in these functions that
are trying to call `context-menu-map` in a non-window buffer,
in this case the bug in the Help functions.  Then indeed instead
of using `help-buffer-under-preparation` in `mouse.el`, maybe
it should be fixed in `describe-map` somehow to not call
`lookup-key` that creates the context menu with:

  (eq definition (lookup-key tail (vector event) t))

>> Is there another way to prevent this?
>
> I think a slightly cleaner way (if you want to keep such a workaround
> rather than chase&fix the underlying bugs) is to move the var to
> `mouse.el` and call it `inhibit-context-menu`, and then let-bind at the
> appropriate place with a prominent comment explaining why we're using
> such a hack.

Then this means using something like this in `describe-map`:

  (let ((inhibit-context-menu t))
    (eq definition (lookup-key tail (vector event) t)))

But indeed, this looks like a workaround.