[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: expand-file-name, DOS/Windows, and directory separator
From: |
Eric Abrahamsen |
Subject: |
Re: expand-file-name, DOS/Windows, and directory separator |
Date: |
Tue, 15 Feb 2022 12:15:08 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Eric Abrahamsen <eric@ericabrahamsen.net>
>> Date: Tue, 15 Feb 2022 11:39:47 -0800
>>
>> >> Can I rely on that behavior?
>> >
>> > I'd rather you didn't. Why do you need such an assumption? Emacs on
>> > Windows can cope with file names that use any style of slashes.
>>
>> This is code dealing with search results in Gnus, and the absolute file
>> names need to be broken up so we can work on their segments. Right now
>> that's done with regexps, which is ugly and fragile, and I'm just
>> looking for the confidence that:
>>
>> (file-name-split (expand-file-name <file> "/"))
>
> file-name-split is one of the functions that support both styles of
> slashes, so you don't need to call expand-file-name at all. (And "/"
> is not really an absolute file name on Windows anyway).
The `expand-file-name' is in there to collapse multiple consecutive
directory separators, which happens in the wild, as `file-name-split'
doesn't do that by itself.
>> Is going to return exactly the segments, no more no less, regardless of
>> the system or separator type or whether there are multiple separators in
>> a row, etc etc. No leftover slashes, no empty strings, all that.
>>
>> (Okay empty strings are fine, I guess `file-name-split' always returns
>> one for absolute file names.)
>
> It would be a bug for file-name-split (or any other file-name-*
> function, really) to fail to recognize the parts of a file name
> depending on the style of slashes. So if you find a case where the
> results depend on the slashes, even without running the file name
> through expand-file-name, please report that as a bug.
I'm not sure, as I wasn't able to test with any confidence. Since the
search results are simply plain strings in a buffer as far as Emacs is
concerned, I wasn't sure if the file name functions would give them any
special treatment. Just running this, where I've doubled the slashes so
as not to raise an error:
(file-name-split "C:\\Users\\eric\\random")
Just returns the whole string. But maybe this is a meaningless test.
This code has to handle all the weirdness of different systems and
filesystem layouts and search engines, so I'm being a little paranoid
about it.
Thanks,
Eric
- expand-file-name, DOS/Windows, and directory separator, Eric Abrahamsen, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator, Stefan Monnier, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator, Eric Abrahamsen, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator, Eli Zaretskii, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator,
Eric Abrahamsen <=
- Re: expand-file-name, DOS/Windows, and directory separator, Eli Zaretskii, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator, Eric Abrahamsen, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator, Stefan Monnier, 2022/02/15
- Re: expand-file-name, DOS/Windows, and directory separator, Eric Abrahamsen, 2022/02/15
Re: expand-file-name, DOS/Windows, and directory separator, Eli Zaretskii, 2022/02/15