diff options
| author | Juri Linkov | 2018-11-25 23:40:00 +0200 |
|---|---|---|
| committer | Juri Linkov | 2018-11-25 23:40:00 +0200 |
| commit | df108bf927494909ad3df206814fe688cd332db5 (patch) | |
| tree | 816639adf7b933bda4b85e23b25aa49449c8ede8 /lisp | |
| parent | 1b8c5961ea6816db9d1bd725c3815ed3dcbd3643 (diff) | |
| download | emacs-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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/windmove.el | 67 |
1 files changed, 67 insertions, 0 deletions
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. | ||
| 685 | If prefix ARG is `C-u', delete the selected window and | ||
| 686 | select the window at direction DIR. | ||
| 687 | When `windmove-wrap-around' is non-nil, takes the window | ||
| 688 | from 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. | ||
| 702 | If prefix ARG is `C-u', delete the selected window and | ||
| 703 | select 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. | ||
| 710 | If prefix ARG is `C-u', delete the selected window and | ||
| 711 | select 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. | ||
| 718 | If prefix ARG is `C-u', delete the selected window and | ||
| 719 | select 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. | ||
| 726 | If prefix ARG is `C-u', delete the selected window and | ||
| 727 | select 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. | ||
| 734 | Keys are bound to commands that delete windows in the specified | ||
| 735 | direction. Keybindings are of the form PREFIX MODIFIERS-{left,right,up,down}, | ||
| 736 | where PREFIX is a prefix key and MODIFIERS is either a list of modifiers or | ||
| 737 | a 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 |