summaryrefslogtreecommitdiff
path: root/lisp/simple.el
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-05-05 13:03:06 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-05-09 18:49:13 -0700
commit054062060e9f57fd037578378c23ad9ec294edac (patch)
treec9eaec1c5c4ce19e6be0c0c1000d0fb58bebd1b1 /lisp/simple.el
parent54ab2b36740166d379c713e843870310f1ccf7a1 (diff)
downloademacs-054062060e9f57fd037578378c23ad9ec294edac.tar.gz
emacs-054062060e9f57fd037578378c23ad9ec294edac.tar.bz2
emacs-054062060e9f57fd037578378c23ad9ec294edac.zip
Factor out *scratch* initialization
* lisp/simple.el (get-scratch-buffer-create): New function, factored out of scratch-buffer, and additionally clearing the modification flag and calling substitute-command-keys (bug#55257). (scratch-buffer): * lisp/server.el (server-execute): * lisp/startup.el (normal-no-mouse-startup-screen, command-line-1): * lisp/window.el (last-buffer, window-normalize-buffer-to-switch-to): * src/buffer.c (Fother_buffer, other_buffer_safely): Use it. (syms_of_buffer): Add Qget_scratch_buffer_create. * lisp/startup.el (startup--get-buffer-create-scratch): Delete now-unused function. * doc/lispref/os.texi (Summary: Sequence of Actions at Startup): * NEWS (Incompatible changes in Emacs 29.1): Document the change.
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el20
1 files changed, 14 insertions, 6 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 861d9eefde9..edcc226bfa8 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10213,16 +10213,24 @@ This is an integer indicating the UTC offset in seconds, i.e.,
the number of seconds east of Greenwich.")
)
+(defun get-scratch-buffer-create ()
+ "Return the \*scratch\* buffer, creating a new one if needed."
+ (or (get-buffer "*scratch*")
+ (let ((scratch (get-buffer-create "*scratch*")))
+ ;; Don't touch the buffer contents or mode unless we know that
+ ;; we just created it.
+ (with-current-buffer scratch
+ (when initial-scratch-message
+ (insert (substitute-command-keys initial-scratch-message))
+ (set-buffer-modified-p nil))
+ (funcall initial-major-mode))
+ scratch)))
+
(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)))
+ (pop-to-buffer-same-window (get-scratch-buffer-create)))