From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#47300: delete-window to select window with same position Date: Sun, 21 Mar 2021 22:31:27 +0200 Organization: LINKOV.NET Message-ID: <87a6qw43gg.fsf@mail.linkov.net> 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="25706"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 47300@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 21 22:17:07 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 1lO5Ra-0006XS-5T for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Mar 2021 22:17:06 +0100 Original-Received: from localhost ([::1]:55922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lO5RY-0007U1-WD for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Mar 2021 17:17:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO5Pb-0006Rs-4s for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:15:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44017) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lO5Pa-0007co-TF for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lO5Pa-0001qS-G2 for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Mar 2021 21:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47300 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16163612707036 (code B ref -1); Sun, 21 Mar 2021 21:15:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Mar 2021 21:14:30 +0000 Original-Received: from localhost ([127.0.0.1]:55563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lO5P4-0001pQ-7F for submit@debbugs.gnu.org; Sun, 21 Mar 2021 17:14:30 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54568) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lO5P2-0001pI-5e for submit@debbugs.gnu.org; Sun, 21 Mar 2021 17:14:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO5P1-000678-WE for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:14:28 -0400 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:48437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO5Oz-0007LC-J9 for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:14:27 -0400 Original-Received: from mail.gandi.net (m91-129-107-223.cust.tele2.ee [91.129.107.223]) (Authenticated sender: juri@linkov.net) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 4F073100003 for ; Sun, 21 Mar 2021 21:14:21 +0000 (UTC) Received-SPF: pass client-ip=217.70.178.231; envelope-from=juri@linkov.net; helo=relay11.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:202809 Archived-At: --=-=-= Content-Type: text/plain People still have trouble with unpredictable behavior of 'C-x 0' that selects an unexpected window after the current window is deleted. This is a recent example: https://old.reddit.com/r/emacs/comments/m8omt0/how_can_deletewindow_cx_0_be_configured_to_stay/ The previous failed attempt to fix this was in bug#32790. I still don't understand the current logic what window is selected after deleting the selected window with 'C-x 0'. But maybe this could be customizable? Tried to write an advice: (advice-add 'delete-window :around (lambda (orig-fun &optional window) (if window ;; Non-interactive call (funcall orig-fun window) ;; Interactive call (let* ((pos (window-absolute-pixel-position)) (x (when pos (/ (car pos) (frame-char-width)))) (y (when pos (/ (cdr pos) (frame-char-height))))) (funcall orig-fun window) ;; Select window that takes space from the deleted window (when (and x y) (select-window (window-at x y)))))) '((name . delete-window-keep-pos))) Maybe something like this could be adapted to delete-window by adding an optional interactive argument keep-pos: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=delete-window-keep-pos.patch diff --git a/lisp/window.el b/lisp/window.el index f27631bb86..e2029406c7 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4177,7 +4177,7 @@ window--before-delete-windows (push (list buf start-m pos-m) prev-buf) (set-window-prev-buffers win prev-buf))))))) -(defun delete-window (&optional window) +(defun delete-window (&optional window keep-pos) "Delete WINDOW. WINDOW must be a valid window and defaults to the selected one. Return nil. @@ -4194,13 +4194,16 @@ delete-window argument. Signal an error if WINDOW is either the only window on its frame, the last non-side window, or part of an atomic window that is its frame's root window." - (interactive) + (interactive (list nil t)) (when switch-to-buffer-preserve-window-point (window--before-delete-windows)) + (setq keep-pos (and keep-pos (not window) (window-absolute-pixel-position))) (setq window (window-normalize-window window)) (let* ((frame (window-frame window)) (function (window-parameter window 'delete-window)) (parent (window-parent window)) + (keep-pos-x (when keep-pos (/ (car keep-pos) (frame-char-width)))) + (keep-pos-y (when keep-pos (/ (cdr keep-pos) (frame-char-height)))) atom-root) (window--check frame) (catch 'done @@ -4259,6 +4262,8 @@ delete-window ;; `delete-window-internal' has selected a window that should ;; not be selected, fix this here. (other-window -1 frame)) + (when (and keep-pos-x keep-pos-y (window-at keep-pos-x keep-pos-y)) + (select-window (window-at keep-pos-x keep-pos-y))) (window--check frame) ;; Always return nil. nil)))) --=-=-=--