From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#63967: 28.2; switch-to-buffer in normal window fails if minibuffer window is active Date: Fri, 09 Jun 2023 19:09:19 +0300 Message-ID: <83fs701uts.fsf@gnu.org> References: <83o7lo28e6.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18864"; mail-complaints-to="usenet@ciao.gmane.io" Cc: al@petrofsky.org, rudalics@gmx.at, 63967@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 09 18:10:22 2023 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 1q7egw-0004dt-7x for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 09 Jun 2023 18:10:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7egf-0001rb-Nq; Fri, 09 Jun 2023 12:10:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7egd-0001rL-IJ for bug-gnu-emacs@gnu.org; Fri, 09 Jun 2023 12:10:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7egd-0008EE-8r for bug-gnu-emacs@gnu.org; Fri, 09 Jun 2023 12:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q7egc-0000ej-BI for bug-gnu-emacs@gnu.org; Fri, 09 Jun 2023 12:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Jun 2023 16:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63967 X-GNU-PR-Package: emacs Original-Received: via spool by 63967-submit@debbugs.gnu.org id=B63967.16863269612463 (code B ref 63967); Fri, 09 Jun 2023 16:10:02 +0000 Original-Received: (at 63967) by debbugs.gnu.org; 9 Jun 2023 16:09:21 +0000 Original-Received: from localhost ([127.0.0.1]:60204 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7efw-0000df-M7 for submit@debbugs.gnu.org; Fri, 09 Jun 2023 12:09:21 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50430) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7efu-0000dS-Nw for 63967@debbugs.gnu.org; Fri, 09 Jun 2023 12:09:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7efo-00089T-DW; Fri, 09 Jun 2023 12:09:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Rzkg4Z3srV6KMqNRp3WhL2GLG6vn44mkNR6pe0yxYvE=; b=qBwGECiHqi2D A75ViVLFLv5UF+Pl1X4yw2UhCSzqYKv/rmLDz/s/UOQBRWiQINs8zD2CDjjrskPNnSSLJ4sQqeoAA nkjuSQOfogcWrs2a7nrk7YunNFoQZpd/R4pvWg9xiIoHjV8CPdqlIo2kf292DI+xX0/qXAgf+J1r0 47gbA16KrhOvImR1VeaTMhaMRGSLLbxNhcOE8GC9W6DOrIx1heYoExdeaouyA9OcQ/7YEv97SEViA RRbWReuJXQtpI1Q/i7HXn7/SeR+k5M2DxLJ3KjRsp7DvIio4rkESENCxbVT1R5QGdN0F1t9Gk2wk9 1OIUmE+H5rZlMbauCqDBzw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7efn-0001LA-UA; Fri, 09 Jun 2023 12:09:12 -0400 In-Reply-To: (message from Stefan Monnier on Fri, 09 Jun 2023 11:08:43 -0400) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263175 Archived-At: > From: Stefan Monnier > Cc: Al Petrofsky , martin rudalics , > 63967@debbugs.gnu.org > Date: Fri, 09 Jun 2023 11:08:43 -0400 > > > Seems like read-buffer-to-switch (called by "C-x b") changes the > > selected-window: when it returns, the rest of the function runs with > > the minibuffer window being the selected-window, which is wrong in > > this case. > > Are you 100% sure that's what happens? Yes, I'm sure. First, the window-minibuffer-p call in the interactive form: (interactive (let ((force-same-window (unless switch-to-buffer-obey-display-actions (cond ((window-minibuffer-p) nil) <<<<<<<<<<<<<<<<<<<<<<<<<<<< ((not (eq (window-dedicated-p) t)) 'force-same-window) ((pcase switch-to-buffer-in-dedicated-window ('nil (user-error "Cannot switch buffers in a dedicated window")) ('prompt (if (y-or-n-p (format "Window is dedicated to %s; undedicate it?" (window-buffer))) (progn (set-window-dedicated-p nil nil) 'force-same-window) (user-error "Cannot switch buffers in a dedicated window"))) ('pop nil) (_ (set-window-dedicated-p nil nil) 'force-same-window))))))) (list (read-buffer-to-switch "Switch to buffer: ") nil force-same-window))) returns nil, as expected (since this runs in the window to which we changed with "C-x p", before Emacs prompts for the buffer to switch to). But then the call to window-minibuffer-p in the body of the function: (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)) (set-window-start-and-point (not switch-to-buffer-obey-display-actions))) (cond ;; Don't call set-window-buffer if it's not needed since it ;; might signal an error (e.g. if the window is dedicated). ((and (eq buffer (window-buffer)) ;; pop-to-buffer-same-window might decide to display ;; the same buffer in another window (not switch-to-buffer-obey-display-actions))) ((and (window-minibuffer-p) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (not switch-to-buffer-obey-display-actions)) (if force-same-window (user-error "Cannot switch buffers in minibuffer window") (pop-to-buffer buffer norecord))) returns non-nil, although we were supposed to be out of the minibuffer by that time. I've verified that selected-window returns the original non-minibuffer window in the first place and the minibuffer window in the second. I then ran the recipe under GDB, with a watchpoint on selected_window, and clearly saw that it stays at its mini-window value by the time we exit read-buffer-to-switch. > And if it happens with `read-buffer-to-switch` I can't see any reason > why it wouldn't happen for most/all other uses of the minibuffer. It probably does, yes.