unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#583: Use XDG basedir spec for configuration files?
@ 2008-07-21  6:59 Fernando
  2012-12-08 12:18 ` bug#583: XDG basedir specification Eric Heintzmann
  2019-08-27 21:57 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
  0 siblings, 2 replies; 45+ messages in thread
From: Fernando @ 2008-07-21  6:59 UTC (permalink / raw)
  To: bug-gnu-emacs

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

The XDG Base Directory
Specification<http://standards.freedesktop.org/basedir-spec/>provides
some common paths in user's home to store personal application
configurations, or, using their own words "*defines where these files should
be looked for by defining one or more base directories relative to which
files should be located*".

XDG Base Directory Specification allows efficient backup, in which you can
easily choose to backup your data and/or your configuration files for
instance. An application could easily propose such backup for the whole
system if all applications were matching these specification.

Therefore, although I think that this bug/enhancement is not vital, it would
be great for Emacs to be "FreeDesktop XDG Base Directory Specification"
compliant.

Currently Emacs is using "$HOME/.emacs.d/". This is what XDG basedir spec
defines:

   - $XDG_DATA_HOME (usually $HOME/.local/share/) as "*the base directory
   relative to which user specific data files should be stored*"
   - $XDG_CONFIG_HOME (usually $HOME/.config/) as "*the base directory
   relative to which user specific configuration files should be stored*"
   - $XDG_CACHE_HOME (usually $HOME/.cache/) as "*the base directory
   relative to which user specific non-essential data files should be stored
   *"

(http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)

In order to make Emacs XDG basedir compliant, I think that it would be nice
to use:

   - $XDG_CONFIG_HOME/emacs  ;;for "init.el" and storing customize
   configuration


   - $XDG_DATA_HOME/emacs  ;;for sessions and backups


   - $XDG_CACHE_HOME/emacs  ;;for cache files

Or maybe some other distribution. What do you think about it?

There's a small C library that may be useful check it out, written for the
sole purpose of xdg basedir spec compliance:
https://n.ethz.ch/student/nevillm/download/libxdg-basedir/

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

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

* bug#583: XDG basedir specification
  2008-07-21  6:59 bug#583: Use XDG basedir spec for configuration files? Fernando
@ 2012-12-08 12:18 ` Eric Heintzmann
  2012-12-08 19:06   ` Jan Djärv
  2019-08-27 21:57 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
  1 sibling, 1 reply; 45+ messages in thread
From: Eric Heintzmann @ 2012-12-08 12:18 UTC (permalink / raw)
  To: 583

What is planned now about FreeDesktop XDG basedir specification for Emacs?


http://ploum.net/post/207-modify-your-application-to-use-xdg-folders
https://live.gnome.org/GnomeGoals/XDGConfigFolders
http://standards.freedesktop.org/basedir-spec/latest/






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

* bug#583: XDG basedir specification
  2012-12-08 12:18 ` bug#583: XDG basedir specification Eric Heintzmann
@ 2012-12-08 19:06   ` Jan Djärv
  2012-12-08 19:31     ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Jan Djärv @ 2012-12-08 19:06 UTC (permalink / raw)
  To: Eric Heintzmann; +Cc: 583


8 dec 2012 kl. 13:18 skrev Eric Heintzmann <Heintzmann.Eric@free.fr>:

> What is planned now about FreeDesktop XDG basedir specification for Emacs?
> 
> 
> http://ploum.net/post/207-modify-your-application-to-use-xdg-folders
> https://live.gnome.org/GnomeGoals/XDGConfigFolders
> http://standards.freedesktop.org/basedir-spec/latest/

Hopefully nothing, as the free desktop specs in this area keeps changing and never reach a stable state.

	Jan D.






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

* bug#583: XDG basedir specification
  2012-12-08 19:06   ` Jan Djärv
@ 2012-12-08 19:31     ` Eli Zaretskii
  0 siblings, 0 replies; 45+ messages in thread
From: Eli Zaretskii @ 2012-12-08 19:31 UTC (permalink / raw)
  To: Jan Djärv; +Cc: Heintzmann.Eric, 583

> From: Jan Djärv <jan.h.d@swipnet.se>
> Date: Sat, 8 Dec 2012 20:06:34 +0100
> Cc: 583@debbugs.gnu.org
> 
> 8 dec 2012 kl. 13:18 skrev Eric Heintzmann <Heintzmann.Eric@free.fr>:
> 
> > What is planned now about FreeDesktop XDG basedir specification for Emacs?
> > 
> > 
> > http://ploum.net/post/207-modify-your-application-to-use-xdg-folders
> > https://live.gnome.org/GnomeGoals/XDGConfigFolders
> > http://standards.freedesktop.org/basedir-spec/latest/
> 
> Hopefully nothing, as the free desktop specs in this area keeps changing and never reach a stable state.

I agree, FWIW.






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

* bug#15539: [PATCH] Setting user-emacs-directory
       [not found] <CAADsv94GP0tVZtsS0na6RWtOc+WpDDAYDZqw299hw6j5Rq8sUw@mail.gmail.com>
@ 2015-04-01 15:24 ` François Févotte
       [not found] ` <CAADsv96dEnf1aD+0=FvOHLPGXg2ARnL440Nya2ipQKRo648Dtw@mail.gmail.com>
  1 sibling, 0 replies; 45+ messages in thread
From: François Févotte @ 2015-04-01 15:24 UTC (permalink / raw)
  To: emacs-devel, 15539

Hello,

On Tue, Mar 24, 2015 at 12:25 AM, François Févotte <fevotte@gmail.com> wrote:
> below is a patch trying to address old bug #15539.

after the lack of reaction to my last email, I would like to have one
more chance of getting emacs-devel's feedback on this issue (namely:
being able to tell Emacs where to find its init file).

Is nobody interested in this feature?  Or is the proposed patch not adequate?
In the former case, please just say so, so that we can maybe mark the
bug as "wontfix" and let it be clear.  In the latter case, I'm still
welcoming any comment on the proposed solution.  And of course I'm
willing to work on any improvement you might suggest.

Thanks in advance,
   François





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

* bug#15539: [PATCH] Setting user-emacs-directory
       [not found] ` <CAADsv96dEnf1aD+0=FvOHLPGXg2ARnL440Nya2ipQKRo648Dtw@mail.gmail.com>
@ 2015-04-01 15:38   ` Oleh Krehel
  2015-04-01 15:49     ` Drew Adams
  2015-04-01 16:48     ` Oleh Krehel
  0 siblings, 2 replies; 45+ messages in thread
From: Oleh Krehel @ 2015-04-01 15:38 UTC (permalink / raw)
  To: François Févotte; +Cc: 15539, emacs-devel

François Févotte <francois.fevotte@ensta.org> writes:

> Hello,
>
> On Tue, Mar 24, 2015 at 12:25 AM, François Févotte <fevotte@gmail.com> wrote:
>> below is a patch trying to address old bug #15539.
>
> after the lack of reaction to my last email, I would like to have one
> more chance of getting emacs-devel's feedback on this issue (namely:
> being able to tell Emacs where to find its init file).
>
> Is nobody interested in this feature?  Or is the proposed patch not adequate?
> In the former case, please just say so, so that we can maybe mark the
> bug as "wontfix" and let it be clear.  In the latter case, I'm still
> welcoming any comment on the proposed solution.  And of course I'm
> willing to work on any improvement you might suggest.

I'm interested in this feature, I just didn't have time to test it yet.
I'll try to look at it soon.

Oleh





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2015-04-01 15:38   ` Oleh Krehel
@ 2015-04-01 15:49     ` Drew Adams
  2015-04-01 16:48     ` Oleh Krehel
  1 sibling, 0 replies; 45+ messages in thread
From: Drew Adams @ 2015-04-01 15:49 UTC (permalink / raw)
  To: Oleh Krehel, François Févotte; +Cc: 15539, emacs-devel

> I'm interested in this feature, I just didn't have time to test it yet.
> I'll try to look at it soon.

Can y'all please drop one of the mailing lists (e.g. emacs-devel)?  Thx.





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2015-04-01 15:38   ` Oleh Krehel
  2015-04-01 15:49     ` Drew Adams
@ 2015-04-01 16:48     ` Oleh Krehel
  2015-04-01 17:16       ` François Févotte
  1 sibling, 1 reply; 45+ messages in thread
From: Oleh Krehel @ 2015-04-01 16:48 UTC (permalink / raw)
  To: François Févotte; +Cc: 15539

Oleh Krehel <ohwoeowho@gmail.com> writes:

> François Févotte <francois.fevotte@ensta.org> writes:
>
>> Hello,
>>
>> On Tue, Mar 24, 2015 at 12:25 AM, François Févotte <fevotte@gmail.com> wrote:
>>> below is a patch trying to address old bug #15539.
>>
>> after the lack of reaction to my last email, I would like to have one
>> more chance of getting emacs-devel's feedback on this issue (namely:
>> being able to tell Emacs where to find its init file).
>>
>> Is nobody interested in this feature?  Or is the proposed patch not adequate?
>> In the former case, please just say so, so that we can maybe mark the
>> bug as "wontfix" and let it be clear.  In the latter case, I'm still
>> welcoming any comment on the proposed solution.  And of course I'm
>> willing to work on any improvement you might suggest.
>
> I'm interested in this feature, I just didn't have time to test it yet.
> I'll try to look at it soon.

OK, I've tested it and it works great. I vote for merging this if
someone is counting.

Just one question: why is `getenv' called twice?

Oleh






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

* bug#15539: [PATCH] Setting user-emacs-directory
  2015-04-01 16:48     ` Oleh Krehel
@ 2015-04-01 17:16       ` François Févotte
  2015-04-01 21:03         ` Stefan Monnier
  0 siblings, 1 reply; 45+ messages in thread
From: François Févotte @ 2015-04-01 17:16 UTC (permalink / raw)
  To: Oleh Krehel; +Cc: 15539

Thanks for testing

On Wed, Apr 1, 2015 at 6:48 PM, Oleh Krehel <ohwoeowho@gmail.com> wrote:
> Just one question: why is `getenv' called twice?

with the currently implemented logic, the environment variable has two
different impacts: (1) it sets the `user-emacs-directory' variable,
and (2) it changes the logic used to determine the init file. There is
currently no `let' form encompassing the whole `command-line'
function, so I had to either
1- add one (which might be the most correct implementation, but
generates a very large patch for mostly unchanged lines)
2- define a global variable (which seems unnecessary), or
3- call `getenv' multiple times.

I chose the latter, but am perfectly open to rewriting the
implementation if you feel it would be better.

    François





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2015-04-01 17:16       ` François Févotte
@ 2015-04-01 21:03         ` Stefan Monnier
  2015-04-02  8:12           ` François Févotte
  0 siblings, 1 reply; 45+ messages in thread
From: Stefan Monnier @ 2015-04-01 21:03 UTC (permalink / raw)
  To: François Févotte; +Cc: 15539, Oleh Krehel

> 1- add one (which might be the most correct implementation, but
> generates a very large patch for mostly unchanged lines)

That's the better option.
You can ask diff to ignore whitespace changes, which keeps the patch readable.


        Stefan





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2015-04-01 21:03         ` Stefan Monnier
@ 2015-04-02  8:12           ` François Févotte
  0 siblings, 0 replies; 45+ messages in thread
From: François Févotte @ 2015-04-02  8:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 15539, Oleh Krehel

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

Here is a new version introducing a `let' form spanning everything
needed.  There is no need for two calls to `getenv' anymore.
I've attached the patch in two versions: with and without whitespace
changes (git diff -b), to make it easier to review.


Thanks,
   François

On Wed, Apr 1, 2015 at 11:03 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> 1- add one (which might be the most correct implementation, but
>> generates a very large patch for mostly unchanged lines)
>
> That's the better option.
> You can ask diff to ignore whitespace changes, which keeps the patch readable.
>
>
>         Stefan

[-- Attachment #2: EMACS_USER_DIRECTORY-nowhitespace.patch --]
[-- Type: text/x-patch, Size: 5465 bytes --]

From e15fd3120a995e38708ca73d293973dd8e596b22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= <francois.fevotte@ensta.org>
Date: Thu, 2 Apr 2015 09:17:03 +0200
Subject: [PATCH] Look for an `EMACS_USER_DIRECTORY' environment variable.

This sets `user-emacs-directory' and looks for `init.el' in it.

Fixes: bug#15539
---
 doc/emacs/cmdargs.texi |    9 ++++++++-
 doc/emacs/custom.texi  |    8 ++++++++
 lisp/custom.el         |    1 +
 lisp/startup.el        |   20 ++++++++++++++++----
 4 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi
index 071cd68..30d3472 100644
--- a/doc/emacs/cmdargs.texi
+++ b/doc/emacs/cmdargs.texi
@@ -349,7 +349,9 @@ Do not reload any saved desktop.  @xref{Saving Emacs Sessions}.
 @opindex --user
 @cindex load init file of another user
 Load @var{user}'s initialization file instead of your
-own@footnote{This option has no effect on MS-Windows.}.
+own@footnote{This option has no effect on MS-Windows, nor when the
+@env{EMACS_USER_DIRECTORY} environment variable is set (@pxref{General
+Variables}).}.
 
 @item --debug-init
 @opindex --debug-init
@@ -642,6 +644,11 @@ does not use @env{TZ} at all.
 @vindex USER, environment variable
 The user's login name.  See also @env{LOGNAME}.  On MS-DOS, this
 defaults to @samp{root}.
+@item EMACS_USER_DIRECTORY
+This specifies a directory in which the initialization file will be
+looked for; @xref{Find Init}. This directory will also be used as the
+default place where user-specific configuration data will be stored;
+@xref{Standard File Names,,, elisp}.
 @item VERSION_CONTROL
 @vindex VERSION_CONTROL, environment variable
 Used to initialize the @code{version-control} variable (@pxref{Backup
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 9fd823b..1e1d482 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -2516,6 +2516,14 @@ otherwise, it looks up the home directory corresponding to that user
 name in the system's data base of users.
 @c  LocalWords:  backtab
 
+  The whole mechanism described above is bypassed if the
+@env{EMACS_USER_DIRECTORY} environment variable is specified, in which
+case Emacs directly looks for @file{init.el} inside the directory
+specified by @env{EMACS_USER_DIRECTORY} (@pxref{General Variables}).
+This directory is also used to hold user-specific configuration
+(@pxref{Standard File Names,,, elisp}).
+
+
 @node Init Non-ASCII
 @subsection Non-@acronym{ASCII} Characters in Init Files
 @cindex international characters in @file{.emacs}
diff --git a/lisp/custom.el b/lisp/custom.el
index e5fe0eb..36983aa 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1119,6 +1119,7 @@ directory.  By default, Emacs searches for custom themes in this
 directory first---see `custom-theme-load-path'."
   :type 'string
   :group 'customize
+  :initialize 'custom-initialize-delay
   :version "22.1")
 
 (defcustom custom-theme-load-path (list 'custom-theme-directory t)
diff --git a/lisp/startup.el b/lisp/startup.el
index 7fa929a..1c403c6 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -397,7 +397,8 @@ Set this to nil if you want to prevent `auto-save-list-file-name'
 from being initialized."
   :type '(choice (const :tag "Don't record a session's auto save list" nil)
 		 string)
-  :group 'auto-save)
+  :group 'auto-save
+  :initialize 'custom-initialize-delay)
 
 (defvar emacs-basic-display nil)
 
@@ -814,6 +815,12 @@ Amongst another things, it parses the command-line arguments."
 	  ((member vc '("never" "simple"))
 	   (setq version-control 'never))))
 
+  ;; Set `user-emacs-directory' early so that delayed init variables
+  ;; can be updated.
+  (let ((user-emacs-directory--from-env (getenv "EMACS_USER_DIRECTORY")))
+    (when user-emacs-directory--from-env
+      (setq user-emacs-directory (file-name-as-directory user-emacs-directory--from-env)))
+
   ;;! This has been commented out; I currently find the behavior when
   ;;! split-window-keep-point is nil disturbing, but if I can get used
   ;;! to it, then it would be better to eliminate the option.
@@ -1105,7 +1112,10 @@ please check its value")
 		      ;; 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)
+
+                        ;; Don't load `~/.emacs' if EMACS_USER_DIRECTORY was set
+                        (unless user-emacs-directory--from-env
+                          (load user-init-file-1 t t))
 
 		      (when (eq user-init-file t)
 			;; If we did not find ~/.emacs, try
@@ -1114,7 +1124,9 @@ please check its value")
 			       (expand-file-name
 				"init"
 				(file-name-as-directory
-				 (concat "~" init-file-user "/.emacs.d")))))
+                                   (if user-emacs-directory--from-env
+                                       user-emacs-directory
+                                     (concat "~" init-file-user "/.emacs.d"))))))
 			  (load otherfile t t)
 
 			  ;; If we did not find the user's init file,
@@ -1227,7 +1239,7 @@ the `--debug-init' option to view a complete error backtrace."
     ;; be realized.
     (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
 		 (eq face-ignored-fonts old-face-ignored-fonts))
-      (clear-face-cache)))
+        (clear-face-cache))))
 
   ;; If any package directory exists, initialize the package system.
   (and user-init-file
-- 
1.7.2.5


[-- Attachment #3: EMACS_USER_DIRECTORY.patch --]
[-- Type: text/x-patch, Size: 40886 bytes --]

From e15fd3120a995e38708ca73d293973dd8e596b22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= <francois.fevotte@ensta.org>
Date: Thu, 2 Apr 2015 09:17:03 +0200
Subject: [PATCH] Look for an `EMACS_USER_DIRECTORY' environment variable.

This sets `user-emacs-directory' and looks for `init.el' in it.

Fixes: bug#15539
---
 doc/emacs/cmdargs.texi |    9 +-
 doc/emacs/custom.texi  |    8 +
 lisp/custom.el         |    1 +
 lisp/startup.el        |  832 ++++++++++++++++++++++++------------------------
 4 files changed, 439 insertions(+), 411 deletions(-)

diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi
index 071cd68..30d3472 100644
--- a/doc/emacs/cmdargs.texi
+++ b/doc/emacs/cmdargs.texi
@@ -349,7 +349,9 @@ Do not reload any saved desktop.  @xref{Saving Emacs Sessions}.
 @opindex --user
 @cindex load init file of another user
 Load @var{user}'s initialization file instead of your
-own@footnote{This option has no effect on MS-Windows.}.
+own@footnote{This option has no effect on MS-Windows, nor when the
+@env{EMACS_USER_DIRECTORY} environment variable is set (@pxref{General
+Variables}).}.
 
 @item --debug-init
 @opindex --debug-init
@@ -642,6 +644,11 @@ does not use @env{TZ} at all.
 @vindex USER, environment variable
 The user's login name.  See also @env{LOGNAME}.  On MS-DOS, this
 defaults to @samp{root}.
+@item EMACS_USER_DIRECTORY
+This specifies a directory in which the initialization file will be
+looked for; @xref{Find Init}. This directory will also be used as the
+default place where user-specific configuration data will be stored;
+@xref{Standard File Names,,, elisp}.
 @item VERSION_CONTROL
 @vindex VERSION_CONTROL, environment variable
 Used to initialize the @code{version-control} variable (@pxref{Backup
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 9fd823b..1e1d482 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -2516,6 +2516,14 @@ otherwise, it looks up the home directory corresponding to that user
 name in the system's data base of users.
 @c  LocalWords:  backtab
 
+  The whole mechanism described above is bypassed if the
+@env{EMACS_USER_DIRECTORY} environment variable is specified, in which
+case Emacs directly looks for @file{init.el} inside the directory
+specified by @env{EMACS_USER_DIRECTORY} (@pxref{General Variables}).
+This directory is also used to hold user-specific configuration
+(@pxref{Standard File Names,,, elisp}).
+
+
 @node Init Non-ASCII
 @subsection Non-@acronym{ASCII} Characters in Init Files
 @cindex international characters in @file{.emacs}
diff --git a/lisp/custom.el b/lisp/custom.el
index e5fe0eb..36983aa 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1119,6 +1119,7 @@ directory.  By default, Emacs searches for custom themes in this
 directory first---see `custom-theme-load-path'."
   :type 'string
   :group 'customize
+  :initialize 'custom-initialize-delay
   :version "22.1")
 
 (defcustom custom-theme-load-path (list 'custom-theme-directory t)
diff --git a/lisp/startup.el b/lisp/startup.el
index 7fa929a..1c403c6 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -397,7 +397,8 @@ Set this to nil if you want to prevent `auto-save-list-file-name'
 from being initialized."
   :type '(choice (const :tag "Don't record a session's auto save list" nil)
 		 string)
-  :group 'auto-save)
+  :group 'auto-save
+  :initialize 'custom-initialize-delay)
 
 (defvar emacs-basic-display nil)
 
@@ -814,420 +815,431 @@ Amongst another things, it parses the command-line arguments."
 	  ((member vc '("never" "simple"))
 	   (setq version-control 'never))))
 
-  ;;! This has been commented out; I currently find the behavior when
-  ;;! split-window-keep-point is nil disturbing, but if I can get used
-  ;;! to it, then it would be better to eliminate the option.
-  ;;! ;; Choose a good default value for split-window-keep-point.
-  ;;! (setq split-window-keep-point (> baud-rate 2400))
-
-  ;; Convert preloaded file names in load-history to absolute.
-  (let ((simple-file-name
-	 ;; Look for simple.el or simple.elc and use their directory
-	 ;; as the place where all Lisp files live.
-	 (locate-file "simple" load-path (get-load-suffixes)))
-	lisp-dir)
-    ;; Don't abort if simple.el cannot be found, but print a warning.
-    ;; Although in most usage we are going to cryptically abort a moment
-    ;; later anyway, due to missing required bidi data files (eg bug#13430).
-    (if (null simple-file-name)
-	(let ((standard-output 'external-debugging-output)
-	      (lispdir (expand-file-name "../lisp" data-directory)))
-	  (princ "Warning: Could not find simple.el or simple.elc")
-	  (terpri)
-	  (when (getenv "EMACSLOADPATH")
-	    (princ "The EMACSLOADPATH environment variable is set, \
+  ;; Set `user-emacs-directory' early so that delayed init variables
+  ;; can be updated.
+  (let ((user-emacs-directory--from-env (getenv "EMACS_USER_DIRECTORY")))
+    (when user-emacs-directory--from-env
+      (setq user-emacs-directory (file-name-as-directory user-emacs-directory--from-env)))
+
+    ;;! This has been commented out; I currently find the behavior when
+    ;;! split-window-keep-point is nil disturbing, but if I can get used
+    ;;! to it, then it would be better to eliminate the option.
+    ;;! ;; Choose a good default value for split-window-keep-point.
+    ;;! (setq split-window-keep-point (> baud-rate 2400))
+
+    ;; Convert preloaded file names in load-history to absolute.
+    (let ((simple-file-name
+           ;; Look for simple.el or simple.elc and use their directory
+           ;; as the place where all Lisp files live.
+           (locate-file "simple" load-path (get-load-suffixes)))
+          lisp-dir)
+      ;; Don't abort if simple.el cannot be found, but print a warning.
+      ;; Although in most usage we are going to cryptically abort a moment
+      ;; later anyway, due to missing required bidi data files (eg bug#13430).
+      (if (null simple-file-name)
+          (let ((standard-output 'external-debugging-output)
+                (lispdir (expand-file-name "../lisp" data-directory)))
+            (princ "Warning: Could not find simple.el or simple.elc")
+            (terpri)
+            (when (getenv "EMACSLOADPATH")
+              (princ "The EMACSLOADPATH environment variable is set, \
 please check its value")
-	    (terpri))
-	  (unless (file-readable-p lispdir)
-	    (princ (format "Lisp directory %s not readable?" lispdir))
-	    (terpri)))
-      (setq lisp-dir (file-truename (file-name-directory simple-file-name)))
-      (setq load-history
-	    (mapcar (lambda (elt)
-		      (if (and (stringp (car elt))
-			       (not (file-name-absolute-p (car elt))))
-			  (cons (concat lisp-dir
-					(car elt))
-				(cdr elt))
-			elt))
-		    load-history))))
-
-  ;; Convert the arguments to Emacs internal representation.
-  (let ((args command-line-args))
-    (while args
-      (setcar args
-	      (decode-coding-string (car args) locale-coding-system t))
-      (pop args)))
-
-  (let ((done nil)
-	(args (cdr command-line-args))
-	display-arg)
-
-    ;; Figure out which user's init file to load,
-    ;; either from the environment or from the options.
-    (setq init-file-user (if noninteractive nil (user-login-name)))
-    ;; If user has not done su, use current $HOME to find .emacs.
-    (and init-file-user
-         (equal init-file-user (user-real-login-name))
-	 (setq init-file-user ""))
-
-    ;; Process the command-line args, and delete the arguments
-    ;; processed.  This is consistent with the way main in emacs.c
-    ;; does things.
-    (while (and (not done) args)
-      (let* ((longopts '(("--no-init-file") ("--no-site-file")
-                         ("--no-x-resources") ("--debug-init")
-                         ("--user") ("--iconic") ("--icon-type") ("--quick")
-			 ("--no-blinking-cursor") ("--basic-display")))
-             (argi (pop args))
-             (orig-argi argi)
-             argval)
-	;; Handle --OPTION=VALUE format.
-	(when (string-match "\\`\\(--[^=]*\\)=" argi)
-	  (setq argval (substring argi (match-end 0))
-                argi (match-string 1 argi)))
-	(when (string-match "\\`--." orig-argi)
-	  (let ((completion (try-completion argi longopts)))
-	    (cond ((eq completion t)
-		   (setq argi (substring argi 1)))
-		  ((stringp completion)
-		   (let ((elt (assoc completion longopts)))
-		     (unless elt
-		       (error "Option `%s' is ambiguous" argi))
-		     (setq argi (substring (car elt) 1))))
-		  (t
-		   (setq argval nil
-			 argi orig-argi)))))
-	(cond
-	 ;; The --display arg is handled partly in C, partly in Lisp.
-	 ;; When it shows up here, we just put it back to be handled
-	 ;; by `command-line-1'.
-	 ((member argi '("-d" "-display"))
-	  (setq display-arg (list argi (pop args))))
-	 ((member argi '("-Q" "-quick"))
-	  (setq init-file-user nil
-		site-run-file nil
-                inhibit-x-resources t))
-         ((member argi '("-no-x-resources"))
-          (setq inhibit-x-resources t))
-	 ((member argi '("-D" "-basic-display"))
-	  (setq no-blinking-cursor t
-		emacs-basic-display t)
-	  (push '(vertical-scroll-bars . nil) initial-frame-alist))
-	 ((member argi '("-q" "-no-init-file"))
-	  (setq init-file-user nil))
-	 ((member argi '("-u" "-user"))
-	  (setq init-file-user (or argval (pop args))
-		argval nil))
-	 ((equal argi "-no-site-file")
-	  (setq site-run-file nil))
-	 ((equal argi "-debug-init")
-	  (setq init-file-debug t))
-	 ((equal argi "-iconic")
-	  (push '(visibility . icon) initial-frame-alist))
-	 ((member argi '("-nbc" "-no-blinking-cursor"))
-	  (setq no-blinking-cursor t))
-	 ;; Push the popped arg back on the list of arguments.
-	 (t
-          (push argi args)
-          (setq done t)))
-	;; Was argval set but not used?
-	(and argval
-	     (error "Option `%s' doesn't allow an argument" argi))))
-
-    ;; Re-attach the --display arg.
-    (and display-arg (setq args (append display-arg args)))
-
-    ;; Re-attach the program name to the front of the arg list.
-    (and command-line-args
-         (setcdr command-line-args args)))
-
-  ;; Make sure window system's init file was loaded in loadup.el if
-  ;; using a window system.
-  ;; Initialize the window-system only after processing the command-line
-  ;; args so that -Q can influence this initialization.
-  (condition-case error
-    (unless noninteractive
-      (if (and initial-window-system
-	       (not (featurep
-		     (intern
-		      (concat (symbol-name initial-window-system) "-win")))))
-	  (error "Unsupported window system `%s'" initial-window-system))
-      ;; Process window-system specific command line parameters.
-      (setq command-line-args
-	    (funcall
-             (gui-method handle-args-function initial-window-system)
-	     command-line-args))
-      ;; Initialize the window system. (Open connection, etc.)
-      (funcall
-       (gui-method window-system-initialization initial-window-system))
-      (put initial-window-system 'window-system-initialized t))
-    ;; If there was an error, print the error message and exit.
-    (error
-     (princ
-      (if (eq (car error) 'error)
-	  (apply 'concat (cdr error))
-	(if (memq 'file-error (get (car error) 'error-conditions))
-	    (format "%s: %s"
-                    (nth 1 error)
+              (terpri))
+            (unless (file-readable-p lispdir)
+              (princ (format "Lisp directory %s not readable?" lispdir))
+              (terpri)))
+        (setq lisp-dir (file-truename (file-name-directory simple-file-name)))
+        (setq load-history
+              (mapcar (lambda (elt)
+                        (if (and (stringp (car elt))
+                                 (not (file-name-absolute-p (car elt))))
+                            (cons (concat lisp-dir
+                                          (car elt))
+                                  (cdr elt))
+                          elt))
+                      load-history))))
+
+    ;; Convert the arguments to Emacs internal representation.
+    (let ((args command-line-args))
+      (while args
+        (setcar args
+                (decode-coding-string (car args) locale-coding-system t))
+        (pop args)))
+
+    (let ((done nil)
+          (args (cdr command-line-args))
+          display-arg)
+
+      ;; Figure out which user's init file to load,
+      ;; either from the environment or from the options.
+      (setq init-file-user (if noninteractive nil (user-login-name)))
+      ;; If user has not done su, use current $HOME to find .emacs.
+      (and init-file-user
+           (equal init-file-user (user-real-login-name))
+           (setq init-file-user ""))
+
+      ;; Process the command-line args, and delete the arguments
+      ;; processed.  This is consistent with the way main in emacs.c
+      ;; does things.
+      (while (and (not done) args)
+        (let* ((longopts '(("--no-init-file") ("--no-site-file")
+                           ("--no-x-resources") ("--debug-init")
+                           ("--user") ("--iconic") ("--icon-type") ("--quick")
+                           ("--no-blinking-cursor") ("--basic-display")))
+               (argi (pop args))
+               (orig-argi argi)
+               argval)
+          ;; Handle --OPTION=VALUE format.
+          (when (string-match "\\`\\(--[^=]*\\)=" argi)
+            (setq argval (substring argi (match-end 0))
+                  argi (match-string 1 argi)))
+          (when (string-match "\\`--." orig-argi)
+            (let ((completion (try-completion argi longopts)))
+              (cond ((eq completion t)
+                     (setq argi (substring argi 1)))
+                    ((stringp completion)
+                     (let ((elt (assoc completion longopts)))
+                       (unless elt
+                         (error "Option `%s' is ambiguous" argi))
+                       (setq argi (substring (car elt) 1))))
+                    (t
+                     (setq argval nil
+                           argi orig-argi)))))
+          (cond
+           ;; The --display arg is handled partly in C, partly in Lisp.
+           ;; When it shows up here, we just put it back to be handled
+           ;; by `command-line-1'.
+           ((member argi '("-d" "-display"))
+            (setq display-arg (list argi (pop args))))
+           ((member argi '("-Q" "-quick"))
+            (setq init-file-user nil
+                  site-run-file nil
+                  inhibit-x-resources t))
+           ((member argi '("-no-x-resources"))
+            (setq inhibit-x-resources t))
+           ((member argi '("-D" "-basic-display"))
+            (setq no-blinking-cursor t
+                  emacs-basic-display t)
+            (push '(vertical-scroll-bars . nil) initial-frame-alist))
+           ((member argi '("-q" "-no-init-file"))
+            (setq init-file-user nil))
+           ((member argi '("-u" "-user"))
+            (setq init-file-user (or argval (pop args))
+                  argval nil))
+           ((equal argi "-no-site-file")
+            (setq site-run-file nil))
+           ((equal argi "-debug-init")
+            (setq init-file-debug t))
+           ((equal argi "-iconic")
+            (push '(visibility . icon) initial-frame-alist))
+           ((member argi '("-nbc" "-no-blinking-cursor"))
+            (setq no-blinking-cursor t))
+           ;; Push the popped arg back on the list of arguments.
+           (t
+            (push argi args)
+            (setq done t)))
+          ;; Was argval set but not used?
+          (and argval
+               (error "Option `%s' doesn't allow an argument" argi))))
+
+      ;; Re-attach the --display arg.
+      (and display-arg (setq args (append display-arg args)))
+
+      ;; Re-attach the program name to the front of the arg list.
+      (and command-line-args
+           (setcdr command-line-args args)))
+
+    ;; Make sure window system's init file was loaded in loadup.el if
+    ;; using a window system.
+    ;; Initialize the window-system only after processing the command-line
+    ;; args so that -Q can influence this initialization.
+    (condition-case error
+        (unless noninteractive
+          (if (and initial-window-system
+                   (not (featurep
+                         (intern
+                          (concat (symbol-name initial-window-system) "-win")))))
+              (error "Unsupported window system `%s'" initial-window-system))
+          ;; Process window-system specific command line parameters.
+          (setq command-line-args
+                (funcall
+                 (gui-method handle-args-function initial-window-system)
+                 command-line-args))
+          ;; Initialize the window system. (Open connection, etc.)
+          (funcall
+           (gui-method window-system-initialization initial-window-system))
+          (put initial-window-system 'window-system-initialized t))
+      ;; If there was an error, print the error message and exit.
+      (error
+       (princ
+        (if (eq (car error) 'error)
+            (apply 'concat (cdr error))
+          (if (memq 'file-error (get (car error) 'error-conditions))
+              (format "%s: %s"
+                      (nth 1 error)
+                      (mapconcat (lambda (obj) (prin1-to-string obj t))
+                                 (cdr (cdr error)) ", "))
+            (format "%s: %s"
+                    (get (car error) 'error-message)
                     (mapconcat (lambda (obj) (prin1-to-string obj t))
-                               (cdr (cdr error)) ", "))
-	  (format "%s: %s"
-                  (get (car error) 'error-message)
-                  (mapconcat (lambda (obj) (prin1-to-string obj t))
-                             (cdr error) ", "))))
-      'external-debugging-output)
-     (terpri 'external-debugging-output)
-     (setq initial-window-system nil)
-     (kill-emacs)))
-
-  (run-hooks 'before-init-hook)
-
-  ;; Under X, create the X frame and delete the terminal frame.
-  (unless (daemonp)
-    (if (or noninteractive emacs-basic-display)
-	(setq menu-bar-mode nil
-	      tool-bar-mode nil
-	      no-blinking-cursor t))
-    (frame-initialize))
-
-  (when (fboundp 'x-create-frame)
-    ;; Set up the tool-bar (even in tty frames, since Emacs might open a
-    ;; graphical frame later).
-    (unless noninteractive
-      (tool-bar-setup)))
-
-  ;; Turn off blinking cursor if so specified in X resources.  This is here
-  ;; only because all other settings of no-blinking-cursor are here.
-  (unless (or noninteractive
-	      emacs-basic-display
-	      (and (memq window-system '(x w32 ns))
-		   (not (member (x-get-resource "cursorBlink" "CursorBlink")
-				'("no" "off" "false" "0")))))
-    (setq no-blinking-cursor t))
-
-  ;; Re-evaluate predefined variables whose initial value depends on
-  ;; the runtime context.
-  (mapc 'custom-reevaluate-setting
-        ;; Initialize them in the same order they were loaded, in case there
-        ;; are dependencies between them.
-        (prog1 (nreverse custom-delayed-init-variables)
-          (setq custom-delayed-init-variables nil)))
-
-  (normal-erase-is-backspace-setup-frame)
-
-  ;; Register default TTY colors for the case the terminal hasn't a
-  ;; terminal init file.  We do this regardless of whether the terminal
-  ;; supports colors or not and regardless the current display type,
-  ;; since users can connect to color-capable terminals and also
-  ;; switch color support on or off in mid-session by setting the
-  ;; tty-color-mode frame parameter.
-  ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
-  ;; and they are already set at this point by a suitable function in
-  ;; window-system-initialization-alist.
-  (or (eq initial-window-system 'pc)
-      (tty-register-default-colors))
-
-  (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
-	(old-face-ignored-fonts face-ignored-fonts))
-
-    ;; Run the site-start library if it exists.  The point of this file is
-    ;; that it is run before .emacs.  There is no point in doing this after
-    ;; .emacs; that is useless.
-    ;; Note that user-init-file is nil at this point.  Code that might
-    ;; be loaded from site-run-file and wants to test if -q was given
-    ;; should check init-file-user instead, since that is already set.
-    ;; See cus-edit.el for an example.
-    (if site-run-file
-	(load site-run-file t t))
-
-    ;; Sites should not disable this.  Only individuals should disable
-    ;; the startup screen.
-    (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)))
-      (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)))))))))
-	(if init-file-debug
-	    ;; Do this without a condition-case if the user wants to debug.
-	    (funcall inner)
-	  (condition-case error
-	      (progn
-		(funcall inner)
-		(setq init-file-had-error nil))
-	    (error
-	     ;; Postpone displaying the warning until all hooks
-	     ;; in `after-init-hook' like `desktop-read' will finalize
-	     ;; possible changes in the window configuration.
-	     (add-hook
-	      'after-init-hook
-	      (lambda ()
-		(display-warning
-		 'initialization
-		 (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
+                               (cdr error) ", "))))
+        'external-debugging-output)
+       (terpri 'external-debugging-output)
+       (setq initial-window-system nil)
+       (kill-emacs)))
+
+    (run-hooks 'before-init-hook)
+
+    ;; Under X, create the X frame and delete the terminal frame.
+    (unless (daemonp)
+      (if (or noninteractive emacs-basic-display)
+          (setq menu-bar-mode nil
+                tool-bar-mode nil
+                no-blinking-cursor t))
+      (frame-initialize))
+
+    (when (fboundp 'x-create-frame)
+      ;; Set up the tool-bar (even in tty frames, since Emacs might open a
+      ;; graphical frame later).
+      (unless noninteractive
+        (tool-bar-setup)))
+
+    ;; Turn off blinking cursor if so specified in X resources.  This is here
+    ;; only because all other settings of no-blinking-cursor are here.
+    (unless (or noninteractive
+                emacs-basic-display
+                (and (memq window-system '(x w32 ns))
+                     (not (member (x-get-resource "cursorBlink" "CursorBlink")
+                                  '("no" "off" "false" "0")))))
+      (setq no-blinking-cursor t))
+
+    ;; Re-evaluate predefined variables whose initial value depends on
+    ;; the runtime context.
+    (mapc 'custom-reevaluate-setting
+          ;; Initialize them in the same order they were loaded, in case there
+          ;; are dependencies between them.
+          (prog1 (nreverse custom-delayed-init-variables)
+            (setq custom-delayed-init-variables nil)))
+
+    (normal-erase-is-backspace-setup-frame)
+
+    ;; Register default TTY colors for the case the terminal hasn't a
+    ;; terminal init file.  We do this regardless of whether the terminal
+    ;; supports colors or not and regardless the current display type,
+    ;; since users can connect to color-capable terminals and also
+    ;; switch color support on or off in mid-session by setting the
+    ;; tty-color-mode frame parameter.
+    ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
+    ;; and they are already set at this point by a suitable function in
+    ;; window-system-initialization-alist.
+    (or (eq initial-window-system 'pc)
+        (tty-register-default-colors))
+
+    (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
+          (old-face-ignored-fonts face-ignored-fonts))
+
+      ;; Run the site-start library if it exists.  The point of this file is
+      ;; that it is run before .emacs.  There is no point in doing this after
+      ;; .emacs; that is useless.
+      ;; Note that user-init-file is nil at this point.  Code that might
+      ;; be loaded from site-run-file and wants to test if -q was given
+      ;; should check init-file-user instead, since that is already set.
+      ;; See cus-edit.el for an example.
+      (if site-run-file
+          (load site-run-file t t))
+
+      ;; Sites should not disable this.  Only individuals should disable
+      ;; the startup screen.
+      (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)))
+        (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)
+
+                        ;; Don't load `~/.emacs' if EMACS_USER_DIRECTORY was set
+                        (unless user-emacs-directory--from-env
+                          (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
+                                   (if user-emacs-directory--from-env
+                                       user-emacs-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)))))))))
+          (if init-file-debug
+              ;; Do this without a condition-case if the user wants to debug.
+              (funcall inner)
+            (condition-case error
+                (progn
+                  (funcall inner)
+                  (setq init-file-had-error nil))
+              (error
+               ;; Postpone displaying the warning until all hooks
+               ;; in `after-init-hook' like `desktop-read' will finalize
+               ;; possible changes in the window configuration.
+               (add-hook
+                'after-init-hook
+                (lambda ()
+                  (display-warning
+                   'initialization
+                   (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
 To ensure normal operation, you should investigate and remove the
 cause of the error in your initialization file.  Start Emacs with
 the `--debug-init' option to view a complete error backtrace."
-			 user-init-file
-			 (get (car error) 'error-message)
-			 (if (cdr error) ": " "")
-			 (mapconcat (lambda (s) (prin1-to-string s t))
-				    (cdr error) ", "))
-		 :warning))
-	      t)
-	     (setq init-file-had-error t))))
-
-      (if (and deactivate-mark transient-mark-mode)
-	    (with-current-buffer (window-buffer)
-	      (deactivate-mark)))
-
-	;; If the user has a file of abbrevs, read it (unless -batch).
-	(when (and (not noninteractive)
-		   (file-exists-p abbrev-file-name)
-		   (file-readable-p abbrev-file-name))
-	    (quietly-read-abbrev-file abbrev-file-name))
-
-	;; If the abbrevs came entirely from the init file or the
-	;; abbrevs file, they do not need saving.
-	(setq abbrevs-changed nil)
-
-	;; If we can tell that the init file altered debug-on-error,
-	;; arrange to preserve the value that it set up.
-	(or (eq debug-on-error debug-on-error-initial)
-	    (setq debug-on-error-should-be-set t
-		  debug-on-error-from-init-file debug-on-error)))
-      (if debug-on-error-should-be-set
-	  (setq debug-on-error debug-on-error-from-init-file))
-      (unless (or (default-value 'enable-multibyte-characters)
-		  (eq orig-enable-multibyte (default-value
-					      'enable-multibyte-characters)))
-	;; Init file changed to unibyte.  Reset existing multibyte
-	;; buffers (probably *scratch*, *Messages*, *Minibuf-0*).
-	;; Arguably this should only be done if they're free of
-	;; multibyte characters.
-	(mapc (lambda (buffer)
-		(with-current-buffer buffer
-		  (if enable-multibyte-characters
-		      (set-buffer-multibyte nil))))
-	      (buffer-list))
-	;; Also re-set the language environment in case it was
-	;; originally done before unibyte was set and is sensitive to
-	;; unibyte (display table, terminal coding system &c).
-	(set-language-environment current-language-environment)))
-
-    ;; Do this here in case the init file sets mail-host-address.
-    (if (equal user-mail-address "")
-	(setq user-mail-address (or (getenv "EMAIL")
-				    (concat (user-login-name) "@"
-					    (or mail-host-address
-						(system-name))))))
-
-    ;; If parameter have been changed in the init file which influence
-    ;; face realization, clear the face cache so that new faces will
-    ;; be realized.
-    (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
-		 (eq face-ignored-fonts old-face-ignored-fonts))
-      (clear-face-cache)))
+                           user-init-file
+                           (get (car error) 'error-message)
+                           (if (cdr error) ": " "")
+                           (mapconcat (lambda (s) (prin1-to-string s t))
+                                      (cdr error) ", "))
+                   :warning))
+                t)
+               (setq init-file-had-error t))))
+
+          (if (and deactivate-mark transient-mark-mode)
+              (with-current-buffer (window-buffer)
+                (deactivate-mark)))
+
+          ;; If the user has a file of abbrevs, read it (unless -batch).
+          (when (and (not noninteractive)
+                     (file-exists-p abbrev-file-name)
+                     (file-readable-p abbrev-file-name))
+            (quietly-read-abbrev-file abbrev-file-name))
+
+          ;; If the abbrevs came entirely from the init file or the
+          ;; abbrevs file, they do not need saving.
+          (setq abbrevs-changed nil)
+
+          ;; If we can tell that the init file altered debug-on-error,
+          ;; arrange to preserve the value that it set up.
+          (or (eq debug-on-error debug-on-error-initial)
+              (setq debug-on-error-should-be-set t
+                    debug-on-error-from-init-file debug-on-error)))
+        (if debug-on-error-should-be-set
+            (setq debug-on-error debug-on-error-from-init-file))
+        (unless (or (default-value 'enable-multibyte-characters)
+                    (eq orig-enable-multibyte (default-value
+                                                'enable-multibyte-characters)))
+          ;; Init file changed to unibyte.  Reset existing multibyte
+          ;; buffers (probably *scratch*, *Messages*, *Minibuf-0*).
+          ;; Arguably this should only be done if they're free of
+          ;; multibyte characters.
+          (mapc (lambda (buffer)
+                  (with-current-buffer buffer
+                    (if enable-multibyte-characters
+                        (set-buffer-multibyte nil))))
+                (buffer-list))
+          ;; Also re-set the language environment in case it was
+          ;; originally done before unibyte was set and is sensitive to
+          ;; unibyte (display table, terminal coding system &c).
+          (set-language-environment current-language-environment)))
+
+      ;; Do this here in case the init file sets mail-host-address.
+      (if (equal user-mail-address "")
+          (setq user-mail-address (or (getenv "EMAIL")
+                                      (concat (user-login-name) "@"
+                                              (or mail-host-address
+                                                  (system-name))))))
+
+      ;; If parameter have been changed in the init file which influence
+      ;; face realization, clear the face cache so that new faces will
+      ;; be realized.
+      (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
+                   (eq face-ignored-fonts old-face-ignored-fonts))
+        (clear-face-cache))))
 
   ;; If any package directory exists, initialize the package system.
   (and user-init-file
-- 
1.7.2.5


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

* bug#15539: [PATCH] Setting user-emacs-directory
  2013-10-06 17:08 bug#15539: 24.3; setting user-emacs-directory at command line invocation Mike Carifio
@ 2016-02-15 10:31 ` Alexis
  2016-02-15 14:15   ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Alexis @ 2016-02-15 10:31 UTC (permalink / raw)
  To: 15539


Ping!

Someone on reddit recently enquired about the status of this 
issue:

https://www.reddit.com/r/emacs/comments/44ojpk/interpreting_the_emacs_bug_list_what_was/

Are there any particular things blocking this patch from being 
applied?


Alexis.





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2016-02-15 10:31 ` bug#15539: [PATCH] Setting user-emacs-directory Alexis
@ 2016-02-15 14:15   ` Eli Zaretskii
  2016-02-24  4:03     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 45+ messages in thread
From: Eli Zaretskii @ 2016-02-15 14:15 UTC (permalink / raw)
  To: Alexis; +Cc: 15539

> From: Alexis <flexibeast@gmail.com>
> Date: Mon, 15 Feb 2016 21:31:23 +1100
> 
> 
> Ping!
> 
> Someone on reddit recently enquired about the status of this 
> issue:
> 
> https://www.reddit.com/r/emacs/comments/44ojpk/interpreting_the_emacs_bug_list_what_was/
> 
> Are there any particular things blocking this patch from being 
> applied?

Frankly, I don't think there are important enough use cases behind
this request to add yet another option that allows to change a
well-established constant.  But that's me.  (Didn't see any
enthusiastic reactions from others, either.  Not sure what that
means.)





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2016-02-15 14:15   ` Eli Zaretskii
@ 2016-02-24  4:03     ` Lars Ingebrigtsen
  2016-02-24 17:15       ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-24  4:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alexis, 15539

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alexis <flexibeast@gmail.com>
>> Date: Mon, 15 Feb 2016 21:31:23 +1100
>> 
>> 
>> Ping!
>> 
>> Someone on reddit recently enquired about the status of this 
>> issue:
>> 
>> https://www.reddit.com/r/emacs/comments/44ojpk/interpreting_the_emacs_bug_list_what_was/
>> 
>> Are there any particular things blocking this patch from being 
>> applied?
>
> Frankly, I don't think there are important enough use cases behind
> this request to add yet another option that allows to change a
> well-established constant.  But that's me.  (Didn't see any
> enthusiastic reactions from others, either.  Not sure what that
> means.)

I think it might make sense...  it might make some debugging and testing
cases easier, for instance.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2016-02-24  4:03     ` Lars Ingebrigtsen
@ 2016-02-24 17:15       ` Eli Zaretskii
  2016-02-25  5:48         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 45+ messages in thread
From: Eli Zaretskii @ 2016-02-24 17:15 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: flexibeast, 15539

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Alexis <flexibeast@gmail.com>,  15539@debbugs.gnu.org
> Date: Wed, 24 Feb 2016 15:03:31 +1100
> 
> > Frankly, I don't think there are important enough use cases behind
> > this request to add yet another option that allows to change a
> > well-established constant.  But that's me.  (Didn't see any
> > enthusiastic reactions from others, either.  Not sure what that
> > means.)
> 
> I think it might make sense...  it might make some debugging and testing
> cases easier, for instance.

You mean, the need to temporarily point HOME to some other place?  Is
that really so problematic as to require yet another knob in Emacs?





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2016-02-24 17:15       ` Eli Zaretskii
@ 2016-02-25  5:48         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 45+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-25  5:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: flexibeast, 15539

Eli Zaretskii <eliz@gnu.org> writes:

>> I think it might make sense...  it might make some debugging and testing
>> cases easier, for instance.
>
> You mean, the need to temporarily point HOME to some other place?  Is
> that really so problematic as to require yet another knob in Emacs?

Yeah, that's true.  HOME is easy to switch around, so it doesn't make
much sense to offer this extra knob.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#583: Use XDG basedir spec for configuration files?
  2008-07-21  6:59 bug#583: Use XDG basedir spec for configuration files? Fernando
  2012-12-08 12:18 ` bug#583: XDG basedir specification Eric Heintzmann
@ 2019-08-27 21:57 ` Paul Eggert
  2019-08-28 16:11   ` Glenn Morris
  1 sibling, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-08-27 21:57 UTC (permalink / raw)
  To: ferkiwi+a; +Cc: 583-done, Jan Djärv, Eric Heintzmann

After discussion we added something along the suggested lines to Emacs master here:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=4118297ae2fab4886b20d193ba511a229637aea3

so I am closing bug report number 583.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-27 21:57 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
@ 2019-08-28 16:11   ` Glenn Morris
  2019-08-28 16:29     ` Eli Zaretskii
  2019-08-28 18:11     ` Paul Eggert
  0 siblings, 2 replies; 45+ messages in thread
From: Glenn Morris @ 2019-08-28 16:11 UTC (permalink / raw)
  To: 583; +Cc: ferkiwi+a, eggert


It's great to finally see some progress in this area, but IIUC this is
still not really following the XDG spec. For example, I think a proper
solution would see user elpa packages stored undo XDG_DATA_HOME, etc.
I think the OP points this out.
It looks like what we have at the moment is basically
~/.emacs.d/ -> ~/.config/emacs/?





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-28 16:11   ` Glenn Morris
@ 2019-08-28 16:29     ` Eli Zaretskii
  2019-08-28 16:50       ` Glenn Morris
  2019-08-28 18:11     ` Paul Eggert
  1 sibling, 1 reply; 45+ messages in thread
From: Eli Zaretskii @ 2019-08-28 16:29 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi+a, eggert, 583

> From: Glenn Morris <rgm@gnu.org>
> Date: Wed, 28 Aug 2019 12:11:21 -0400
> Cc: ferkiwi+a@gmail.com, eggert@cs.ucla.edu
> 
> It's great to finally see some progress in this area, but IIUC this is
> still not really following the XDG spec. For example, I think a proper
> solution would see user elpa packages stored undo XDG_DATA_HOME, etc.

Yes, because we don't set user-emacs-directory from XDG_DATA_HOME.  We
only load the init files from there.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-28 16:29     ` Eli Zaretskii
@ 2019-08-28 16:50       ` Glenn Morris
  2019-08-28 17:18         ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Glenn Morris @ 2019-08-28 16:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ferkiwi+a, eggert, 583

Eli Zaretskii wrote:

>> It's great to finally see some progress in this area, but IIUC this is
>> still not really following the XDG spec. For example, I think a proper
>> solution would see user elpa packages stored undo XDG_DATA_HOME, etc.
>
> Yes, because we don't set user-emacs-directory from XDG_DATA_HOME.  We
> only load the init files from there.

I'm not sure I've made my point.
With a proper following of the XDG spec, the concept of (a single)
"user-emacs-directory" would no longer be present. Obviously this
requires more radical changes.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-28 16:50       ` Glenn Morris
@ 2019-08-28 17:18         ` Eli Zaretskii
  2019-08-29  2:17           ` Glenn Morris
  0 siblings, 1 reply; 45+ messages in thread
From: Eli Zaretskii @ 2019-08-28 17:18 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi+a, eggert, 583

> From: Glenn Morris <rgm@gnu.org>
> Cc: 583@debbugs.gnu.org,  ferkiwi+a@gmail.com,  eggert@cs.ucla.edu
> Date: Wed, 28 Aug 2019 12:50:46 -0400
> 
> With a proper following of the XDG spec, the concept of (a single)
> "user-emacs-directory" would no longer be present.

I'm not sure I understand why.  Can you tell more?  (I know very
little about XDG.)





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-28 16:11   ` Glenn Morris
  2019-08-28 16:29     ` Eli Zaretskii
@ 2019-08-28 18:11     ` Paul Eggert
  2019-08-29  2:14       ` Glenn Morris
  1 sibling, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-08-28 18:11 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi, 583

Glenn Morris wrote:
> It's great to finally see some progress in this area, but IIUC this is
> still not really following the XDG spec. For example, I think a proper
> solution would see user elpa packages stored undo XDG_DATA_HOME, etc.
> I think the OP points this out.
> It looks like what we have at the moment is basically
> ~/.emacs.d/ -> ~/.config/emacs/?

Yes, that's what Emacs basically has in master now. I don't see where Fernando 
mentioned ELPA, though. And it's not clear that an ELPA package's files should 
be considered "user specific data files" (XDG_DATA_HOME) as opposed to "user 
specific configuration files" (XDG_CONFIG_HOME).

Looking at my own home directory for what other XDG-ish programs do, I see data 
files under ~/.local/share (XDG_DATA_FILES default): things like 
xorg/Xorg.0.log, gnome-shell/application_state, gvfs-metadata/home, and 
evolution/addressbook/system/contacts.db. Programs (if any) are few and far 
between. (Not that I use many plugins in any programs, so perhaps I'm not the 
best person to check this.)

For what it's worth, I found an old directory named '~/.gimp-2.8' and a newer 
one named '~/.config/GIMP/2.10' with similar structure. It appears that when 
GIMP made the transition to XDG style in GIMP version 2.9.2, it did what Emacs 
just did in master now: that is, GIMP moved all its stuff into ~/config/GIMP. 
Although I don't use GIMP plug-ins, the GIMP plug-ins directory moved too.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-28 18:11     ` Paul Eggert
@ 2019-08-29  2:14       ` Glenn Morris
  2019-08-29  6:22         ` Paul Eggert
  0 siblings, 1 reply; 45+ messages in thread
From: Glenn Morris @ 2019-08-29  2:14 UTC (permalink / raw)
  To: Paul Eggert; +Cc: ferkiwi, 583

Paul Eggert wrote:

>> ~/.emacs.d/ -> ~/.config/emacs/?
>
> Yes, that's what Emacs basically has in master now. I don't see where
> Fernando mentioned ELPA, though.

He didn't. Elpa may not even have existed when this report was opened.
I was using it as an example.

> And it's not clear that an ELPA package's files should be considered
> "user specific data files" (XDG_DATA_HOME) as opposed to "user
> specific configuration files" (XDG_CONFIG_HOME).

It seems clear to me. They are data, not configuration. You would not
install them under /etc, but somewhere like /usr/share.

> For what it's worth, I found an old directory named '~/.gimp-2.8' and
> a newer one named '~/.config/GIMP/2.10' with similar structure. It
> appears that when GIMP made the transition to XDG style in GIMP
> version 2.9.2, it did what Emacs just did in master now: that is, GIMP
> moved all its stuff into ~/config/GIMP. Although I don't use GIMP
> plug-ins, the GIMP plug-ins directory moved too.

IMO "dump everything under ~/.config/emacs" isn't a proper
implementation, even if some other packages have done this.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-28 17:18         ` Eli Zaretskii
@ 2019-08-29  2:17           ` Glenn Morris
  2019-08-29  7:03             ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Glenn Morris @ 2019-08-29  2:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ferkiwi+a, eggert, 583

Eli Zaretskii wrote:

>> From: Glenn Morris <rgm@gnu.org>
>> Cc: 583@debbugs.gnu.org,  ferkiwi+a@gmail.com,  eggert@cs.ucla.edu
>> Date: Wed, 28 Aug 2019 12:50:46 -0400
>> 
>> With a proper following of the XDG spec, the concept of (a single)
>> "user-emacs-directory" would no longer be present.
>
> I'm not sure I understand why.  Can you tell more?  (I know very
> little about XDG.)

It's well documented, the link in the OP still works.
See also eg https://wiki.archlinux.org/index.php/XDG_Base_Directory

IMO a true conversion of Emacs to the XDG spec would involve the
addition of new variables (user-config-directory, user-data-directory,
user-cache-directory, etc). Each use of user-emacs-directory would have
to be reviewed to see where it actually belongs. For some, it would
probably be ambiguous.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29  2:14       ` Glenn Morris
@ 2019-08-29  6:22         ` Paul Eggert
  2019-08-29  8:42           ` Štěpán Němec
  2019-08-29 18:30           ` Glenn Morris
  0 siblings, 2 replies; 45+ messages in thread
From: Paul Eggert @ 2019-08-29  6:22 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi, 583

Glenn Morris wrote:
>> And it's not clear that an ELPA package's files should be considered
>> "user specific data files" (XDG_DATA_HOME) as opposed to "user
>> specific configuration files" (XDG_CONFIG_HOME).

> It seems clear to me. They are data, not configuration. You would not
> install them under /etc, but somewhere like /usr/share.

If I understand correctly, ELPA packages are not really either "data" or 
"configuration": they're software packages. And the XDG scheme doesn't appear to 
be designed for installing software packages: it's designed only for user 
preferences (aka configuration), user data, and information cached for the user.

If ELPA packages are just local copies from a server somewhere, it seems the 
most plausible place for them is the XDG cache (XDG_CACHE_HOME, which is 
~/.cache by default) rather than either in "data" or "configuration"; only the 
list of downloaded packages should be placed in XDG_CONFIG_HOME. Presumably the 
ELPA package manager could arrange for this.

Not being an expert in these matters, I looked at another popular packaging 
scheme: Flatpak. It appears to put everything under ~/.local/share, i.e., under 
XDG_DATA_HOME. This includes configuration. See 
<https://github.com/flatpak/flatpak/wiki/Filesystem>.

It's quite a mess, huh?





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29  2:17           ` Glenn Morris
@ 2019-08-29  7:03             ` Eli Zaretskii
  0 siblings, 0 replies; 45+ messages in thread
From: Eli Zaretskii @ 2019-08-29  7:03 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi+a, eggert, 583

> From: Glenn Morris <rgm@gnu.org>
> Cc: 583@debbugs.gnu.org,  ferkiwi+a@gmail.com,  eggert@cs.ucla.edu
> Date: Wed, 28 Aug 2019 22:17:55 -0400
> 
> IMO a true conversion of Emacs to the XDG spec would involve the
> addition of new variables (user-config-directory, user-data-directory,
> user-cache-directory, etc). Each use of user-emacs-directory would have
> to be reviewed to see where it actually belongs. For some, it would
> probably be ambiguous.

I'm afraid almost all of them will be ambiguous.  Moreover, defining a
clear enough set of rules for where to put files that will be added in
the future is a non-trivial job, and enforcing it will not be easy.  I
predict confusion and arguments.

My gut feeling is that Emacs should have one, at most 2 XDG-derived
directories, certainly not 3.  And if we want to support that
correctly, these environment variables should be accessed much earlier
in the startup process, somewhere in init_callproc and friends,
because setting user-emacs-directory in startup is too late and
creates problems, as we saw already.

We've made a small step in that direction; if we want to continue that
way, someone should volunteer to do the job of defining what files
will go were.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29  6:22         ` Paul Eggert
@ 2019-08-29  8:42           ` Štěpán Němec
  2019-08-29 18:30           ` Glenn Morris
  1 sibling, 0 replies; 45+ messages in thread
From: Štěpán Němec @ 2019-08-29  8:42 UTC (permalink / raw)
  To: Paul Eggert; +Cc: ferkiwi, 583

On Wed, 28 Aug 2019 23:22:35 -0700
Paul Eggert wrote:

> If ELPA packages are just local copies from a server somewhere, it
> seems the most plausible place for them is the XDG cache
> (XDG_CACHE_HOME, which is ~/.cache by default) rather than either in
> "data" or "configuration"; only the list of downloaded packages should
> be placed in XDG_CONFIG_HOME. Presumably the ELPA package manager
> could arrange for this.

XDG_CACHE_HOME is for "non-essential data files" (quoting the spec).
Some people put it on tmpfs, so it is deleted on system restart.

> Not being an expert in these matters, I looked at another popular
> packaging scheme: Flatpak. It appears to put everything under
> ~/.local/share, i.e., under XDG_DATA_HOME. This includes
> configuration. See
> <https://github.com/flatpak/flatpak/wiki/Filesystem>.

Some programs (notably Python[1]) use ~/.local/lib/, which makes sense,
but is not part of the XDG spec.

> It's quite a mess, huh?

It is.

[1] https://www.python.org/dev/peps/pep-0370/

-- 
Štěpán





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29  6:22         ` Paul Eggert
  2019-08-29  8:42           ` Štěpán Němec
@ 2019-08-29 18:30           ` Glenn Morris
  2019-08-29 18:35             ` Glenn Morris
                               ` (3 more replies)
  1 sibling, 4 replies; 45+ messages in thread
From: Glenn Morris @ 2019-08-29 18:30 UTC (permalink / raw)
  To: Paul Eggert; +Cc: ferkiwi, 583


BTW, I think the handling of user-emacs-directory is buggy:

rm -rf /tmp/foo
mkdir -p /tmp/foo/.config/emacs
HOME=/tmp/foo emacs

Now:
user-init-file         -> /tmp/foo/.config/emacs/init
user-emacs-directory   -> ~/.emacs.d/

I guess user-emacs-directory is being set at build time, not run time.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29 18:30           ` Glenn Morris
@ 2019-08-29 18:35             ` Glenn Morris
  2019-08-29 18:53             ` Eli Zaretskii
                               ` (2 subsequent siblings)
  3 siblings, 0 replies; 45+ messages in thread
From: Glenn Morris @ 2019-08-29 18:35 UTC (permalink / raw)
  To: Paul Eggert; +Cc: ferkiwi, 583


PS I should have prefaced this recipe with "having built Emacs in an
environment where ~/.config/emacs does not exist".





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29 18:30           ` Glenn Morris
  2019-08-29 18:35             ` Glenn Morris
@ 2019-08-29 18:53             ` Eli Zaretskii
  2019-08-30  8:02             ` Paul Eggert
  2019-08-31 21:51             ` Paul Eggert
  3 siblings, 0 replies; 45+ messages in thread
From: Eli Zaretskii @ 2019-08-29 18:53 UTC (permalink / raw)
  To: Glenn Morris; +Cc: eggert, ferkiwi, 583

> From: Glenn Morris <rgm@gnu.org>
> Date: Thu, 29 Aug 2019 14:30:54 -0400
> Cc: ferkiwi@gmail.com, 583@debbugs.gnu.org
> 
> rm -rf /tmp/foo
> mkdir -p /tmp/foo/.config/emacs
> HOME=/tmp/foo emacs
> 
> Now:
> user-init-file         -> /tmp/foo/.config/emacs/init
> user-emacs-directory   -> ~/.emacs.d/
> 
> I guess user-emacs-directory is being set at build time, not run time.

It's a defconst in subr.el, and I believe one of my review comments
for the initial version of the patch was that I didn't think using
defconst for this was correct.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29 18:30           ` Glenn Morris
  2019-08-29 18:35             ` Glenn Morris
  2019-08-29 18:53             ` Eli Zaretskii
@ 2019-08-30  8:02             ` Paul Eggert
  2019-08-30 16:18               ` Glenn Morris
  2019-08-31 21:51             ` Paul Eggert
  3 siblings, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-08-30  8:02 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi, 583

Glenn Morris wrote:
> BTW, I think the handling of user-emacs-directory is buggy:

Yes, it is. I'll have to take a look at that. I guess we'll have to change 
user-home-directory to a variable, since we can't easily determine it until 
command-line runs.

Also, a good many places in the documentaiton refer to ~/.emacs.d and these need 
to be updated.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-30  8:02             ` Paul Eggert
@ 2019-08-30 16:18               ` Glenn Morris
  2019-08-30 17:44                 ` Eli Zaretskii
                                   ` (2 more replies)
  0 siblings, 3 replies; 45+ messages in thread
From: Glenn Morris @ 2019-08-30 16:18 UTC (permalink / raw)
  To: Paul Eggert; +Cc: ferkiwi, 583

Paul Eggert wrote:

>> BTW, I think the handling of user-emacs-directory is buggy:
>
> Yes, it is. I'll have to take a look at that. I guess we'll have to
> change user-home-directory to a variable, since we can't easily
> determine it until command-line runs.
>
> Also, a good many places in the documentaiton refer to ~/.emacs.d and
> these need to be updated.

IMO this means one should allow a user-defined user-emacs-directory,
which means un-wontfix'ing https://debbugs.gnu.org/15539 .
Maybe the patch in https://debbugs.gnu.org/15539#40 contains some useful ideas.
Although in hindsight an environment variable doesn't seem like the way
to go.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-30 16:18               ` Glenn Morris
@ 2019-08-30 17:44                 ` Eli Zaretskii
  2019-09-01  1:56                 ` bug#15539: [PATCH] Setting user-emacs-directory Paul Eggert
  2019-09-01  2:02                 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
  2 siblings, 0 replies; 45+ messages in thread
From: Eli Zaretskii @ 2019-08-30 17:44 UTC (permalink / raw)
  To: Glenn Morris; +Cc: eggert, ferkiwi, 583

> From: Glenn Morris <rgm@gnu.org>
> Date: Fri, 30 Aug 2019 12:18:40 -0400
> Cc: ferkiwi@gmail.com, 583@debbugs.gnu.org
> 
> Although in hindsight an environment variable doesn't seem like the way
> to go.

Actually, I think it does, because otherwise the user-defined value
will be noticed too late, after defcustom's that depend on it were
already recomputed.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-29 18:30           ` Glenn Morris
                               ` (2 preceding siblings ...)
  2019-08-30  8:02             ` Paul Eggert
@ 2019-08-31 21:51             ` Paul Eggert
  2019-09-11  9:21               ` Sven Joachim
  3 siblings, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-08-31 21:51 UTC (permalink / raw)
  To: Glenn Morris; +Cc: ferkiwi, 583

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

Glenn Morris wrote:
> I guess user-emacs-directory is being set at build time, not run time.

Thanks for reporting that. I installed the attached to fix it. I plan to follow 
up soon on the other issues raised here.

[-- Attachment #2: 0001-Calculate-user-emacs-directory-on-startup.patch --]
[-- Type: text/x-patch, Size: 4737 bytes --]

From 2befb4f0a1494f699f56215d5f28ba055663d881 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 31 Aug 2019 14:47:04 -0700
Subject: [PATCH] Calculate user-emacs-directory on startup

Problem reported by Glenn Morris (Bug#583#56).
* lisp/startup.el (startup--xdg-config-default): New constant.
(startup--xdg-config-home-emacs): New var.
(startup--xdg-or-homedot): New function.
(normal-top-level): Use it to set user-emacs-directory early on.
(command-line): Also use it to determine the startup init directory.
* lisp/subr.el (user-emacs-directory): Just initialize to nil.
---
 lisp/startup.el | 51 +++++++++++++++++++++++++++++++++++++------------
 lisp/subr.el    | 14 ++------------
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index c1e429b8db..a16db242da 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -490,6 +490,27 @@ normal-top-level-add-to-load-path
     (when tail
       (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
 
+;; The default location for XDG-convention Emacs init files.
+(defconst startup--xdg-config-default "~/.config/emacs/")
+;; The location for XDG-convention Emacs init files.
+(defvar startup--xdg-config-home-emacs)
+
+;; Return the name of the init file directory for Emacs, assuming
+;; XDG-DIR is the XDG location and USER-NAME is the user name.
+;; If USER-NAME is nil or "", use the current user.
+;; Prefer the XDG location unless it does does not exist and the
+;; .emacs.d location does exist.
+(defun startup--xdg-or-homedot (xdg-dir user-name)
+  (if (file-exists-p xdg-dir)
+      xdg-dir
+    (let ((emacs-d-dir (concat "~" user-name
+			       (if (eq system-type 'ms-dos)
+				   "/_emacs.d/"
+				 "/.emacs.d/"))))
+      (if (file-exists-p emacs-d-dir)
+	  emacs-d-dir
+	xdg-dir))))
+
 (defun normal-top-level ()
   "Emacs calls this function when it first starts up.
 It sets `command-line-processed', processes the command-line,
@@ -499,6 +520,14 @@ normal-top-level
       (message internal--top-level-message)
     (setq command-line-processed t)
 
+    (setq startup--xdg-config-home-emacs
+	  (let ((xdg-config-home (getenv-internal "XDG_CONFIG_HOME")))
+	    (if xdg-config-home
+		(concat xdg-config-home "/emacs/")
+	      startup--xdg-config-default)))
+    (setq user-emacs-directory
+	  (startup--xdg-or-homedot startup--xdg-config-home-emacs nil))
+
     ;; Look in each dir in load-path for a subdirs.el file.  If we
     ;; find one, load it, which will add the appropriate subdirs of
     ;; that dir into load-path.  This needs to be done before setting
@@ -1167,19 +1196,17 @@ command-line
                          :error))))
 
   ;; Calculate the name of the Emacs init directory.
-  ;; This is typically equivalent to ~/.config/emacs if the user is
-  ;; following the XDG convention, and is ~INIT-FILE-USER/.emacs.d
-  ;; on other systems.
-  (setq xdg-dir (concat (or (getenv "XDG_CONFIG_HOME")
-			    (concat "~" init-file-user "/.config"))
-			"/emacs/"))
+  ;; This is typically ~INIT-FILE-USER/.config/emacs unless the user
+  ;; is following the ~INIT-FILE-USER/.emacs.d convention.
+  (setq xdg-dir startup--xdg-config-home-emacs)
   (setq startup-init-directory
-	(if (file-exists-p xdg-dir)
-	    xdg-dir
-	  (let ((emacs-d-dir (concat "~" init-file-user "/.emacs.d/")))
-	    (if (file-exists-p emacs-d-dir)
-		emacs-d-dir
-	      xdg-dir))))
+	(if (or (zerop (length init-file-user))
+		(and (eq xdg-dir user-emacs-directory)
+		     (not (eq xdg-dir startup--xdg-config-default))))
+	    user-emacs-directory
+	  ;; The name is not obvious, so access more directories to calculate it.
+	  (setq xdg-dir (concat "~" init-file-user "/.config/emacs/"))
+	  (startup--xdg-or-homedot xdg-dir init-file-user)))
 
   ;; Load the early init file, if found.
   (startup--load-user-init-file
diff --git a/lisp/subr.el b/lisp/subr.el
index 566a3fc758..cf6fb108e9 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2938,18 +2938,8 @@ temp-buffer-setup-hook
 mode.")
 
 (defconst user-emacs-directory
-  (let ((config-dir (concat (or (getenv-internal "XDG_CONFIG_HOME")
-				"~/.config")
-			    "/emacs/")))
-    (if (file-exists-p config-dir)
-	config-dir
-      (let ((emacs-d-dir (if (eq system-type 'ms-dos)
-			     ;; MS-DOS cannot have initial dot.
-			     "~/_emacs.d/"
-			   "~/.emacs.d/")))
-	(if (file-exists-p emacs-d-dir)
-	    emacs-d-dir
-	  config-dir))))
+  ;; The value does not matter since Emacs sets this at startup.
+  nil
   "Directory beneath which additional per-user Emacs-specific files are placed.
 Various programs in Emacs store information in this directory.
 Note that this should end with a directory separator.
-- 
2.17.1


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

* bug#15539: [PATCH] Setting user-emacs-directory
  2019-08-30 16:18               ` Glenn Morris
  2019-08-30 17:44                 ` Eli Zaretskii
@ 2019-09-01  1:56                 ` Paul Eggert
  2019-09-02 23:45                   ` Glenn Morris
  2019-09-01  2:02                 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
  2 siblings, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-09-01  1:56 UTC (permalink / raw)
  To: 15539
  Cc: Max, Mike Carifio, Evgeny Roubinchtein,
	François Févotte, John Wiegley, Noam Postavsky,
	Oleh Krehel, Alexis, Lars Ingebrigtsen

Glenn Morris mentioned Bug#15539's user-emacs-directory issue here:

https://bugs.gnu.org/583#68

... so this email is giving you a heads-up that I recently installed a patch 
into GNU Emacs master that should allow something approximating Bug#15539's 
requested behavior. For example, one can run Emacs like this:

XDG_CONFIG_HOME=/home/rms/.config emacs

to employ user rms's Emacs configuration, instead of your configuration.

The patch I installed did not do anything special to fix bug#15539, as the new 
Emacs behavior is a natural fallout of supporting the XDG spec's requirements 
for XDG_CONFIG_HOME.

This all assumes people are using the XDG-conforming locations for config files, 
which I hope is good enough since older Emacs obviously wasn't meeting the 
Bug#15539 need anyway.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-30 16:18               ` Glenn Morris
  2019-08-30 17:44                 ` Eli Zaretskii
  2019-09-01  1:56                 ` bug#15539: [PATCH] Setting user-emacs-directory Paul Eggert
@ 2019-09-01  2:02                 ` Paul Eggert
  2019-09-01 14:38                   ` Eli Zaretskii
  2 siblings, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-09-01  2:02 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 583

Glenn Morris wrote:
> IMO this means one should allow a user-defined user-emacs-directory,
> which means un-wontfix'ing https://debbugs.gnu.org/15539  .

Thanks for mentioning that. I followed up in that bug report, here:

https://bugs.gnu.org/15539#109

By the way, making user-emacs-directory a variable instead of a constant has its 
downsides, because if a user changes user-emacs-directory, then a lot of other 
variables will keep their old values derived from the previous value of 
user-emacs-directory, leading to a confusing mish-mosh of old and new behavior. 
Changing user-emacs-directory works coherently only if it's done very early in 
startup (which is all that Bug#15539 was asking for).





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-09-01  2:02                 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
@ 2019-09-01 14:38                   ` Eli Zaretskii
  2019-09-01 18:40                     ` Paul Eggert
  0 siblings, 1 reply; 45+ messages in thread
From: Eli Zaretskii @ 2019-09-01 14:38 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 583

> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Sat, 31 Aug 2019 19:02:01 -0700
> Cc: 583@debbugs.gnu.org
> 
> Changing user-emacs-directory works coherently only if it's done very early in 
> startup (which is all that Bug#15539 was asking for).

We should document what that "very early" means in practice.  Does it
mean in the early-init file? or can this be done reliably in the
normal init file as well?

The problem here is that some defcustom's refer to
user-emacs-directory, and so changing the value of
user-emacs-directory after those defcustoms were computed during
startup will leave those defcustoms pointing at the old place.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-09-01 14:38                   ` Eli Zaretskii
@ 2019-09-01 18:40                     ` Paul Eggert
  2019-09-01 18:50                       ` Eli Zaretskii
  0 siblings, 1 reply; 45+ messages in thread
From: Paul Eggert @ 2019-09-01 18:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 583

Eli Zaretskii wrote:
> We should document what that "very early" means in practice.  Does it
> mean in the early-init file? or can this be done reliably in the
> normal init file as well?

Sorry, I don't know. That's why I didn't document it.

> The problem here is that some defcustom's refer to
> user-emacs-directory, and so changing the value of
> user-emacs-directory after those defcustoms were computed during
> startup will leave those defcustoms pointing at the old place.

Yes, it's quite a mess.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-09-01 18:40                     ` Paul Eggert
@ 2019-09-01 18:50                       ` Eli Zaretskii
  2019-09-01 23:01                         ` Paul Eggert
  0 siblings, 1 reply; 45+ messages in thread
From: Eli Zaretskii @ 2019-09-01 18:50 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 583

> Cc: rgm@gnu.org, 583@debbugs.gnu.org
> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Sun, 1 Sep 2019 11:40:21 -0700
> 
> Eli Zaretskii wrote:
> > We should document what that "very early" means in practice.  Does it
> > mean in the early-init file? or can this be done reliably in the
> > normal init file as well?
> 
> Sorry, I don't know. That's why I didn't document it.
> 
> > The problem here is that some defcustom's refer to
> > user-emacs-directory, and so changing the value of
> > user-emacs-directory after those defcustoms were computed during
> > startup will leave those defcustoms pointing at the old place.
> 
> Yes, it's quite a mess.

If doing this in early-init works, I'd rather we documented that as
the canonical place that saves users from the mess.





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

* bug#583: Use XDG basedir spec for configuration files?
  2019-09-01 18:50                       ` Eli Zaretskii
@ 2019-09-01 23:01                         ` Paul Eggert
  0 siblings, 0 replies; 45+ messages in thread
From: Paul Eggert @ 2019-09-01 23:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 583

Eli Zaretskii wrote:
>> Yes, it's quite a mess.
> If doing this in early-init works, I'd rather we documented that as
> the canonical place that saves users from the mess.

I doubt whether it even works in early-init. Not that I've tested it; I don't 
use early-init and would not be a good person to delve deeper into that part of 
the mess.





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2019-09-01  1:56                 ` bug#15539: [PATCH] Setting user-emacs-directory Paul Eggert
@ 2019-09-02 23:45                   ` Glenn Morris
  2019-09-03  6:29                     ` Paul Eggert
  0 siblings, 1 reply; 45+ messages in thread
From: Glenn Morris @ 2019-09-02 23:45 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Alexis, François Févotte, Max, Mike Carifio,
	Evgeny Roubinchtein, Noam Postavsky, John Wiegley, Oleh Krehel,
	15539, Lars Ingebrigtsen

Paul Eggert wrote:

> ... so this email is giving you a heads-up that I recently installed a
> patch into GNU Emacs master that should allow something approximating
> Bug#15539's requested behavior. For example, one can run Emacs like
> this:
>
> XDG_CONFIG_HOME=/home/rms/.config emacs
>
> to employ user rms's Emacs configuration, instead of your configuration.

This is an improvement, but it is not a proper solution to #15539, for
some of the same reasons that "just change HOME" wasn't. XDG_CONFIG_HOME
is not an Emacs-specific variable, so changing it will impact other
things that may be called from within Emacs.





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2019-09-02 23:45                   ` Glenn Morris
@ 2019-09-03  6:29                     ` Paul Eggert
  2019-09-08 14:54                       ` Mike Carifio
  2020-08-13 11:06                       ` Lars Ingebrigtsen
  0 siblings, 2 replies; 45+ messages in thread
From: Paul Eggert @ 2019-09-03  6:29 UTC (permalink / raw)
  To: Glenn Morris
  Cc: Alexis, François Févotte, Max, Mike Carifio,
	Evgeny Roubinchtein, Noam Postavsky, John Wiegley, Oleh Krehel,
	15539, Lars Ingebrigtsen

Glenn Morris wrote:
> XDG_CONFIG_HOME
> is not an Emacs-specific variable, so changing it will impact other
> things that may be called from within Emacs.

True, but it should suffice for many use cases mentioned in Bug#15539. Of the 
cases mentioned here:

https://bugs.gnu.org/15539#66

XDG_HOME should suffice for most of issues mentioned. Not all: for example, 
overriding XDG_CONFIG_HOME overrides Gtk configuration, font configuration, and 
other settings covered by the XDG convention, whereas one might want to override 
just ~/.config/emacs. But it strikes me that this is often just as much of a 
feature as a drawback, since Gtk etc. configurations influence Emacs so much 
that they really ought to be saved/restored when one is thinking of 
saving/restoring Emacs settings.

One might have a situation where one wants to vary (or save) files traditionally 
kept in ~/.emacs.d/, and no other files. But it's also quite plausible that one 
will want some of those files and not others, just as one might want 
~/.config/emacs and ~/.config/fontconfig but not ~/.config/gtk-3.0. And it's 
unlikely that a single option will have all the fine-grained control that one 
would need for all these situations. Instead, it's probably better just to 
suggest to people that they set up $HOME (or perhaps $XDG_CONFIG_HOME) to point 
to a directory full of configurations that are just they way they like it.





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2019-09-03  6:29                     ` Paul Eggert
@ 2019-09-08 14:54                       ` Mike Carifio
  2020-08-13 11:06                       ` Lars Ingebrigtsen
  1 sibling, 0 replies; 45+ messages in thread
From: Mike Carifio @ 2019-09-08 14:54 UTC (permalink / raw)
  To: Paul Eggert, Glenn Morris
  Cc: Alexis, François Févotte, Max, Evgeny Roubinchtein,
	Noam Postavsky, John Wiegley, Oleh Krehel, 15539,
	Lars Ingebrigtsen

As the OP approximately six years ago, I neglected to add the "use-case" 
I wanted --user-emacs-directory for, namely to experiment with 
~/.emacs.d/init.el including installing new packages via elpa. I still 
think there's a need, especially as the number of useful packages have 
grown and they can interact. I currently use the "symlink" approach when 
I want to start adding new packages and configurations. It's useful to 
return to a "known good state" if my init.el hacking careens off the 
tracks. Since there was already a _variable_ user-emacs-directory, I 
thought I was just asking to set it early at the command line. It seemed 
to be analogous to --load for an emacs file or --user for another user's 
init file. I didn't realize it had a "read-only" flavor.

Yes, this switch adds another knob, but I happen to think its a useful 
knob and is consistent with --load and --user, both of which allow the 
user to designate a different init file at the command line. Redefining 
HOME at the command line and then "setting it back" inside init.el seems 
convoluted. It could also potentially break site-start.el if some code 
there relied on the right binding of HOME. Admittedly that's a 
farfetched scenario, but not impossible either. Sure would be confusing 
to debug if you didn't know what to look for. All the "do it yourself" 
strategies (other than symlink) also force the user to deeply understand 
the details of the init process, e.g. what switches to throw to override 
various features. So if the criticism is "yet another knob" I would say 
you are pushing people to construct homegrown solutions ... repeatedly.

The XDG patch will let emacs adhere to the XDG desktop conventions and 
you can designate the user-emacs-directory implicitly as well, a 
two-for-one special. Not every platform follows the XDG conventions, but 
I personally mostly use linux, so I'm less concerned with those.








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

* bug#583: Use XDG basedir spec for configuration files?
  2019-08-31 21:51             ` Paul Eggert
@ 2019-09-11  9:21               ` Sven Joachim
  0 siblings, 0 replies; 45+ messages in thread
From: Sven Joachim @ 2019-09-11  9:21 UTC (permalink / raw)
  To: Paul Eggert; +Cc: ferkiwi, 583

On 2019-08-31 14:51 -0700, Paul Eggert wrote:

> Glenn Morris wrote:
>> I guess user-emacs-directory is being set at build time, not run time.
>
> Thanks for reporting that. I installed the attached to fix it. I plan
> to follow up soon on the other issues raised here.

FWIW, this patch broke auto-save-list-file-prefix, at least when
user-emacs-directory is "~/.emacs.d/".  See bug #37354.

,----
| auto-save-list-file-prefix is a variable defined in ‘startup.el’.
| Its value is "auto-save-list/.saves-"
| Original value was
| "~/.emacs.d/auto-save-list/.saves-"
`----

Cheers,
       Sven


> From 2befb4f0a1494f699f56215d5f28ba055663d881 Mon Sep 17 00:00:00 2001
> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Sat, 31 Aug 2019 14:47:04 -0700
> Subject: [PATCH] Calculate user-emacs-directory on startup
>
> Problem reported by Glenn Morris (Bug#583#56).
> * lisp/startup.el (startup--xdg-config-default): New constant.
> (startup--xdg-config-home-emacs): New var.
> (startup--xdg-or-homedot): New function.
> (normal-top-level): Use it to set user-emacs-directory early on.
> (command-line): Also use it to determine the startup init directory.
> * lisp/subr.el (user-emacs-directory): Just initialize to nil.
> ---
>  lisp/startup.el | 51 +++++++++++++++++++++++++++++++++++++------------
>  lisp/subr.el    | 14 ++------------
>  2 files changed, 41 insertions(+), 24 deletions(-)
>
> diff --git a/lisp/startup.el b/lisp/startup.el
> index c1e429b8db..a16db242da 100644
> --- a/lisp/startup.el
> +++ b/lisp/startup.el
> @@ -490,6 +490,27 @@ normal-top-level-add-to-load-path
>      (when tail
>        (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
>  
> +;; The default location for XDG-convention Emacs init files.
> +(defconst startup--xdg-config-default "~/.config/emacs/")
> +;; The location for XDG-convention Emacs init files.
> +(defvar startup--xdg-config-home-emacs)
> +
> +;; Return the name of the init file directory for Emacs, assuming
> +;; XDG-DIR is the XDG location and USER-NAME is the user name.
> +;; If USER-NAME is nil or "", use the current user.
> +;; Prefer the XDG location unless it does does not exist and the
> +;; .emacs.d location does exist.
> +(defun startup--xdg-or-homedot (xdg-dir user-name)
> +  (if (file-exists-p xdg-dir)
> +      xdg-dir
> +    (let ((emacs-d-dir (concat "~" user-name
> +			       (if (eq system-type 'ms-dos)
> +				   "/_emacs.d/"
> +				 "/.emacs.d/"))))
> +      (if (file-exists-p emacs-d-dir)
> +	  emacs-d-dir
> +	xdg-dir))))
> +
>  (defun normal-top-level ()
>    "Emacs calls this function when it first starts up.
>  It sets `command-line-processed', processes the command-line,
> @@ -499,6 +520,14 @@ normal-top-level
>        (message internal--top-level-message)
>      (setq command-line-processed t)
>  
> +    (setq startup--xdg-config-home-emacs
> +	  (let ((xdg-config-home (getenv-internal "XDG_CONFIG_HOME")))
> +	    (if xdg-config-home
> +		(concat xdg-config-home "/emacs/")
> +	      startup--xdg-config-default)))
> +    (setq user-emacs-directory
> +	  (startup--xdg-or-homedot startup--xdg-config-home-emacs nil))
> +
>      ;; Look in each dir in load-path for a subdirs.el file.  If we
>      ;; find one, load it, which will add the appropriate subdirs of
>      ;; that dir into load-path.  This needs to be done before setting
> @@ -1167,19 +1196,17 @@ command-line
>                           :error))))
>  
>    ;; Calculate the name of the Emacs init directory.
> -  ;; This is typically equivalent to ~/.config/emacs if the user is
> -  ;; following the XDG convention, and is ~INIT-FILE-USER/.emacs.d
> -  ;; on other systems.
> -  (setq xdg-dir (concat (or (getenv "XDG_CONFIG_HOME")
> -			    (concat "~" init-file-user "/.config"))
> -			"/emacs/"))
> +  ;; This is typically ~INIT-FILE-USER/.config/emacs unless the user
> +  ;; is following the ~INIT-FILE-USER/.emacs.d convention.
> +  (setq xdg-dir startup--xdg-config-home-emacs)
>    (setq startup-init-directory
> -	(if (file-exists-p xdg-dir)
> -	    xdg-dir
> -	  (let ((emacs-d-dir (concat "~" init-file-user "/.emacs.d/")))
> -	    (if (file-exists-p emacs-d-dir)
> -		emacs-d-dir
> -	      xdg-dir))))
> +	(if (or (zerop (length init-file-user))
> +		(and (eq xdg-dir user-emacs-directory)
> +		     (not (eq xdg-dir startup--xdg-config-default))))
> +	    user-emacs-directory
> +	  ;; The name is not obvious, so access more directories to calculate it.
> +	  (setq xdg-dir (concat "~" init-file-user "/.config/emacs/"))
> +	  (startup--xdg-or-homedot xdg-dir init-file-user)))
>  
>    ;; Load the early init file, if found.
>    (startup--load-user-init-file
> diff --git a/lisp/subr.el b/lisp/subr.el
> index 566a3fc758..cf6fb108e9 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -2938,18 +2938,8 @@ temp-buffer-setup-hook
>  mode.")
>  
>  (defconst user-emacs-directory
> -  (let ((config-dir (concat (or (getenv-internal "XDG_CONFIG_HOME")
> -				"~/.config")
> -			    "/emacs/")))
> -    (if (file-exists-p config-dir)
> -	config-dir
> -      (let ((emacs-d-dir (if (eq system-type 'ms-dos)
> -			     ;; MS-DOS cannot have initial dot.
> -			     "~/_emacs.d/"
> -			   "~/.emacs.d/")))
> -	(if (file-exists-p emacs-d-dir)
> -	    emacs-d-dir
> -	  config-dir))))
> +  ;; The value does not matter since Emacs sets this at startup.
> +  nil
>    "Directory beneath which additional per-user Emacs-specific files are placed.
>  Various programs in Emacs store information in this directory.
>  Note that this should end with a directory separator.
> -- 
> 2.17.1





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

* bug#15539: [PATCH] Setting user-emacs-directory
  2019-09-03  6:29                     ` Paul Eggert
  2019-09-08 14:54                       ` Mike Carifio
@ 2020-08-13 11:06                       ` Lars Ingebrigtsen
  1 sibling, 0 replies; 45+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-13 11:06 UTC (permalink / raw)
  To: Paul Eggert
  Cc: Glenn Morris, Max, Mike Carifio, Evgeny Roubinchtein,
	François Févotte, John Wiegley, Noam Postavsky,
	Oleh Krehel, 15539, Alexis

Paul Eggert <eggert@cs.ucla.edu> writes:

> One might have a situation where one wants to vary (or save) files
> traditionally kept in ~/.emacs.d/, and no other files. But it's also
> quite plausible that one will want some of those files and not others,
> just as one might want ~/.config/emacs and ~/.config/fontconfig but
> not ~/.config/gtk-3.0. And it's unlikely that a single option will
> have all the fine-grained control that one would need for all these
> situations. Instead, it's probably better just to suggest to people
> that they set up $HOME (or perhaps $XDG_CONFIG_HOME) to point to a
> directory full of configurations that are just they way they like it.

So I think the conclusion to this long thread was that we don't want to
add a specific switch for this, and instead people can say
"XDG_CONFIG_HOME=/whatever emacs" when they want to change these paths.
So I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2020-08-13 11:06 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-21  6:59 bug#583: Use XDG basedir spec for configuration files? Fernando
2012-12-08 12:18 ` bug#583: XDG basedir specification Eric Heintzmann
2012-12-08 19:06   ` Jan Djärv
2012-12-08 19:31     ` Eli Zaretskii
2019-08-27 21:57 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
2019-08-28 16:11   ` Glenn Morris
2019-08-28 16:29     ` Eli Zaretskii
2019-08-28 16:50       ` Glenn Morris
2019-08-28 17:18         ` Eli Zaretskii
2019-08-29  2:17           ` Glenn Morris
2019-08-29  7:03             ` Eli Zaretskii
2019-08-28 18:11     ` Paul Eggert
2019-08-29  2:14       ` Glenn Morris
2019-08-29  6:22         ` Paul Eggert
2019-08-29  8:42           ` Štěpán Němec
2019-08-29 18:30           ` Glenn Morris
2019-08-29 18:35             ` Glenn Morris
2019-08-29 18:53             ` Eli Zaretskii
2019-08-30  8:02             ` Paul Eggert
2019-08-30 16:18               ` Glenn Morris
2019-08-30 17:44                 ` Eli Zaretskii
2019-09-01  1:56                 ` bug#15539: [PATCH] Setting user-emacs-directory Paul Eggert
2019-09-02 23:45                   ` Glenn Morris
2019-09-03  6:29                     ` Paul Eggert
2019-09-08 14:54                       ` Mike Carifio
2020-08-13 11:06                       ` Lars Ingebrigtsen
2019-09-01  2:02                 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
2019-09-01 14:38                   ` Eli Zaretskii
2019-09-01 18:40                     ` Paul Eggert
2019-09-01 18:50                       ` Eli Zaretskii
2019-09-01 23:01                         ` Paul Eggert
2019-08-31 21:51             ` Paul Eggert
2019-09-11  9:21               ` Sven Joachim
  -- strict thread matches above, loose matches on Subject: below --
2013-10-06 17:08 bug#15539: 24.3; setting user-emacs-directory at command line invocation Mike Carifio
2016-02-15 10:31 ` bug#15539: [PATCH] Setting user-emacs-directory Alexis
2016-02-15 14:15   ` Eli Zaretskii
2016-02-24  4:03     ` Lars Ingebrigtsen
2016-02-24 17:15       ` Eli Zaretskii
2016-02-25  5:48         ` Lars Ingebrigtsen
     [not found] <CAADsv94GP0tVZtsS0na6RWtOc+WpDDAYDZqw299hw6j5Rq8sUw@mail.gmail.com>
2015-04-01 15:24 ` François Févotte
     [not found] ` <CAADsv96dEnf1aD+0=FvOHLPGXg2ARnL440Nya2ipQKRo648Dtw@mail.gmail.com>
2015-04-01 15:38   ` Oleh Krehel
2015-04-01 15:49     ` Drew Adams
2015-04-01 16:48     ` Oleh Krehel
2015-04-01 17:16       ` François Févotte
2015-04-01 21:03         ` Stefan Monnier
2015-04-02  8:12           ` François Févotte

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