This section describes the functions normally used to visit files. For historical reasons, these functions have names starting with ‘find-’ rather than ‘visit-’. See Buffer File Name, for functions and variables that access the visited file name of a buffer or that find an existing buffer by its visited file name.
In a Lisp program, if you want to look at the contents of a file but
not alter it, the fastest way is to use insert-file-contents in a
temporary buffer. Visiting the file is not necessary and takes longer.
See Reading from Files.
This command selects a buffer visiting the file filename, using an existing buffer if there is one, and otherwise creating a new buffer and reading the file into it. It also returns that buffer.
The body of the
find-filefunction is very simple and looks like this:(switch-to-buffer (find-file-noselect filename))(See
switch-to-bufferin Displaying Buffers.)When
find-fileis called interactively, it prompts for filename in the minibuffer.
This function is the guts of all the file-visiting functions. It finds or creates a buffer visiting the file filename, and returns it. It uses an existing buffer if there is one, and otherwise creates a new buffer and reads the file into it. You may make the buffer current or display it in a window if you wish, but this function does not do so.
When
find-file-noselectuses an existing buffer, it first verifies that the file has not changed since it was last visited or saved in that buffer. If the file has changed, then this function asks the user whether to reread the changed file. If the user says ‘yes’, any changes previously made in the buffer are lost.If
find-file-noselectneeds to create a buffer, and there is no file named filename, it displays the message ‘New file’ in the echo area, and leaves the buffer empty.If nowarn is non-
nil, various warnings that SXEmacs normally gives (e.g. if another buffer is already visiting filename but filename has been removed from disk since that buffer was created) are suppressed.The
find-file-noselectfunction callsafter-find-fileafter reading the file (see Subroutines of Visiting). That function sets the buffer major mode, parses local variables, warns the user if there exists an auto-save file more recent than the file just visited, and finishes by running the functions infind-file-hooks.The
find-file-noselectfunction returns the buffer that is visiting the file filename.(find-file-noselect "/etc/fstab") ⇒ #<buffer fstab>
This command selects a buffer visiting the file filename, but does so in a window other than the selected window. It may use another existing window or split a window; see Displaying Buffers.
When this command is called interactively, it prompts for filename.
This command selects a buffer visiting the file filename, like
find-file, but it marks the buffer as read-only. See Read Only Buffers, for related functions and variables.When this command is called interactively, it prompts for filename.
This command visits filename in View mode, and displays it in a recursive edit, returning to the previous buffer when done. View mode is a mode that allows you to skim rapidly through the file but does not let you modify it. Entering View mode runs the normal hook
view-mode-hook. See Hooks.When
view-fileis called interactively, it prompts for filename.With non-
nilprefix arg other-window-p, visit filename in another window.
The value of this variable is a list of functions to be called after a file is visited. The file's local-variables specification (if any) will have been processed before the hooks are run. The buffer visiting the file is current when the hook functions are run.
This variable works just like a normal hook, but we think that renaming it would not be advisable.
The value of this variable is a list of functions to be called when
find-fileorfind-file-noselectis passed a nonexistent file name.find-file-noselectcalls these functions as soon as it detects a nonexistent file. It calls them in the order of the list, until one of them returns non-nil.buffer-file-nameis already set up.This is not a normal hook because the values of the functions are used and they may not all be called.