如何设置Emacs窗口的大小?

时间:2008-09-18 14:20:29

标签: emacs elisp

我正在尝试检测我正在启动emacs的屏幕大小,并相应地调整它开始的窗口的大小和位置(我猜这是emacs中的帧)。我正在尝试设置我的.emacs,以便我总是得到一个“相当大的”窗口,它的左上角靠近屏幕的左上角。

我想这是一个 big 请求一般情况,所以为了缩小范围,我对Windows和(Debian)Linux上的GNU Emacs 22最感兴趣。

10 个答案:

答案 0 :(得分:87)

如果您想根据分辨率更改尺寸,可以执行以下操作(根据您的具体需要调整首选宽度和分辨率):

(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)。有关更多背景信息,请参阅问题this answerHow to detect that emacs is in terminal-mode?

答案 1 :(得分:47)

我的.emacs中有以下内容:

(if (window-system)
  (set-frame-height (selected-frame) 60))

您还可以查看函数set-frame-sizeset-frame-positionset-frame-width。使用C-h f(又名M-x describe-function)来显示详细的文档。

我不确定是否有办法计算当前窗口环境中帧的最大高度/宽度。

答案 2 :(得分:21)

取自: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的原始帧。

答案 3 :(得分:16)

我发现在X-Window环境中这样做的最简单方法是X resources。我的.Xdefaults的相关部分如下所示:

Emacs.geometry: 80x70

您应该能够使用+ 0 + 0位置坐标对其进行后缀,以强制它显示在显示屏的左上角。 (我不这样做的原因是我偶尔会产生新的帧,如果它们出现在与前一帧完全相同的位置,会让人感到困惑)

根据手册this technique works on MS Windows too,将资源作为键/值对存储在注册表中。我从来没有测试过。它可能很棒,与简单编辑文件相比,这可能会带来更多不便。

答案 4 :(得分:16)

尝试将以下代码添加到.emacs

(add-to-list 'default-frame-alist '(height . 24))

(add-to-list 'default-frame-alist '(width . 80)) 

答案 5 :(得分:12)

启动emacs时你也可以使用-geometry参数:emacs -geometry 80x60+20+30会给你一个80个字符宽,60行高的窗口,左上角20个像素,右上角30个像素左下角的背景。

答案 6 :(得分:7)

在ubuntu上执行:

(defun toggle-fullscreen ()
  (interactive)
  (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                 '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
  (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
                 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
)
(toggle-fullscreen)

答案 7 :(得分:5)

在Windows上,您可以使用此功能使emacs框架最大化:

(defun w32-maximize-frame ()
  "Maximize the current frame"
  (interactive)
  (w32-send-sys-command 61488))

答案 8 :(得分:1)

(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))

答案 9 :(得分:0)

(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)

我更喜欢Bryan Oakley的设置。但是'height 在我的GNU Emacs 24.1.1中无法正常工作。

相关问题