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

From: "Drew Adams" <[email-masked]>
Date: Wed, 6 Feb 2013 15:04:53 -0800

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

I see this behavior with my own setup, which has a standalone minibuffer
frame: It seems like the hook is invoked for each toggle between
states active & inactive, i.e., including from inactive to active,
which would be wrong.  I would expect the hook to be invoked only
when the minibuffer becomes inactive.

E.g.:

(defun move-frame-right (&optional n frame)
  (interactive "p")
  (unless n (setq n  1))
  (setq n  (* n (frame-char-width frame)))
  (modify-frame-parameters frame
    (list (list 'left '+ (new-frame-position frame 'left n)))))

(add-hook 'minibuffer-inactive-mode-hook #'move-frame-right)

Start with the minibuffer inactive and some frame other than the
minibuffer frame selected, and do M-x.  That selected frame moves to the
right.  Why?  Then hit C-g to cancel M-x.  The minibuffer frame moves to
the right.

The latter makes sense, because C-g inactivates the minibuffer.  The
former invocation of the hook seems like a bug to me.

Then remove that hook function and do this instead:

Show buffer *Messages* in its own frame, then:
 
(add-hook 'minibuffer-inactive-mode-hook
 (lambda ()
   (message "fr: %S, active: %S"
            (selected-frame) (active-minibuffer-window))))
 
Then, with frame *Messages* selected, do M-x, then C-g.  This confirms
the double invocation.  This is what I see (my minibuffer frame has a
long name):
 
fr: #<frame *Messages* 03F9CC10>, active: #<window 6 on  *Minibuf-0*> [2 times]
fr: #<frame Emacs minibuffer - show/hide: hold CTRL + click in window 03FDDA48>,
active: nil
 
The first message, including the [2 times], appears after M-x.  The
second message appears after C-g.  Note that the first message indicates that
the minibuffer is _active_ - so why is the hook firing?
 
Now remove that hook function and then do this:
 
(add-hook 'minibuffer-inactive-mode-hook #'make-frame-invisible)
 
This is how I started.  I was expecting the minibuffer frame to
essentially stay hidden except when the minibuffer was activated.
 
With *Messages* selected, M-x makes *Messages* disappear.  Then C-g
makes the minibuffer frame disappear and brings back *Messages*.
 
Seems broken to me, but perhaps I'm missing something.
 
In GNU Emacs 24.3.50.1 (i386-mingw-nt5.1.2600)
 of 2013-01-30 on ODIEONE
Bzr revision: 111631 [email-masked]
Windowing system distributor `Microsoft Corp.', version 5.1.2600
Configured using:
 `configure --with-gcc (4.7) --no-opt --enable-checking --cflags
 -IC:/Devel/emacs/build/include --ldflags -LC:/Devel/emacs/build/lib'