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 | |
| 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.
| -rw-r--r-- | etc/NEWS | 12 | ||||
| -rw-r--r-- | lisp/windmove.el | 67 |
2 files changed, 77 insertions, 2 deletions
| @@ -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 | ||
| 308 | the edge of the frame. | ||
| 309 | |||
| 307 | *** Windmove supports directional window display and selection. | 310 | *** Windmove supports directional window display and selection. |
| 308 | The new command 'windmove-display-default-keybindings' binds default | 311 | The new command 'windmove-display-default-keybindings' binds default |
| 309 | keys with provided modifiers (by default, Shift-Meta) to the commands | 312 | keys 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 | |||
| 316 | display the buffer in the same window, for example, 'S-M-0 C-h e' | 319 | display the buffer in the same window, for example, 'S-M-0 C-h e' |
| 317 | displays the *Messages* buffer in the same window. | 320 | displays 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. |
| 320 | the edge of the frame. | 323 | The new command 'windmove-delete-default-keybindings' binds default |
| 324 | keys with provided prefix (by default, C-x) and modifiers (by default, | ||
| 325 | Shift) to the commands that delete the window in the specified | ||
| 326 | direction. For example, 'C-x S-down' deletes the window below. | ||
| 327 | With a prefix arg 'C-u', deletes the selected window and selects | ||
| 328 | the window that was in the specified direction. | ||
| 321 | 329 | ||
| 322 | ** Octave mode | 330 | ** Octave mode |
| 323 | The mode is automatically enabled in files that start with the | 331 | The 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. | ||
| 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 |