GNU bug report logs -
#56355
29.0.50; Implement file-parent-directory
Previous Next
Reported by: daanturo <daanturo <at> gmail.com>
Date: Sat, 2 Jul 2022 11:07:01 UTC
Severity: normal
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 56355 <at> debbugs.gnu.org (full text, mbox):
> > Thanks, but it looks as a very thin wrapper around
> > file-name-directory, so I wonder whether we really
> > need a separate function fir this.
Need? How easy is it for a user to find and figure
out that a combination of `file-name-directory',
`directory-file-name', and `expand-file-name' can
give you the parent directory name?
Maybe your "we" is focused mainly on Emacs developers?
Such a function is helpful for users more generally,
even if not for those with greater familiarity with
the available set of functions.
And yes, how to do this has been asked multiple times
by users. Here's one such:
https://emacs.stackexchange.com/q/9554/105
> I think it looks like a handy utility function -- we have quite a few
> instances of (file-name-directory (directory-file-name filename))
>
> (possibly with an expand-file-name in there, too) and using
> `file-parent-directory' would both express the intention of the code
> better, and be less error prone (because many people forget the
> `directory-file-name' in the first attempt).
I proposed it long, long ago. This version, from
Dired+, allows an optional argument to return the
relative name, i.e., just the parent component.
(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))))
This bug report was last modified 2 years and 316 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.