Automatically closing the scratch buffer

2020-05-23 03:15发布

What I must write in my .emacs file so that the *scratch* buffer is closed when I open Emacs?

标签: emacs
6条回答
我想做一个坏孩纸
2楼-- · 2020-05-23 03:47

You can customize:

initial-buffer-choice

I set it to my homedir: "~/" to start in Dired mode.

查看更多
SAY GOODBYE
3楼-- · 2020-05-23 03:49

I suspect from your question that you probably start emacs fairly often, perhaps even once for each file you want to edit. (If I'm wrong in this assumption, then the following comments don't apply to you.)

Emacs is designed to be started and then left running for weeks or months while you visit various files as you need to edit them. Emacs handles multiple files very well, so it's hardly even necessary to kill the associated buffers until you get 50 or 100 of them hanging around. I start emacs just after my window system starts, and it runs until my system shuts down or crashes. The initial scratch buffer is a non-problem in this mode, because I see it so infrequently.

查看更多
贪生不怕死
4楼-- · 2020-05-23 03:52

I use this to kill the scratch buffer and open a new buffer in text mode called Untitled. Found it on a newsgroup and modified it slightly.

(defun 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 ()
  "Opens a new empty 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)
  )

To close Untitled when opening files from filemanager when emacs is not open I use this:

(defun my-close-untitled ()
  (if (get-buffer "Untitled")
      (kill-buffers-by-name "Untitled")))

(add-hook 'find-file-hook 'my-close-untitled)
查看更多
▲ chillily
5楼-- · 2020-05-23 03:56

The proper way is to add inhibit-startup-screen to the custom-set-variables section of your .emacs file.

(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)
)
查看更多
放我归山
6楼-- · 2020-05-23 04:01
(kill-buffer "*scratch*")
查看更多
Luminary・发光体
7楼-- · 2020-05-23 04:03

Not exactly the answer to your question, but you might like to know that you can choose to have a different buffer open on startup, or change the contents of the *scratch* buffer. For example:

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

In the first example, the *scratch* buffer will be empty. In the second example, the *scratch* buffer will still exist, but user-init-file will be focused.

查看更多
登录 后发表回答