From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58343: 29.0.50; ELisp code run in "inconsitent" selected-window state Date: Wed, 12 Oct 2022 14:35:33 -0400 Message-ID: References: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10834"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 58343@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 12 20:36:39 2022 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 1oigat-0002ey-FO for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 20:36:39 +0200 Original-Received: from localhost ([::1]:59190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigas-0008Nu-1A for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 14:36:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigaI-0008M1-Bp for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 14:36:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59355) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigaI-0004CM-3g for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 14:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oigaH-0007n4-N7 for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 14:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Oct 2022 18:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58343 X-GNU-PR-Package: emacs Original-Received: via spool by 58343-submit@debbugs.gnu.org id=B58343.166559974829924 (code B ref 58343); Wed, 12 Oct 2022 18:36:01 +0000 Original-Received: (at 58343) by debbugs.gnu.org; 12 Oct 2022 18:35:48 +0000 Original-Received: from localhost ([127.0.0.1]:58433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiga3-0007ma-Ix for submit@debbugs.gnu.org; Wed, 12 Oct 2022 14:35:48 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:1139) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiga1-0007mM-DP for 58343@debbugs.gnu.org; Wed, 12 Oct 2022 14:35:46 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7DC7A1001D0; Wed, 12 Oct 2022 14:35:39 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id DA04C1000FC; Wed, 12 Oct 2022 14:35:36 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1665599736; bh=Uc/ZQJDU0qO+W9fwROAyKFf84EYPwKqliRzjR+0fFLA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bp1CtfugkKeImYCd1Wj4r9EtA9LfU2Gb8Gqv5QbOx9wn4udRm8aLNg6+Sqnz86A6l jyt4zcvt98FKh+nC3nI+3VY9wCtAF7c4HzVpkmGyxIf3Rx/7Hb3KYI/ga9LAYkgz8k 1x/3Qanv2b6Uz4FtoYZu6PJcT4WIwppUfJwQuaYzdaldz3DDyzkzu8TyHooLQhg6PT AfAUjSnxZNDrUgxliZI57tgBKUiPxMUMO7o42hfdAKBSF0gIQX7dGvjosxyTmevXe9 fYv9lJTBpoBMBp6OIX+GPnolDNC3A5bvlHQWqR2MTHYG/ZuKuDvNWyeSx5JDlBpMHM Yb+FHOG6YDiug== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A6EFC1208E2; Wed, 12 Oct 2022 14:35:36 -0400 (EDT) In-Reply-To: (Alan Mackenzie's message of "Wed, 12 Oct 2022 18:08:47 +0000") 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:245243 Archived-At: Hi Alan, > One minor problem I see at the moment is that the call to > move_minibuffers_onto_frame wasn't moved together with the surrounding > code. With its current calling convention, it needs to be called > _after_ selected_frame has been set, because it uses selected_frame. Aha! > Is there any reason this function call was left where it was? I was afraid that swapping `move_minibuffers_onto_frame` and if (EQ (f->selected_window, f->minibuffer_window) /* The following test might fail if the mini-window contains a non-active minibuffer. */ && NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) { Lisp_Object w = call1 (Qget_mru_window, frame); if (WINDOW_LIVE_P (w)) /* W can be nil in minibuffer-only frames. */ Fset_frame_selected_window (frame, w, Qnil); } would not result in the same final result, e.g. because the name "move_minibuffers_onto_frame" suggests it might change the result of `XWINDOW (f->minibuffer_window)->contents`. > Or could it just be moved, too? Otherwise, its calling convention > will need to be adapted. The patch below refrains from moving it and passes it the to-be-selected frame as argument instead. Stefan diff --git a/src/frame.c b/src/frame.c index 91b9bec82c3..24de0701d13 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1503,17 +1503,7 @@ do_switch_frame (Lisp_Object frame, int for_deletion, Lisp_Object norecord) sf->select_mini_window_flag = MINI_WINDOW_P (XWINDOW (sf->selected_window)); - selected_frame = frame; - - move_minibuffers_onto_frame (sf, for_deletion); - - if (f->select_mini_window_flag - && !NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) - f->selected_window = f->minibuffer_window; - f->select_mini_window_flag = false; - - if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) - last_nonminibuf_frame = XFRAME (selected_frame); + move_minibuffers_onto_frame (sf, frame, for_deletion); /* If the selected window in the target frame is its mini-window, we move to a different window, the most recently used one, unless there is a @@ -1528,6 +1518,16 @@ do_switch_frame (Lisp_Object frame, int for_deletion, Lisp_Object norecord) Fset_frame_selected_window (frame, w, Qnil); } + selected_frame = frame; + + if (f->select_mini_window_flag + && !NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) + f->selected_window = f->minibuffer_window; + f->select_mini_window_flag = false; + + if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) + last_nonminibuf_frame = XFRAME (selected_frame); + Fselect_window (f->selected_window, norecord); /* We want to make sure that the next event generates a frame-switch @@ -2110,7 +2110,7 @@ delete_frame (Lisp_Object frame, Lisp_Object force) else /* Ensure any minibuffers on FRAME are moved onto the selected frame. */ - move_minibuffers_onto_frame (f, true); + move_minibuffers_onto_frame (f, selected_frame, true); /* Don't let echo_area_window to remain on a deleted frame. */ if (EQ (f->minibuffer_window, echo_area_window)) diff --git a/src/lisp.h b/src/lisp.h index 56f24d82810..5f6721595c0 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4792,7 +4792,7 @@ fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) extern Lisp_Object Vminibuffer_list; extern Lisp_Object last_minibuf_string; -extern void move_minibuffers_onto_frame (struct frame *, bool); +extern void move_minibuffers_onto_frame (struct frame *, Lisp_Object, bool); extern bool is_minibuffer (EMACS_INT, Lisp_Object); extern EMACS_INT this_minibuffer_depth (Lisp_Object); extern EMACS_INT minibuf_level; diff --git a/src/minibuf.c b/src/minibuf.c index bedc5644807..aebd17c0b76 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -187,13 +187,15 @@ zip_minibuffer_stacks (Lisp_Object dest_window, Lisp_Object source_window) /* If `minibuffer_follows_selected_frame' is t, or we're about to delete a frame which potentially "contains" minibuffers, move them - from the old frame to the selected frame. This function is + from the old frame to the to-be-selected frame. This function is intended to be called from `do_switch_frame' in frame.c. OF is the - old frame, FOR_DELETION is true if OF is about to be deleted. */ + old frame, SF is the to-be-selected frame, and FOR_DELETION is true + if OF is about to be deleted. */ void -move_minibuffers_onto_frame (struct frame *of, bool for_deletion) +move_minibuffers_onto_frame (struct frame *of, Lisp_Object sf, + bool for_deletion) { - struct frame *f = XFRAME (selected_frame); + struct frame *f = XFRAME (sf); minibuf_window = f->minibuffer_window; if (!(minibuf_level @@ -206,7 +208,7 @@ 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; + MB_frame = sf; } }