Skip to content

Instantly share code, notes, and snippets.

@caioaao
Last active May 18, 2017 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caioaao/d5b02109493f9d234bcfdd56f576c63f to your computer and use it in GitHub Desktop.
Save caioaao/d5b02109493f9d234bcfdd56f576c63f to your computer and use it in GitHub Desktop.
StumpWM - Split frame in equal parts.
(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