From dccb57747efe78c498951deefff0ddba2f28050d Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 20 Aug 2020 22:12:49 +0100 Subject: [PATCH] feat(windows): use new windmove-swap-* functions on Emacs 27 and later Fallback onto buffer-move package for Emacs versions prior to 27. --- core/siren-core-modules.el | 1 - modules/windows/siren-windmove.el | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/siren-core-modules.el b/core/siren-core-modules.el index 14b7036..3551cbf 100644 --- a/core/siren-core-modules.el +++ b/core/siren-core-modules.el @@ -107,7 +107,6 @@ (require 'siren-magit) ;; Window management -(require 'siren-buffer-move) (require 'siren-resize-window) (require 'siren-windmove) (require 'siren-zoom-window) diff --git a/modules/windows/siren-windmove.el b/modules/windows/siren-windmove.el index ef35ab8..88502ed 100644 --- a/modules/windows/siren-windmove.el +++ b/modules/windows/siren-windmove.el @@ -6,6 +6,9 @@ ;;; Code: +(when (version< emacs-version "27.0") + (require 'siren-buffer-move)) + (use-package windmove :straight (:type built-in) @@ -14,6 +17,10 @@ ("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) :custom (siren-windmove-tmux-fallback (if (getenv "TMUX") t nil)) @@ -41,7 +48,21 @@ (interactive) (if (and (not (ignore-errors (windmove-right))) siren-windmove-tmux-fallback) - (shell-command "tmux select-pane -R")))) + (shell-command "tmux select-pane -R"))) + (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