Re-open *scratch* buffer in Emacs?

后端 未结 16 1329
北海茫月
北海茫月 2020-12-12 10:29

If I accidentally closed the scratch buffer in Emacs, how do I create a new scratch buffer?

16条回答
  •  一向
    一向 (楼主)
    2020-12-12 11:20

    Like the docstring says, this function will:

    Switch to the scratch buffer. If the buffer doesn't exist create it and write the initial message into it."

    This will bring a new scratch buffer up which looks like the initial scratch buffer.

    (defun switch-buffer-scratch ()
      "Switch to the scratch buffer. If the buffer doesn't exist,
    create it and write the initial message into it."
      (interactive)
      (let* ((scratch-buffer-name "*scratch*")
             (scratch-buffer (get-buffer scratch-buffer-name)))
        (unless scratch-buffer
          (setq scratch-buffer (get-buffer-create scratch-buffer-name))
          (with-current-buffer scratch-buffer
            (lisp-interaction-mode)
            (insert initial-scratch-message)))
        (switch-to-buffer scratch-buffer)))
    
    (global-set-key "\C-cbs" 'switch-buffer-scratch)
    

提交回复
热议问题