From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: $USERPROFILE for $HOME on W32 Date: Thu, 25 Nov 2004 11:00:39 -0500 Message-ID: <87mzx69bkn.fsf-monnier+emacs@gnu.org> References: <87vfbycsgj.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1101398740 19510 80.91.229.6 (25 Nov 2004 16:05:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 25 Nov 2004 16:05:40 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 25 17:05:31 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CXM42-0006u5-00 for ; Thu, 25 Nov 2004 17:01:46 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CXMDF-0005na-7E for ged-emacs-devel@m.gmane.org; Thu, 25 Nov 2004 11:11:17 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CXMCQ-0005c7-Im for emacs-devel@gnu.org; Thu, 25 Nov 2004 11:10:26 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CXMCP-0005b8-Fd for emacs-devel@gnu.org; Thu, 25 Nov 2004 11:10:25 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CXMCP-0005ay-7S for emacs-devel@gnu.org; Thu, 25 Nov 2004 11:10:25 -0500 Original-Received: from [209.226.175.184] (helo=tomts22-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CXM2y-0000QO-GA; Thu, 25 Nov 2004 11:00:40 -0500 Original-Received: from alfajor ([65.92.240.220]) by tomts22-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20041125160039.SUKL1919.tomts22-srv.bellnexxia.net@alfajor>; Thu, 25 Nov 2004 11:00:39 -0500 Original-Received: by alfajor (Postfix, from userid 1000) id 9A2AED73CB; Thu, 25 Nov 2004 11:00:39 -0500 (EST) Original-To: Jason Rumney In-Reply-To: (Jason Rumney's message of "Mon, 22 Nov 2004 08:44:26 +0000") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) 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: main.gmane.org gmane.emacs.devel:30347 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:30347 Here is a new patch. Could people try it out and tell me if it works? And tell me how to fix it (I can't try it out, I wish someone could help me out, really, because coding and debugging blindly like that isn't much fun). Stefan Index: src/w32.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/w32.c,v retrieving revision 1.89 diff -u -r1.89 w32.c --- src/w32.c 19 Oct 2004 19:08:58 -0000 1.89 +++ src/w32.c 25 Nov 2004 16:03:01 -0000 @@ -1,5 +1,5 @@ /* Utility and Unix shadow routines for GNU Emacs on the Microsoft W32 API. - Copyright (C) 1994, 1995, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1994, 1995, 2000, 2001, 2004 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -424,7 +424,12 @@ getpwuid (int uid) { if (uid == the_passwd.pw_uid) - return &the_passwd; + { + /* Set dir and shell from environment variables. */ + strcpy (the_passwd.pw_dir, getenv ("HOME")); + strcpy (the_passwd.pw_shell, getenv ("SHELL")); + return &the_passwd; + } return NULL; } @@ -531,16 +536,6 @@ the_passwd.pw_gid = 123; } - /* Ensure HOME and SHELL are defined. */ - if (getenv ("HOME") == NULL) - abort (); - if (getenv ("SHELL") == NULL) - abort (); - - /* Set dir and shell from environment variables. */ - strcpy (the_passwd.pw_dir, getenv ("HOME")); - strcpy (the_passwd.pw_shell, getenv ("SHELL")); - if (token) CloseHandle (token); } @@ -949,11 +944,9 @@ char * def_value; } env_vars[] = { - {"HOME", "C:/"}, {"PRELOAD_WINSOCK", NULL}, {"emacs_dir", "C:/emacs"}, {"EMACSLOADPATH", "%emacs_dir%/site-lisp;%emacs_dir%/../site-lisp;%emacs_dir%/lisp;%emacs_dir%/leim"}, - {"SHELL", "%emacs_dir%/bin/cmdproxy.exe"}, {"EMACSDATA", "%emacs_dir%/etc"}, {"EMACSPATH", "%emacs_dir%/bin"}, /* We no longer set INFOPATH because Info-default-directory-list Index: lisp/w32-fns.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/w32-fns.el,v retrieving revision 1.54 diff -u -r1.54 w32-fns.el --- lisp/w32-fns.el 30 May 2004 21:19:06 -0000 1.54 +++ lisp/w32-fns.el 25 Nov 2004 16:03:01 -0000 @@ -195,6 +195,28 @@ (goto-char (point-min))) + +(defun w32-early-setenv () + "Setup sane default values for important environment variables." + (unless (getenv "HOME") + ;; Try to use $USERPROFILE if $HOME isn't properly set. + (setenv "HOME" + (cond + ((or (file-readable-p "C:/.emacs") (file-readable-p "C:/_emacs")) + ;; Backward compatibility with old default of "C:/". + "C:/") + ((and (getenv "USERPROFILE") + (file-writable-p (getenv "USERPROFILE"))) + (getenv "USERPROFILE")) + ((and (getenv "HOMEPATH") (getenv "HOMEDRIVE") + (file-writable-p + (expand-file-name (getenv "HOMEPATH") (getenv "HOMEDRIVE")))) + (expand-file-name (getenv "HOMEPATH") (getenv "HOMEDRIVE"))) + (t "C:/")))) + (unless (getenv "SHELL") + ;; When is %emacs_dir% expanded? Should I do it here? + (setenv "SHELL" "%emacs_dir%/bin/cmdproxy.exe"))) + ;;; Setup Info-default-directory-list to include the info directory ;;; near where Emacs executable was installed. We used to set INFOPATH, ;;; but when this is set Info-default-directory-list is ignored. We @@ -454,5 +476,5 @@ (setq interprogram-paste-function 'x-get-selection-value) -;;; arch-tag: c49b48cc-0f4f-454f-a274-c2dc34815e14 +;; arch-tag: c49b48cc-0f4f-454f-a274-c2dc34815e14 ;;; w32-fns.el ends here Index: lisp/startup.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.333 diff -u -r1.333 startup.el --- lisp/startup.el 17 Oct 2004 06:56:40 -0000 1.333 +++ lisp/startup.el 25 Nov 2004 16:03:01 -0000 @@ -340,6 +340,9 @@ (if command-line-processed (message "Back to top level.") (setq command-line-processed t) + (when (memq system-type '(windows-nt)) + ;; Set HOME and SHELL if necessary. + (w32-early-setenv)) ;; Give *Messages* the same default-directory as *scratch*, ;; just to keep things predictable. (let ((dir default-directory)) @@ -1728,5 +1731,5 @@ (setq file (replace-match "/" t t file))) file)) -;;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db +;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db ;;; startup.el ends here