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 the buffer is renamed according to
uniquify-buffer-name-style 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.
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,
(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 the buffer is renamed according to
`uniquify-buffer-name-style' 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 (directory-file-name filename)))
(lastname (if (string= lastname "") ; FILENAME is a root directory
filename lastname))
(lastname (cond
((not (and uniquify-trailing-separator-p
(file-directory-p filename)))
lastname)
((eq uniquify-buffer-name-style 'forward)
(file-name-as-directory lastname))
((eq uniquify-buffer-name-style 'reverse)
(concat (or uniquify-separator "\\") lastname))
(t lastname)))
(basename (if (string-prefix-p " " lastname)
(concat "|" lastname)
lastname))
(buf (generate-new-buffer basename)))
(uniquify--create-file-buffer-advice buf filename basename)
buf))