最近我买了一台装有 Windows XP 的笔记本电脑。我真的很想开始在上面使用 emacs,但有一个问题 - 当我启动 emacs 时,它无法垂直适应我的屏幕。所以每次启动 emacs 时,我都必须先调整其窗口大小,这非常尴尬和不方便。有没有办法在退出时自动保存并在启动时恢复 emacs 窗口大小?
更新我将代码移到了问题答案中
答案1
只需输入.emacs
这段代码
(defun restore-saved-window-size()
(unless (load "~/.emacs.d/whsettings" t nil t)
(setq saved-window-size '(80 30)))
(nconc default-frame-alist `((width . ,(car saved-window-size))
(height . ,(cadr saved-window-size)))))
(restore-saved-window-size)
(defun save-window-size-if-changed (&optional unused)
(let ((original-window-size `(,(frame-width) ,(frame-height))))
(unless (equal original-window-size saved-window-size)
(with-temp-buffer
(setq saved-window-size original-window-size)
(insert (concat "(setq saved-window-size '"
(prin1-to-string saved-window-size) ")"))
(write-file "~/.emacs.d/whsettings")))))
(add-hook 'window-size-change-functions 'save-window-size-if-changed)
在我的 Windows XP 上运行良好,对于快捷方式,可以在文件夹中
创建包含以下内容的文件:emacs.cmd
%system32%
C:\
path-to-emacs
\bin\runemacs.exe %*
能够从任何地方的 cmd 启动它。
答案2
将以下内容保存到 .reg 文件并将其导入注册表:
REGEDIT4
[HKEY_CURRENT_USER\SOFTWARE\GNU\Emacs]
"Emacs.Geometry"="80x32+100+0"
答案3
我在 .emacs 中使用它来修复大小
(defvar max-width 80)
(defvar max-height 50)