Subject: bug#4823: w32 paths `substitute-in-file-name' fails when environmental variable is set for \\ style paths:

From: Juanma Barranquero <[email-masked]>
Date: Wed, 28 Oct 2009 22:38:34 +0100

On Wed, Oct 28, 2009 at 21:19, MON KEY <[email-masked]> wrote:

> ;; :SITUATION-1 w/out trailing `\\'

> (substitute-in-file-name "$HOME2\\.emacs")
> ;=> "C:\\home\\me/emacs"

I get "C:\\home\\me/.emacs", which seems correct.

> (substitute-in-file-name "$HOME2/.emacs")
> ;=>"C:\\home\\me/.emacs"
> (substitute-in-file-name "$HOME2.emacs")
> ;=> "C:\\home\\me.emacs"

These seem correct to me.

> ;; :SITUATION-2 with trailing `\\'

> (substitute-in-file-name "$HOME2\\.emacs")
> ;=> "/.emacs"

$HOME2\\.emacs ==> "C:\\home\\me\\\\.emacs" ==> C:\home\me\\.emacs

According to the docstring of `substitute-in-file-name':

  If `//' appears, everything up to and including the first of
  those `/' is discarded.

and \\ (quoted to \\\\) is equivalent to // in w32 filenames (at least
for Emacs).

> (substitute-in-file-name "$HOME2\.emacs")
> ;=> "C:\\home\\me\\.emacs"

$HOME2\.emacs ==> "C:\\home\\me\\\.emacs" ==> C:\home\me\.emacs

so this is correct (remember that "\." == ".").

> (substitute-in-file-name "$HOME2//.emacs")
> ;=> "/.emacs"

This is similar to the \\\\ case above:

$HOME2//.emacs ==> "C:\\home\\me\\//.emacs" ==> C:\home\me\//.emacs

which could arguably be //.emacs, but that does not seem very useful.

> (substitute-in-file-name "$HOME2.emacs")
> ;=> "C:\\home\\me\\.emacs"

That seems correct.

What where you expecting in each case?

    Juanma