From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: pillule Newsgroups: gmane.emacs.bugs Subject: bug#48493: 28.0.50; quit-window doesn't work Date: Wed, 26 May 2021 16:10:15 +0000 Message-ID: <8735u94gt4.fsf@host.localdomain> References: <87h7j0wwkf.fsf@gmail.com> <87cztg41zy.fsf@host.localdomain> <878s434ls1.fsf@host.localdomain> <877djn3r3i.fsf@host.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39816"; mail-complaints-to="usenet@ciao.gmane.io" Cc: pillule , Sujith Manoharan , 48493@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 26 18:11:12 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 1llw7j-000AAv-4r for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 May 2021 18:11:11 +0200 Original-Received: from localhost ([::1]:42090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llw7i-0000n8-1x for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 May 2021 12:11:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llw7a-0000lV-Rb for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:11:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38229) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llw7a-0004AQ-Js for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:11:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1llw7a-0002f1-EP for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: pillule Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 May 2021 16:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48493 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 48493-submit@debbugs.gnu.org id=B48493.162204543010166 (code B ref 48493); Wed, 26 May 2021 16:11:02 +0000 Original-Received: (at 48493) by debbugs.gnu.org; 26 May 2021 16:10:30 +0000 Original-Received: from localhost ([127.0.0.1]:49775 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llw74-0002dt-30 for submit@debbugs.gnu.org; Wed, 26 May 2021 12:10:30 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]:42002) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llw71-0002df-RI for 48493@debbugs.gnu.org; Wed, 26 May 2021 12:10:28 -0400 Original-Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4FqwsB0cv6zDxX2; Wed, 26 May 2021 09:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1622045422; bh=Et77wjCIqcw11JKKXyK703c9kLs06GRgDgPLJxa2h/s=; h=References:From:To:Cc:Subject:In-reply-to:Date:From; b=RicC0tk0JLDHTGig211TkhwjjQupKAuzxWDFKVC18mCfah8UCvmeQvIAcosf8oPZJ SQoViEKkGdB+vY7KXaRSVt9XFyqYzkEUOfuxiwwMbX6FJb/MCE2ExGfGQTUYJPx+44 mNcQBRUKGQuzj0/whpMf8Medg7CQgjak2vxtTSnc= X-Riseup-User-ID: 426B03E65F47446D25E0971954A1335A7C685987744F624E646E6AE9D9C6D2D0 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Fqws72gWTz1y6h; Wed, 26 May 2021 09:10:18 -0700 (PDT) In-reply-to: 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:207301 Archived-At: --=-=-= Content-Type: text/plain martin rudalics writes: > The dedicated flag in a side window serves to prevent "normal" buffer > display to "avoid" that window. A side window may be reused for showing > another buffer only by `display-buffer-in-side-window'. This sense of > dedication is somewhat different from the normal sense where killing the > buffer always attempts to delete its dedicated windows (and maybe their > frames too) first. > > Hence it is perfectly valid to switch to the previous buffer here - any > such buffer was meant to be displayed in that side window. It would be, > however, invalid to switch to some buffer that was never shown in that > window here. Note in this context that we can always delete a side > window, a side window can never be alone on its frame. Yes. > Tell me whether this works with DOOM's `kill-buffer-hook'. I can test the changes against a version of DOOM, yes. For the draft below it seems to be ok, but keep in mind that their library bypass these parts window.el > If you feel that it's more natural to delete the window in the case at > hand, we can consider that too. Not at all. For me it is ok with switch-to-prev-buffer, if users want to delete the window and/or buffer explicitly, they have commands for that. In the case of DOOM it is implemented as a workaround against some bugs, it is explicated in : (+popup/quit-window) Documentation The regular quit-window sometimes kills the popup buffer and switches to a buffer that shouldn't be in a popup. We prevent that by remapping quit-window to this commmand. So here is the *draft* that pass the previous cases of this thread. `replace-buffer-in-windows' take care of killing buffers. I restore the dedication of side-window because : 1. it seems to me it is the right think to do, and it prevents 2. 2. I lost the trace when we kill a buffer and no previous-buffer is found but still an undesirable buffer replace the current, is it in the C part ? I can't inspect C... --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Better-handling-of-side-windows.patch Content-Description: better handling of side windows >From 8305210da9e2215a8b38cd5cf88cd4c6c856fa0b Mon Sep 17 00:00:00 2001 From: Trust me I am a doctor Date: Wed, 26 May 2021 15:40:39 +0200 Subject: [PATCH] Better handling of side-windows * lisp/window.el (switch-to-prev-buffer) : Return nil when prev-buffer unavailable (switch-to-next-buffer) : Return nil when next-buffer unavailable (replace-buffer-in-windows) : Does not systematically delete side-windows, instead try to `switch-to-prev-buffer' and delete the window only if prev-buffer was unavailable (quit-restore-window) : Add exceptions for side-windows, so it try to to `switch-to-prev-buffer' and delete the window only if prev-buffer was unavailable (bug#48493) --- lisp/window.el | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/lisp/window.el b/lisp/window.el index fd1c617d6b..33f4409fcf 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4559,11 +4559,11 @@ This function is called by `prev-buffer'." ;; Scan WINDOW's previous buffers first, skipping entries of next ;; buffers. (dolist (entry (window-prev-buffers window)) - (when (and (setq new-buffer (car entry)) + (when (and (not (eq (car entry) old-buffer)) + (setq new-buffer (car entry)) (or (buffer-live-p new-buffer) (not (setq killed-buffers (cons new-buffer killed-buffers)))) - (not (eq new-buffer old-buffer)) (or (null pred) (funcall pred new-buffer)) ;; When BURY-OR-KILL is nil, avoid switching to a ;; buffer in WINDOW's next buffers list. @@ -4726,11 +4726,11 @@ This function is called by `next-buffer'." ;; Scan WINDOW's reverted previous buffers last (must not use ;; nreverse here!) (dolist (entry (reverse (window-prev-buffers window))) - (when (and (setq new-buffer (car entry)) + (when (and (not (eq (car entry) old-buffer)) + (setq new-buffer (car entry)) (or (buffer-live-p new-buffer) (not (setq killed-buffers (cons new-buffer killed-buffers)))) - (not (eq new-buffer old-buffer)) (or (null pred) (funcall pred new-buffer))) (if (switch-to-prev-buffer-skip-p skip window new-buffer) (setq skipped (or skipped new-buffer)) @@ -4989,10 +4989,14 @@ all window-local buffer lists." (let ((buffer (window-normalize-buffer buffer-or-name))) (dolist (window (window-list-1 nil nil t)) (if (eq (window-buffer window) buffer) - (unless (window--delete window t t) - ;; Switch to another buffer in window. - (set-window-dedicated-p window nil) - (switch-to-prev-buffer window 'kill)) + (let ((dedicated-side (eq (window-dedicated-p window) 'side))) + ;; Try to delete the window, with the exception of side-windows + (when (or dedicated-side (not (window--delete window t t))) + ;; Switch to another buffer in window. + (set-window-dedicated-p window nil) + (if (switch-to-prev-buffer window 'kill) + (and dedicated-side (set-window-dedicated-p window 'side)) + (window--delete window nil 'kill)))) ;; Unrecord BUFFER in WINDOW. (unrecord-window-buffer window buffer))))) @@ -5040,6 +5044,7 @@ nil means to not handle the buffer in a particular way. This (dolist (buf (window-prev-buffers window)) (unless (eq (car buf) buffer) (throw 'prev-buffer (car buf)))))) + (dedicated (window-dedicated-p window)) quad entry) (cond ((and (not prev-buffer) @@ -5084,6 +5089,8 @@ nil means to not handle the buffer in a particular way. This ;; Restore WINDOW's previous buffer, start and point position. (set-window-buffer-start-and-point window (nth 0 quad) (nth 1 quad) (nth 2 quad)) + ;; Preserve the side-window dedication + (when (eq dedicated 'side) (set-window-dedicated-p window 'side)) ;; Deal with the buffer we just removed from WINDOW. (setq entry (and (eq bury-or-kill 'append) (assq buffer (window-prev-buffers window)))) @@ -5110,9 +5117,18 @@ nil means to not handle the buffer in a particular way. This (set-window-parameter window 'quit-restore nil) ;; Make sure that WINDOW is no more dedicated. (set-window-dedicated-p window nil) - (unless (switch-to-prev-buffer window bury-or-kill) - ;; Delete WINDOW if there is no previous buffer (Bug#48367). - (window--delete window nil (eq bury-or-kill 'kill))))) + (if (and prev-buffer (eq dedicated 'side)) + ;; If a previous buffer exists, try to switch to it and + ;; to preserve the side-window dedication. If that + ;; fails for whatever reason, try to delete the window. + (if (switch-to-prev-buffer window bury-or-kill) + (set-dedicated-window-p window 'side) + (window--delete window nil (eq bury-or-kill 'kill))) + ;; If no previous buffer exists, try to delete the window. If + ;; that fails for whatever reason, try to switch to some other + ;; buffer. + (unless (window--delete window nil (eq bury-or-kill 'kill)) + (switch-to-prev-buffer window bury-or-kill))))) ;; Deal with the buffer. (cond -- 2.20.1 --=-=-= Content-Type: text/plain I will pass the rest of they day to look at ERT to see if I can learn how to write reusable tests and see if this discussion needs to be reflected in the documentation. -- --=-=-=--