* bug#57450: [PATCH] Option to choose the major model new scratch buffers
@ 2022-08-27 13:01 Augusto Stoffel
2022-08-27 13:06 ` Eli Zaretskii
2022-08-27 13:12 ` Lars Ingebrigtsen
0 siblings, 2 replies; 5+ messages in thread
From: Augusto Stoffel @ 2022-08-27 13:01 UTC (permalink / raw)
To: 57450
[-- Attachment #1: Type: text/plain, Size: 399 bytes --]
Tags: patch
I just noticed the new `scratch-buffer' command and I think it would be
nice to provide an option to create scratch buffers with different major
modes. WDYT?
What is the best way to get a list of all available major modes? I can
think of two methods, none of which is perfect. One is commented out in
the patch; I like the uncommented one (using the auto-mode-alist) a bit
better.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Provide-option-to-choose-a-major-mode-in-scratch-buf.patch --]
[-- Type: text/x-patch, Size: 3664 bytes --]
From c710c8d65d62292e22282da90fa471c16b1d3cb6 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@gmail.com>
Date: Sat, 27 Aug 2022 09:50:17 +0200
Subject: [PATCH] Provide option to choose a major mode in 'scratch-buffer'
* lisp/simple.e (get-scratch-buffer-create, scratch-buffer): New
optional MODE argument.
---
lisp/simple.el | 61 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 44 insertions(+), 17 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 460aff8bd8..bc9c71dee9 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10650,24 +10650,51 @@ capitalize-dwim
(fn CL-X)")
-(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 ()
+(defun get-scratch-buffer-create (&optional mode)
+ "Return a scratch buffer for MODE, creating a new one if needed.
+If MODE is nil, use `initial-major-mode' and insert
+`initial-scratch-message'."
+ (let ((name (if mode
+ (format "*scratch-%s*"
+ (string-trim-right (symbol-name mode) "-mode"))
+ "*scratch*")))
+ (or (get-buffer name)
+ (let ((scratch (get-buffer-create name)))
+ ;; Don't touch the buffer contents or mode unless we know that
+ ;; we just created it.
+ (with-current-buffer scratch
+ (when (and (not mode) initial-scratch-message)
+ (insert (substitute-command-keys initial-scratch-message))
+ (set-buffer-modified-p nil))
+ (funcall (or mode initial-major-mode)))
+ scratch))))
+
+(defun scratch-buffer (&optional mode)
"Switch to the *scratch* buffer.
-If the buffer doesn't exist, create it first."
- (interactive)
- (pop-to-buffer-same-window (get-scratch-buffer-create)))
+If the buffer doesn't exist, create it first.
+With a prefix argument, select a major mode for the scratch buffer."
+ (interactive
+ (list (when current-prefix-arg
+ (intern
+ (completing-read "Scratch buffer mode: "
+ (delete-dups
+ (delq nil
+ (mapcar (pcase-lambda (`(_ . ,it))
+ (and (symbolp it)
+ (commandp it)
+ it))
+ auto-mode-alist))))))))
+ ;; (completing-read "Scratch buffer mode: "
+ ;; obarray
+ ;; (lambda (sym)
+ ;; (and (commandp sym)
+ ;; (if (autoloadp (symbol-function sym))
+ ;; (string-suffix-p "-mode"
+ ;; (symbol-name sym))
+ ;; (memq 'derived-mode-parent
+ ;; (symbol-plist sym)))))
+ ;; t)))))
+ (pop-to-buffer-same-window (get-scratch-buffer-create mode)))
(defun kill-buffer--possibly-save (buffer)
(let ((response
--
2.37.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-29 15:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-27 13:01 bug#57450: [PATCH] Option to choose the major model new scratch buffers Augusto Stoffel
2022-08-27 13:06 ` Eli Zaretskii
[not found] ` <CAHixrvZjE7nbG37WxXP7wTN=pj4DEF5-hMb6z+ufMJWr5v8PXg@mail.gmail.com>
2022-08-27 13:36 ` Eli Zaretskii
2022-08-29 15:25 ` Lars Ingebrigtsen
2022-08-27 13:12 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.