From aaa987040c38bb5818b41199d9c60e6dbf591ee5 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 24 Jun 2024 16:53:45 +0200 Subject: [PATCH] windmove.el: Remove bespoke key binding machinery --- doc/emacs/windows.texi | 16 --- lisp/windmove.el | 221 ----------------------------------------- 2 files changed, 237 deletions(-) diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi index 5ad6850fed9..bdf2fe9aa0d 100644 --- a/doc/emacs/windows.texi +++ b/doc/emacs/windows.texi @@ -618,26 +618,10 @@ buffer. @xref{Follow Mode}. @cindex Windmove package @cindex directional window selection @findex windmove-right -@findex windmove-default-keybindings -@findex windmove-display-default-keybindings -@findex windmove-delete-default-keybindings -@findex windmove-swap-states-default-keybindings The Windmove package defines commands for moving directionally between neighboring windows in a frame. @kbd{M-x windmove-right} selects the window immediately to the right of the currently selected one, and similarly for the left, up, and down counterparts. -@code{windmove-default-keybindings} binds these commands to -@kbd{S-right} etc.; doing so disables shift selection for those keys -(@pxref{Shift Selection}). In the same way as key bindings can be -defined for commands that select windows directionally, you can use -@code{windmove-display-default-keybindings} to define keybindings for -commands that specify in what direction to display the window for the -buffer that the next command is going to display. Also there is -@code{windmove-delete-default-keybindings} to define keybindings for -commands that delete windows directionally, and -@code{windmove-swap-states-default-keybindings} that defines -key bindings for commands that swap the window contents of the selected -window with the window in the specified direction. The command @kbd{M-x compare-windows} lets you compare the text shown in different windows. @xref{Comparing Files}. diff --git a/lisp/windmove.el b/lisp/windmove.el index b4e77102abd..633a121a21c 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el @@ -84,25 +84,6 @@ ;; windmove-up will move to the minibuffer if it is active, or to ;; either B or C depending on the prefix argument. ;; -;; -;; A set of default keybindings is supplied: shift-{left,up,right,down} -;; invoke the corresponding Windmove function. See the installation -;; section if you wish to use these keybindings. - - -;; Installation: -;; -;; Put the following line in your init file: -;; -;; (windmove-default-keybindings) ; shifted arrow keys -;; -;; or -;; -;; (windmove-default-keybindings 'hyper) ; etc. -;; -;; to use another modifier key. -;; -;; ;; If you wish to enable wrap-around, also add a line like: ;; ;; (setq windmove-wrap-around t) @@ -436,62 +417,6 @@ unless `windmove-create-window' is non-nil and a new window is created." (interactive "P") (windmove-do-window-select 'down (and arg (prefix-numeric-value arg)))) - -;;; set up keybindings -;; Idea for this function is from iswitchb.el, by Stephen Eglen -;; (stephen@cns.ed.ac.uk). -;; I don't think these bindings will work on non-X terminals; you -;; probably want to use different bindings in that case. - -(defvar-keymap windmove-mode-map - :doc "Map used by `windmove-install-defaults'.") - -;;;###autoload -(define-minor-mode windmove-mode - "Global minor mode for default windmove commands." - :keymap windmove-mode-map - :init-value t - :global t) - -(defun windmove-install-defaults (prefix modifiers alist &optional uninstall) - "Install keys as specified by ALIST. -Every element of ALIST has the form (FN KEY), where KEY is -appended to MODIFIERS, adding PREFIX to the beginning, before -installing the key. Previous bindings of FN are unbound. -If UNINSTALL is non-nil, just remove the keys from ALIST." - (dolist (bind alist) - (dolist (old (where-is-internal (car bind) windmove-mode-map)) - (define-key windmove-mode-map old nil)) - (unless uninstall - (let ((key (vconcat (if (or (equal prefix [ignore]) - (eq prefix 'none)) - nil prefix) - (list (append modifiers (cdr bind)))))) - (when (eq (key-binding key) #'self-insert-command) - (warn "Command %S is shadowing self-insert-key" (car bind))) - (let ((old-fn (lookup-key windmove-mode-map key))) - (when (functionp old-fn) - (warn "Overriding %S with %S" old-fn (car bind)))) - (define-key windmove-mode-map key (car bind)))))) - -;;;###autoload -(defun windmove-default-keybindings (&optional modifiers) - "Set up keybindings for `windmove'. -Keybindings are of the form MODIFIERS-{left,right,up,down}, -where MODIFIERS is either a list of modifiers or a single modifier. -If MODIFIERS is `none', the keybindings will be directly bound to -the arrow keys. -Default value of MODIFIERS is `shift'." - (interactive) - (unless modifiers (setq modifiers 'shift)) - (when (eq modifiers 'none) (setq modifiers nil)) - (setq modifiers (ensure-list modifiers)) - (windmove-install-defaults nil modifiers - '((windmove-left left) - (windmove-right right) - (windmove-up up) - (windmove-down down)))) - ;;; Directional window display and selection @@ -614,28 +539,6 @@ in `windmove-display-in-direction'." (interactive "P") (windmove-display-in-direction 'new-tab arg)) -;;;###autoload -(defun windmove-display-default-keybindings (&optional modifiers) - "Set up keybindings for directional buffer display. -Keys are bound to commands that display the next buffer in the specified -direction. Keybindings are of the form MODIFIERS-{left,right,up,down}, -where MODIFIERS is either a list of modifiers or a single modifier. -If MODIFIERS is `none', the keybindings will be directly bound to -the arrow keys. -Default value of MODIFIERS is `shift-meta'." - (interactive) - (unless modifiers (setq modifiers '(shift meta))) - (when (eq modifiers 'none) (setq modifiers nil)) - (setq modifiers (ensure-list modifiers)) - (windmove-install-defaults nil modifiers - '((windmove-display-left left) - (windmove-display-right right) - (windmove-display-up up) - (windmove-display-down down) - (windmove-display-same-window ?0) - (windmove-display-new-frame ?f) - (windmove-display-new-tab ?t)))) - ;;; Directional window deletion @@ -690,29 +593,6 @@ select the window that was below the current one." (interactive "P") (windmove-delete-in-direction 'down arg)) -;;;###autoload -(defun windmove-delete-default-keybindings (&optional prefix modifiers) - "Set up keybindings for directional window deletion. -Keys are bound to commands that delete windows in the specified -direction. Keybindings are of the form PREFIX MODIFIERS-{left,right,up,down}, -where PREFIX is a prefix key and MODIFIERS is either a list of modifiers or -a single modifier. -If PREFIX is `none', no prefix is used. If MODIFIERS is `none', -the keybindings are directly bound to the arrow keys. -Default value of PREFIX is \\`C-x' and MODIFIERS is `shift'." - (interactive) - (unless prefix (setq prefix '(?\C-x))) - (when (eq prefix 'none) (setq prefix nil)) - (setq prefix (ensure-list prefix)) - (unless modifiers (setq modifiers '(shift))) - (when (eq modifiers 'none) (setq modifiers nil)) - (setq modifiers (ensure-list modifiers)) - (windmove-install-defaults prefix modifiers - '((windmove-delete-left left) - (windmove-delete-right right) - (windmove-delete-up up) - (windmove-delete-down down)))) - ;;; Directional window swap states @@ -753,107 +633,6 @@ from the opposite side of the frame." (interactive) (windmove-swap-states-in-direction 'right)) -;;;###autoload -(defun windmove-swap-states-default-keybindings (&optional modifiers) - "Set up keybindings for directional window swap states. -Keys are bound to commands that swap the states of the selected window -with the window in the specified direction. Keybindings are of the form -MODIFIERS-{left,right,up,down}, where MODIFIERS is either a list of modifiers -or a single modifier. -If MODIFIERS is `none', the keybindings will be directly bound to the -arrow keys. -Default value of MODIFIERS is `shift-super'." - (interactive) - (unless modifiers (setq modifiers '(shift super))) - (when (eq modifiers 'none) (setq modifiers nil)) - (setq modifiers (ensure-list modifiers)) - (windmove-install-defaults nil modifiers - '((windmove-swap-states-left left) - (windmove-swap-states-right right) - (windmove-swap-states-up up) - (windmove-swap-states-down down)))) - - - -(defconst windmove--default-keybindings-type - `(choice (const :tag "Don't bind" nil) - (cons :tag "Bind using" - (choice (key-sequence :tag "Prefix") - (const :tag "No Prefix" nil)) - (set :tag "Modifier" - :greedy t - ;; See `(elisp) Keyboard Events' - (const :tag "Meta" meta) - (const :tag "Control" control) - (const :tag "Shift" shift) - (const :tag "Hyper" hyper) - (const :tag "Super" super) - (const :tag "Alt" alt)))) - "Customization type for windmove modifiers.") - -(defcustom windmove-default-keybindings nil - "Default keybindings for regular windmove commands. -See `windmove-default-keybindings' for more detail." - :set (lambda (sym val) - (windmove-install-defaults - (car val) (cdr val) - '((windmove-left left) - (windmove-right right) - (windmove-up up) - (windmove-down down)) - (null val)) - (set-default sym val)) - :type windmove--default-keybindings-type - :version "28.1") - -(defcustom windmove-display-default-keybindings nil - "Default keybindings for windmove directional buffer display commands. -See `windmove-display-default-keybindings' for more detail." - :set (lambda (sym val) - (windmove-install-defaults - (car val) (cdr val) - '((windmove-display-left left) - (windmove-display-right right) - (windmove-display-up up) - (windmove-display-down down) - (windmove-display-same-window ?0) - (windmove-display-new-frame ?f) - (windmove-display-new-tab ?t)) - (null val)) - (set-default sym val)) - :type windmove--default-keybindings-type - :version "28.1") - -(defcustom windmove-delete-default-keybindings nil - "Default keybindings for windmove directional window deletion commands. -See `windmove-delete-default-keybindings' for more detail." - :set (lambda (sym val) - (windmove-install-defaults - (car val) (cdr val) - '((windmove-delete-left left) - (windmove-delete-right right) - (windmove-delete-up up) - (windmove-delete-down down)) - (null val)) - (set-default sym val)) - :type windmove--default-keybindings-type - :version "28.1") - -(defcustom windmove-swap-states-default-keybindings nil - "Default keybindings for windmove's directional window swap-state commands. -See `windmove-swap-states-default-keybindings' for more detail." - :set (lambda (sym val) - (windmove-install-defaults - (car val) (cdr val) - '((windmove-swap-states-left left) - (windmove-swap-states-right right) - (windmove-swap-states-up up) - (windmove-swap-states-down down)) - (null val)) - (set-default sym val)) - :type windmove--default-keybindings-type - :version "28.1") - (provide 'windmove) -- 2.39.2