From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: abbreviate-file-name on Windows seems incorrect Date: Fri, 5 Jan 2007 23:56:45 -0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1168070264 32483 80.91.229.12 (6 Jan 2007 07:57:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 6 Jan 2007 07:57:44 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 06 08:57:43 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1H36Qw-0000a2-8b for ged-emacs-devel@m.gmane.org; Sat, 06 Jan 2007 08:57:42 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H36Qv-00071D-TK for ged-emacs-devel@m.gmane.org; Sat, 06 Jan 2007 02:57:41 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H36Ql-000718-FD for emacs-devel@gnu.org; Sat, 06 Jan 2007 02:57:31 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H36Qi-00070w-VI for emacs-devel@gnu.org; Sat, 06 Jan 2007 02:57:30 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H36Qi-00070t-Pu for emacs-devel@gnu.org; Sat, 06 Jan 2007 02:57:28 -0500 Original-Received: from [148.87.113.118] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1H36Qi-0006Ot-6A for emacs-devel@gnu.org; Sat, 06 Jan 2007 02:57:28 -0500 Original-Received: from rgmgw1.us.oracle.com (rgmgw1.us.oracle.com [138.1.186.110]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id l067vPan006584 for ; Sat, 6 Jan 2007 00:57:25 -0700 Original-Received: from rcsmt251.oracle.com (rcsmt251.oracle.com [148.87.90.196]) by rgmgw1.us.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l067bCm0025101 for ; Sat, 6 Jan 2007 00:57:25 -0700 Original-Received: from dhcp-amer-rmdc-csvpn-gw4-141-144-102-221.vpn.oracle.com by rcsmt250.oracle.com with ESMTP id 2343040471168070211; Sat, 06 Jan 2007 00:56:51 -0700 Original-To: "Emacs-Devel" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 Importance: Normal X-Whitelist: TRUE X-Whitelist: TRUE X-Brightmail-Tracker: AAAAAQAAAAI= X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:64865 Archived-At: On MS Windows, my $HOME is "c:\\". That is what is returned by (getenv "HOME"), and that is what I see in Windows itself, in the list of environment vars. The code for `abbreviate-file-name' defines `abbreviated-home-dir' as follows, in order to be able to "substitute `~' for the user's home directory", as the doc string says: (or abbreviated-home-dir (setq abbreviated-home-dir (let ((abbreviated-home-dir "$foo")) (concat "^" (abbreviate-file-name (expand-file-name "~")) "\\(/\\|\\'\\)")))) The comment for this code is as follows, which indicates that a slash is added to distinguish the home dir from a file in that dir: ;; We include a slash at the end, to avoid spurious matches ;; such as `/usr/foobar' when the home dir is `/usr/foo'. However, that is improper for a Windows home directory such as mine (not an uncommon value). (expand-file-name "~") returns "c:/", which is correct, but the result for `abbreviated-home-dir' becomes "^c:/\\(/\\|\\'\\)", which is incorrect and useless, AFAICT. It should be something like "^c:\\(/\\|\\'\\)", I would think. I would expect (abbreviate-file-name "c:/foo/bar") to return "~/foo/bar", but it returns "c:/foo/bar". If `abbreviated-home-dir' were "^c:\\(/\\|\\'\\)", then the result would be correct: "~/foo/bar". I'm not sure exactly what the resulting regexp should be or how it should be constructed. "^c:\\(/\\|\\'\\)" works for "c:/foo/bar" (returning "~/foo/bar"), but not for "c:/" (it returns "c:/", not "~"). The point is that I don't see how the current regexp could ever work for a Windows $HOME that starts with a drive letter. This seems like a bug, to me. This behavior is the same in Emacs 20, 21, and 22, but I think it is wrong. Since `abbreviate-file-name' is used a lot, I imagine that the code that uses it must be compensating for this bug somehow when it comes to Windows, or else there are other, dependent bugs lurking elsewhere. (?) I want to be able to do, for instance, (abbreviate-file-name (expand-file-name "~/WHATEVER")), and have it work normally on Windows, returning "~/WHATEVER". It currently does not - it returns "c:/WHATEVER" instead. It should also work for empty WHATEVER, of course (i.e. "~/" and "~").