Add a command to recreate the *scratch* buffer
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 2 May 2022 10:26:31 +0000 (12:26 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 2 May 2022 10:26:31 +0000 (12:26 +0200)
* doc/emacs/building.texi (Lisp Interaction): Mention it.
* lisp/simple.el (scratch-buffer): New command.

doc/emacs/building.texi
etc/NEWS
lisp/simple.el

index 5bf4c8c73963764dce382a3ccfe8154e36c8699e..994ad460333300386b408c7ce195745fc92a10a7 100644 (file)
@@ -1742,6 +1742,10 @@ which is provided for evaluating Emacs Lisp expressions interactively.
 Its major mode is Lisp Interaction mode.  You can also enable Lisp
 Interaction mode by typing @kbd{M-x lisp-interaction-mode}.
 
+@findex scratch-buffer
+  If you kill the @file{*scratch*} buffer, you can recreate it with
+the @kbd{M-x scratch-buffer} command.
+
 @findex eval-print-last-sexp
 @kindex C-j @r{(Lisp Interaction mode)}
   In the @file{*scratch*} buffer, and other Lisp Interaction mode
index 5e7baab109601ab1d0cd340a886690588d20df59..25a976db5858753aa48c65fef3dd97b8620942e5 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -707,6 +707,13 @@ script that was used in ancient South Asia.  A new input method,
 \f
 * Changes in Specialized Modes and Packages in Emacs 29.1
 
+** Miscellaneous
+
++++
+*** New command 'scratch-buffer'.
+This switches to the *scratch* buffer.  If it doesn't exist, create it
+first.
+
 ** Debugging
 
 *** New user option 'debug-allow-recursive-debug'.
index d638e641c3e9ff9139c6d2945f421b521e987fbe..861d9eefde90da127b82ff58ebc2a217dc31d7c4 100644 (file)
@@ -10213,6 +10213,17 @@ This is an integer indicating the UTC offset in seconds, i.e.,
 the number of seconds east of Greenwich.")
   )
 
+(defun scratch-buffer ()
+  "Switch to the \*scratch\* buffer.
+If the buffer doesn't exist, create it first."
+  (interactive)
+  (if (get-buffer "*scratch*")
+      (pop-to-buffer-same-window "*scratch*")
+    (pop-to-buffer-same-window (get-buffer-create "*scratch*"))
+    (when initial-scratch-message
+      (insert initial-scratch-message))
+    (funcall initial-major-mode)))
+
 \f
 
 (provide 'simple)