all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Stephen Leake <stephen_leake@stephe-leake.org>
Cc: michael_heerdegen@web.de, emacs-devel@gnu.org
Subject: Re: load-path contains directories or directory names?
Date: Sun, 25 Oct 2015 20:39:21 +0200	[thread overview]
Message-ID: <83vb9udc86.fsf@gnu.org> (raw)
In-Reply-To: <867fmcey8k.fsf@stephe-leake.org>

Potential bikeshedding alert!

> From: Stephen Leake <stephen_leake@stephe-leake.org>
> Date: Sat, 24 Oct 2015 16:46:19 -0500
> Cc: emacs-devel@gnu.org
> 
> "John Wiegley" <address@hidden> writes:
> 
> >>>>>> Michael Heerdegen <address@hidden> writes:
> >
> >> I try to avoid string operations on file names.
> >> In the above case, using
> >>   (expand-file-name name dir)
> >> seems cleaner to me.

I'm with John on this one, see below for reasons.

> (info "(elisp) Directory Names" says to use:
> 
> (concat DIRNAME RELFILE)

No, it says you CAN use that.  And it continues:

  Be sure to verify that the file name is relative before doing that.  If
  you use an absolute file name, the results could be syntactically
  invalid or refer to the wrong file.

which all but explains why using 'concat' is less desirable than using
'expand-file-name': the code will be more complicated because it needs
to call another function if the directory name doesn't end in a slash.

Also, 'expand-file-name' transparently treats a nil correctly.

In addition, on MS-Windows 'expand-file-name' converts all backslashes
to forward slashes, thus producing nicer and more "standard" results.

> So if I'm iterating thru a path that is defined to contain directory
> names (as `load-path' is, but see other email), this code is correct:
> 
> (concat dir name)
> 
> However, if the path contains directory file names (as
> `load-path' is implemented), then this code is correct:
> 
> (concat (file-name-as-directory dir) filename)
> 
> However, `file-name-as-directory' tolerates ending slashes or not in
> `dir', so the latter code is robust against people putting the wrong
> things in the path.
> 
> Same for `expand-file-name' of course.

Exactly.  So I think 'expand-file-name' is a (slightly) better
alternative in these cases.



  parent reply	other threads:[~2015-10-25 18:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23  4:26 load-path contains directories or directory names? Stephen Leake
2015-10-23  7:25 ` Eli Zaretskii
2015-10-23 14:01   ` Stephen Leake
2015-10-23 22:57 ` Michael Heerdegen
2015-10-24  1:00   ` John Wiegley
2015-10-24 21:46     ` Stephen Leake
2015-10-24 22:48       ` Michael Heerdegen
2015-10-25 18:39       ` Eli Zaretskii [this message]
2015-10-25 19:02         ` John Wiegley
2015-10-25 19:08           ` Eli Zaretskii
2015-10-25 19:12             ` John Wiegley
2015-10-25 21:58               ` Drew Adams
2015-10-26 13:27               ` Stephen Leake
2015-10-26 13:46         ` Stephen Leake
2015-10-26 16:29           ` Eli Zaretskii

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83vb9udc86.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=stephen_leake@stephe-leake.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.