I can resize the emacs frame to whatever size by mouse, is there a way that the frame size be set in init.el by pixels? Or anything similar in the window manager?
2 Answers
I have a screen with resolution of 1024X600, but i set the display to 1024X724, here is my solution.
(setq frame-resize-pixelwise t)
(set-frame-position (selected-frame) 0 0)
(set-frame-size (selected-frame) 1024 600 t)
As of October 13, 2015, Feature request #21415 has been incorporated into the master branch (aka Emacs trunk), such that frame creation may now include a pixel specification -- this includes items such as the initial-frame-alist
, default-frame-alist
, and the make-frame
function. The git commit identification number is d4fe840df0b5fdb3aed538fae2ced143a471f60a. It is built-in to the public release of Emacs 25.
Example of usage for the width
parameter: '(width . (text-pixels . 1900))
Example of usage for the height
parameter: '(height . (text-pixels . 1054))
Here is an example using make-frame
-- the font I have chosen is available on OSX 10.6.8 (substitute your own favorite font in the example accordingly):
(defun my-example-make-frame ()
"Doc-string."
(interactive)
(make-frame '((name . "HELLO-WORLD")
(font . "-*-Courier-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1")
(top . 100)
(left . 100)
(left-fringe . 8)
(right-fringe . 8)
(vertical-scroll-bars . right)
(cursor-color . "yellow")
(cursor-type . (bar . 1))
(background-color . "black")
(foreground-color . "white")
(tool-bar-lines . 0)
(menu-bar-lines . 0)
(width . (text-pixels . 400))
(height . (text-pixels . 400)))))
default-frame-alist
can be used to come very close, but only pixelwise on OSX with the latest patch in bug number 21415: debbugs.gnu.org/cgi/bugreport.cgi?bug=21415 For exact sizes, adjusting after the fact is necessary withset-frame-size
using the optionalpixelwise
argument. I'll put in a request for Emacs on Microsoft Windows later on today. Most people usetoggle-frame-maximized
or other full-frame arguments inmake-frame
or thedefault-frame-alist
, but if the user wants a specific size that is not full-screen, thenset-frame-size
is the way to go if not OSXinitial-frame-alist
: gnu.org/software/emacs/manual/html_node/elisp/…