unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: Eli Zaretskii <eliz@gnu.org>, Pete Williamson <petewil@google.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] for review - Allow expansion of "~" (as opposed to	"~user")
Date: Mon, 02 Mar 2015 10:44:07 +0100	[thread overview]
Message-ID: <xa1tegp7ohso.fsf@mina86.com> (raw)
In-Reply-To: <83r3ta4fwk.fsf@gnu.org>

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



  reply	other threads:[~2015-03-02  9:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xa1tegp7ohso.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=petewil@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).