Skip to content

Instantly share code, notes, and snippets.

@eev2
eev2 / create-scratch-buffer.el
Last active June 29, 2025 09:10
Create a new scratch buffer in emacs
(defun create-scratch-buffer (&optional nomode)
"Create a new scratch buffer and switch to it. If the region is active, then
paste the contents of the region in the new buffer. The new buffer inherits
the mode of the original buffer unless nomode is set.
Return the buffer."
(interactive "P")
(let ((thisbuf (current-buffer))
(beg)
(end)
(bufname (generate-new-buffer-name "*scratch*"))