unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* abbreviate-file-name on Windows seems incorrect
@ 2007-01-06  7:56 Drew Adams
  2007-01-06 11:37 ` Lennart Borgman (gmail)
  2007-01-06 11:56 ` Eli Zaretskii
  0 siblings, 2 replies; 26+ messages in thread
From: Drew Adams @ 2007-01-06  7:56 UTC (permalink / raw)


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
"~").

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2007-01-09 17:57 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-06  7:56 abbreviate-file-name on Windows seems incorrect Drew Adams
2007-01-06 11:37 ` Lennart Borgman (gmail)
2007-01-06 14:18   ` Eli Zaretskii
2007-01-06 15:03     ` Lennart Borgman (gmail)
2007-01-06 11:56 ` Eli Zaretskii
2007-01-06 16:22   ` Drew Adams
2007-01-06 21:51     ` Eli Zaretskii
2007-01-06 22:42       ` Drew Adams
2007-01-07  2:44       ` Miles Bader
2007-01-07  4:12         ` Eli Zaretskii
2007-01-07 14:29           ` Stephen Leake
2007-01-07 20:47             ` Eli Zaretskii
2007-01-07 22:03               ` Drew Adams
2007-01-07 22:08                 ` Drew Adams
2007-01-08  1:40                   ` Chris Moore
2007-01-08  2:04                     ` Drew Adams
2007-01-08 10:15                       ` Jason Rumney
2007-01-08 16:29                         ` Drew Adams
2007-01-09  0:01                         ` Richard Stallman
2007-01-09  0:30                           ` Jason Rumney
2007-01-09 12:55                             ` Stephen Leake
2007-01-09 17:57                             ` Richard Stallman
2007-01-08  8:44               ` Stephen Leake
2007-01-08 13:07                 ` Chris Moore
2007-01-08 19:30                 ` Eli Zaretskii
2007-01-09 12:52                   ` Stephen Leake

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).