Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new, unnamed file in emacs?

Tags:

emacs

This is a very simple request: I want to create a new, blank file without giving it a name (yet). I can use the scratch buffer but there's only one. I can C-x C-f and open a new file, but then I have to give it a name and path. If I'm just writing notes to myself or sketching out ideas, I don't want to have to give it a name. How do I create a new, empty, unnamed file?

like image 774
limp_chimp Avatar asked Nov 17 '14 18:11

limp_chimp


2 Answers

You can create a new buffer with: C-xb and type in the buffer name and it will create a new buffer with a name that you choose.

If you want to save that buffer, just hit C-x w to create the file with its contents to a desired location.

My recommendation is that you give org-mode a try. It will do what want among a million other things.

like image 70
Mahmoud Abdelkader Avatar answered Nov 10 '22 19:11

Mahmoud Abdelkader


Give it a name. Just don't save it.

Not what you wanted to hear, but this is the Emacs way.

Use C-x C-f, giving the (to-be-file-visiting) buffer a name. Edit the text. Do not use C-x C-s to save the buffer to the file (i.e., to disk).

Note that you can first put yourself in a directory whose contents you don't care about, so that if you accidentally do save the buffer there then you can easily find, recognize and toss the file. To change directories, you can use M-x cd. Or just do it by editing the directory part when you first use C-x C-f. Or use C-x d to put yourself in a Dired buffer for the directory.


If you don't want to take the chance of accidentally hitting C-x C-s and thus saving your edits, then use C-x b instead of C-x C-f. You are (even here) prompted for the buffer name. Giving it a new name (not the name of an existing buffer) creates a new buffer. In this case, if you use C-x C-s then Emacs prompts you for the file location to save the buffer in.


Why would you want to use C-x C-f instead of C-x b, if you might not want to save the buffer? Providing a file extension in the file name you give automatically puts the buffer in the proper major mode (typically). Otherwise (for C-x b) you need to put the buffer in the mode you want.

Buffer *scratch* is by default in Lisp-Interaction mode, which is similar to Emacs-Lisp mode (but not the same).

like image 26
Drew Avatar answered Nov 10 '22 18:11

Drew