unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
@ 2015-02-28  0:06 Pete Williamson
  2015-02-28  8:08 ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Pete Williamson @ 2015-02-28  0:06 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 978 bytes --]

I'm porting Emacs to run on NaCl (Chrome Native Client) and the Chromebook.
 (You can see slides about this in the FOSDEM 2015 archives).

The NaCl platform does not support expanding the "~user" syntax for
filenames (where user is the name of the logged in user), but it does
support expanding "~" in filenames when looking for the init.el file.

I've made a patch to startup.el to check in "~" for .emacs.d/init.el if it
is not found in "~user".  Is taking this patch a good idea?  I'm not sure
how much emacs should adapt to the platform, and how much should be done in
a private patch that does not affect other platforms, and I would be
grateful for any guidance.

Currently for the NaCl port, we have a patch in naclports which does OS
specific fixes, and I can leave this patch in naclports if that is thought
by others to be a better place, or I would be happy to contribute it back
to Gnu if it is seen as generally useful.

All comments on the patch welcome.

Thanks!

[-- Attachment #1.2: Type: text/html, Size: 1175 bytes --]

[-- Attachment #2: 0001-Allow-expansion-of-bare-tilde-when-looking-for-.emac.patch --]
[-- Type: text/x-patch, Size: 2297 bytes --]

From 05f9b47226f2653c88818d22f9ec81c59ad53c55 Mon Sep 17 00:00:00 2001
From: Pete Williamson <petewil@chromium.org>
Date: Fri, 27 Feb 2015 15:47:34 -0800
Subject: [PATCH] Allow expansion of bare tilde when looking for .emacs file

On some systems, the shortcut "~user" is not expanded properly, but "~" is.
So, I added code in startup.el to check first for ~user/.emacs.d/init.el,
and if that is not found, to then try ~/.emacs.d/init.el.
---
 ChangeLog       |  6 ++++++
 lisp/startup.el | 16 ++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0bfdfbb..243dd4b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-27 Pete Williamson <petewil@chromium.org>
+
+	To find the .emacs file, check both ~user/.emacs.d and ~/.emacs.d
+	* lisp/startup.el: If The system does not support expanding ~user,
+	try expanding ~ when looking for the .emacs.d/init.el file.
+
 2015-02-27  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Don't require GNU putenv
diff --git a/lisp/startup.el b/lisp/startup.el
index 999e53e..c0d6059 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1105,14 +1105,22 @@ please check its value")
 		      (load user-init-file-1 t t)
 
 		      (when (eq user-init-file t)
-			;; If we did not find ~/.emacs, try
-			;; ~/.emacs.d/init.el.
+			;; If we did not find ~<user>/.emacs or ~/.emacs, try
+			;; ~<user>/.emacs.d/init.el or ~/.emacs.d/init.el
 			(let ((otherfile
 			       (expand-file-name
 				"init"
 				(file-name-as-directory
-				 (concat "~" init-file-user "/.emacs.d")))))
-			  (load otherfile t t)
+				 (concat "~" init-file-user "/.emacs.d"))))
+                              ;; Generate a filename for ~/.emacs.d/init.el.
+                              (otherfile-tilde-only
+                               (expand-file-name
+                                "init"
+                                (file-name-as-directory "~/.emacs.d"))))
+			  (when (nilp (load otherfile t t))
+                            ;; If ~<user>/.emacs.d/init.el was not found, try
+                            ;; ~/.emacs.d/init.el
+                            (load otherfile-tilde-only t t))
 
 			  ;; If we did not find the user's init file,
 			  ;; set user-init-file conclusively.
-- 
2.2.0.rc0.207.ga3a616c


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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-02-28  0:06 [PATCH] for review - Allow expansion of "~" (as opposed to "~user") Pete Williamson
@ 2015-02-28  8:08 ` Eli Zaretskii
  2015-03-02  9:44   ` Michal Nazarewicz
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2015-02-28  8:08 UTC (permalink / raw)
  To: Pete Williamson; +Cc: emacs-devel

> Date: Fri, 27 Feb 2015 16:06:02 -0800
> From: Pete Williamson <petewil@google.com>
> 
> I'm porting Emacs to run on NaCl (Chrome Native Client) and the Chromebook.
> (You can see slides about this in the FOSDEM 2015 archives).
> 
> The NaCl platform does not support expanding the "~user" syntax for filenames
> (where user is the name of the logged in user), but it does support expanding
> "~" in filenames when looking for the init.el file.
> 
> I've made a patch to startup.el to check in "~" for .emacs.d/init.el if it is
> not found in "~user". Is taking this patch a good idea? I'm not sure how much
> emacs should adapt to the platform, and how much should be done in a private
> patch that does not affect other platforms, and I would be grateful for any
> guidance.
> 
> Currently for the NaCl port, we have a patch in naclports which does OS
> specific fixes, and I can leave this patch in naclports if that is thought by
> others to be a better place, or I would be happy to contribute it back to Gnu
> if it is seen as generally useful.
> 
> All comments on the patch welcome.

Simply reuse for NaCl what we already do for MS-Windows:

        (if (file-directory-p (expand-file-name
                               ;; We don't support ~USER on MS-Windows
                               ;; and MS-DOS except for the current
                               ;; user, and always load .emacs from
                               ;; the current user's home directory
                               ;; (see below).  So always check "~",
                               ;; even if invoked with "-u USER", or
                               ;; if $USER or $LOGNAME are set to
                               ;; something different.
                               (if (memq system-type '(windows-nt ms-dos))
                                   "~"
                                 (concat "~" init-file-user))))

If you still need something beyond that, please explain why, as the
situation you describe seems to be identical to what happens on
MS-Windows.



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-02-28  8:08 ` Eli Zaretskii
@ 2015-03-02  9:44   ` Michal Nazarewicz
  2015-03-02 13:50     ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Michal Nazarewicz @ 2015-03-02  9:44 UTC (permalink / raw)
  To: Eli Zaretskii, Pete Williamson; +Cc: emacs-devel

On Sat, Feb 28 2015, Eli Zaretskii wrote:
>> Date: Fri, 27 Feb 2015 16:06:02 -0800
>> From: Pete Williamson <petewil@google.com>
>> 
>> I'm porting Emacs to run on NaCl (Chrome Native Client) and the Chromebook.
>> (You can see slides about this in the FOSDEM 2015 archives).
>> 
>> The NaCl platform does not support expanding the "~user" syntax for filenames
>> (where user is the name of the logged in user), but it does support expanding
>> "~" in filenames when looking for the init.el file.
>> 
>> I've made a patch to startup.el to check in "~" for .emacs.d/init.el if it is
>> not found in "~user". Is taking this patch a good idea? I'm not sure how much
>> emacs should adapt to the platform, and how much should be done in a private
>> patch that does not affect other platforms, and I would be grateful for any
>> guidance.
>> 
>> Currently for the NaCl port, we have a patch in naclports which does OS
>> specific fixes, and I can leave this patch in naclports if that is thought by
>> others to be a better place, or I would be happy to contribute it back to Gnu
>> if it is seen as generally useful.
>> 
>> All comments on the patch welcome.
>
> Simply reuse for NaCl what we already do for MS-Windows:
>
>         (if (file-directory-p (expand-file-name
>                                ;; We don't support ~USER on MS-Windows
>                                ;; and MS-DOS except for the current
>                                ;; user, and always load .emacs from
>                                ;; the current user's home directory
>                                ;; (see below).  So always check "~",
>                                ;; even if invoked with "-u USER", or
>                                ;; if $USER or $LOGNAME are set to
>                                ;; something different.
>                                (if (memq system-type '(windows-nt ms-dos))
>                                    "~"
>                                  (concat "~" init-file-user))))
>
> If you still need something beyond that, please explain why, as the
> situation you describe seems to be identical to what happens on
> MS-Windows.

Looking at that code, it appears it’s inconsistent on Windows when it
comes to handling ~/.emacs.d/init.el.  If I understand it correctly,
here’s how Emacs behave on Windows:

* emacs        -> load ~/.emacs, ~/_emacs or ~/.emacs.d/init.el
* emacs -u foo -> load ~/.emacs or ~/_emacs

I would expect it to try loading ~/.emacs.d/init.el as well.  Perhaps we
need something along the lines of:

diff --git a/lisp/startup.el b/lisp/startup.el
index 999e53e..5998e62 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1042,6 +1042,22 @@ (defun command-line ()
     ;; the startup screen.
     (setq inhibit-startup-screen nil)
 
+    ;; Load that user's init file, or the default one, or none.
+    (let (debug-on-error-from-init-file
+	  debug-on-error-should-be-set
+	  (debug-on-error-initial
+	   (if (eq init-file-debug t) 'startup init-file-debug))
+	  (orig-enable-multibyte (default-value 'enable-multibyte-characters))
+          (home-dir (expand-file-name
+                     ;; We don't support ~USER on MS-Windows and MS-DOS except
+                     ;; for the current user, and always load .emacs from the
+                     ;; current user's home directory (see below).  So always
+                     ;; check "~", even if invoked with "-u USER", or if $USER
+                     ;; or $LOGNAME are set to something different.
+                     (if (memq system-type '(windows-nt ms-dos))
+                         "~"
+                       (concat "~" init-file-user)))))
+
     ;; Warn for invalid user name.
     (when init-file-user
       (if (string-match "[~/:\n]" init-file-user)
@@ -1049,19 +1065,7 @@ (defun command-line ()
 			   (format "Invalid user name %s"
 				   init-file-user)
 			   :error)
-	(if (file-directory-p (expand-file-name
-			       ;; We don't support ~USER on MS-Windows
-			       ;; and MS-DOS except for the current
-			       ;; user, and always load .emacs from
-			       ;; the current user's home directory
-			       ;; (see below).  So always check "~",
-			       ;; even if invoked with "-u USER", or
-			       ;; if $USER or $LOGNAME are set to
-			       ;; something different.
-			       (if (memq system-type '(windows-nt ms-dos))
-				   "~"
-				 (concat "~" init-file-user))))
-	    nil
+	(unless (file-directory-p home-dir)
 	  (display-warning 'initialization
 			   (format "User %s has no home directory"
 				   (if (equal init-file-user "")
@@ -1069,82 +1073,73 @@ (defun command-line ()
 				     init-file-user))
 			   :error))))
 
-    ;; Load that user's init file, or the default one, or none.
-    (let (debug-on-error-from-init-file
-	  debug-on-error-should-be-set
-	  (debug-on-error-initial
-	   (if (eq init-file-debug t) 'startup init-file-debug))
-	  (orig-enable-multibyte (default-value 'enable-multibyte-characters)))
       (let ((debug-on-error debug-on-error-initial)
 	    ;; This function actually reads the init files.
 	    (inner
 	     (function
 	      (lambda ()
-		(if init-file-user
-		    (let ((user-init-file-1
-			   (cond
-			     ((eq system-type 'ms-dos)
-			      (concat "~" init-file-user "/_emacs"))
-			     ((not (eq system-type 'windows-nt))
-			      (concat "~" init-file-user "/.emacs"))
-			     ;; Else deal with the Windows situation
-			     ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
-			      ;; Prefer .emacs on Windows.
-			      "~/.emacs")
-			     ((directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
-			      ;; Also support _emacs for compatibility, but warn about it.
-			      (push '(initialization
-				      "`_emacs' init file is deprecated, please use `.emacs'")
-				    delayed-warnings-list)
-			      "~/_emacs")
-			     (t ;; But default to .emacs if _emacs does not exist.
-			      "~/.emacs"))))
-		      ;; This tells `load' to store the file name found
-		      ;; into user-init-file.
-		      (setq user-init-file t)
-		      (load user-init-file-1 t t)
-
-		      (when (eq user-init-file t)
-			;; If we did not find ~/.emacs, try
-			;; ~/.emacs.d/init.el.
-			(let ((otherfile
-			       (expand-file-name
-				"init"
-				(file-name-as-directory
-				 (concat "~" init-file-user "/.emacs.d")))))
-			  (load otherfile t t)
-
-			  ;; If we did not find the user's init file,
-			  ;; set user-init-file conclusively.
-			  ;; Don't let it be set from default.el.
-			  (when (eq user-init-file t)
-			    (setq user-init-file user-init-file-1))))
-
-		      ;; If we loaded a compiled file, set
-		      ;; `user-init-file' to the source version if that
-		      ;; exists.
-		      (when (and user-init-file
-				 (equal (file-name-extension user-init-file)
-					"elc"))
-			(let* ((source (file-name-sans-extension user-init-file))
-			       (alt (concat source ".el")))
-			  (setq source (cond ((file-exists-p alt) alt)
-					     ((file-exists-p source) source)
-					     (t nil)))
-			  (when source
-			    (when (file-newer-than-file-p source user-init-file)
-			      (message "Warning: %s is newer than %s"
-				       source user-init-file)
-			      (sit-for 1))
-			    (setq user-init-file source))))
-
-		      (unless inhibit-default-init
-                        (let ((inhibit-startup-screen nil))
-                          ;; Users are supposed to be told their rights.
-                          ;; (Plus how to get help and how to undo.)
-                          ;; Don't you dare turn this off for anyone
-                          ;; except yourself.
-                          (load "default" t t)))))))))
+		(when init-file-user
+                  (let ((user-init-file-1
+                         (cond
+                          ((eq system-type 'ms-dos)
+                           ;; DOS does not support dot files
+                           (concat home-dir "_emacs"))
+                          ((not (eq system-type 'windows-nt))
+                           ;; Everything sane, just use .emacs
+                           (concat home-dir ".emacs"))
+                          ((or (file-exists-p (concat home-dir ".emacs"))
+                               (file-exists-p (concat home-dir ".emacs.elc")))
+                           ;; Prefer .emacs on Windows.
+                           (concat home-dir ".emacs"))
+                          ((or (file-exists-p (concat home-dir "_emacs"))
+                               (file-exists-p (concat home-dir "_emacs.elc")))
+                           ;; Support _emacs for compatibility, but warn.
+                          (push '(initialization
+                                  "`_emacs' init file is deprecated, please use `.emacs'")
+                                delayed-warnings-list)
+                           (concat home-dir "_emacs"))
+                         (t ;; But default to .emacs if _emacs does not exist.
+                          (concat home-dir "_emacs")))))
+                    ;; This tells `load' to store the file name found
+                    ;; into user-init-file.
+                    (setq user-init-file t)
+                    (load user-init-file-1 t t)
+
+                    (when (eq user-init-file t)
+                      (when (eq system-type 'ms-dos)
+                        ;; If we did not find ~/.emacs, try ~/.emacs.d/init.el.
+                        (load (concat "~" home-dir "/.emacs.d/init.el")) t t)
+                      ;; If we did not find the user's init file, set
+                      ;; user-init-file conclusively.  Don't let it be set from
+                      ;; default.el.
+                      (when (eq user-init-file t)
+                        (setq user-init-file user-init-file-1)))
+
+                    ;; If we loaded a compiled file, set
+                    ;; `user-init-file' to the source version if that
+                    ;; exists.
+                    (when (and user-init-file
+                               (equal (file-name-extension user-init-file)
+                                      "elc"))
+                      (let* ((source (file-name-sans-extension user-init-file))
+                             (alt (concat source ".el")))
+                        (setq source (cond ((file-exists-p alt) alt)
+                                           ((file-exists-p source) source)
+                                           (t nil)))
+                        (when source
+                          (when (file-newer-than-file-p source user-init-file)
+                            (message "Warning: %s is newer than %s"
+                                     source user-init-file)
+                            (sit-for 1))
+                          (setq user-init-file source))))
+
+                    (unless inhibit-default-init
+                      (let ((inhibit-startup-screen nil))
+                        ;; Users are supposed to be told their rights.
+                        ;; (Plus how to get help and how to undo.)
+                        ;; Don't you dare turn this off for anyone
+                        ;; except yourself.
+                        (load "default" t t)))))))))
 	(if init-file-debug
 	    ;; Do this without a condition-case if the user wants to debug.
 	    (funcall inner)


This moves the whole checking of ~ vs. ~USER to a single place (where
home-dir is set).

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-02  9:44   ` Michal Nazarewicz
@ 2015-03-02 13:50     ` Eli Zaretskii
  2015-03-02 20:37       ` Michal Nazarewicz
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2015-03-02 13:50 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: petewil, emacs-devel

> From: Michal Nazarewicz <mina86@mina86.com>
> Cc: emacs-devel@gnu.org
> Date: Mon, 02 Mar 2015 10:44:07 +0100
> 
> Looking at that code, it appears it’s inconsistent on Windows when it
> comes to handling ~/.emacs.d/init.el.  If I understand it correctly,
> here’s how Emacs behave on Windows:
> 
> * emacs        -> load ~/.emacs, ~/_emacs or ~/.emacs.d/init.el
> * emacs -u foo -> load ~/.emacs or ~/_emacs

I'm not bothered about the inconsistency, since the "-u foo"
"handling" is a kludge for a situation that shouldn't happen.  I
wouldn't object to emitting an error in that case.

> I would expect it to try loading ~/.emacs.d/init.el as well.  Perhaps we
> need something along the lines of:

I have no opinion about the suggested changes (nor do I object to
them).  But please keep ~USER "supported" on MS-DOS, exactly as it is
now.  I don't want to change anything in that port, unless really
needed.

Thanks.




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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-02 13:50     ` Eli Zaretskii
@ 2015-03-02 20:37       ` Michal Nazarewicz
  2015-03-03 15:37         ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Michal Nazarewicz @ 2015-03-02 20:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: petewil, emacs-devel

On Mon, Mar 02 2015, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Michal Nazarewicz <mina86@mina86.com>
>> Cc: emacs-devel@gnu.org
>> Date: Mon, 02 Mar 2015 10:44:07 +0100
>> 
>> Looking at that code, it appears it’s inconsistent on Windows when it
>> comes to handling ~/.emacs.d/init.el.  If I understand it correctly,
>> here’s how Emacs behave on Windows:
>> 
>> * emacs        -> load ~/.emacs, ~/_emacs or ~/.emacs.d/init.el
>> * emacs -u foo -> load ~/.emacs or ~/_emacs
>
> I'm not bothered about the inconsistency, since the "-u foo"
> "handling" is a kludge for a situation that shouldn't happen.  I
> wouldn't object to emitting an error in that case.

Doesn’t this basically mean doing this:

-       (if (file-directory-p (expand-file-name
-                              ;; We don't support ~USER on MS-Windows
-                              ;; and MS-DOS except for the current
-                              ;; user, and always load .emacs from
-                              ;; the current user's home directory
-                              ;; (see below).  So always check "~",
-                              ;; even if invoked with "-u USER", or
-                              ;; if $USER or $LOGNAME are set to
-                              ;; something different.
-                              (if (memq system-type '(windows-nt ms-dos))
-                                  "~"
-                                (concat "~" init-file-user))))
-           nil
-         (display-warning 'initialization
+       (unless (file-directory-p (expand-file-name
+                                   (concat "~" init-file-user)))
+          (display-warning 'initialization

and then using ~user/… for every system including windows-nt?

If I understand correctly, ~user/… expansion depends on getpwnam and a)
on MS-DOS DJGPP provides it (by having a single pw entry for user ==
current user), b) on W32 src/w32.c provides it (with the same
implementation) and on POSIX we have it properly implemented.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-02 20:37       ` Michal Nazarewicz
@ 2015-03-03 15:37         ` Eli Zaretskii
  2015-03-03 17:48           ` Michal Nazarewicz
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2015-03-03 15:37 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: petewil, emacs-devel

> From: Michal Nazarewicz <mina86@mina86.com>
> Cc: petewil@google.com, emacs-devel@gnu.org
> Date: Mon, 02 Mar 2015 21:37:56 +0100
> 
> >> Looking at that code, it appears it’s inconsistent on Windows when it
> >> comes to handling ~/.emacs.d/init.el.  If I understand it correctly,
> >> here’s how Emacs behave on Windows:
> >> 
> >> * emacs        -> load ~/.emacs, ~/_emacs or ~/.emacs.d/init.el
> >> * emacs -u foo -> load ~/.emacs or ~/_emacs
> >
> > I'm not bothered about the inconsistency, since the "-u foo"
> > "handling" is a kludge for a situation that shouldn't happen.  I
> > wouldn't object to emitting an error in that case.
> 
> Doesn’t this basically mean doing this:
> 
> -       (if (file-directory-p (expand-file-name
> -                              ;; We don't support ~USER on MS-Windows
> -                              ;; and MS-DOS except for the current
> -                              ;; user, and always load .emacs from
> -                              ;; the current user's home directory
> -                              ;; (see below).  So always check "~",
> -                              ;; even if invoked with "-u USER", or
> -                              ;; if $USER or $LOGNAME are set to
> -                              ;; something different.
> -                              (if (memq system-type '(windows-nt ms-dos))
> -                                  "~"
> -                                (concat "~" init-file-user))))
> -           nil
> -         (display-warning 'initialization
> +       (unless (file-directory-p (expand-file-name
> +                                   (concat "~" init-file-user)))
> +          (display-warning 'initialization
> 
> and then using ~user/… for every system including windows-nt?

Not exactly.  First, we had what you suggest before 1df1e49eb, so
going back to that code means re-introducing the problem it solved.

Second, it's not really nice to have init-file-user have the value of,
say, "~bob/.emacs", when Emacs was invoked with "-u bob", whereas in
fact we loaded "C:/fred's-home/.emacs".  It's a lie, and one that's
tricky to untangle: you need to know that to get a _real_ file name,
you need to run it through expand-file-name.  If you don't, things
will subtly fail, e.g., if you compare this with some other file name.

So I'd rather we either errored out with such invocation, or fixed the
value to not lie, as we do now.

> If I understand correctly, ~user/… expansion depends on getpwnam and a)
> on MS-DOS DJGPP provides it (by having a single pw entry for user ==
> current user), b) on W32 src/w32.c provides it (with the same
> implementation) and on POSIX we have it properly implemented.

Approximately true, but not entirely.  w32.c's emulation of getpwnam
only recognizes the actual name of the current user of the Windows
session, while the DJGPP version allows to "customize" the user by
setting environment variables.  So "-u USER" on Windows will only work
if USER is identical to the current user, while on DOS we can have
other "users" by tweaking the environment.

Another important piece of the puzzle is that if USER is not
recognized as a valid user by the getpwnam emulation on
MS-Windows/MS-DOS, you get this:

  (expand-file-name "~USER") => /current/directory/~USER

And it is possible to have a literal "~USER" directory, in which case
the warning will be incorrectly skipped.




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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 15:37         ` Eli Zaretskii
@ 2015-03-03 17:48           ` Michal Nazarewicz
  2015-03-03 18:09             ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Michal Nazarewicz @ 2015-03-03 17:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: petewil, emacs-devel

On Tue, Mar 03 2015, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Michal Nazarewicz <mina86@mina86.com>
>> Cc: petewil@google.com, emacs-devel@gnu.org
>> Date: Mon, 02 Mar 2015 21:37:56 +0100
>> 
>> >> Looking at that code, it appears it’s inconsistent on Windows when it
>> >> comes to handling ~/.emacs.d/init.el.  If I understand it correctly,
>> >> here’s how Emacs behave on Windows:
>> >> 
>> >> * emacs        -> load ~/.emacs, ~/_emacs or ~/.emacs.d/init.el
>> >> * emacs -u foo -> load ~/.emacs or ~/_emacs
>> >
>> > I'm not bothered about the inconsistency, since the "-u foo"
>> > "handling" is a kludge for a situation that shouldn't happen.  I
>> > wouldn't object to emitting an error in that case.
>> 
>> Doesn’t this basically mean doing this:
>> 
>> -       (if (file-directory-p (expand-file-name
>> -                              ;; We don't support ~USER on MS-Windows
>> -                              ;; and MS-DOS except for the current
>> -                              ;; user, and always load .emacs from
>> -                              ;; the current user's home directory
>> -                              ;; (see below).  So always check "~",
>> -                              ;; even if invoked with "-u USER", or
>> -                              ;; if $USER or $LOGNAME are set to
>> -                              ;; something different.
>> -                              (if (memq system-type '(windows-nt ms-dos))
>> -                                  "~"
>> -                                (concat "~" init-file-user))))
>> -           nil
>> -         (display-warning 'initialization
>> +       (unless (file-directory-p (expand-file-name
>> +                                   (concat "~" init-file-user)))
>> +          (display-warning 'initialization
>> 
>> and then using ~user/… for every system including windows-nt?
>
> Not exactly.  First, we had what you suggest before 1df1e49eb, so
> going back to that code means re-introducing the problem it solved.

1df1e49eb actually makes sense to me (since windows-nt ignores
`init-file-user' when looking for .emacs) but 5463218ce doesn’t since
ms-dos uses `init-file-user' when looking for _emacs.

> Second, it's not really nice to have init-file-user have the value of,
> say, "~bob/.emacs", when Emacs was invoked with "-u bob", whereas in
> fact we loaded "C:/fred's-home/.emacs".

That does not happen.  If an init file has been loaded, `user-itni-file'
variable *will* point to it.

However, if ‘bob’ is not a valid user, and fred runs Emacs with ‘-u
bob’, `init-file-user' will be "bob" while `user-init-file' will be:

* on Windows: "C:/fred's-home/.emacs"      (if that file exists) or
              "~/.emacs"                   (if it does not);
* on DOS:     "D:/current/dir/~bob/_emacs" (if that file exists) or
              "~bob/_emacs"                (if it does not); and
* on POSIX:   "/current/dir/~bob/.emacs"   (if that file exists) or 
              "~bob/.emacs"                (if it does not).

If ‘bob’ is a valid user with a home directory though, `user-init-file'
will be:

* on Windows: "C:/fred's-home/.emacs"      (if that file exists) or
              "~/.emacs"                   (if it does not);
* on DOS:     "C:/bob's-home/_emacs"       (if that file exists) or
              "~bob/_emacs"                (if it does not); and
* on POSIX:   "/home/bob/.emacs"           (if that file exists) or 
              "~bob/.emacs"                (if it does not).

Furthermore:

* DOS port will check "C:/fred's-home" directory even though it will try
  to load "C:/fred's-home/~bob/_emacs" or "C:/bob's-home/_emacs" file; and
* Windows port will load "C:/fred's-home/.emacs" even if
  "C:/bob's-home/.emacs" or "C:/fred's-home/~bob/.emacs" exists.

> It's a lie, and one that's tricky to untangle: you need to know that
> to get a _real_ file name, you need to run it through
> expand-file-name.  If you don't, things will subtly fail, e.g., if you
> compare this with some other file name.

This is already a problem on *all* systems and it happens if user init
file is not found.  If you run ‘emacs -u foo’ on GNU/Linux, you’ll end
up with `user-init-file" equal to "~foo/.emacs".

> So I'd rather we either errored out with such invocation, or fixed the
> value to not lie, as we do now.
>
>> If I understand correctly, ~user/… expansion depends on getpwnam and a)
>> on MS-DOS DJGPP provides it (by having a single pw entry for user ==
>> current user), b) on W32 src/w32.c provides it (with the same
>> implementation) and on POSIX we have it properly implemented.

> Another important piece of the puzzle is that if USER is not
> recognized as a valid user by the getpwnam emulation on
> MS-Windows/MS-DOS, you get this:
>
>   (expand-file-name "~USER") => /current/directory/~USER
>
> And it is possible to have a literal "~USER" directory, in which case
> the warning will be incorrectly skipped.

This also happens on UNIX-like systems.  Like I’ve said above, if you
run ‘emacs -u foo’ on GNU/Linux, you end up with "~foo/.emacs"
`user-init-file'.  You also end up with ‘User foo has no home directory’
warning.

Based on all that, I think the most consistent option is to:

1) always check if ~USER/ directory exists for the ‘User foo has no home
   directory’ warning;

2) user ~USER/.emacs and ~USER/_emacs on MS-Windows; and

3) use `expand-file-name' when setting `user-init-file' if init file has
   not been loaded.

The below untested patch does that plus stops Emacs from attempting to
load init file if `init-file-user' is ‘invalid’, i.e. contains ~, /, :
or \n.

From d96e4d6e4f9ed3919351f81bdb50412f9a1ea178 Mon Sep 17 00:00:00 2001
From: Michal Nazarewicz <mina86@mina86.com>
Date: Tue, 3 Mar 2015 18:44:27 +0100
Subject: [PATCH] startup.el: Harmonise initialisation file loading across
 systems
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/startup.el (command-line): Change how initialisation file is
  loaded on various systems in the effort to harmonise it and get rid
  of various inconsistencies.

  1. If init file has not been loaded, the `user-file-user' will now
  be an absolute path rather than "~/.emacs" (or "~/_emacs" on DOS).

  2. With ‘-u’ argument, MS-Windows version of Emacs will now try to
  load ~USER/.emacs, ~USER/_emacs and finally ~USER/.emacs.d/init
  files (in that order) rather than ~/.emacs, ~/_emacs and
  ~USER/.emacs.d/init.

  NB: If `-u’ argument specifies an unknown user, expansion of
  "~USER/…" yields "/current/working/directory/~USER/…"  This is
  nothing new and it’s how *NIX and DOS ports behaved already.

  3. With ‘-u’ argument, MS-DOS and MS-Windows versions will check if
  "~USER/" directory exists before issuing a ‘user has no home’
  warning.  This is consistent with the fact that both those ports
  will attempt to read files inside of "~USER/".  (For MS-DOS port,
  the latter has already been the case, but it checked "~/"
  nonetheless).
---
 lisp/startup.el | 159 ++++++++++++++++++++++----------------------------------
 1 file changed, 63 insertions(+), 96 deletions(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 999e53e..0bfb5f0 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1043,108 +1043,75 @@ (defun command-line ()
     (setq inhibit-startup-screen nil)
 
     ;; Warn for invalid user name.
-    (when init-file-user
-      (if (string-match "[~/:\n]" init-file-user)
-	  (display-warning 'initialization
-			   (format "Invalid user name %s"
-				   init-file-user)
-			   :error)
-	(if (file-directory-p (expand-file-name
-			       ;; We don't support ~USER on MS-Windows
-			       ;; and MS-DOS except for the current
-			       ;; user, and always load .emacs from
-			       ;; the current user's home directory
-			       ;; (see below).  So always check "~",
-			       ;; even if invoked with "-u USER", or
-			       ;; if $USER or $LOGNAME are set to
-			       ;; something different.
-			       (if (memq system-type '(windows-nt ms-dos))
-				   "~"
-				 (concat "~" init-file-user))))
-	    nil
-	  (display-warning 'initialization
-			   (format "User %s has no home directory"
-				   (if (equal init-file-user "")
-				       (user-real-login-name)
-				     init-file-user))
-			   :error))))
-
     ;; Load that user's init file, or the default one, or none.
     (let (debug-on-error-from-init-file
 	  debug-on-error-should-be-set
 	  (debug-on-error-initial
 	   (if (eq init-file-debug t) 'startup init-file-debug))
-	  (orig-enable-multibyte (default-value 'enable-multibyte-characters)))
+	  (orig-enable-multibyte (default-value 'enable-multibyte-characters))
+          home-dir)
+
+      (when init-file-user
+        (if (string-match "[~/:\n]" init-file-user)
+            (display-warning 'initialization
+                             (format "Invalid user name %s" init-file-user)
+                             :error)
+          (setq home-dir (file-name-as-directory
+                          (expand-file-name (concat "~" init-file-user))))
+          (unless (file-directory-p home-dir)
+            (display-warning 'initialization
+                             (format "User %s has no home directory"
+                                     (if (equal init-file-user "")
+                                         (user-real-login-name)
+                                       init-file-user))
+                             :error))))
+
       (let ((debug-on-error debug-on-error-initial)
-	    ;; This function actually reads the init files.
-	    (inner
-	     (function
-	      (lambda ()
-		(if init-file-user
-		    (let ((user-init-file-1
-			   (cond
-			     ((eq system-type 'ms-dos)
-			      (concat "~" init-file-user "/_emacs"))
-			     ((not (eq system-type 'windows-nt))
-			      (concat "~" init-file-user "/.emacs"))
-			     ;; Else deal with the Windows situation
-			     ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
-			      ;; Prefer .emacs on Windows.
-			      "~/.emacs")
-			     ((directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
-			      ;; Also support _emacs for compatibility, but warn about it.
-			      (push '(initialization
-				      "`_emacs' init file is deprecated, please use `.emacs'")
-				    delayed-warnings-list)
-			      "~/_emacs")
-			     (t ;; But default to .emacs if _emacs does not exist.
-			      "~/.emacs"))))
-		      ;; This tells `load' to store the file name found
-		      ;; into user-init-file.
-		      (setq user-init-file t)
-		      (load user-init-file-1 t t)
-
-		      (when (eq user-init-file t)
-			;; If we did not find ~/.emacs, try
-			;; ~/.emacs.d/init.el.
-			(let ((otherfile
-			       (expand-file-name
-				"init"
-				(file-name-as-directory
-				 (concat "~" init-file-user "/.emacs.d")))))
-			  (load otherfile t t)
-
-			  ;; If we did not find the user's init file,
-			  ;; set user-init-file conclusively.
-			  ;; Don't let it be set from default.el.
-			  (when (eq user-init-file t)
-			    (setq user-init-file user-init-file-1))))
-
-		      ;; If we loaded a compiled file, set
-		      ;; `user-init-file' to the source version if that
-		      ;; exists.
-		      (when (and user-init-file
-				 (equal (file-name-extension user-init-file)
-					"elc"))
-			(let* ((source (file-name-sans-extension user-init-file))
-			       (alt (concat source ".el")))
-			  (setq source (cond ((file-exists-p alt) alt)
-					     ((file-exists-p source) source)
-					     (t nil)))
-			  (when source
-			    (when (file-newer-than-file-p source user-init-file)
-			      (message "Warning: %s is newer than %s"
-				       source user-init-file)
-			      (sit-for 1))
-			    (setq user-init-file source))))
-
-		      (unless inhibit-default-init
-                        (let ((inhibit-startup-screen nil))
-                          ;; Users are supposed to be told their rights.
-                          ;; (Plus how to get help and how to undo.)
-                          ;; Don't you dare turn this off for anyone
-                          ;; except yourself.
-                          (load "default" t t)))))))))
+            ;; This function actually reads the init files.
+            (inner
+             (function
+              (lambda ()
+                (when home-dir
+                  ;; This tells `load' to store the file name found
+                  ;; into user-init-file.
+                  (setq user-init-file t)
+                  ;; On MS-DOS, try ~USER/_emacs.  On MS-Windows try
+                  ;; ~USER/.emacs, ~USER/_emacs and ~/emacs.d/init.  On all
+                  ;; other systems, try ~USER/.emacs and ~/emacs.d/init.
+                  (if (or (and (not (eq system-type 'ms-dos))
+                               (load (concat home-dir ".emacs") t t))
+                          (and (memq system-type '(ms-dos windows-nt))
+                               (load (concat home-dir "_emacs") t t))
+                          (and (not (eq system-type 'ms-dos))
+                               (load (concat home-dir ".emacs.d/init") t t)))
+                      ;; If we loaded a compiled file, set `user-init-file' to
+                      ;; the source version if that exists.
+                      (when (equal (file-name-extension user-init-file) "elc")
+                        (let* ((src (file-name-sans-extension user-init-file))
+                               (alt (concat src ".el")))
+                          (setq src (cond ((file-exists-p alt) alt)
+                                          ((file-exists-p src) src)
+                                          (t nil)))
+                          (when source
+                            (when (file-newer-than-file-p src user-init-file)
+                              (message "Warning: %s is newer than %s"
+                                       src user-init-file)
+                              (sit-for 1))
+                            (setq user-init-file src))))
+                    ;; If we failed to load the init file, set `user-init-file'
+                    ;; to the default location for it.  On MS-DOS that’s
+                    ;; ~USER/_emacs and on all other systems it’s ~USER/.emacs
+                    (setq user-init-file (if (eq system-type 'ms-dos)
+                                             (concat home-dir "_emacs")
+                                           (concat home-dir ".emacs")))
+
+                    (unless inhibit-default-init
+                      (let ((inhibit-startup-screen nil))
+                        ;; Users are supposed to be told their rights.  (Plus
+                        ;; how to get help and how to undo.)  Don't you dare
+                        ;; turn this off for anyone except yourself.
+                        (load "default" t t)))))))))
+
 	(if init-file-debug
 	    ;; Do this without a condition-case if the user wants to debug.
 	    (funcall inner)
-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 17:48           ` Michal Nazarewicz
@ 2015-03-03 18:09             ` Eli Zaretskii
  2015-03-03 18:20               ` Eli Zaretskii
  2015-03-03 21:03               ` Michal Nazarewicz
  0 siblings, 2 replies; 15+ messages in thread
From: Eli Zaretskii @ 2015-03-03 18:09 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: petewil, emacs-devel

> From: Michal Nazarewicz <mina86@mina86.com>
> Cc: petewil@google.com, emacs-devel@gnu.org
> Date: Tue, 03 Mar 2015 18:48:24 +0100
> 
> > It's a lie, and one that's tricky to untangle: you need to know that
> > to get a _real_ file name, you need to run it through
> > expand-file-name.  If you don't, things will subtly fail, e.g., if you
> > compare this with some other file name.
> 
> This is already a problem on *all* systems and it happens if user init
> file is not found.  If you run ‘emacs -u foo’ on GNU/Linux, you’ll end
> up with `user-init-file" equal to "~foo/.emacs".

I don't understand how what you say is a contradiction to what I said.

> > Another important piece of the puzzle is that if USER is not
> > recognized as a valid user by the getpwnam emulation on
> > MS-Windows/MS-DOS, you get this:
> >
> >   (expand-file-name "~USER") => /current/directory/~USER
> >
> > And it is possible to have a literal "~USER" directory, in which case
> > the warning will be incorrectly skipped.
> 
> This also happens on UNIX-like systems.

Of course, it does.  So what?

> Based on all that, I think the most consistent option is to:
> 
> 1) always check if ~USER/ directory exists for the ‘User foo has no home
>    directory’ warning;
> 
> 2) user ~USER/.emacs and ~USER/_emacs on MS-Windows; and
> 
> 3) use `expand-file-name' when setting `user-init-file' if init file has
>    not been loaded.

Sorry, I cannot follow the logic that led to these 3 conclusions.
Please explain.  (And don't we already do all that?)

> The below untested patch does that plus stops Emacs from attempting to
> load init file if `init-file-user' is ‘invalid’, i.e. contains ~, /, :
> or \n.

Why?




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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 18:09             ` Eli Zaretskii
@ 2015-03-03 18:20               ` Eli Zaretskii
  2015-03-03 18:22                 ` Pete Williamson
  2015-03-03 21:03               ` Michal Nazarewicz
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2015-03-03 18:20 UTC (permalink / raw)
  To: mina86; +Cc: petewil, emacs-devel

> Date: Tue, 03 Mar 2015 20:09:56 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: petewil@google.com, emacs-devel@gnu.org
> 
> > Based on all that, I think the most consistent option is to:
> > 
> > 1) always check if ~USER/ directory exists for the ‘User foo has no home
> >    directory’ warning;
> > 
> > 2) user ~USER/.emacs and ~USER/_emacs on MS-Windows; and
> > 
> > 3) use `expand-file-name' when setting `user-init-file' if init file has
> >    not been loaded.
> 
> Sorry, I cannot follow the logic that led to these 3 conclusions.
> Please explain.  (And don't we already do all that?)

Btw, I'd like to reiterate something I already suggested near the
beginning: just error out if "-u USER" is used on DOS/Windows.  I
think this should put all this issue to rest, and avoid unneeded
complexity, FAQs, etc.




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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 18:20               ` Eli Zaretskii
@ 2015-03-03 18:22                 ` Pete Williamson
  2015-03-03 18:36                   ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Pete Williamson @ 2015-03-03 18:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michal Nazarewicz, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1223 bytes --]

So to solve my porting problem for NaCl, would it be best if I just did a
system check for NaCl, and if it is the current system, then clear the
"init-file-user" string?

In my case, init-file-user is set to "user", but "~user" is not expanding
properly

On Tue, Mar 3, 2015 at 10:20 AM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Tue, 03 Mar 2015 20:09:56 +0200
> > From: Eli Zaretskii <eliz@gnu.org>
> > Cc: petewil@google.com, emacs-devel@gnu.org
> >
> > > Based on all that, I think the most consistent option is to:
> > >
> > > 1) always check if ~USER/ directory exists for the ‘User foo has no
> home
> > >    directory’ warning;
> > >
> > > 2) user ~USER/.emacs and ~USER/_emacs on MS-Windows; and
> > >
> > > 3) use `expand-file-name' when setting `user-init-file' if init file
> has
> > >    not been loaded.
> >
> > Sorry, I cannot follow the logic that led to these 3 conclusions.
> > Please explain.  (And don't we already do all that?)
>
> Btw, I'd like to reiterate something I already suggested near the
> beginning: just error out if "-u USER" is used on DOS/Windows.  I
> think this should put all this issue to rest, and avoid unneeded
> complexity, FAQs, etc.
>

[-- Attachment #2: Type: text/html, Size: 1839 bytes --]

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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 18:22                 ` Pete Williamson
@ 2015-03-03 18:36                   ` Eli Zaretskii
  2015-03-03 18:38                     ` Pete Williamson
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2015-03-03 18:36 UTC (permalink / raw)
  To: Pete Williamson; +Cc: mina86, emacs-devel

> Date: Tue, 3 Mar 2015 10:22:39 -0800
> From: Pete Williamson <petewil@google.com>
> Cc: Michal Nazarewicz <mina86@mina86.com>, emacs-devel@gnu.org
> 
> So to solve my porting problem for NaCl, would it be best if I just did a
> system check for NaCl, and if it is the current system, then clear the
> "init-file-user" string?

If by "clear" you mean make it an empty string, then yes, I think
that's what you should do.



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 18:36                   ` Eli Zaretskii
@ 2015-03-03 18:38                     ` Pete Williamson
  2015-03-03 21:01                       ` Michal Nazarewicz
  0 siblings, 1 reply; 15+ messages in thread
From: Pete Williamson @ 2015-03-03 18:38 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michal Nazarewicz, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

Yes, I mean make it an empty string.  I'll send an updated patch.

Michael, is there still another issue I should solve if I make that
change?  Thanks for all your help trying to get this figured out!

On Tue, Mar 3, 2015 at 10:36 AM, Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Tue, 3 Mar 2015 10:22:39 -0800
> > From: Pete Williamson <petewil@google.com>
> > Cc: Michal Nazarewicz <mina86@mina86.com>, emacs-devel@gnu.org
> >
> > So to solve my porting problem for NaCl, would it be best if I just did a
> > system check for NaCl, and if it is the current system, then clear the
> > "init-file-user" string?
>
> If by "clear" you mean make it an empty string, then yes, I think
> that's what you should do.
>

[-- Attachment #2: Type: text/html, Size: 1259 bytes --]

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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 18:38                     ` Pete Williamson
@ 2015-03-03 21:01                       ` Michal Nazarewicz
  0 siblings, 0 replies; 15+ messages in thread
From: Michal Nazarewicz @ 2015-03-03 21:01 UTC (permalink / raw)
  To: Pete Williamson, Eli Zaretskii; +Cc: emacs-devel

On Tue, Mar 03 2015, Pete Williamson wrote:
> Yes, I mean make it an empty string.  I'll send an updated patch.
>
> Michael, is there still another issue I should solve if I make that
> change?  Thanks for all your help trying to get this figured out!

Don’t mind me.  Just do your thing. :]

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 18:09             ` Eli Zaretskii
  2015-03-03 18:20               ` Eli Zaretskii
@ 2015-03-03 21:03               ` Michal Nazarewicz
  2015-03-04 18:06                 ` Eli Zaretskii
  1 sibling, 1 reply; 15+ messages in thread
From: Michal Nazarewicz @ 2015-03-03 21:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: petewil, emacs-devel

On Tue, Mar 03 2015, Eli Zaretskii wrote:
>> Date: Tue, 03 Mar 2015 20:09:56 +0200
>> From: Eli Zaretskii <eliz@gnu.org>
>> Cc: petewil@google.com, emacs-devel@gnu.org
>> 
>> > Based on all that, I think the most consistent option is to:
>> > 
>> > 1) always check if ~USER/ directory exists for the ‘User foo has no home
>> >    directory’ warning;
>> > 
>> > 2) user ~USER/.emacs and ~USER/_emacs on MS-Windows; and
>> > 
>> > 3) use `expand-file-name' when setting `user-init-file' if init file has
>> >    not been loaded.
>> 
>> Sorry, I cannot follow the logic that led to these 3 conclusions.
>> Please explain.  (And don't we already do all that?)

> Btw, I'd like to reiterate something I already suggested near the
> beginning: just error out if "-u USER" is used on DOS/Windows.  I
> think this should put all this issue to rest, and avoid unneeded
> complexity, FAQs, etc.

OK.  I was looking at the code with an assumption that it’s desired to
have ‘-u USER’ working in some way.  If that is not the case, much of
what I wrote is irrelevant.

Still, for the third point, if no init file has been loaded,
`expand-file-name' is *not* used on `user-init-file' which ends up being
something like "~/.emacs" (i.e. not an absolute path but one which needs
expanding).  Since you’ve suggested this is undesired, we should start
expanding the path.

>>> Another important piece of the puzzle is that if USER is not
>>> recognized as a valid user by the getpwnam emulation on
>>> MS-Windows/MS-DOS, you get this:
>>>
>>>   (expand-file-name "~USER") => /current/directory/~USER
>>>
>>> And it is possible to have a literal "~USER" directory, in which case
>>> the warning will be incorrectly skipped.

>> This also happens on UNIX-like systems.

On Tue, Mar 03 2015, Eli Zaretskii wrote:
> Of course, it does.  So what?

If the situation you’ve described is incorrect, then it needs to be
fixed for *NIX.  If it is correct, why are you mentioning it?

>> The below untested patch does that plus stops Emacs from attempting to
>> load init file if `init-file-user' is ‘invalid’, i.e. contains ~, /, :
>> or \n.

> Why?

So… why are we checking if user name is valid if we then just gonna read
the files anyway?  What’s the point of this:

      (if (string-match "[~/:\n]" init-file-user)
	  (display-warning 'initialization
			   (format "Invalid user name %s"
				   init-file-user)
			   :error)

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--



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

* Re: [PATCH] for review - Allow expansion of "~" (as opposed to "~user")
  2015-03-03 21:03               ` Michal Nazarewicz
@ 2015-03-04 18:06                 ` Eli Zaretskii
  0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2015-03-04 18:06 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: petewil, emacs-devel

> From: Michal Nazarewicz <mina86@mina86.com>
> Cc: petewil@google.com, emacs-devel@gnu.org
> Date: Tue, 03 Mar 2015 22:03:38 +0100
> 
> > Btw, I'd like to reiterate something I already suggested near the
> > beginning: just error out if "-u USER" is used on DOS/Windows.  I
> > think this should put all this issue to rest, and avoid unneeded
> > complexity, FAQs, etc.
> 
> OK.  I was looking at the code with an assumption that it’s desired to
> have ‘-u USER’ working in some way.  If that is not the case, much of
> what I wrote is irrelevant.

I doubt if this "feature" gets any use at all on non-Posix systems.
The code is there, and does its job, so we could leave it alone.  But
if we want to clean this up, I say let's error out when "-u USER" is
used on systems where that makes no sense at all, or is impossible.

> Still, for the third point, if no init file has been loaded,
> `expand-file-name' is *not* used on `user-init-file' which ends up being
> something like "~/.emacs" (i.e. not an absolute path but one which needs
> expanding).  Since you’ve suggested this is undesired, we should start
> expanding the path.

Yes, probably.  OTOH, I don't think I've ever heard any complains with
such a situation.

> >>> Another important piece of the puzzle is that if USER is not
> >>> recognized as a valid user by the getpwnam emulation on
> >>> MS-Windows/MS-DOS, you get this:
> >>>
> >>>   (expand-file-name "~USER") => /current/directory/~USER
> >>>
> >>> And it is possible to have a literal "~USER" directory, in which case
> >>> the warning will be incorrectly skipped.
> 
> >> This also happens on UNIX-like systems.
> 
> On Tue, Mar 03 2015, Eli Zaretskii wrote:
> > Of course, it does.  So what?
> 
> If the situation you’ve described is incorrect, then it needs to be
> fixed for *NIX.  If it is correct, why are you mentioning it?

As a reminder that ~USER/ will not magically expand into ~/ on these
systems, since the code was specifically tweaked to behave like Posix
systems do.

> >> The below untested patch does that plus stops Emacs from attempting to
> >> load init file if `init-file-user' is ‘invalid’, i.e. contains ~, /, :
> >> or \n.
> 
> > Why?
> 
> So… why are we checking if user name is valid if we then just gonna read
> the files anyway?  What’s the point of this:
> 
>       (if (string-match "[~/:\n]" init-file-user)
> 	  (display-warning 'initialization
> 			   (format "Invalid user name %s"
> 				   init-file-user)
> 			   :error)

It's a warning.  I was asking why treat it as a fatal error.




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

end of thread, other threads:[~2015-03-04 18:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-28  0:06 [PATCH] for review - Allow expansion of "~" (as opposed to "~user") Pete Williamson
2015-02-28  8:08 ` Eli Zaretskii
2015-03-02  9:44   ` Michal Nazarewicz
2015-03-02 13:50     ` Eli Zaretskii
2015-03-02 20:37       ` Michal Nazarewicz
2015-03-03 15:37         ` Eli Zaretskii
2015-03-03 17:48           ` Michal Nazarewicz
2015-03-03 18:09             ` Eli Zaretskii
2015-03-03 18:20               ` Eli Zaretskii
2015-03-03 18:22                 ` Pete Williamson
2015-03-03 18:36                   ` Eli Zaretskii
2015-03-03 18:38                     ` Pete Williamson
2015-03-03 21:01                       ` Michal Nazarewicz
2015-03-03 21:03               ` Michal Nazarewicz
2015-03-04 18:06                 ` Eli Zaretskii

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