Odpowiedzi:
file-name-directory
robi to, o co prosisz.
Jednak (file-name-directory "/home/sk/parent/")
(z ukośnikiem końcowym) zwraca ten sam katalog, a nie jego element nadrzędny.
Robi to, co myślę, że naprawdę chcesz:
(file-name-directory (directory-file-name "/home/sk/parent/ab.el")) ; => "/home/sk/parent/"
(file-name-directory (directory-file-name "/home/sk/parent/")) ; => "/home/sk/"
(file-name-directory (directory-file-name "/home/sk/parent")) ; => "/home/sk/"
A biblioteka Dired + korzysta z tej funkcji:
(defun diredp-parent-dir (file &optional relativep)
"Return the parent directory of FILE, or nil if none.
Optional arg RELATIVEP non-nil means return a relative name, that is,
just the parent component."
(let ((parent (file-name-directory (directory-file-name (expand-file-name file))))
relparent)
(when relativep
(setq relparent (file-name-nondirectory (directory-file-name parent))))
(and (not (equal parent file)) (or relparent parent))))
(defun parent-directory (dir)
(unless (equal "/" dir)
(file-name-directory (directory-file-name dir))))
Zaczerpnięte z https://stackoverflow.com/a/14096693/5103881