Automatically closing the scratch buffer

前端 未结 6 1960
-上瘾入骨i
-上瘾入骨i 2021-02-04 05:32

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

相关标签:
6条回答
  • 2021-02-04 05:56

    You can customize:

    initial-buffer-choice
    

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

    0 讨论(0)
  • 2021-02-04 05:57

    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)
    0 讨论(0)
  • 2021-02-04 05:58

    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.

    0 讨论(0)
  • 2021-02-04 06:08

    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)
    )
    
    0 讨论(0)
  • 2021-02-04 06:15

    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.

    0 讨论(0)
  • 2021-02-04 06:16
    (kill-buffer "*scratch*")
    
    0 讨论(0)
提交回复
热议问题