Function: find-file

find-file is an interactive and byte-compiled function defined in files.el.gz.

Signature

(find-file FILENAME &optional WILDCARDS)

Documentation

Edit file FILENAME.

Switch to a buffer visiting file FILENAME, creating one if none already exists. Interactively, the default if you just type RET is the current directory, but the visited file name is available through the minibuffer history: type M-n (next-history-element) to pull it into the minibuffer.

The first time M-n (next-history-element) is used after Emacs prompts for the file name, the result is affected by file-name-at-point-functions, which by default try to guess the file name by looking at point in the current buffer. Customize the value of file-name-at-point-functions or set it to nil, if you want only the visited file name and the current directory to be available on first M-n (next-history-element) request.

You can visit files on remote machines by specifying something like /ssh:SOME_REMOTE_MACHINE:FILE for the file name. You can also visit local files as a different user by specifying
/sudo::FILE for the file name.
See the Info node (tramp)File name Syntax in the Tramp Info manual, for more about this.

Interactively, or if WILDCARDS is non-nil in a call from Lisp, expand wildcards (if any) and visit multiple files. You can suppress wildcard expansion by setting find-file-wildcards to nil.

To visit a file without any kind of conversion and without automatically choosing a major mode, use M-x find-file-literally (find-file-literally).

Other relevant functions are documented in the file group.

Probably introduced at or before Emacs version 1.5.

Key Bindings

Shortdoc

;; file
(find-file "/tmp/foo")
    e.g. => #<buffer foo>

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun find-file (filename &optional wildcards)
  "Edit file FILENAME.
\\<minibuffer-local-map>Switch to a buffer visiting file FILENAME, creating one if none
already exists.
Interactively, the default if you just type RET is the current directory,
but the visited file name is available through the minibuffer history:
type \\[next-history-element] to pull it into the minibuffer.

The first time \\[next-history-element] is used after Emacs prompts for the file name,
the result is affected by `file-name-at-point-functions', which by
default try to guess the file name by looking at point in the current
buffer.  Customize the value of `file-name-at-point-functions' or set
it to nil, if you want only the visited file name and the current
directory to be available on first \\[next-history-element] request.

You can visit files on remote machines by specifying something
like /ssh:SOME_REMOTE_MACHINE:FILE for the file name.  You can
also visit local files as a different user by specifying
/sudo::FILE for the file name.
See the Info node `(tramp)File name Syntax' in the Tramp Info
manual, for more about this.

Interactively, or if WILDCARDS is non-nil in a call from Lisp,
expand wildcards (if any) and visit multiple files.  You can
suppress wildcard expansion by setting `find-file-wildcards' to nil.

\\<global-map>To visit a file without any kind of conversion and without
automatically choosing a major mode, use \\[find-file-literally]."
  (interactive
   (find-file-read-args "Find file: "
                        (confirm-nonexistent-file-or-buffer)))
  (let ((value (find-file-noselect filename nil nil wildcards)))
    (if (listp value)
	(mapcar 'pop-to-buffer-same-window (nreverse value))
      (pop-to-buffer-same-window value))))