Subject: bug#16087: Setting HOME environment variable in Emacs on Windows has side effects

From: Eli Zaretskii <[email-masked]>
Date: Sun, 08 Dec 2013 19:38:41 +0200

> Date: Sat, 07 Dec 2013 15:45:01 -0500
> From: SDS <[email-masked]>
> 
> When running "emacs.exe -Q" for precompiled Emacs binaries on Windows, 
> and after setting the HOME environment variable to a path different than 
> the registry's HKCU\SOFTWARE\GNU\Emacs\HOME, attempting to access the 
> old HOME directory returns the new HOME directory.

This is in no way specific to Windows.  I tried similar steps on
GNU/Linux, and saw very similar signs of trouble.  Of course, there's
no registry on Unix, but it is enough to start with step #2.

> The steps to reproduce the bug are as follows:
> 1) Set the registry key "HKCU\SOFTWARE\GNU\Emacs\HOME" to "C:\Old\Home"
> 2) Run "emacs.exe -Q"
> 3) In a scratch buffer, evaluate "(setenv "HOME" "C:/New/Home")"
> 4) Using Dired (C-x d), open "C:\Old\Home"
> 5) The directory in the new Dired buffer is "C:\New\Home"

FWIW, I wouldn't expect this to work.  Every buffer has its default
directory stored as a string in its buffer object.  If you change
where the home directory points to, most, if not all, of these
directories will become invalid, because their expansions, which
always go through "~" if possible, will not exist, except by chance.
And Emacs uses the default directories of the buffers freely when it
manipulates file names.

OTOH, the use case for supporting such a strange change in the middle
of an Emacs session is entirely not clear to me.  On the contrary, it
seems to me like doing this is asking for a lot of trouble, and not
only in Emacs (because 'setenv' modifies process-environment, so every
subprocess will get this new value of HOME, so, e.g., the shell will
not find its init files). Could you please describe why you needed
this?