At first, with functions like
(set-frame-height)
, (frame-pixel-height)
and (display-pixel-height)
, it seems like it should be trivial, but the problem is that Emacs measures its frame height and width in characters, whereas the pixel functions (obviously) work in pixels.The link comes in the from of
(frame-char-height)
and (frame-char-width)
, which give the height and width of an idividual character in pixels. Just evaluating the following expression should centre Emacs on your primary monitor:
(set-frame-height (selected-frame)
(floor (* 0.95 (/ (display-pixel-height)
(frame-char-height)))))
(set-frame-position (selected-frame)
(floor (/ (- (display-pixel-width) (frame-pixel-width))
2))
(floor (* 0.02 (display-pixel-height))))
If you like this (maybe after some tweaking), you can just stuff the instructions in your
.emacs
to get it every time.