Last active
May 18, 2017 01:34
-
-
Save caioaao/d5b02109493f9d234bcfdd56f576c63f to your computer and use it in GitHub Desktop.
StumpWM - Split frame in equal parts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun split-frame-eql-parts* (group dir amt) | |
(when (not (eq amt 1)) | |
(when-let ((new-frame (split-frame group dir (/ (- amt 1) amt)))) | |
(cons new-frame (split-frame-eql-parts* group dir (- amt 1)))))) | |
(defun split-frame-eql-parts (group dir amt) | |
"Splits frame in equal parts defined by amt." | |
(assert (> amt 1)) | |
(let ((f (tile-group-current-frame group)) | |
(new-frame-numbers (split-frame-eql-parts* group dir amt))) | |
(if (= (list-length new-frame-numbers) (- amt 1)) | |
(progn | |
(when (frame-window f) | |
(update-decoration (frame-window f))) | |
(show-frame-indicator group)) | |
(progn | |
(let ((head (frame-head group f))) | |
(setf (tile-group-frame-head group head) | |
(reduce (lambda (tree num) (remove-frame tree | |
(frame-by-number group num))) | |
new-frame-numbers | |
:initial-value (tile-group-frame-head group head)))) | |
(message "Cannot split. Maybe current frame is too small."))))) | |
(defcommand (hsplit2 tile-group) (&optional (amt "2")) (:string) | |
(split-frame-eql-parts (current-group) :row (read-from-string amt))) | |
(defcommand (vsplit2 tile-group) (&optional (amt "2")) (:string) | |
(split-frame-eql-parts (current-group) :column (read-from-string amt))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment