自动关闭Scratch缓冲区

16

我该在我的.emacs文件中写什么,才能让打开Emacs时关闭*scratch*缓冲区?

6个回答

24
(kill-buffer "*scratch*")

17

虽然不完全回答了你的问题,但你可能会想知道,在启动时可以选择打开一个不同的缓冲区,或更改 *scratch* 缓冲区的内容。例如:

;; Make *scratch* buffer blank.
(setq initial-scratch-message nil)

;; Make the buffer that opens on startup your init file ("~/.emacs" or
;; "~/.emacs.d/init.el").
(setq initial-buffer-choice user-init-file) 
在第一个示例中,*scratch* 缓冲区将为空。在第二个示例中,*scratch* 缓冲区仍将存在,但 user-init-file 将是焦点。

3
我认为第一个变量实际上被称为“initial-scratch-message”(而不是“-buffer”)。 - A. Rex
“message” 指的是在 Scratch 缓冲区内显示的消息,例如:“你好世界!你已经到达了初始目的地,也就是所谓的“scratch缓冲区”。 - lawlist
当对文件进行字节编译时,我收到了“警告:分配给自由变量'initial-scratch-buffer'”的提示... - Ciprian Tomoiagă

7

您可以自定义:

initial-buffer-choice

我将它设置为我的主目录:"~/",以便在Dired模式下启动。


6
我猜测您可能经常启动emacs,甚至每次需要编辑文件时都要启动它(如果我的推断不正确,则以下评论不适用于您)。
Emacs被设计为启动后长时间运行,可在数周或数月内访问各种文件以进行编辑。 Emacs非常擅长处理多个文件,因此即使有50或100个相关的缓冲区挂起,也几乎不需要杀死它们。 我会在窗口系统启动后立即启动emacs,并一直运行到系统关闭或崩溃。 在这种模式下,初始的scratch缓冲区不是问题,因为我很少看到它。

4
我使用这个函数来关闭scratch缓冲区并打开一个名为Untitled的文本模式新缓冲区。我在一个新闻组上找到了它并稍作修改。
以下是代码:
(defn my-close-scratch() (kill-buffer "*scratch*") (if (not (delq nil (mapcar 'buffer-file-name (buffer-list)))) (new-untitled-buffer) ))
(defun my-emacs-startup-hook () (my-close-scratch)) (add-hook 'emacs-startup-hook 'my-emacs-startup-hook)
(defun new-untitled-buffer () "打开一个新的空缓冲区." (interactive) (let ((buf (generate-new-buffer "Untitled"))) (switch-to-buffer buf) (normal-mode) (setq buffer-offer-save t)) (add-hook 'kill-buffer-query-functions 'ask-to-save-modified nil t) )
而要在从文件管理器打开文件时关闭Untitled,可以使用以下函数:
(defun my-close-untitled () (if (get-buffer "Untitled") (kill-buffers-by-name "Untitled")))
(add-hook 'find-file-hook 'my-close-untitled)

1
为什么不直接使用 Scratch 缓冲区作为无标题缓冲区呢? - Marc Stober

-3
正确的方法是将inhibit-startup-screen添加到您的.emacs文件的custom-set-variables部分。
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t)
)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接