关于elisp:如何设置Emacs窗口的大小?

关于elisp:如何设置Emacs窗口的大小?

How do I set the size of Emacs' window?

我正在尝试检测要在其上启动emacs的屏幕的大小,并相应地调整其大小和位置(在emacs中,这就是emacs的框架)。 我正在尝试设置.emacs,以便始终获得一个"合理大"的窗口,该窗口的左上角靠近屏幕的左上角。

我想这对一般情况来说是一个很大的要求,因此要缩小范围,我对Windows和(Debian)Linux上的GNU Emacs 22最感兴趣。


如果要根据分辨率更改大小,可以执行以下操作(根据您的特定需求调整首选的宽度和分辨率):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(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中包含以下内容:

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

您可能还会查看功能set-frame-sizeset-frame-positionset-frame-width。使用C-h f(又名M-x describe-function)调出详细的文档。

我不确定在当前的窗口环境中是否可以计算框架的最大高度/宽度。


摘自:http://www.gnu.org/software/emacs/windows/old/faq4.html

1
2
3
4
5
6
7
8
9
10
(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的原始框架。


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

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

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

我发现在X-Window环境中执行此操作的最简单方法是通过X资源。我的.Xdefaults的相关部分如下所示:

1
Emacs.geometry: 80x70

您应该可以使用+ 0 + 0位置坐标作为后缀,以将其强制显示在显示器的左上角。 (我之所以不这样做,是因为我偶尔会产生新的帧,如果它们出现在与上一帧完全相同的位置,则会使事情感到困惑)

根据手册,该技术也适用于MS Windows,将资源作为键/值对存储在注册表中。我从来没有测试过。与仅编辑文件相比,这可能很棒,可能带来更多的不便。


您也可以在启动emacs时使用-geometry参数:emacs -geometry 80x60+20+30将为您提供一个宽度为80个字符,高度为60行的窗口,其左上角为背景右侧的20像素,而背景的左上角为向下30像素。


在ubuntu上执行:

1
2
3
4
5
6
7
8
(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)

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

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

1
2
3
4
5
6
7
(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))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(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的设置。但是,在我的GNU Emacs 24.1.1中,"高度不能正常工作"。


推荐阅读

    linux设置命令行长度?

    linux设置命令行长度?,系统,工作,信息,地址,命令,工具,异常,管理,目录,文件,l

    linux设置代替命令?

    linux设置代替命令?,系统,地址,网络,工作,软件,工具,服务,信息,命令,别名,lin

    linux命令设置时区?

    linux命令设置时区?,时间,系统,国家,大陆,命令,时区,时钟,日期,指令,时分,lin

    linux设置命令限制?

    linux设置命令限制?,数字,情况,信息,管理,系统,最新,在线,设备,第一,发行,Lin

    linux设置日志命令行?

    linux设置日志命令行?,异常,系统,实时,日志,管理,信息,对比,项目,名称,情况,L

    linux命令行设置网卡?

    linux命令行设置网卡?,系统,地址,信息,网络,工具,电脑,工作,名称,设备,网卡,l

    linux命令优先级设置?

    linux命令优先级设置?,系统,时间,实时,策略,优先级,分时,管理,周期性,进程,

    linux调整优先级命令?

    linux调整优先级命令?,策略,系统,工作,时间,实时,信息,网络,优先级,命令,中

    linux设置ip命令?

    linux设置ip命令?,地址,系统,密码,设备,命令,服务,工具,网络,网卡,计算机,在L

    linux设置命令是什么?

    linux设置命令是什么?,系统,工作,信息,名称,地址,命令,在线,基础,标准,工具,l

    linux磁盘检测命令?

    linux磁盘检测命令?,情况,系统,数据,检测,管理,信息,命令,磁盘,设备,单位,lin

    linux调整声音命令?

    linux调整声音命令?,系统,手机,电脑,设备,工作,位置,地方,地址,服务,情况,lin

    linux检测gpu命令?

    linux检测gpu命令?,信息,系统,工具,检测,情况,电脑,数字,环境,网上,报告,linu

    linux命令设置密码?

    linux命令设置密码?,密码,系统,服务,软件,地址,电脑,流程,管理,用户,命令,问

    硬盘检测命令linux?

    硬盘检测命令linux?,信息,情况,系统,管理,数据,检测,百分比,命令,工具,设备,l

    linux设置编码命令?

    linux设置编码命令?,系统,数据,发展,文件,字符集,命令,数据库,以下,终端,大

    linux命令行设置语言?

    linux命令行设置语言?,系统,管理,环境,国家,工具,电脑,软件,文化,底部,语言,l

    linux设置壁纸的命令?

    linux设置壁纸的命令?,图片,系统,电脑,照片,位置,终端,颜色,字体,单击,壁纸,

    linux打印屏幕命令?

    linux打印屏幕命令?,信息,系统,工作,标准,地址,命令,工具,状态,设备,网络,我

    linux恢复命令行设置?

    linux恢复命令行设置?,系统,工作,密码,信息,工具,地址,电脑,命令,情况,地方,