From 259ffe48d12e1720cbf60782c26ef4d8ed2b3b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= Date: Tue, 8 Jan 2013 15:59:34 +0100 Subject: [PATCH] Make `rotate-windows` aware of dedicated windows. --- defuns/buffer-defuns.el | 52 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/defuns/buffer-defuns.el b/defuns/buffer-defuns.el index 51189148f..ed1c963cf 100644 --- a/defuns/buffer-defuns.el +++ b/defuns/buffer-defuns.el @@ -59,30 +59,34 @@ (select-window first-win) (if this-win-2nd (other-window 1)))))) -(defun rotate-windows () - "Rotate your windows" - (interactive) - (cond ((not (> (count-windows)1)) - (message "You can't rotate a single window!")) - (t - (setq i 1) - (setq numWindows (count-windows)) - (while (< i numWindows) - (let* ( - (w1 (elt (window-list) i)) - (w2 (elt (window-list) (+ (% i numWindows) 1))) - - (b1 (window-buffer w1)) - (b2 (window-buffer w2)) - - (s1 (window-start w1)) - (s2 (window-start w2)) - ) - (set-window-buffer w1 b2) - (set-window-buffer w2 b1) - (set-window-start w1 s2) - (set-window-start w2 s1) - (setq i (1+ i))))))) +(defun rotate-windows (count) + "Rotate your windows. +Dedicated windows are left untouched. Giving a negative prefix +argument makes the windows rotate backwards." + (interactive "p") + (let* ((non-dedicated-windows (remove-if 'window-dedicated-p (window-list))) + (num-windows (length non-dedicated-windows)) + (i 0) + (step (+ num-windows count))) + (cond ((not (> num-windows 1)) + (message "You can't rotate a single window!")) + (t + (dotimes (counter (- num-windows 1)) + (let* ((next-i (% (+ step i) num-windows)) + + (w1 (elt non-dedicated-windows i)) + (w2 (elt non-dedicated-windows next-i)) + + (b1 (window-buffer w1)) + (b2 (window-buffer w2)) + + (s1 (window-start w1)) + (s2 (window-start w2))) + (set-window-buffer w1 b2) + (set-window-buffer w2 b1) + (set-window-start w1 s2) + (set-window-start w2 s1) + (setq i next-i))))))) (defun ido-imenu () "Update the imenu index and then use ido to select a symbol to navigate to.