Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Created November 14, 2023 02:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdtsmith/75d76bee292357cbfe18d7eb4a25c9a9 to your computer and use it in GitHub Desktop.
Save jdtsmith/75d76bee292357cbfe18d7eb4a25c9a9 to your computer and use it in GitHub Desktop.
maximize-window-vertically in emacs
(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" (lambda () (interactive (maximize-window-in-direction 'horizontal))))
(bind-key "C-x 9" #'maximize-window-in-direction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment