From: Karl Fogel <kfogel@red-bean.com>
To: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Cc: "Stephen J. Turnbull" <stephen@xemacs.org>,
Stefan Monnier <monnier@iro.umontreal.ca>,
emacs-devel@gnu.org
Subject: Re: how having the basename of a file or directory
Date: Mon, 31 Jan 2011 11:43:23 -0500 [thread overview]
Message-ID: <87lj2158ic.fsf@red-bean.com> (raw)
In-Reply-To: <87y6613ujh.fsf@gmail.com> (Thierry Volpiatto's message of "Mon, 31 Jan 2011 17:30:26 +0100")
I think Thierry's point is that it would be useful for Emacs to have a
function called "basename", that does what functions of similar name do
in other programming language standard libraries and in the shell.
FWIW, I agree. Many times I've done an Apropos search on "basename",
only to remember that there's some complicated recipe involving
`file-name-nondirectory' (which I then go look up).
Now, what the exact behavior of `basename' should be is open to debate.
Perhaps it should be:
(defun basename (path)
(file-name-nondirectory (directory-file-name path)))
Or perhaps it should be:
(defun basename (path)
(thing-thierry-recently-defined))
Or perhaps something else.
Can we treat the two questions separately, though? If we agree that
having something called `basename' in Emacs Lisp would be good, then we
can probably quickly agree on exactly how it should behave, so let's
start with the first question: should we have `basename'?
-Karl
Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> Yes thanks, that's work too, but it would be nice to do not have to take
>>> care of that:
>>
>>> (file-name-nondirectory "path/to/a/directory")
>>> should return ==> directory
>>
>> It does.
>>
>>> (file-name-nondirectory "path/to/a/file")
>>> should return ==> file
>>
>> It does.
>>
>>> So modifying `file-name-nondirectory' or creating a basename function
>>> or macro like:
>>
>>> (defun basename (fname)
>>> (if (file-directory-p fname)
>>> (let ((dirname (directory-file-name fname)))
>>> (file-name-nondirectory dirname))
>>> (file-name-nondirectory fname)))
>>
>> That won't work on (basename "/non/existing/thing/").
>> You really want to use (file-name-nondirectory (directory-file-name fname))
>Indeed, yes, thanks Stefan, but something like
>
>
>(defun basename (fname)
> (if (or (file-directory-p fname)
> (string-match "/$" fname))
> (let ((dirname (directory-file-name fname)))
> (file-name-nondirectory dirname))
> (file-name-nondirectory fname)))
>
>would work and be useful.
next prev parent reply other threads:[~2011-01-31 16:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-31 7:25 how having the basename of a file or directory Thierry Volpiatto
2011-01-31 8:30 ` Stephen J. Turnbull
2011-01-31 8:59 ` Thierry Volpiatto
2011-01-31 10:28 ` Andreas Schwab
2011-01-31 11:03 ` Thierry Volpiatto
2011-01-31 12:07 ` Andreas Schwab
2011-01-31 12:19 ` Thierry Volpiatto
2011-01-31 12:53 ` Andreas Schwab
2011-01-31 15:29 ` Stefan Monnier
2011-01-31 16:30 ` Thierry Volpiatto
2011-01-31 16:43 ` Karl Fogel [this message]
2011-01-31 19:53 ` Stefan Monnier
2011-01-31 20:39 ` Thierry Volpiatto
2011-02-01 11:55 ` Stephen J. Turnbull
2011-02-01 15:37 ` Karl Fogel
2011-02-01 16:26 ` Stephen J. Turnbull
2011-02-01 16:52 ` Karl Fogel
2011-02-02 12:27 ` Stephen J. Turnbull
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lj2158ic.fsf@red-bean.com \
--to=kfogel@red-bean.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=stephen@xemacs.org \
--cc=thierry.volpiatto@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).