Function: create-file-buffer

create-file-buffer is a byte-compiled function defined in files.el.gz.

Signature

(create-file-buffer FILENAME)

Documentation

Create a suitably named buffer for visiting FILENAME, and return it.

FILENAME (sans directory) is used unchanged if that name is free; otherwise a string <2> or <3> or ... is appended to get an unused name.

Emacs treats buffers whose names begin with a space as internal buffers. To avoid confusion when visiting a file whose name begins with a space, this function prepends a "|" to the final result if necessary.

View in manual

Probably introduced at or before Emacs version 18.

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
;; FIXME we really need to fold the uniquify stuff in here by default,
;; not using advice, and add it to the doc string.
(defun create-file-buffer (filename)
  "Create a suitably named buffer for visiting FILENAME, and return it.
FILENAME (sans directory) is used unchanged if that name is free;
otherwise a string <2> or <3> or ... is appended to get an unused name.

Emacs treats buffers whose names begin with a space as internal buffers.
To avoid confusion when visiting a file whose name begins with a space,
this function prepends a \"|\" to the final result if necessary."
  (let* ((lastname (file-name-nondirectory filename))
	 (lastname (if (string= lastname "")
                       filename lastname))
	 (buf (generate-new-buffer (if (string-prefix-p " " lastname)
                                       (concat "|" lastname)
                                     lastname))))
    (uniquify--create-file-buffer-advice buf filename)
    buf))