aboutsummaryrefslogtreecommitdiff
path: root/evil-commands.el
diff options
context:
space:
mode:
authorAxel Forsman <axelsfor@gmail.com>2023-01-09 17:18:36 +0100
committerAxel Forsman <axelsfor@gmail.com>2023-01-09 17:39:08 +0100
commita5ab49a49068b419f92de39ec046aa49aa80d3f1 (patch)
tree2738019005701ce9e6b06b723b84449fb416afae /evil-commands.el
parent67115c894f4be23bec843cacf0622500bb1b38e1 (diff)
Swap window sizes when exchanging windows
Use the function window-swap-states added in GNU Emacs 26.1 when available. Also leave the correct window selected, i.e. not the window that was originally selected. Closes #338
Diffstat (limited to 'evil-commands.el')
-rw-r--r--evil-commands.el24
1 files changed, 10 insertions, 14 deletions
diff --git a/evil-commands.el b/evil-commands.el
index 50288de..d6558b9 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -4599,22 +4599,18 @@ If ARG is empty, maximize the current window height."
(select-window (car (window-list))))))
(evil-define-command evil-window-exchange (count)
- "Without COUNT: exchange current window with next one.
-With COUNT: Exchange current window with COUNTth window."
+ "Exchange the current window with the next, or the COUNT-th, one."
:repeat nil
(interactive "<c>")
- (let ((this-buffer (window-buffer))
- other-buffer other-window)
- (if (not count)
- (setq other-buffer (window-buffer (next-window))
- other-window (next-window))
- (save-window-excursion
- (evil-window-next count)
- (setq other-buffer (window-buffer)
- other-window (selected-window))))
- (switch-to-buffer other-buffer nil t)
- (select-window other-window)
- (switch-to-buffer this-buffer nil t)))
+ (let ((original-window (selected-window)))
+ (evil-window-next count)
+ (if (fboundp 'window-swap-states)
+ (window-swap-states nil original-window t)
+ (let* ((other-window (selected-window))
+ (original-state (window-state-get original-window))
+ (other-state (window-state-get other-window)))
+ (window-state-put other-state original-window t)
+ (window-state-put original-state other-window t)))))
(evil-define-command evil-window-move-very-top ()
"Close the current window, split the upper-left one horizontally