Programmatically setting Emacs frame size

ぃ、小莉子 提交于 2019-11-28 16:43:14
Bill White

Here's what I use in my ~/.emacs:

(add-to-list 'default-frame-alist '(left . 0))
(add-to-list 'default-frame-alist '(top . 0))
(add-to-list 'default-frame-alist '(height . 50))
(add-to-list 'default-frame-alist '(width . 155))
(setq initial-frame-alist '(
            (top . 40) (left . 10)
            (width . 128) (height . 68)
            )
  )

Did you try this : emacs -geometry 110x58+200+2 &

Found at :

http://web.mit.edu/answers/emacs/emacs_window_size.64R.html

None of the solutions posted before could solve my resizing problem, so I thought I'd share an additional solution: upon start-up, Emacs 23 uses a certain font, before switching to the user-defined one; as a consequence, if this font is large, Emacs also reduces the window size so that it fits in the screen. Then, the user font is applied, and the window might appear smaller than what desired by the user. Thus, adding the following in my ~/.Xresource solved the problem:

Emacs.font: -*-fixed-*-*-*-*-8-*-*-*-*-*-*-*
Emacs.pane.menubar.*.fontList: 8x16
Emacs.menu*.fontList:         -*-fixed-*-*-*-*-8-*-*-*-*-*-*-*
Emacs.dialog*.fontList:        -*-fixed-*-*-*-*-8-*-*-*-*-*-*-*

This makes Emacs use a small font during start-up, so that its window is not too large and is not truncated. Of course, you might want to customize the font you want here, or in the Emacs init file.

Between Emacs 19 and 21, I used to have a perfectly working .emacs that did exactly what you are looking for, by distinguishing between default-frame and initial-frame:

  (setq default-frame-alist '((foreground-color . "LightGray")
                  (background-color . "Black")
                  (cursor-color . "Medium Sea Green")
                  (width . 80)
                  (height . 36)
                  (menu-bar-lines . 1)
                  (vertical-scroll-bars . right)))

and

  (setq initial-frame-alist
                (cons '(width . 96)
                      (cons '(height . 72)
                        (cons '(menu-bar-lines . 1)
                          initial-frame-alist))))

Alas, when I "upgraded" to Emacs 23.2 the above doesn't fully anymore. Emacs is not my career. I am using it as a tool, so I can't devote too much time delving into understanding why. So I simply worked around the problem by adding to the Emacs Windows XP shortcut "-geometry 96x72". So the shortcut target now looks:

C:\emacs-23.2\bin\runemacs.exe -geometry 96x72

For emacs on windows, I generally put it in the registry.

HKCU\Software\GNU\Emacs\
    Emacs.Geometry REG_SZ "245x74"

(This keeps machine-local settings out of my .emacs file, which I share with many other machines...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!