Next: , Previous: , Up: Basic   [Contents][Index]


4.4 Files

The commands described above are sufficient for creating and altering text in an Emacs buffer; the more advanced Emacs commands just make things easier. But to keep any text permanently you must put it in a file. Files are named units of text which are stored by the operating system for you to retrieve later by name. To look at or use the contents of a file in any way, including editing the file with Emacs, you must specify the file name.

Consider a file named /usr/rms/foo.c. To begin editing this file from Emacs, type:

C-x C-f /usr/rms/foo.c RET

Here the file name is given as an argument to the command C-x C-f (find-file). That command uses the minibuffer to read the argument, and you type RET to terminate the argument (see Minibuffer).

You can also use the Open... menu item from the File menu, then type the name of the file to the prompt.

Emacs obeys the command by visiting the file: creating a buffer, copying the contents of the file into the buffer, and then displaying the buffer for you to edit. If you alter the text, you can save the new text in the file by typing C-x C-s (save-buffer) or choosing Save Buffer from the File menu. This makes the changes permanent by copying the altered buffer contents back into the file /usr/rms/foo.c. Until you save, the changes exist only inside Emacs, and the file foo.c is unaltered.

To create a file, visit the file with C-x C-f as if it already existed or choose Open... from the File menu and provide the name for the new file. Emacs will create an empty buffer in which you can insert the text you want to put in the file. When you save the buffer with C-x C-s, or by choosing Save Buffer from the File menu, the file is created.

To learn more about using files, See Files.


Next: , Previous: , Up: Basic   [Contents][Index]