Center Window on the Current Monitor in Emacs, Simplified
Louis Brauer over on Xah Lee’s Discord helped simplify my Emacs window centering code (cf. original single monitor solution. It’s great, and only a handful of lines!
It’s compatible with Emacs 26.0.90 (reference commit or newer:
(defun my/frame-recenter (&optional frame)
"Center FRAME on the screen.
FRAME can be a frame name, a terminal name, or a frame.
If FRAME is omitted or nil, use currently selected frame."
(interactive)
(unless (eq 'maximised (frame-parameter nil 'fullscreen))
(modify-frame-parameters
frame '((user-position . t) (top . 0.5) (left . 0.5)))))
That is, uh, very simple in comparison to my old approach where I computed the center of the frame inside the monitor’s manually!
All credit goes to Luis for this.