diff options
| author | Juri Linkov | 2019-02-27 23:12:00 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-02-27 23:12:00 +0200 |
| commit | 5962a7c341a163a7080aa0a69873a6c14e64151b (patch) | |
| tree | 664b92dc921858fd5671daf4e56878d01004b7b7 | |
| parent | 5644369008966ef7a69a2a36dd0c08c52d4bc720 (diff) | |
| download | emacs-5962a7c341a163a7080aa0a69873a6c14e64151b.tar.gz emacs-5962a7c341a163a7080aa0a69873a6c14e64151b.zip | |
Directional window swap states (bug#34656)
* lisp/windmove.el (windmove-swap-states-in-direction)
(windmove-swap-states-left, windmove-swap-states-up)
(windmove-swap-states-down, windmove-swap-states-right)
(windmove-swap-states-default-keybindings): New functions.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/windmove.el | 66 |
2 files changed, 65 insertions, 5 deletions
| @@ -397,6 +397,10 @@ With a prefix arg 'C-u', also kills the buffer in that window. | |||
| 397 | With 'M-0', deletes the selected window and selects the window | 397 | With 'M-0', deletes the selected window and selects the window |
| 398 | that was in the specified direction. | 398 | that was in the specified direction. |
| 399 | 399 | ||
| 400 | *** New command 'windmove-swap-states-in-direction' binds default keys | ||
| 401 | to the commands that swap the states of the selected window with the | ||
| 402 | window in the specified direction. | ||
| 403 | |||
| 400 | ** Octave mode | 404 | ** Octave mode |
| 401 | The mode is automatically enabled in files that start with the | 405 | The mode is automatically enabled in files that start with the |
| 402 | 'function' keyword. | 406 | 'function' keyword. |
diff --git a/lisp/windmove.el b/lisp/windmove.el index 65270d9bbe4..0853f7ec7f9 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el | |||
| @@ -168,8 +168,7 @@ placement bugs in old versions of Emacs." | |||
| 168 | :type 'number | 168 | :type 'number |
| 169 | :group 'windmove) | 169 | :group 'windmove) |
| 170 | 170 | ||
| 171 | 171 | ||
| 172 | |||
| 173 | ;; Implementation overview: | 172 | ;; Implementation overview: |
| 174 | ;; | 173 | ;; |
| 175 | ;; The conceptual framework behind this code is all fairly simple. We | 174 | ;; The conceptual framework behind this code is all fairly simple. We |
| @@ -468,6 +467,7 @@ movement is relative to." | |||
| 468 | windmove-window-distance-delta))) ; (x, y1+d-1) | 467 | windmove-window-distance-delta))) ; (x, y1+d-1) |
| 469 | (t (error "Invalid direction of movement: %s" dir))))) | 468 | (t (error "Invalid direction of movement: %s" dir))))) |
| 470 | 469 | ||
| 470 | |||
| 471 | ;; Rewritten on 2013-12-13 using `window-in-direction'. After the | 471 | ;; Rewritten on 2013-12-13 using `window-in-direction'. After the |
| 472 | ;; pixelwise change the old approach didn't work any more. martin | 472 | ;; pixelwise change the old approach didn't work any more. martin |
| 473 | (defun windmove-find-other-window (dir &optional arg window) | 473 | (defun windmove-find-other-window (dir &optional arg window) |
| @@ -497,9 +497,9 @@ in direction DIR instead." | |||
| 497 | (t | 497 | (t |
| 498 | (select-window other-window))))) | 498 | (select-window other-window))))) |
| 499 | 499 | ||
| 500 | 500 | ||
| 501 | ;;; end-user functions | 501 | ;;; End-user functions |
| 502 | ;; these are all simple interactive wrappers to | 502 | ;; These are all simple interactive wrappers to |
| 503 | ;; `windmove-do-window-select', meant to be bound to keys. | 503 | ;; `windmove-do-window-select', meant to be bound to keys. |
| 504 | 504 | ||
| 505 | ;;;###autoload | 505 | ;;;###autoload |
| @@ -571,6 +571,7 @@ Default value of MODIFIERS is `shift'." | |||
| 571 | (global-set-key (vector (append modifiers '(up))) 'windmove-up) | 571 | (global-set-key (vector (append modifiers '(up))) 'windmove-up) |
| 572 | (global-set-key (vector (append modifiers '(down))) 'windmove-down)) | 572 | (global-set-key (vector (append modifiers '(down))) 'windmove-down)) |
| 573 | 573 | ||
| 574 | |||
| 574 | ;;; Directional window display and selection | 575 | ;;; Directional window display and selection |
| 575 | 576 | ||
| 576 | (defcustom windmove-display-no-select nil | 577 | (defcustom windmove-display-no-select nil |
| @@ -680,6 +681,7 @@ Default value of MODIFIERS is `shift-meta'." | |||
| 680 | (global-set-key (vector (append modifiers '(down))) 'windmove-display-down) | 681 | (global-set-key (vector (append modifiers '(down))) 'windmove-display-down) |
| 681 | (global-set-key (vector (append modifiers '(?0))) 'windmove-display-same-window)) | 682 | (global-set-key (vector (append modifiers '(?0))) 'windmove-display-same-window)) |
| 682 | 683 | ||
| 684 | |||
| 683 | ;;; Directional window deletion | 685 | ;;; Directional window deletion |
| 684 | 686 | ||
| 685 | (defun windmove-delete-in-direction (dir &optional arg) | 687 | (defun windmove-delete-in-direction (dir &optional arg) |
| @@ -750,6 +752,60 @@ a single modifier. Default value of PREFIX is `C-x' and MODIFIERS is `shift'." | |||
| 750 | (global-set-key (vector prefix (append modifiers '(up))) 'windmove-delete-up) | 752 | (global-set-key (vector prefix (append modifiers '(up))) 'windmove-delete-up) |
| 751 | (global-set-key (vector prefix (append modifiers '(down))) 'windmove-delete-down)) | 753 | (global-set-key (vector prefix (append modifiers '(down))) 'windmove-delete-down)) |
| 752 | 754 | ||
| 755 | |||
| 756 | ;;; Directional window swap states | ||
| 757 | |||
| 758 | (defun windmove-swap-states-in-direction (dir) | ||
| 759 | "Swap the states of the selected window and the window at direction DIR. | ||
| 760 | When `windmove-wrap-around' is non-nil, takes the window | ||
| 761 | from the opposite side of the frame." | ||
| 762 | (let ((other-window (window-in-direction dir nil nil nil | ||
| 763 | windmove-wrap-around t))) | ||
| 764 | (cond ((or (null other-window) (window-minibuffer-p other-window)) | ||
| 765 | (user-error "No window %s from selected window" dir)) | ||
| 766 | (t | ||
| 767 | (window-swap-states nil other-window))))) | ||
| 768 | |||
| 769 | ;;;###autoload | ||
| 770 | (defun windmove-swap-states-left () | ||
| 771 | "Swap the states with the window on the left from the current one." | ||
| 772 | (interactive) | ||
| 773 | (windmove-swap-states-in-direction 'left)) | ||
| 774 | |||
| 775 | ;;;###autoload | ||
| 776 | (defun windmove-swap-states-up () | ||
| 777 | "Swap the states with the window above from the current one." | ||
| 778 | (interactive) | ||
| 779 | (windmove-swap-states-in-direction 'up)) | ||
| 780 | |||
| 781 | ;;;###autoload | ||
| 782 | (defun windmove-swap-states-down () | ||
| 783 | "Swap the states with the window below from the current one." | ||
| 784 | (interactive) | ||
| 785 | (windmove-swap-states-in-direction 'down)) | ||
| 786 | |||
| 787 | ;;;###autoload | ||
| 788 | (defun windmove-swap-states-right () | ||
| 789 | "Swap the states with the window on the right from the current one." | ||
| 790 | (interactive) | ||
| 791 | (windmove-swap-states-in-direction 'right)) | ||
| 792 | |||
| 793 | ;;;###autoload | ||
| 794 | (defun windmove-swap-states-default-keybindings (&optional modifiers) | ||
| 795 | "Set up keybindings for directional window swap states. | ||
| 796 | Keys are bound to commands that swap the states of the selected window | ||
| 797 | with the window in the specified direction. Keybindings are of the form | ||
| 798 | MODIFIERS-{left,right,up,down}, where MODIFIERS is either a list of modifiers | ||
| 799 | or a single modifier. Default value of MODIFIERS is `shift-super'." | ||
| 800 | (interactive) | ||
| 801 | (unless modifiers (setq modifiers '(shift super))) | ||
| 802 | (unless (listp modifiers) (setq modifiers (list modifiers))) | ||
| 803 | (global-set-key (vector (append modifiers '(left))) 'windmove-swap-states-left) | ||
| 804 | (global-set-key (vector (append modifiers '(right))) 'windmove-swap-states-right) | ||
| 805 | (global-set-key (vector (append modifiers '(up))) 'windmove-swap-states-up) | ||
| 806 | (global-set-key (vector (append modifiers '(down))) 'windmove-swap-states-down)) | ||
| 807 | |||
| 808 | |||
| 753 | (provide 'windmove) | 809 | (provide 'windmove) |
| 754 | 810 | ||
| 755 | ;;; windmove.el ends here | 811 | ;;; windmove.el ends here |