From: Juri Linkov <juri@linkov.net>
To: 47300@debbugs.gnu.org
Subject: bug#47300: delete-window to select window with same position
Date: Sun, 21 Mar 2021 22:31:27 +0200 [thread overview]
Message-ID: <87a6qw43gg.fsf@mail.linkov.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]
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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: delete-window-keep-pos.patch --]
[-- Type: text/x-diff, Size: 1635 bytes --]
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))))
next reply other threads:[~2021-03-21 20:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-21 20:31 Juri Linkov [this message]
2021-05-18 14:49 ` bug#47300: delete-window to select window with same position Lars Ingebrigtsen
2021-05-18 16:00 ` martin rudalics
2021-05-18 20:17 ` Juri Linkov
2021-05-19 7:42 ` martin rudalics
2021-05-19 16:07 ` Juri Linkov
2021-05-19 17:41 ` martin rudalics
2021-05-22 8:05 ` martin rudalics
2021-05-22 21:25 ` Juri Linkov
2021-05-23 8:43 ` martin rudalics
2021-05-25 6:50 ` martin rudalics
2021-05-26 21:29 ` Juri Linkov
2021-05-27 15:20 ` martin rudalics
2021-05-31 20:46 ` Juri Linkov
2021-06-02 9:08 ` martin rudalics
2021-06-03 21:20 ` Juri Linkov
2021-06-04 9:19 ` martin rudalics
2021-06-04 16:29 ` Juri Linkov
2021-06-06 7:43 ` martin rudalics
2021-06-06 20:47 ` Juri Linkov
2021-06-07 7:35 ` martin rudalics
2021-06-07 21:00 ` Juri Linkov
2021-06-10 7:44 ` martin rudalics
2021-06-11 17:06 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a6qw43gg.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=47300@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).