aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2018-11-25 23:40:00 +0200
committerJuri Linkov2018-11-25 23:40:00 +0200
commitdf108bf927494909ad3df206814fe688cd332db5 (patch)
tree816639adf7b933bda4b85e23b25aa49449c8ede8
parent1b8c5961ea6816db9d1bd725c3815ed3dcbd3643 (diff)
downloademacs-df108bf927494909ad3df206814fe688cd332db5.tar.gz
emacs-df108bf927494909ad3df206814fe688cd332db5.zip
* lisp/windmove.el: Directional window deletion (bug#32790)
* lisp/windmove.el (windmove-delete-in-direction) (windmove-delete-left, windmove-delete-up) (windmove-delete-right, windmove-delete-down) (windmove-delete-default-keybindings): New functions.
-rw-r--r--etc/NEWS12
-rw-r--r--lisp/windmove.el67
2 files changed, 77 insertions, 2 deletions
diff --git a/etc/NEWS b/etc/NEWS
index eb3f314ccf4..1ddc565b8ba 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -304,6 +304,9 @@ back, customize 'follow-hide-ghost-cursors' to nil.
304 304
305** Windmove 305** Windmove
306 306
307*** 'windmove-create-window' when non-nil makes a new window on moving off
308the edge of the frame.
309
307*** Windmove supports directional window display and selection. 310*** Windmove supports directional window display and selection.
308The new command 'windmove-display-default-keybindings' binds default 311The new command 'windmove-display-default-keybindings' binds default
309keys with provided modifiers (by default, Shift-Meta) to the commands 312keys with provided modifiers (by default, Shift-Meta) to the commands
@@ -316,8 +319,13 @@ creating the window if necessary. A special key can be customized to
316display the buffer in the same window, for example, 'S-M-0 C-h e' 319display the buffer in the same window, for example, 'S-M-0 C-h e'
317displays the *Messages* buffer in the same window. 320displays the *Messages* buffer in the same window.
318 321
319*** 'windmove-create-window' when non-nil makes a new window on moving off 322*** Windmove also supports directional window deletion.
320the edge of the frame. 323The new command 'windmove-delete-default-keybindings' binds default
324keys with provided prefix (by default, C-x) and modifiers (by default,
325Shift) to the commands that delete the window in the specified
326direction. For example, 'C-x S-down' deletes the window below.
327With a prefix arg 'C-u', deletes the selected window and selects
328the window that was in the specified direction.
321 329
322** Octave mode 330** Octave mode
323The mode is automatically enabled in files that start with the 331The mode is automatically enabled in files that start with the
diff --git a/lisp/windmove.el b/lisp/windmove.el
index 898f87e2dbf..6d61806a831 100644
--- a/lisp/windmove.el
+++ b/lisp/windmove.el
@@ -678,6 +678,73 @@ Default value of MODIFIERS is `shift-meta'."
678 (global-set-key (vector (append modifiers '(down))) 'windmove-display-down) 678 (global-set-key (vector (append modifiers '(down))) 'windmove-display-down)
679 (global-set-key (vector (append modifiers '(?0))) 'windmove-display-same-window)) 679 (global-set-key (vector (append modifiers '(?0))) 'windmove-display-same-window))
680 680
681;;; Directional window deletion
682
683(defun windmove-delete-in-direction (dir &optional arg)
684 "Delete the window at direction DIR.
685If prefix ARG is `C-u', delete the selected window and
686select the window at direction DIR.
687When `windmove-wrap-around' is non-nil, takes the window
688from the opposite side of the frame."
689 (let ((other-window (window-in-direction dir nil nil arg
690 windmove-wrap-around t)))
691 (cond ((null other-window)
692 (user-error "No window %s from selected window" dir))
693 (t
694 (if (not (consp arg))
695 (delete-window other-window)
696 (delete-window (selected-window))
697 (select-window other-window))))))
698
699;;;###autoload
700(defun windmove-delete-left (&optional arg)
701 "Delete the window to the left of the current one.
702If prefix ARG is `C-u', delete the selected window and
703select the window that was to the left of the current one."
704 (interactive "P")
705 (windmove-delete-in-direction 'left arg))
706
707;;;###autoload
708(defun windmove-delete-up (&optional arg)
709 "Delete the window above the current one.
710If prefix ARG is `C-u', delete the selected window and
711select the window that was above the current one."
712 (interactive "P")
713 (windmove-delete-in-direction 'up arg))
714
715;;;###autoload
716(defun windmove-delete-right (&optional arg)
717 "Delete the window to the right of the current one.
718If prefix ARG is `C-u', delete the selected window and
719select the window that was to the right of the current one."
720 (interactive "P")
721 (windmove-delete-in-direction 'right arg))
722
723;;;###autoload
724(defun windmove-delete-down (&optional arg)
725 "Delete the window below the current one.
726If prefix ARG is `C-u', delete the selected window and
727select the window that was below the current one."
728 (interactive "P")
729 (windmove-delete-in-direction 'down arg))
730
731;;;###autoload
732(defun windmove-delete-default-keybindings (&optional prefix modifiers)
733 "Set up keybindings for directional window deletion.
734Keys are bound to commands that delete windows in the specified
735direction. Keybindings are of the form PREFIX MODIFIERS-{left,right,up,down},
736where PREFIX is a prefix key and MODIFIERS is either a list of modifiers or
737a single modifier. Default value of PREFIX is `C-x' and MODIFIERS is `shift'."
738 (interactive)
739 (unless prefix (setq prefix '(?\C-x)))
740 (unless (listp prefix) (setq prefix (list prefix)))
741 (unless modifiers (setq modifiers '(shift)))
742 (unless (listp modifiers) (setq modifiers (list modifiers)))
743 (global-set-key (vector prefix (append modifiers '(left))) 'windmove-delete-left)
744 (global-set-key (vector prefix (append modifiers '(right))) 'windmove-delete-right)
745 (global-set-key (vector prefix (append modifiers '(up))) 'windmove-delete-up)
746 (global-set-key (vector prefix (append modifiers '(down))) 'windmove-delete-down))
747
681(provide 'windmove) 748(provide 'windmove)
682 749
683;;; windmove.el ends here 750;;; windmove.el ends here