Simplify doom/window-enlargen & doom/window-maximize-buffer

+ No longer toggle window conf on consecutive presses. It's redundant
  with winner-undo and only adds a degree of uncertainty to the command.
+ `doom/window-maximize-buffer` now works with popup windows (before
  it'd spout an unhelp error about running +popup/raise).
This commit is contained in:
Henrik Lissner 2021-01-28 18:36:15 -05:00
parent 334e054ab0
commit 56e9d273e1

View file

@ -127,65 +127,32 @@ Activate again to undo this. If prefix ARG is non-nil, don't restore the last
window configuration and re-maximize the current window. Alternatively, use window configuration and re-maximize the current window. Alternatively, use
`doom/window-enlargen'." `doom/window-enlargen'."
(interactive "P") (interactive "P")
(let ((param 'doom--maximize-last-wconf)) (when (and (bound-and-true-p +popup-mode)
(cl-destructuring-bind (window . wconf) (+popup-window-p))
(or (frame-parameter nil param) (+popup/raise (selected-window)))
(cons nil nil)) (delete-other-windows))
(set-frame-parameter
nil param
(if (and (equal window (selected-window))
(not arg)
(null (cdr (cl-remove-if #'window-dedicated-p (window-list))))
wconf)
(ignore
(let ((source-window (selected-window)))
(set-window-configuration wconf)
(when (window-live-p source-window)
(select-window source-window))))
(when (and (bound-and-true-p +popup-mode)
(+popup-window-p))
(user-error "Cannot maximize a popup, use `+popup/raise' first or use `doom/window-enlargen' instead"))
(prog1 (cons (selected-window) (or wconf (current-window-configuration)))
(delete-other-windows)
(add-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h)))))))
;;;###autoload ;;;###autoload
(defun doom/window-enlargen (&optional arg) (defun doom/window-enlargen (&optional arg)
"Enlargen the current window to focus on this one. Does not close other "Enlargen the current window to focus on this one. Does not close other
windows (unlike `doom/window-maximize-buffer'). Activate again to undo." windows (unlike `doom/window-maximize-buffer'). Activate again to undo."
(interactive "P") (interactive "P")
(let ((param 'doom--enlargen-last-wconf)) (let* ((window (selected-window))
(cl-destructuring-bind (window . wconf) (dedicated-p (window-dedicated-p window))
(or (frame-parameter nil param) (preserved-p (window-parameter window 'window-preserved-size))
(cons nil nil)) (ignore-window-parameters t)
(set-frame-parameter (window-resize-pixelwise nil)
nil param (frame-resize-pixelwise nil))
(if (and (equal window (selected-window)) (unwind-protect
(not arg) (progn
wconf) (when dedicated-p
(ignore (set-window-dedicated-p window nil))
(let ((source-window (selected-window))) (when preserved-p
(set-window-configuration wconf) (set-window-parameter window 'window-preserved-size nil))
(when (window-live-p source-window) (maximize-window window))
(select-window source-window)))) (set-window-dedicated-p window dedicated-p)
(prog1 (cons (selected-window) (or wconf (current-window-configuration))) (when preserved-p
(let* ((window (selected-window)) (set-window-parameter window 'window-preserved-size preserved-p)))))
(dedicated-p (window-dedicated-p window))
(preserved-p (window-parameter window 'window-preserved-size))
(ignore-window-parameters t)
(window-resize-pixelwise nil)
(frame-resize-pixelwise nil))
(unwind-protect
(progn
(when dedicated-p
(set-window-dedicated-p window nil))
(when preserved-p
(set-window-parameter window 'window-preserved-size nil))
(maximize-window window))
(set-window-dedicated-p window dedicated-p)
(when preserved-p
(set-window-parameter window 'window-preserved-size preserved-p))
(add-hook 'doom-switch-window-hook #'doom--enlargened-forget-last-wconf-h)))))))))
;;;###autoload ;;;###autoload
(defun doom/window-maximize-horizontally () (defun doom/window-maximize-horizontally ()