Last active
May 11, 2024 14:18
-
-
Save jdtsmith/75d76bee292357cbfe18d7eb4a25c9a9 to your computer and use it in GitHub Desktop.
maximize-window-vertically in emacs
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
;; Maximize a window vertically or horizontally within its frame | |
(defun maximize-window-in-direction (&optional horizontally) | |
"Maximize window. | |
Default vertically, unless HORIZONTALLY is non-nil." | |
(interactive) | |
(unless (seq-every-p | |
(apply-partially #'window-at-side-p nil) | |
(if horizontally '(left right) '(top bottom))) | |
(let* ((buf (window-buffer)) | |
(top-size (window-size (frame-root-window) (not horizontally))) | |
(size (min (/ top-size 2) (window-size nil (not horizontally)))) | |
(dir (if horizontally | |
(if (window-at-side-p nil 'top) 'above 'below) | |
(if (window-at-side-p nil 'right) 'right 'left)))) | |
(delete-window) | |
(set-window-buffer | |
(select-window (split-window (frame-root-window) (- size) dir)) | |
buf)))) | |
(bind-key "C-x 7 1" #'tear-off-window) ; into a new frame | |
(bind-key "C-x 7 2" #'maximize-window-in-direction) ; vertically | |
(bind-key "C-x 7 3" (lambda () (interactive (maximize-window-in-direction 'horizontal)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment