(emacs)Visiting


Next: Saving Prev: File Names Up: Files

Visiting Files
==============

`C-x C-f'
     Visit a file (`find-file').

`C-x C-r'
     Visit a file for viewing, without allowing changes to it
     (`find-file-read-only').

`C-x C-v'
     Visit a different file instead of the one visited last
     (`find-alternate-file').

`C-x 4 C-f'
     Visit a file, in another window (`find-file-other-window').  Don't
     change the selected window.

`C-x 5 C-f'
     Visit a file, in a new frame (`find-file-other-frame').  Don't
     change the selected frame.

   "Visiting" a file means copying its contents into an Emacs buffer so
you can edit them.  Emacs makes a new buffer for each file that you
visit.  We say that this buffer is visiting the file that it was created
to hold.  Emacs constructs the buffer name from the file name by
throwing away the directory, keeping just the name proper.  For example,
a file named `/usr/rms/emacs.tex' would get a buffer named `emacs.tex'.
If there is already a buffer with that name, a unique name is
constructed by appending `<2>', `<3>', or so on, using the lowest
number that makes a name that is not already in use.

   Each window's mode line shows the name of the buffer that is being
displayed in that window, so you can always tell what buffer you are
editing.

   The changes you make with Emacs are made in the Emacs buffer.  They
do not take effect in the file that you visited, or any place
permanent, until you "save" the buffer.  Saving the buffer means that
Emacs writes the current contents of the buffer into its visited file.
Note: Saving.

   If a buffer contains changes that have not been saved, we say the
buffer is "modified".  This is important because it implies that some
changes will be lost if the buffer is not saved.  The mode line
displays two stars near the left margin to indicate that the buffer is
modified.

   To visit a file, use the command `C-x C-f' (`find-file').  Follow
the command with the name of the file you wish to visit, terminated by a
RET.

   The file name is read using the minibuffer (Note: Minibuffer.),
with defaulting and completion in the standard manner (Note: File
Names.).  While in the minibuffer, you can abort `C-x C-f' by typing
`C-g'.

   Your confirmation that `C-x C-f' has completed successfully is the
appearance of new text on the screen and a new buffer name in the mode
line.  If the specified file does not exist and could not be created, or
cannot be read, then you get an error, with an error message displayed
in the echo area.

   If you visit a file that is already in Emacs, `C-x C-f' does not make
another copy.  It selects the existing buffer containing that file.
However, before doing so, it checks that the file itself has not changed
since you visited or saved it last.  If the file has changed, a warning
message is printed.  Note: Simultaneous Editing.

   What if you want to create a new file?  Just visit it.  Emacs prints
`(New File)' in the echo area, but in other respects behaves as if you
had visited an existing empty file.  If you make any changes and save
them, the file is created.

   If the file you specify is actually a directory, Dired is called on
that directory (Note: Dired.).  This can be inhibited by setting the
variable `find-file-run-dired' to `nil'; then it is an error to try to
visit a directory.

   If you visit a file that the operating system won't let you modify,
Emacs makes the buffer read-only, so that you won't go ahead and make
changes that you'll have trouble saving afterward.  You can make the
buffer writable with `C-x C-q' (`toggle-read-only').  Note: Misc
Buffer.

   Occasionally you might want to visit a file as read-only in order to
protect yourself from entering changes accidentally; do so by visiting
the file with the command `C-x C-r' (`find-file-read-only').

   If you visit a nonexistent file unintentionally (because you typed
the wrong file name), use the `C-x C-v' command (`find-alternate-file')
to visit the file you really wanted.  `C-x C-v' is similar to `C-x
C-f', but it kills the current buffer (after first offering to save it
if it is modified).  When it reads the file name to visit, it inserts
the entire default file name in the buffer, with point just after the
directory part; this is convenient if you made a slight error in typing
the name.

   `C-x 4 f' (`find-file-other-window') is like `C-x C-f' except that
the buffer containing the specified file is selected in another window.
The window that was selected before `C-x 4 f' continues to show the
same buffer it was already showing.  If this command is used when only
one window is being displayed, that window is split in two, with one
window showing the same buffer as before, and the other one showing the
newly requested file.  Note: Windows.

   `C-x 5 f' (`find-file-other-frame') is similar, but opens a new
frame.  This feature is available only when you are using a window
system.  Note: Frames.

   Two special hook variables allow extensions to modify the operation
of visiting files.  Visiting a file that does not exist runs the
functions in the list `find-file-not-found-hooks'; this variable holds
a list of functions, and the functions are called one by one until one
of them returns non-`nil'.  Any visiting of a file, whether extant or
not, expects `find-file-hooks' to contain a list of functions and calls
them all, one by one.  In both cases the functions receive no
arguments.  Of these two variables, `find-file-not-found-hooks' takes
effect first.  These variables are *not* normal hooks, and their names
end in `-hooks' rather than `-hook' to indicate that fact.

   There are several ways to specify automatically the major mode for
editing the file (Note: Choosing Modes.), and to specify local
variables defined for that file (Note: File Variables.).


automatically generated by info2www