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 ...
You can (ab-)use kill-buffer-query-functions for this purpose:
(add-hook 'kill-buffer-query-functions #'my/dont-kill-scratch)
(defun my/dont-kill-scratch ()
(if (not (equal (buffer-name) "*scratch*"))
(message "Not allowed to kill %s, burying instead" (buffer-name))
In my old Emacs configuration I used this to ...
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:
Which will format the output in a more readable way.
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 ...
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 ...
Just redefine the function with its original definition again.
You'll probably find this article very helpful:
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 ...
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 ...
GNU Emacs default bindings:
or, more verbosely
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 "...
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"))))
I think you're also confused about how dotimes works. From the doc string:
A new feature has been introduced for persistent scratch called "remember"
The new command ``remember-notes`` creates a buffer which is saved
You may think of it as a \*scratch\* buffer whose content is preserved.
In fact, it was designed as a replacement for \*...
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 ...
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, ...
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 ...
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*)"
(let ((n 0)
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 ...
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 ...
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.
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-...
I'd probably use a different approach, using mapconcat to apply the function and concatenate the results:
(let ((range (number-sequence 1 20)))
(format "%03d" (* x y)))
range " "))
This returns the string that you can insert or whatever else.
This will do the job.
(let ((filename "~/.emacs.d/startup.txt"))
(when (and (file-exists-p filename)
If you just want to put *scratch* in its own frame and use special frame parameters for it (e.g. give it its own background color, font, or whatever) then you can do this just by doing these two things:
Customize special-display-alist to have the frame parameters you want.
Customize special-display-buffer-names, adding *scratch* to it.
In a comment you ...
There is no need to provide the "." in your command. However, by default, there is a startup message shown.
emacs -nw --eval '(setq inhibit-startup-message t)'
emacs -nw --no-splash
should do what you want.
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 ...
The function assigned to the variable initial-major-mode is only called when *Scratch* is created by Emacs (e.g., startup.el, or when certain criteria is met when killing a buffer). It can be a custom function -- e.g., set the major-mode and do anything else under the sun.
(setq initial-major-mode (lambda () (lisp-interaction-mode) (message "*scratch*")))...
I had a similar problem getting web-mode to play nice with Django templates. For me the fix was as simple as adding the following to my init file:
'(("django" . "\\.html\\'"))
For you, try adding something like:
'(("dust" . "\\.html\\'"))
For more details, see the section ...