Skip to content

Commit 9fd36ab

Browse files
committed
Initialize local scratch buffers with a major mode
1 parent ea61e1f commit 9fd36ab

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

bufferlo.el

+14-3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ For example, create a dedicated local scratch buffer for all tabs and frames:
129129
You can set this to \"*scratch*\"."
130130
:type 'string)
131131

132+
(defcustom bufferlo-local-scratch-buffer-initial-major-mode nil
133+
"The initial major mode for local scratch buffers.
134+
If nil, the local scratch buffers' major mode is set to `initial-major-mode'."
135+
:type 'function)
136+
132137
(defvar bufferlo--desktop-advice-active nil)
133138
(defvar bufferlo--desktop-advice-active-force nil)
134139

@@ -623,9 +628,15 @@ This is like `bufferlo-find-buffer' but additionally selects the buffer."
623628
"\\(<[0-9]*>\\)?$")
624629
(buffer-name b)))
625630
(bufferlo-buffer-list nil nil t))))
626-
(or buffer
627-
(get-buffer-create
628-
(generate-new-buffer-name bufferlo-local-scratch-buffer-name)))))
631+
(unless buffer
632+
(setq buffer (get-buffer-create
633+
(generate-new-buffer-name bufferlo-local-scratch-buffer-name)))
634+
(with-current-buffer buffer
635+
(when (eq major-mode 'fundamental-mode)
636+
(funcall (or bufferlo-local-scratch-buffer-initial-major-mode
637+
initial-major-mode
638+
#'ignore)))))
639+
buffer))
629640

630641
(defun bufferlo-create-local-scratch-buffer ()
631642
"Create a local scratch buffer and return it."

0 commit comments

Comments
 (0)