unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
@ 2013-02-06 23:04 Drew Adams
  2013-02-06 23:55 ` Drew Adams
  2021-07-15  6:49 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Drew Adams @ 2013-02-06 23:04 UTC (permalink / raw)
  To: 13641

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 michael.albinus@gmx.de-20130130192046-nx4rskw7jemmtrw8
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'
 






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
  2013-02-06 23:04 bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong Drew Adams
@ 2013-02-06 23:55 ` Drew Adams
  2013-03-07  2:59   ` Drew Adams
  2021-07-15  6:49 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Drew Adams @ 2013-02-06 23:55 UTC (permalink / raw)
  To: 13641

> (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*.

Thinking it might have something to do with the minibuffer level, I tried this:

(add-hook 'minibuffer-inactive-mode-hook
          (lambda ()
            (message "fr: %S, active: %S, depth: %S"
                     (selected-frame)
                     (active-minibuffer-window)
                     (minibuffer-depth))
            (unless (> (minibuffer-depth) 0)
              (make-frame-invisible))))

Then M-x followed by C-g works, but only every other time.
The inactive minibuffer reappears every other time (why?).

It reappears even when the message shows that the depth is 0 and the minibuffer
is inactive.






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
  2013-02-06 23:55 ` Drew Adams
@ 2013-03-07  2:59   ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2013-03-07  2:59 UTC (permalink / raw)
  To: 13641

Any chance someone could please take a look at this behavior and explain what is
going on?  Thx.






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
  2013-02-06 23:04 bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong Drew Adams
  2013-02-06 23:55 ` Drew Adams
@ 2021-07-15  6:49 ` Lars Ingebrigtsen
  2021-07-15  7:21   ` Eli Zaretskii
  2021-08-12 15:16   ` Lars Ingebrigtsen
  1 sibling, 2 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-15  6:49 UTC (permalink / raw)
  To: Drew Adams; +Cc: 13641

"Drew Adams" <drew.adams@oracle.com> 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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
  2021-07-15  6:49 ` Lars Ingebrigtsen
@ 2021-07-15  7:21   ` Eli Zaretskii
  2021-07-15  7:26     ` Lars Ingebrigtsen
  2021-08-12 15:16   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2021-07-15  7:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 13641

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Thu, 15 Jul 2021 08:49:38 +0200
> Cc: 13641@debbugs.gnu.org
> 
> The mode is called both on entering and exiting the minibuffer, which
> sounds slightly surprising

Isn't it generally true that a mode function is called both when
turning a mode on and when turning it off?  Then why is the above
surprising?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
  2021-07-15  7:21   ` Eli Zaretskii
@ 2021-07-15  7:26     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-15  7:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 13641

Eli Zaretskii <eliz@gnu.org> writes:

>> The mode is called both on entering and exiting the minibuffer, which
>> sounds slightly surprising
>
> Isn't it generally true that a mode function is called both when
> turning a mode on and when turning it off?  Then why is the above
> surprising?

`minibuffer-inactive-mode' is a major mode, so I don't know whether the
concept "turning it off" makes sense?

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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong
  2021-07-15  6:49 ` Lars Ingebrigtsen
  2021-07-15  7:21   ` Eli Zaretskii
@ 2021-08-12 15:16   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-12 15:16 UTC (permalink / raw)
  To: Drew Adams; +Cc: 13641

Lars Ingebrigtsen <larsi@gnus.org> writes:

> 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? 

Now done in Emacs 28.

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





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-12 15:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-06 23:04 bug#13641: 24.3.50; `minibuffer-inactive-mode' - hook seems wrong Drew Adams
2013-02-06 23:55 ` Drew Adams
2013-03-07  2:59   ` Drew Adams
2021-07-15  6:49 ` Lars Ingebrigtsen
2021-07-15  7:21   ` Eli Zaretskii
2021-07-15  7:26     ` Lars Ingebrigtsen
2021-08-12 15:16   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).