emacs - 在 OS X 上的 Emacs 中同时设置 `fullheight` 和 `width`

标签 emacs emacs24 dot-emacs

我发现 Emacs 框架的默认大小有点太小了。通过阅读,我知道我可以很容易地设置高度和宽度,如下所示:

;;; 140 x 60 window size
(setq default-frame-alist '((width . 140) (height . 60)))
这在我的外接显示器上效果很好,但是对于笔记本电脑显示器来说有点太大了。我可以通过更改为以下解决高度问题:
;;; automatically set the height
(setq default-frame-alist '((fullscreen . fullheight)))
它将当前屏幕的框架设置为尽可能高。但是,如果我使用这种方法,我无法设置框架的宽度。添加 (width . 140)到上面的 alist 将宽度设置为正确的值,但也将高度再次设置为默认高度。
当我看到框架出现时,它会将自己设置为全高,然后将宽度设置为我请求的值,并缩小高度。
我可以用下面的代码克服这个问题:
;;; Full height for the default window
(setq default-frame-alist
      '((fullscreen . fullheight)))
;; Set the width in a hook and have all windows inherit
(setq frame-inherited-parameters
      '(width height))
(add-hook 'after-init-hook
          (lambda ()
                  (set-frame-parameter nil 'width 140)))
它使用钩子(Hook)将第一帧的宽度设置为我想要的值,然后将所有其他窗口设置为继承该值。
然而,这不是很优雅,所以问题是“我怎样才能以更简单(或不那么老套)的方式完成这个?”。
如果你想看我的确切init.el脚本,take a look at this gist
TL;博士
如何在 OS X 上设置框架的宽度,并将框架设置为在当前显示器上尽可能高?好像不能指定 (width . 140)(fullscreen . fullheight)default-frame-alist .

最佳答案

我已经想出了一个解决方案。我明确计算了窗口的高度,而不是依赖 (fullscreen . fullheight)为我做。

设置高度和宽度值的更新代码非常简单:

;;; Nice size for the default window
(defun get-default-height ()
       (/ (- (display-pixel-height) 120)
          (frame-char-height)))

(add-to-list 'default-frame-alist '(width . 140))
(add-to-list 'default-frame-alist (cons 'height (get-default-height)))

在此代码中,从屏幕高度减去 120 确保窗口的高度考虑了停靠栏和菜单栏的高度。为了获得正确的结果,您必须确保在选择要使用的字体后执行此代码,否则计算的高度值将无效。

将高度计算放在它自己的函数中应该允许特殊的外壳某些操作系统和版本。此方法还有一个额外的优势,即打开窗口更快,因为它不会将高度“动画”到完整高度值。

关于emacs - 在 OS X 上的 Emacs 中同时设置 `fullheight` 和 `width`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17362999/

相关文章:

command-line - 什么程序可以帮助 REPL shell 记住和搜索历史记录?

emacs - 如何检查 Emacs 下的功能(例如 server-running-p)是否可用?

emacs - "Press"交互函数中的一个键

emacs - 创建 LaTeX 跳转到 PDF 的键绑定(bind) --synctex

emacs - 分析 Emacs Lisp 行为不当的技巧?

html - 如何从 Emacs Lisp 文档生成 HTML?

windows - Windows 中的 Emacs

emacs - 在 emacs 23 和 emacs 24 之间共享 emacs 配置

emacs - 防止SLIME切换到repl缓冲区

cocoa - 如何在 .emacs 文件中检测 Cocoa Emacs?