使用场景

在原有的scratch保存新文件时,scratch buffer会消失

创建新命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
;;create-new-scratch-buffer
(defun create-scratch-buffer nil
  "create a scratch buffer"
  (interactive)
  (switch-to-buffer (get-buffer-create "*scratch*"))
  (lisp-interaction-mode))

(defun switch-to-scratch-and-back ()
    "Toggle between *scratch* buffer and the current buffer.
     If the *scratch* buffer does not exist, create it."
    (interactive)
    (let ((scratch-buffer-name (get-buffer-create "*scratch*")))
        (if (equal (current-buffer) scratch-buffer-name)
            (switch-to-buffer (other-buffer))
            (switch-to-buffer scratch-buffer-name (lisp-interaction-mode)))))

参考链接如下:

RecreateScratchBuffer