emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 10f347a062: Add a command to recreate the *scratch* buffer


From: Lars Ingebrigtsen
Subject: master 10f347a062: Add a command to recreate the *scratch* buffer
Date: Mon, 2 May 2022 06:26:47 -0400 (EDT)

branch: master
commit 10f347a06286272c7dcfdeb47b3511b6f53adcbd
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add a command to recreate the *scratch* buffer
    
    * doc/emacs/building.texi (Lisp Interaction): Mention it.
    * lisp/simple.el (scratch-buffer): New command.
---
 doc/emacs/building.texi |  4 ++++
 etc/NEWS                |  7 +++++++
 lisp/simple.el          | 11 +++++++++++
 3 files changed, 22 insertions(+)

diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi
index 5bf4c8c739..994ad46033 100644
--- a/doc/emacs/building.texi
+++ b/doc/emacs/building.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index 5e7baab109..25a976db58 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -707,6 +707,13 @@ script that was used in ancient South Asia.  A new input 
method,
 
 * 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'.
diff --git a/lisp/simple.el b/lisp/simple.el
index d638e641c3..861d9eefde 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -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)))
+
 
 
 (provide 'simple)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]