Skip to content

Instantly share code, notes, and snippets.

@paulbdavis
Last active February 6, 2020 01:15
Show Gist options
  • Save paulbdavis/9b83c0bba46ab91b96f48485b3257378 to your computer and use it in GitHub Desktop.
Save paulbdavis/9b83c0bba46ab91b96f48485b3257378 to your computer and use it in GitHub Desktop.
(defun ds/handle-new-window (window)
(let ((new-class (window-class window))
(current-class (window-class (current-window))))
(let* ((frames (group-frames (current-group)))
(isempty (= 1 (length (group-windows (current-group)))))
(fx (- (screen-width (current-screen)) 5))
(fy (- (screen-height (current-screen)) 30))
(dir (if (= (mod (length frames) 2) 0) :row :column)))
(focus-frame (current-group) (find-frame (current-group) fx fy))
;; (ds/split-frame-to-empty (current-group) dir 0.61803)))
(if (not isempty)
(let ((newframe (frame-by-number (current-group) (split-frame (current-group) dir 0.61803))))
(focus-frame (current-group) newframe)
(pull-window window newframe)
(if (ds/group-empty-frames (current-group))
(remove-split)))))
))
(defun ds/group-empty-frames (group)
(remove-if-not (lambda (f) (equal nil (frame-window f))) (group-frames group)))
(defun ds/handle-destroy-window (window)
(let ((new-class (window-class window)))
(if (< 1 (length (group-frames (current-group))))
(remove-split))))
(add-hook *new-window-hook* 'ds/handle-new-window)
(add-hook *destroy-window-hook* 'ds/handle-destroy-window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment