EXWM: Swap windows like windmove

master
Pierre Neidhardt 2017-10-28 08:58:10 +01:00
parent 31bc38581b
commit b1c72b29c8
2 changed files with 39 additions and 11 deletions

View File

@ -352,13 +352,20 @@ The shell can use it to automatically change directory to it."
(when (executable-find term)
(start-process "dummy" nil "env" (concat "SHELL_CD=" (expand-file-name default-directory)) term))))
(defun swap-windows ()
"If 2 windows are up, swap them."
(defun swap-windows (&optional w1 w2)
"If 2 windows are up, swap them.
Else if W1 is a window, swap it with current window.
If W2 is a window too, swap both."
(interactive)
(unless (= 2 (count-windows))
(error "There are not 2 windows"))
(let* ((w1 (car (window-list)))
(w2 (nth 1 (window-list)))
(unless (or (= 2 (count-windows))
(windowp w1)
(windowp w2))
(error "Ambiguous window selection"))
(let* ((w1 (or w1 (car (window-list))))
(w2 (or w2
(if (eq w1 (car (window-list)))
(nth 1 (window-list))
(car (window-list)))))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
@ -367,9 +374,26 @@ The shell can use it to automatically change directory to it."
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1))
(other-window 1))
(select-window w1))
(global-set-key (kbd "C-x \\") 'swap-windows)
(defun swap-windows-left ()
"Swap current window with the window to the left."
(interactive)
(swap-windows (window-in-direction 'left)))
(defun swap-windows-below ()
"Swap current window with the window below."
(interactive)
(swap-windows (window-in-direction 'below)))
(defun swap-windows-above ()
"Swap current window with the window above."
(interactive)
(swap-windows (window-in-direction 'above)))
(defun swap-windows-right ()
"Swap current window with the window to the right."
(interactive)
(swap-windows (window-in-direction 'right)))
(defun switch-to-last-buffer ()
"Switch to last open buffer in current window."
(interactive)

View File

@ -51,9 +51,16 @@
(exwm-input-set-key (kbd "s-k") #'windmove-up)
(exwm-input-set-key (kbd "s-l") #'windmove-right)
(exwm-input-set-key (kbd "s-D") #'kill-this-buffer)
(exwm-input-set-key (kbd "s-|") #'swap-windows)
(exwm-input-set-key (kbd "s-b") #'list-buffers)
(exwm-input-set-key (kbd "s-f") #'find-file)
(when (require 'functions)
(exwm-input-set-key (kbd "s-\\") #'toggle-window-split)
(exwm-input-set-key (kbd "s-H") 'swap-windows-left)
(exwm-input-set-key (kbd "s-J") 'swap-windows-below)
(exwm-input-set-key (kbd "s-K") 'swap-windows-above)
(exwm-input-set-key (kbd "s-L") 'swap-windows-right))
;; The following can only apply to EXWM buffers, else it could have unexpected effects.
(push ?\s- exwm-input-prefix-keys)
(define-key exwm-mode-map (kbd "s-SPC") #'exwm-floating-toggle-floating)
@ -61,9 +68,6 @@
(exwm-input-set-key (kbd "s-o") #'toggle-single-window)
(exwm-input-set-key (kbd "s-O") #'exwm-layout-toggle-fullscreen)
(require 'functions)
(exwm-input-set-key (kbd "s-\\") #'toggle-window-split)
(with-eval-after-load 'helm
;; Need `with-eval-after-load' here since 'helm-map is not defined in 'helm-config.
(define-keys helm-map