Function: file-name-parent-directory
file-name-parent-directory is a byte-compiled function defined in
compat-29.el.
Signature
(file-name-parent-directory FILENAME)
Documentation
[Compatibility function for file-name-parent-directory, defined in Emacs
29.1. See (compat) Emacs 29.1' for more details.]
Return the directory name of the parent directory of FILENAME. If FILENAME is
at the root of the filesystem, return nil. If FILENAME is relative, it is
interpreted to be relative to default-directory, and the result will also be
relative.
Source Code
;; Defined in ~/.emacs.d/elpa/compat-30.1.0.1/compat-29.el
(compat-defun file-name-parent-directory (filename) ;; <compat-tests:file-name-parent-directory>
"Return the directory name of the parent directory of FILENAME.
If FILENAME is at the root of the filesystem, return nil.
If FILENAME is relative, it is interpreted to be relative
to `default-directory', and the result will also be relative."
(let* ((expanded-filename (expand-file-name filename))
(parent (file-name-directory (directory-file-name expanded-filename))))
(cond
;; filename is at top-level, therefore no parent
((or (null parent)
;; `equal' is enough, we don't need to resolve symlinks here
;; with `file-equal-p', also for performance
(equal parent expanded-filename))
nil)
;; filename is relative, return relative parent
((not (file-name-absolute-p filename))
(file-relative-name parent))
(t
parent))))