From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: load-path contains directories or directory names? Date: Sun, 25 Oct 2015 20:39:21 +0200 Message-ID: <83vb9udc86.fsf@gnu.org> References: <86lhauus4x.fsf@stephe-leake.org> <87vb9x42io.fsf@web.de> <867fmcey8k.fsf@stephe-leake.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1445798372 17350 80.91.229.3 (25 Oct 2015 18:39:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Oct 2015 18:39:32 +0000 (UTC) Cc: michael_heerdegen@web.de, emacs-devel@gnu.org To: Stephen Leake Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 25 19:39:23 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZqQCP-0004QX-Vk for ged-emacs-devel@m.gmane.org; Sun, 25 Oct 2015 19:39:22 +0100 Original-Received: from localhost ([::1]:49101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqQCP-0003E4-6d for ged-emacs-devel@m.gmane.org; Sun, 25 Oct 2015 14:39:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqQCL-0003Dz-QV for emacs-devel@gnu.org; Sun, 25 Oct 2015 14:39:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqQCG-0003eS-Mr for emacs-devel@gnu.org; Sun, 25 Oct 2015 14:39:17 -0400 Original-Received: from mtaout29.012.net.il ([80.179.55.185]:34079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqQCG-0003dD-Ey for emacs-devel@gnu.org; Sun, 25 Oct 2015 14:39:12 -0400 Original-Received: from conversion-daemon.mtaout29.012.net.il by mtaout29.012.net.il (HyperSendmail v2007.08) id <0NWS00900GU1NL00@mtaout29.012.net.il> for emacs-devel@gnu.org; Sun, 25 Oct 2015 20:38:33 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([84.94.185.246]) by mtaout29.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NWS00A1CH499B10@mtaout29.012.net.il>; Sun, 25 Oct 2015 20:38:33 +0200 (IST) In-reply-to: <867fmcey8k.fsf@stephe-leake.org> X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.179.55.185 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:192609 Archived-At: Potential bikeshedding alert! > From: Stephen Leake > Date: Sat, 24 Oct 2015 16:46:19 -0500 > Cc: emacs-devel@gnu.org > > "John Wiegley" writes: > > >>>>>> Michael Heerdegen 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.