mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
chore(windows): clean up and improve windmove setup
This commit is contained in:
@@ -6,64 +6,71 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
;; Emacs 26.x and earlier
|
||||
(when (version< emacs-version "27.0")
|
||||
(use-package windmove
|
||||
:straight (:type built-in)
|
||||
|
||||
:bind
|
||||
("M-i" . siren-windmove-up)
|
||||
("M-k" . siren-windmove-down)
|
||||
("M-j" . siren-windmove-left)
|
||||
("M-l" . siren-windmove-right))
|
||||
|
||||
(use-package buffer-move
|
||||
:defer t))
|
||||
:bind
|
||||
("M-K" . buf-move-down)
|
||||
("M-I" . buf-move-up)
|
||||
("M-J" . buf-move-left)
|
||||
("M-L" . buf-move-right)))
|
||||
|
||||
(use-package windmove
|
||||
:straight (:type built-in)
|
||||
;; Emacs 27.0 and later
|
||||
(when (not (version< emacs-version "27.0"))
|
||||
(use-package windmove
|
||||
:straight (:type built-in)
|
||||
|
||||
:bind
|
||||
("M-i" . siren-windmove-up)
|
||||
("M-k" . siren-windmove-down)
|
||||
("M-j" . siren-windmove-left)
|
||||
("M-l" . siren-windmove-right)
|
||||
("M-K" . siren-windmove-swap-down)
|
||||
("M-I" . siren-windmove-swap-up)
|
||||
("M-J" . siren-windmove-swap-left)
|
||||
("M-L" . siren-windmove-swap-right)
|
||||
:bind
|
||||
("M-i" . windmove-up)
|
||||
("M-k" . windmove-down)
|
||||
("M-j" . windmove-left)
|
||||
("M-l" . windmove-right)
|
||||
("M-K" . windmove-swap-states-down)
|
||||
("M-I" . windmove-swap-states-up)
|
||||
("M-J" . windmove-swap-states-left)
|
||||
("M-L" . windmove-swap-states-right)
|
||||
("C-x M-i" . windmove-delete-up)
|
||||
("C-x M-k" . windmove-delete-down)
|
||||
("C-x M-j" . windmove-delete-left)
|
||||
("C-x M-l" . windmove-delete-right)))
|
||||
|
||||
:custom
|
||||
(siren-windmove-tmux-fallback (if (getenv "TMUX") t nil))
|
||||
;; Tmux integration with windmove
|
||||
(when (and (getenv "TMUX")
|
||||
(executable-find "tmux"))
|
||||
(with-eval-after-load 'windmove
|
||||
(defun siren-windmove-tmux-left-advice (orig-fun &rest args)
|
||||
"Advice windmove-left to enable Tmux integration"
|
||||
(if (not (ignore-errors (apply orig-fun args)))
|
||||
(call-process "tmux" nil nil nil "select-pane" "-L")))
|
||||
|
||||
:init
|
||||
(defun siren-windmove-up ()
|
||||
(interactive)
|
||||
(if (and (not (ignore-errors (windmove-up)))
|
||||
siren-windmove-tmux-fallback)
|
||||
(shell-command "tmux select-pane -U")))
|
||||
(defun siren-windmove-tmux-right-advice (orig-fun &rest args)
|
||||
"Advice windmove-right to enable Tmux integration"
|
||||
(if (not (ignore-errors (apply orig-fun args)))
|
||||
(call-process "tmux" nil nil nil "select-pane" "-R")))
|
||||
|
||||
(defun siren-windmove-down ()
|
||||
(interactive)
|
||||
(if (and (not (ignore-errors (windmove-down)))
|
||||
siren-windmove-tmux-fallback)
|
||||
(shell-command "tmux select-pane -D")))
|
||||
(defun siren-windmove-tmux-up-advice (orig-fun &rest args)
|
||||
"Advice windmove-up to enable Tmux integration"
|
||||
(if (not (ignore-errors (apply orig-fun args)))
|
||||
(call-process "tmux" nil nil nil "select-pane" "-U")))
|
||||
|
||||
(defun siren-windmove-left ()
|
||||
(interactive)
|
||||
(if (and (not (ignore-errors (windmove-left)))
|
||||
siren-windmove-tmux-fallback)
|
||||
(shell-command "tmux select-pane -L")))
|
||||
(defun siren-windmove-tmux-down-advice (orig-fun &rest args)
|
||||
"Advice windmove-down to enable Tmux integration"
|
||||
(if (not (ignore-errors (apply orig-fun args)))
|
||||
(call-process "tmux" nil nil nil "select-pane" "-D")))
|
||||
|
||||
(defun siren-windmove-right ()
|
||||
(interactive)
|
||||
(if (and (not (ignore-errors (windmove-right)))
|
||||
siren-windmove-tmux-fallback)
|
||||
(shell-command "tmux select-pane -R")))
|
||||
(advice-add 'windmove-left :around 'siren-windmove-tmux-left-advice)
|
||||
(advice-add 'windmove-right :around 'siren-windmove-tmux-right-advice)
|
||||
(advice-add 'windmove-up :around 'siren-windmove-tmux-up-advice)
|
||||
(advice-add 'windmove-down :around 'siren-windmove-tmux-down-advice)))
|
||||
|
||||
(defun siren-windmove-swap-defun (direction)
|
||||
"Define window swap function for DIRECTION.
|
||||
On Emacs 27.0 or later use windmove, on earlier use buffer-move package."
|
||||
`(defun ,(intern (format "siren-windmove-swap-%s" direction)) ()
|
||||
(interactive)
|
||||
(,(intern (format (if (version< emacs-version "27.0")
|
||||
"buf-move-%s"
|
||||
"windmove-swap-states-%s")
|
||||
direction)))))
|
||||
|
||||
(defmacro siren-windmove-swap-defuns (directions)
|
||||
`(progn ,@(mapcar 'siren-windmove-swap-defun directions)))
|
||||
|
||||
(siren-windmove-swap-defuns (up down left right)))
|
||||
(provide 'siren-windmove)
|
||||
;;; siren-windmove.el ends here
|
||||
|
||||
Reference in New Issue
Block a user