Subject: Re: bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 15 Jul 2021 08:49:38 +0200

"Drew Adams" <[email-masked]> writes:

> I don't have the C sources, so cannot see just how/when
> the hook `minibuffer-inactive-mode-hook' gets called.

It seems that it's called twice.  To test:

(add-hook 'minibuffer-inactive-mode-hook 'debug)
M-x

Debugger entered: nil
  (closure (t) nil (debug) (message "foo"))()
  run-hooks(change-major-mode-after-body-hook minibuffer-inactive-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook minibuffer-inactive-mode-hook))
  run-mode-hooks(minibuffer-inactive-mode-hook)
  minibuffer-inactive-mode()
  read-from-minibuffer("M-x " nil (keymap (10 . minibuffer-complete-and-exit) (
  completing-read-default("M-x " #f(compiled-function (string pred action) #<by
  completing-read("M-x " #f(compiled-function (string pred action) #<bytecode -
  read-extended-command()

The mode is called both on entering and exiting the minibuffer, which
sounds slightly surprising (but it doesn't really say anything about
when it's invoked, either).  I guess it's this:

  /* In case the previous minibuffer displayed in this miniwindow is
     dead, we may keep displaying this buffer (tho it's inactive), so reset it,
     to make sure we don't leave around bindings and stuff which only
     made sense during the read_minibuf invocation.  */
  call0 (Qminibuffer_inactive_mode);

Perhaps the doc string of `minibuffer-inactive-mode' should mention that
it may be called several times, and that people looking at the mode's
hook should probably be looking at minibuffer-exit-hook instead?  Any
opinions?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no