33

Just re-create the buffer by switching to it: C-x b *scratch* RET. Since Emacs 21.2, if you create a buffer called *scratch*, it's automatically put in Lisp Interaction mode.


25

It will be convenient to bind the below function to a key binding of your choice. If you are currently working on a FILE buffer, calling the below function will toggle between FILE's major-mode specific *scratch* buffer called *scratch-MAJOR-MODE* and the FILE buffer. Given the example in question, if I am working on a Perl script called myperl.pl, calling ...


14

You can customize the value of initial-major-mode, which defaults to lisp-interaction-mode. Here's the variable's docstring: initial-major-mode is a variable defined in startup.el. Its value is lisp-interaction-mode Documentation: Major mode command symbol to use for the initial *scratch* buffer. You can customize this variable. For the ...


12

The initial major-mode for the *Scratch* buffer is controlled by the variable initial-major-mode -- the value needs to be a symbol (which in layman's terms means put a single quote in front of the major-mode name): http://www.gnu.org/software/emacs/manual/html_node/elisp/Auto-Major-Mode.html (setq initial-major-mode 'org-mode) EDIT: Based on a comment ...


11

As mentioned in the comments you can tweak eval-expression-print-* or expand by hitting RET or mouse-2 on the ellipses (which calls last-sexp-toggle-display). However probably the most useful for general messing around in the *scratch* buffer is: (pp package-alist) Which will format the output in a more readable way.


11

There's an extension called scratch, which allows creating mode-specific scratch buffers. It is available from MELPA, so you should be able to install it easily. With this package installed, when you are in an org-mode buffer, you can run M-xscratch to get a scratch buffer in org-mode. If you give a prefix argument, you get the opportunity to choose the ...


7

It's arguably better to re-create the *scratch* buffer automatically whenever it gets deleted, and avoid having to retype its name. (defun prepare-scratch-for-kill () (save-excursion (set-buffer (get-buffer-create "*scratch*")) (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer t))) (defun kill-scratch-buffer () (let (kill-buffer-query-...


7

Check the value of option initial-major-mode: M-x customize-option RET initial-major-mode RET. Its default value is lisp-interaction-mode, which puts *scratch* in that mode. C-h v initial-major-mode tells you this: Major mode command symbol to use for the initial *scratch* buffer. You can customize this variable. So remove the customization that changed ...


6

Set eval-expression-print-length and eval-expression-print-level to nil.


6

Just redefine the function with its original definition again. You'll probably find this article very helpful: https://masteringemacs.org/article/evaluating-elisp-emacs You can't 'undo' lisp evaluation like you can undo text editing -- Emacs isn't keeping a history of all previous states of the lisp interpreter (it couldn't do so -- the idea just isn't ...


5

I think one simple way to achieve it is simply to run M-x org-mode when you're in *snatch* buffer, and thus enabling org-mode directly. This can be applied to enabling any major mode.


5

A new feature has been introduced for persistent scratch called "remember" From https://www.masteringemacs.org/article/whats-new-in-emacs-24-4 The new command ``remember-notes`` creates a buffer which is saved on ``kill-emacs``. You may think of it as a \*scratch\* buffer whose content is preserved. In fact, it was designed as a replacement for \*...


5

GNU Emacs default bindings: C-xb*scratch* or, more verbosely M-xswitch-to-buffer Typing: *scratch* And then hitting the RET key. The *scratch* buffer is the buffer selected upon startup, and has the major mode Lisp Interaction. Note: the mode for the *scratch* buffer is controlled by the variable initial-major-mode. In general you can create as many &...


4

You'll notice that you're using a variable called auto-save-file-name-transforms. Since *scratch* has no filename, it falls back to autosaving in default-directory. For the *scratch* buffer, or any other buffers like this with no filename, you can use: (setq-local default-directory "~/.emacs.d/data/autosave") Edit: I see that you don't really care about ...


4

format generates a string, but it doesn't do anything with it. You probably want to pass the result of format on to something that does: (defun mt () (dotimes (x 20) (dotimes (y 20) (insert (format "%3d " (* (1+ x) (1+ y))))) (insert (format "\n")))) UPDATE I think you're also confused about how dotimes works. From the doc string: (...


4

My original suggestion to the OP based on my own slightly misguided experimentation was this: make sure that the mode you want to set as the initial-major-mode is loaded before you set initial-major-mode with (setq initial-major-mode 'name-of-mode). This seems to have solved the problem that the OP was having. However, I have also tested changing my entire ...


3

Rather than changing the mode of an Emacs stalwart Scratch, configure initial-buffer-choice. C-h v initial-buffer-choice


3

I like to use scratch buffers for throw-away stuff. Having only one is somewhat limiting though, therefore I have scratch as an interactive command for opening a new scratch buffer (no matter how many exist already): (defun scratch () "create a new scratch buffer to work in. (could be *scratch* - *scratchX*)" (interactive) (let ((n 0) bufname)...


3

defun and while are macros, and are highlighted as such. set and + are functions, and are not highlighted like macros. Old versions of Emacs seem to have a list of specific macros to highlight, but more recent (possibly unreleased?) versions simply highlight all known macros. Here are the docs on functions and macros so you can tell them apart. I admit, ...


3

initial-buffer-choice allows to specify a path to a file or directory: (let ((filename "~/.emacs.d/startup.txt")) (when (file-exists-p filename) (setq initial-buffer-choice filename)))


3

This will do the job. (let ((filename (concat user-emacs-directory "scratch.txt"))) (when (file-exists-p filename) (let ((scratch-buf (get-buffer "*scratch*"))) (when scratch-buf (with-current-buffer scratch-buf (erase-buffer) (insert-file-contents filename))))))


3

Try the async package (M-x package-install, if you don't already have it). See the functions async-start and async-inject-variables. The given example is: (async-start `(lambda () (require 'smtpmail) (with-temp-buffer (insert ,(buffer-substring-no-properties (point-min) (point-max))) ;; Pass in the variable environment for ...


2

I made it slightly different (but the previous answers helped me a lot, thanks guys), to avoid string matching. I modified the "new-empty-buffer" function suggested by Xah Lee from ErgoEmacs, making it set a local-variable 'custom-scratch-buffer when the buffer is created. Therefore, we know when the buffer is a scratch buffer created by this function and ...


2

I guess much of this is a matter of taste and usage patterns. I tend to use something inbetween your solution and @Drew's usage (according to the comments). Here is the gist of it: I want "throwaway" buffers to be quickly available, without having to think ahead of time where to save them; I want them to be file buffers in order for Emacs to warn me if I ...


2

This can be done using initial-buffer-choice, While initial-buffer-choice can be set to a filename, this will load the file as well as any files passed via the command line (splitting the window or not even showing the buffer depending on your setup).So reading file data into *scratch* buffer has the advantage that exact behavior is preserved, just replacing ...


2

In step 23 of the startup sequence emacs inserts initial-scratch-message into the *scratch* buffer. That step is after loading the init file, after running after-init-hook, and before emacs-startup-hook. Ergoemacs uses its own themes defined with ergoemacs-theme. The standard theme is defined in library ergoemacs-themes.el. The value of initial-scratch-...


2

ok, this whole discussion has prompted me to return to an approach I've tried to setup but @Drew has rekindled an interest in. Create a file like this in ~/.emacs.d/scratch.el ;;; scratch.el --- Emacs Lisp Scratch -*- lexical-binding: t -*- ;; Local Variables: ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc) ;; byte-compile-warnings: (not free-vars ...


2

Try this: C-x b (type a name for your new scratch buffer, e.g. "asdf") M-x org-mode (change "asdf" buffer's major mode) When closing this buffer you won't get a query for saving its contents. I.e. you get a proper scratch buffer. And the *scratch* buffer remains intact.


2

I'd probably use a different approach, using mapconcat to apply the function and concatenate the results: (let ((range (number-sequence 1 20))) (mapconcat (lambda (y) (mapconcat (lambda (x) (format "%03d" (* x y))) range " ")) range "\n")) This returns the string that you can insert or whatever else.


Only top voted, non community-wiki answers of a minimum length are eligible