From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: expand-file-name, DOS/Windows, and directory separator Date: Tue, 15 Feb 2022 12:15:08 -0800 Message-ID: <87sfsjdgz7.fsf@ericabrahamsen.net> References: <87czjodn8m.fsf@ericabrahamsen.net> <87wnhvdim4.fsf@ericabrahamsen.net> <83o8373ntc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33314"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: emacs-devel@gnu.org Cancel-Lock: sha1:KPUdAIMhwBPh7KBwN9AOYPmI1v0= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 15 21:16:24 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nK4FM-0008TM-2D for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Feb 2022 21:16:24 +0100 Original-Received: from localhost ([::1]:57880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nK4FK-00011x-JB for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Feb 2022 15:16:22 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nK4ET-0000Dc-St for emacs-devel@gnu.org; Tue, 15 Feb 2022 15:15:29 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]:54512) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nK4ES-0005l0-6d for emacs-devel@gnu.org; Tue, 15 Feb 2022 15:15:29 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nK4EO-0007Ka-Q0 for emacs-devel@gnu.org; Tue, 15 Feb 2022 21:15:24 +0100 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:286350 Archived-At: Eli Zaretskii writes: >> From: Eric Abrahamsen >> 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-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