Subject: Re: [External] : bug#47150: 28.0.50; Incorrect major-mode in minibuffer

From: Stefan Monnier <[email-masked]>
Date: Mon, 22 Mar 2021 15:30:47 -0400

>> I'm in favor of introducing a `minibuffer-mode`.
> Why?

Because that's already what "fundamental-mode + minibuffer-local-map"
is, tho without the benefit of all the associated conventions of a major
mode (e.g. C-h m to name just one).

>> Part of the question is also when and how that mode is activated (since
>> activating such a mode has the effect of deleting the local variables).
>> I think we should call `minibuffer-mode` every time we (re)activate
>> a minibuffer.
> Why?

So a minibuffer isn't affected by what happened in its previous invocation.

>> The way I see it, `eval-expression` would want to use a new major mode
>> that derives from `minibuffer-mode`.
> Why change the major mode?

Why not.  That's already what `eval-expression` does, except it does it
piecemeal instead of via the well known major-mode concept.

> What's involved, besides keymaps?

In the case of `eval-expression, potentially anything that applies to
a normal buffer seems to be applicable, e.g. indentation,
show-paren-mode, eldoc, font-lock, flymake, company-mode, you name it...

>> It would also provide a cleaner way to do what we currently do via the
>> `minibuffer-with-setup-hook` hack.
> Really?  Everything that someone might do on that
> hook you would have passed as a function arg?

I don't think we could replace all uses of `minibuffer-with-setup-hook`
with that, no, at least not without additional changes (since my
suggestion only covers code which currently directly uses
`read-from-minibuffer`, so we'd at least have to change
`completing-read` so it too can take a major-mode as argument).

> Why would you find that cleaner?

If you don't know, it's because you haven't looked at the implementation
of `minibuffer-with-setup-hook`, which is fundamentally inherently
brittle (tho it's sufficiently tuned that it's normally never a problem
in practice, of course).

> Right.  There was nothing missing before `minibuffer-inactive-mode'
> was added, except possibly the corner case you mentioned for
> a standalone minibuffer frame.  (And I use such a frame, and I've
> never felt the need to use it in an "inactive" active way.)

Nobody forces you to use it.  It should be harmless.
Have you suffered from the addition of `minibuffer-inactive-mode`?
I can't remember seeing many bug reports about it (although I was
worried when I added it).

        Stefan