From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#48674: Frames and minibuffer bug Date: Fri, 28 May 2021 20:14:41 +0000 Message-ID: References: <1911d1b0-ed9f-7359-b28c-fbaef27df8f3@gmx.at> <1e21b121-91c1-cbe9-d9ae-24915f163ae5@gmx.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35552"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 48674@debbugs.gnu.org, Iris =?UTF-8?Q?Garc=C3=ADa?= To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 28 22:15:30 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmitG-00099A-A4 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 28 May 2021 22:15:30 +0200 Original-Received: from localhost ([::1]:37974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmitF-0004e6-Br for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 28 May 2021 16:15:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmiso-0004dw-Mp for bug-gnu-emacs@gnu.org; Fri, 28 May 2021 16:15:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lmiso-0000AK-By for bug-gnu-emacs@gnu.org; Fri, 28 May 2021 16:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lmiso-0002XG-7w for bug-gnu-emacs@gnu.org; Fri, 28 May 2021 16:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 28 May 2021 20:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48674 X-GNU-PR-Package: emacs Original-Received: via spool by 48674-submit@debbugs.gnu.org id=B48674.16222328909715 (code B ref 48674); Fri, 28 May 2021 20:15:02 +0000 Original-Received: (at 48674) by debbugs.gnu.org; 28 May 2021 20:14:50 +0000 Original-Received: from localhost ([127.0.0.1]:55417 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lmisc-0002Wc-Bs for submit@debbugs.gnu.org; Fri, 28 May 2021 16:14:50 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:49331 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lmisa-0002WN-7w for 48674@debbugs.gnu.org; Fri, 28 May 2021 16:14:49 -0400 Original-Received: (qmail 39000 invoked by uid 3782); 28 May 2021 20:14:41 -0000 Original-Received: from acm.muc.de (p4fe155b9.dip0.t-ipconnect.de [79.225.85.185]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 28 May 2021 22:14:41 +0200 Original-Received: (qmail 27328 invoked by uid 1000); 28 May 2021 20:14:41 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:207478 Archived-At: Hello, Martin. On Fri, May 28, 2021 at 17:15:37 +0000, Alan Mackenzie wrote: > On Fri, May 28, 2021 at 10:26:32 +0200, martin rudalics wrote: [ .... ] > > But why precisely does Fselect_window fail here? > Sorry, my last night's reply wasn't very clear. That Fselect_window in > do_switch_frame will fail when a later Fselect_window (or more precisely, > Fset_frame_selected_window) in move_minibuffers_onto_frame selects a > different window for that frame. That happens when with-selected-frame > selects a different frame, moving the minibuffers onto that other frame. > I have another idea for solving this problem. Suppose when we switch > from F1 to F2, and F1's selected window is the mini-window, we allow F1 > to remain in the MW. The minibuffer stack gets moved to F2. Some sort > of commands or Lisp runs in F2, then we return to F1. Should any > minibuffer come back to F1, we allow the MW to remain selected. > Otherwise we select a different window in F1. > I think this would work better that what I proposed last night. I'll try > and formulate a patch for this this evening. I think the following patch, along the above lines, solves the bug completely. Could you review it for me, please? diff --git a/src/minibuf.c b/src/minibuf.c index cffb7fe787..c97a672ad6 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -192,10 +192,10 @@ move_minibuffers_onto_frame (struct frame *of, bool for_deletion) struct frame *f = XFRAME (selected_frame); minibuf_window = f->minibuffer_window; - if (!(minibuf_level - && (for_deletion || minibuf_follows_frame () || FRAME_INITIAL_P (of)))) + if (!(for_deletion || minibuf_follows_frame () || FRAME_INITIAL_P (of))) return; - if (FRAME_LIVE_P (f) + if (minibuf_level + && FRAME_LIVE_P (f) && !EQ (f->minibuffer_window, of->minibuffer_window) && WINDOW_LIVE_P (f->minibuffer_window) /* F not a tootip frame */ && WINDOW_LIVE_P (of->minibuffer_window)) @@ -203,15 +203,12 @@ move_minibuffers_onto_frame (struct frame *of, bool for_deletion) zip_minibuffer_stacks (f->minibuffer_window, of->minibuffer_window); if (for_deletion && XFRAME (MB_frame) != of) MB_frame = selected_frame; - if (!for_deletion - && MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (of)))) - { - Lisp_Object old_frame; - XSETFRAME (old_frame, of); - Fset_frame_selected_window (old_frame, - Fframe_first_window (old_frame), Qnil); - } } + /* If the new frame's selected window is the mini-window, select + some other window if we don't have an active minibuffer there. */ + if (MINI_WINDOW_P (XWINDOW (FRAME_SELECTED_WINDOW (f))) + && !live_minibuffer_p (XWINDOW (FRAME_SELECTED_WINDOW (f))->contents)) + Fselect_window (Fframe_first_window (selected_frame), Qnil); } DEFUN ("active-minibuffer-window", Factive_minibuffer_window, -- Alan Mackenzie (Nuremberg, Germany).