From cd31c3cb423baaaa9f7f3fa9eab274c09f2db1e9 Mon Sep 17 00:00:00 2001 From: James Thomas Date: Mon, 16 Jun 2025 01:20:31 +0530 Subject: [PATCH] Add 'other-window-backward' for a default binding (bug#78803) This moves in the opposite direction to 'other-window' by default, and is consistent with its repeat map. * lisp/window.el (other-window-backward): New function bound to 'C-x O'. (ctl-x-map): Update definition. * doc/emacs/windows.texi (Other Window): Update docs. * etc/NEWS: Annouce the new command. --- doc/emacs/windows.texi | 5 ++++- etc/NEWS | 4 ++++ lisp/window.el | 14 ++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi index 9473f189c25..4f04dc542eb 100644 --- a/doc/emacs/windows.texi +++ b/doc/emacs/windows.texi @@ -158,6 +158,8 @@ this option is @code{nil}. @table @kbd @item C-x o Select another window (@code{other-window}). +@item C-x O +Select another window, backwards (@code{other-window-backward}). @item C-M-v Scroll the next window upward (@code{scroll-other-window}). @item C-M-S-v @@ -183,7 +185,8 @@ cycle in the opposite order. When the minibuffer is active, the minibuffer window is the last window in the cycle; you can switch from the minibuffer window to one of the other windows, and later switch back and finish supplying the minibuffer argument that is requested. -@xref{Minibuffer Edit}. +@xref{Minibuffer Edit}. @kbd{C-x O} is similar, but defaults to the +opposite order. @findex next-window-any-frame The @code{other-window} command will normally only switch to the next diff --git a/etc/NEWS b/etc/NEWS index 3b9e06f99d9..e12a9dcb127 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -333,6 +333,10 @@ helps to restore window buffers across Emacs sessions. You can use this in 'display-buffer-alist' to match buffers displayed during the execution of particular commands. +*** New command 'other-window-backward' ('C-x O'). +This moves in the opposite direction of 'other-window' and is for its +default keybinding consistent with 'repeat-mode'. + ** Frames +++ diff --git a/lisp/window.el b/lisp/window.el index 44cb682d6dd..512e85dc29a 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4073,6 +4073,14 @@ nil, which considers all windows on the selected frame." ;; Always return nil. nil)))) +(defun other-window-backward (count &optional all-frames interactive) + "Select another window in the reverse cyclic ordering of windows. +COUNT specifies the number of windows to skip, (by default) backward, +starting with the selected window, before making the selection. Like +`other-window', but moves in the opposite direction." + (interactive "p\ni\np") + (other-window (- (or count 1)) all-frames interactive)) + (defun other-window-prefix () "Display the buffer of the next command in a new window. The next buffer is the buffer displayed by the next command invoked @@ -11373,6 +11381,7 @@ found by the provided context." (define-key ctl-x-map "2" 'split-window-below) (define-key ctl-x-map "3" 'split-window-right) (define-key ctl-x-map "o" 'other-window) +(define-key ctl-x-map "O" 'other-window-backward) (define-key ctl-x-map "^" 'enlarge-window) (define-key ctl-x-map "}" 'enlarge-window-horizontally) (define-key ctl-x-map "{" 'shrink-window-horizontally) @@ -11386,10 +11395,7 @@ found by the provided context." :doc "Keymap to repeat `other-window'. Used in `repeat-mode'." :repeat t "o" #'other-window - "O" (lambda () - (interactive) - (setq repeat-map 'other-window-repeat-map) - (other-window -1))) + "O" #'other-window-backward) (defvar-keymap resize-window-repeat-map :doc "Keymap to repeat window resizing commands.