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#58343: 29.0.50; ELisp code run in "inconsitent" selected-window state Date: Wed, 12 Oct 2022 18:08:47 +0000 Message-ID: References: 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="33822"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58343@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 12 20:09:14 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 1oigAL-0008cA-Nx for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 20:09:13 +0200 Original-Received: from localhost ([::1]:41444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oigAK-0004v8-9f for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 14:09:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oigAA-0004uU-Uk for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 14:09:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oigAA-0008Ls-MK for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 14:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oigAA-0004uC-5q for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 14:09: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: Wed, 12 Oct 2022 18:09:02 +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.166559813718845 (code B ref 58343); Wed, 12 Oct 2022 18:09:02 +0000 Original-Received: (at 58343) by debbugs.gnu.org; 12 Oct 2022 18:08:57 +0000 Original-Received: from localhost ([127.0.0.1]:58400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oigA4-0004tt-Ep for submit@debbugs.gnu.org; Wed, 12 Oct 2022 14:08:56 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:57745) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oigA2-0004tf-Pg for 58343@debbugs.gnu.org; Wed, 12 Oct 2022 14:08:55 -0400 Original-Received: (qmail 48875 invoked by uid 3782); 12 Oct 2022 20:08:48 +0200 Original-Received: from acm.muc.de (p4fe15af2.dip0.t-ipconnect.de [79.225.90.242]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 12 Oct 2022 20:08:47 +0200 Original-Received: (qmail 12215 invoked by uid 1000); 12 Oct 2022 18:08:47 -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:245241 Archived-At: Hello, Stefan. On Thu, Oct 06, 2022 at 20:06:25 -0400, Stefan Monnier wrote: > Package: Emacs > Version: 29.0.50 > Hi Alan and friends, > In commit dfa3e6f424b20fe27d9041b2ce7d69811df5d8cd, Alan added the > following code to do_switch_frame: > diff --git a/src/frame.c b/src/frame.c > index ccac18d23c2..dc8045f41e6 100644 > --- a/src/frame.c > +++ b/src/frame.c > @@ -1564,6 +1564,13 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor > if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) > last_nonminibuf_frame = XFRAME (selected_frame); > + /* 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 > + valid active minibuffer in the mini-window. */ > + if (EQ (f->selected_window, f->minibuffer_window) > + && NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) > + Fset_frame_selected_window (frame, call1 (Qget_mru_window, frame), Qnil); > + > Fselect_window (f->selected_window, norecord); > /* We want to make sure that the next event generates a frame-switch > the problem with this is that it calls `Qget_mru_window` which is ELisp > code, and that we're in the very middle of changing the selected frame, > so we have already changed the `selected-frame` variable a few lines > earlier, but the select-window has not yet been adjusted accordingly. > Running ELisp code in a state where (selected-window) and > (frame-selected-window) aren't equal is a recipe for problems. I have > already wasted many hours in the past tracking down bugs linked to this > kind of situation (back when the mode-line was processed in such an > inconsistent state, for example), and I really don't want to go there. > So we should arrange to run this `get-mru-window` function at some other > time, for example a few lines earlier before we set `selected-frame`. > I don't understand this code nearly enough to know how to move the code, > because it probably interacts with the other statements in non-trivial > ways, so the patch below is just a naive suggestion (it seems to work > here without triggering my many sprinkled assertions checking that > `EQ (XFRAME (selected_frame)->selected_window, selected_window)`, > but it's a far cry from a confirmation that it's right). > Hopefully someone here is aware of some of the potential pitfalls. 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. Is there any reason this function call was left where it was? Or could it just be moved, too? Otherwise, its calling convention will need to be adapted. Other than that, I haven't seen any problems as yet, though I admit I haven't tried it out. > Stefan [ .... ] -- Alan Mackenzie (Nuremberg, Germany).