├── .gitignore ├── image ├── rotate-window.gif ├── rotate-layout-2.gif └── rotate-layout-4.gif ├── README.md └── rotate.el /.gitignore: -------------------------------------------------------------------------------- 1 | *.elc -------------------------------------------------------------------------------- /image/rotate-window.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daichirata/emacs-rotate/HEAD/image/rotate-window.gif -------------------------------------------------------------------------------- /image/rotate-layout-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daichirata/emacs-rotate/HEAD/image/rotate-layout-2.gif -------------------------------------------------------------------------------- /image/rotate-layout-4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daichirata/emacs-rotate/HEAD/image/rotate-layout-4.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # emacs-rotate.el 2 | 3 | [![MELPA](https://melpa.org/packages/rotate-badge.svg)](https://melpa.org/#/rotate) 4 | 5 | ## What's it 6 | 7 | This package will help the operation for the multiple windows. 8 | 9 | Behavior has been prepared with reference to tmux. 10 | 11 | 12 | ## Basic Usage 13 | 14 | #### `rotate-window` 15 | 16 | Rotate the positions of the window. 17 | 18 | **rotate-window** 19 | 20 | ![emacs-rotate](image/rotate-window.gif) 21 | 22 | 23 | #### `rotate-layout` 24 | 25 | Move a window to the next layout and rearrange the window to fit. 26 | 27 | **rotate-layout** 2 windows 28 | 29 | ![emacs-rotate](image/rotate-layout-2.gif) 30 | 31 | **rotate-layout** 4 windows 32 | 33 | ![emacs-rotate](image/rotate-layout-4.gif) 34 | 35 | 36 | ## Customize Variables 37 | 38 | #### `rotate-functions` 39 | 40 | Default value is 41 | 42 | ``` 43 | '(rotate:even-horizontal 44 | rotate:even-vertical 45 | rotate:main-horizontal 46 | rotate:main-vertical 47 | rotate:tiled) 48 | ``` 49 | 50 | A number of preset layouts are available. These may be selected with the rotate-layout command or cycled with next-layout; once a layout is chosen, window within it may be moved and resized as normal. 51 | 52 | By replacing this value, you can circulate freely. 53 | 54 | 55 | ## Preset layouts 56 | 57 | The following layouts are supported: 58 | 59 | #### `rotate:even-horizontal` 60 | 61 | Spread out evenly from left to right across the window. 62 | 63 | #### `rotate:even-vertical` 64 | 65 | Spread evenly from top to bottom. 66 | 67 | #### `rotate:main-horizontal` 68 | 69 | A large (main) window is shown at the top of the window and the remaining windows are spread from left to right in the leftover space at the bottom. 70 | 71 | #### `rotate:main-vertical` 72 | 73 | Similar to main-horizontal but the large window is placed on the left and the others spread from top to bottom along the right. 74 | 75 | #### `rotate:tiled` 76 | 77 | Spread out as evenly as possible over the window in both rows and columns. 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /rotate.el: -------------------------------------------------------------------------------- 1 | ;;; rotate.el --- Rotate the layout of emacs 2 | 3 | ;; Copyright (C) 2013 daichirata 4 | 5 | ;; Author: daichi.hirata 6 | ;; Version: 0.1.0 7 | ;; Keywords: window, layout 8 | ;; URL: https://github.com/daichirata/emacs-rotate 9 | 10 | ;; This file is free software; you can redistribute it and/or modify 11 | ;; it under the terms of the GNU General Public License as published by 12 | ;; the Free Software Foundation; either version 2, or (at your option) 13 | ;; any later version. 14 | 15 | ;; This file is distributed in the hope that it will be useful, 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | ;; GNU General Public License for more details. 19 | 20 | ;; You should have received a copy of the GNU General Public License 21 | ;; along with GNU Emacs; see the file COPYING. If not, write to 22 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 | ;; Boston, MA 02110-1301, USA. 24 | 25 | ;;; Code: 26 | 27 | (require 'cl-seq) 28 | 29 | (eval-when-compile (require 'cl-lib)) 30 | 31 | (defvar rotate-count 0) 32 | 33 | (defvar rotate-functions 34 | '(rotate:even-horizontal 35 | rotate:even-vertical 36 | rotate:main-horizontal 37 | rotate:main-vertical 38 | rotate:tiled)) 39 | 40 | ;;;###autoload 41 | (defun rotate-layout () 42 | (interactive) 43 | (let* ((len (length rotate-functions)) 44 | (func (elt rotate-functions (% rotate-count len)))) 45 | (prog1 (message "%s" func) 46 | (call-interactively func) 47 | (if (>= rotate-count (- len 1)) 48 | (setq rotate-count 0) 49 | (cl-incf rotate-count))))) 50 | 51 | ;;;###autoload 52 | (defun rotate-window () 53 | (interactive) 54 | (let* ((bl (reverse (rotate:buffer-list))) 55 | (nbl (append (cdr bl) (list (car bl))))) 56 | (cl-loop for w in (rotate:window-list) 57 | for b in (reverse nbl) 58 | do (set-window-buffer w b)) 59 | (select-window (next-window)))) 60 | 61 | ;;;###autoload 62 | (defun rotate:even-horizontal () 63 | (interactive) 64 | (rotate:refresh-window #'rotate:horizontally-n)) 65 | 66 | ;;;###autoload 67 | (defun rotate:even-vertical () 68 | (interactive) 69 | (rotate:refresh-window #'rotate:vertically-n)) 70 | 71 | ;;;###autoload 72 | (defun rotate:main-horizontal () 73 | (interactive) 74 | (rotate:refresh-window #'rotate:main-horizontally-n)) 75 | 76 | ;;;###autoload 77 | (defun rotate:main-vertical () 78 | (interactive) 79 | (rotate:refresh-window #'rotate:main-vertically-n)) 80 | 81 | ;;;###autoload 82 | (defun rotate:tiled () 83 | (interactive) 84 | (rotate:refresh-window #'rotate:tiled-n)) 85 | 86 | (defun rotate:main-horizontally-n (num) 87 | (if (<= num 2) 88 | (split-window-horizontally 89 | (floor (* (window-width) (/ 2.0 3.0)))) 90 | (split-window-vertically) 91 | (other-window 1) 92 | (rotate:horizontally-n (- num 1)))) 93 | 94 | (defun rotate:main-vertically-n (num) 95 | (if (<= num 2) 96 | (split-window-vertically 97 | (floor (* (window-height) (/ 2.0 3.0)))) 98 | (split-window-horizontally) 99 | (other-window 1) 100 | (rotate:vertically-n (- num 1)))) 101 | 102 | (defun rotate:horizontally-n (num) 103 | (if (<= num 2) 104 | (split-window-horizontally) 105 | (split-window-horizontally 106 | (- (window-width) (/ (window-width) num))) 107 | (rotate:horizontally-n (- num 1)))) 108 | 109 | (defun rotate:vertically-n (num) 110 | (if (<= num 2) 111 | (split-window-vertically) 112 | (split-window-vertically 113 | (- (window-height) (/ (window-height) num))) 114 | (rotate:vertically-n (- num 1)))) 115 | 116 | (defun rotate:tiled-n (num) 117 | (cond 118 | ((<= num 2) 119 | (split-window-vertically)) 120 | ((<= num 6) 121 | (rotate:tiled-2column num)) 122 | (t 123 | (rotate:tiled-3column num)))) 124 | 125 | (defun rotate:tiled-2column (num) 126 | (rotate:vertically-n (/ (+ num 1) 2)) 127 | (dotimes (i (/ num 2)) 128 | (split-window-horizontally) 129 | (other-window 2))) 130 | 131 | (defun rotate:tiled-3column (num) 132 | (rotate:vertically-n (/ (+ num 2) 3)) 133 | (dotimes (i (/ (+ num 1) 3)) 134 | (rotate:horizontally-n 3) 135 | (other-window 3)) 136 | (when (= (% num 3) 2) 137 | (other-window -1) 138 | (delete-window))) 139 | 140 | (defun rotate:window-list () 141 | (window-list nil nil (minibuffer-window))) 142 | 143 | (defun rotate:buffer-list () 144 | (mapcar (lambda (w) (window-buffer w)) (rotate:window-list))) 145 | 146 | (defun rotate:refresh-window (proc) 147 | (when (not (one-window-p)) 148 | (let ((window-num (count-windows)) 149 | (buffer-list (rotate:buffer-list)) 150 | (current-pos (cl-position (selected-window) (rotate:window-list)))) 151 | (delete-other-windows) 152 | (funcall proc window-num) 153 | (cl-loop for w in (rotate:window-list) 154 | for b in buffer-list 155 | do (set-window-buffer w b)) 156 | (select-window (nth current-pos (rotate:window-list)))))) 157 | 158 | (provide 'rotate) 159 | --------------------------------------------------------------------------------