如何设置Emacs窗口的大小?
我正在尝试检测要在其上启动emacs的屏幕的大小,并相应地调整其大小和位置(在emacs中,这是emacs的框架)。我正在尝试设置.emacs,以便始终获得一个"合理大"的窗口,该窗口的左上角靠近屏幕的左上角。
我想这对一般情况来说是一个很大的要求,因此要缩小范围,我对Windows和(Debian)Linux上的GNU Emacs 22最感兴趣。
解决方案
(setq initial-frame-alist (append '((width . 263) (height . 112) (top . -5) (left . 5) (font . "4.System VIO")) initial-frame-alist)) (setq default-frame-alist (append '((width . 263) (height . 112) (top . -5) (left . 5) (font . "4.System VIO")) default-frame-alist))
摘自:http://www.gnu.org/software/emacs/windows/old/faq4.html
(setq default-frame-alist '((top . 200) (left . 400) (width . 80) (height . 40) (cursor-color . "white") (cursor-type . box) (foreground-color . "yellow") (background-color . "black") (font . "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1"))) (setq initial-frame-alist '((top . 10) (left . 30)))
第一个设置适用于所有emacs框架,包括第一个在我们启动时弹出的框架。第二设置将其他属性添加到第一帧。这是因为有时很高兴知道启动emacs的原始框架。
我发现在X-Window环境中执行此操作的最简单方法是通过X资源。我的.Xdefaults的相关部分如下所示:
Emacs.geometry: 80x70
我们应该可以使用+ 0 + 0位置坐标作为后缀,以将其强制显示在显示器的左上角。 (我之所以不这样做,是因为我偶尔会产生新的帧,如果它们出现在与前一帧完全相同的位置,则会使事情感到困惑)
根据手册,该技术也适用于MS Windows,将资源作为键/值对存储在注册表中。我从来没有测试过。与仅编辑文件相比,这可能很棒,可能带来更多的不便。
我的.emacs
中包含以下内容:
(if (window-system) (set-frame-height (selected-frame) 60))
我们可能还会查看函数set-frame-size,set-frame-position和set-frame-width。使用C-h f
(又称M-x describe-function
)来显示详细的文档。
我不确定在当前的窗口环境中是否可以计算框架的最大高度/宽度。
如果要根据分辨率更改大小,可以执行以下操作(根据特定需求调整首选的宽度和分辨率):
(defun set-frame-size-according-to-resolution () (interactive) (if window-system (progn ;; use 120 char wide window for largeish displays ;; and smaller 80 column windows for smaller displays ;; pick whatever numbers make sense for you (if (> (x-display-pixel-width) 1280) (add-to-list 'default-frame-alist (cons 'width 120)) (add-to-list 'default-frame-alist (cons 'width 80))) ;; for the height, subtract a couple hundred pixels ;; from the screen height (for panels, menubars and ;; whatnot), then divide by the height of a char to ;; get the height we want (add-to-list 'default-frame-alist (cons 'height (/ (- (x-display-pixel-height) 200) (frame-char-height))))))) (set-frame-size-according-to-resolution)
请注意,在较新的emacs版本中不建议使用window-system。合适的替代是(display-graphic-p)
。查看此问题的答案如何检测emacs是否处于终端模式?以获得更多背景信息。
我们也可以在启动emacs时使用-geometry参数:emacs -geometry 80x60 + 20 + 30
将为我们提供一个宽80个字符,高60行,左上角向右20像素,向下30像素的窗口背景的左上角。
在Windows上,我们可以使用以下功能使emacs框架最大化:
(defun w32-maximize-frame () "Maximize the current frame" (interactive) (w32-send-sys-command 61488))