Skip to content

Commit

Permalink
Merge pull request magnars#1 from ffevotte/rotate-windows
Browse files Browse the repository at this point in the history
Make `rotate-windows` aware of dedicated windows.
  • Loading branch information
magnars authored Sep 8, 2018
2 parents 434974b + 259ffe4 commit fccd6ac
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions defuns/buffer-defuns.el
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,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.
Expand Down

0 comments on commit fccd6ac

Please sign in to comment.