unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.
       [not found] ` <20190525172357.86D4F207F5@vcs0.savannah.gnu.org>
@ 2019-05-26 22:40   ` Stefan Monnier
  2019-06-03  2:32     ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2019-05-26 22:40 UTC (permalink / raw)
  To: emacs-devel; +Cc: Eric S. Raymond

> -;;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
> +;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-

This is an error, it should be 3 semi-colons.

> +(defun find-init-path (fn)
> +  "Look in ~/.config/FOO or ~/.FOO for the dotfile or dot directory FOO.
> +It is expected that the output will undergo ~ expansion.  Implements the
> +XDG convention for dotfiles."
> +  (let* ((xdg-path (concat "~" init-file-user "/.config/" fn))
> +        (oldstyle-path (concat "~" init-file-user "/." fn))
> +        (found-path (if (file-exists-p xdg-path) xdg-path oldstyle-path)))
> +    found-path))

AFAICT this is only used during startup and hence shouldn't have such
an "official sounding" name.  It could/should use a "startup--" prefix,
for example.

Furthermore it shouldn't say "path" but "filename" to follow our
naming convention.


        Stefan




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

* Re: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.
  2019-05-26 22:40   ` [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config Stefan Monnier
@ 2019-06-03  2:32     ` Eli Zaretskii
  2019-06-09  7:01       ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Amin Bandali
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-06-03  2:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: esr, emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Sun, 26 May 2019 18:40:10 -0400
> Cc: "Eric S. Raymond" <esr@thyrsus.com>
> 
> > -;;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
> > +;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
> 
> This is an error, it should be 3 semi-colons.
> 
> > +(defun find-init-path (fn)
> > +  "Look in ~/.config/FOO or ~/.FOO for the dotfile or dot directory FOO.
> > +It is expected that the output will undergo ~ expansion.  Implements the
> > +XDG convention for dotfiles."
> > +  (let* ((xdg-path (concat "~" init-file-user "/.config/" fn))
> > +        (oldstyle-path (concat "~" init-file-user "/." fn))
> > +        (found-path (if (file-exists-p xdg-path) xdg-path oldstyle-path)))
> > +    found-path))
> 
> AFAICT this is only used during startup and hence shouldn't have such
> an "official sounding" name.  It could/should use a "startup--" prefix,
> for example.
> 
> Furthermore it shouldn't say "path" but "filename" to follow our
> naming convention.

No response in a week.

Would someone like to suggest changes to fix the problems in this
commit?  If so, please show the proposed changes, and let's discuss
them.  Failing that, I will revert that commit in a couple of days.



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

* [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.)
  2019-06-03  2:32     ` Eli Zaretskii
@ 2019-06-09  7:01       ` Amin Bandali
  2019-06-09  8:10         ` Eli Zaretskii
                           ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Amin Bandali @ 2019-06-09  7:01 UTC (permalink / raw)
  To: emacs-devel; +Cc: Eli Zaretskii, Stefan Monnier

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

Hello,

Eli Zaretskii <eliz@gnu.org> writes:

[...]

>
> No response in a week.
>
> Would someone like to suggest changes to fix the problems in this
> commit?  If so, please show the proposed changes, and let's discuss
> them.  Failing that, I will revert that commit in a couple of days.
>
>

I’ve attached my first try at this.  At first it was only concerned with
lisp/startup.el—like ESR’s change—but then I thought it would be even
nicer to do it at the user-emacs-directory itself.  It’s not quite there
yet—as it tries to use things in lisp/subr.el before they’re actually
defined/loaded—but it lays out what I have in mind.

Feedback and help appreciated.

Thanks,
amin


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-XDG-Base-Directory-specification-for-user-.patch --]
[-- Type: text/x-patch, Size: 10863 bytes --]

From 4d66998bff5de197e097870c30cc0b533bc134ac Mon Sep 17 00:00:00 2001
From: Amin Bandali <bandali@gnu.org>
Date: Sun, 9 Jun 2019 02:29:52 -0400
Subject: [PATCH] Implement XDG Base Directory specification for
 user-emacs-directory

* lisp/startup.el (command-line): Use user-emacs-directory instead of
  hard-coding "~/.emacs.d".

* lisp/subr.el (user-emacs-directory): Use "$XDG_CONFIG_HOME/emacs/"
  if XDG_CONFIG_HOME is set and has an "emacs/" subdirectory.
  Otherwise, try "~/.config/emacs/" before falling back to
  "~/.emacs.d/".
---
 doc/emacs/custom.texi | 72 +++++++++++++++++++++++--------------------
 etc/NEWS              |  6 ++++
 lisp/startup.el       | 19 +++---------
 lisp/subr.el          |  6 +++-
 4 files changed, 54 insertions(+), 49 deletions(-)

diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 982cea1f21..b582601cae 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -380,7 +380,7 @@ Saving Customizations
 file.  For example:
 
 @example
-(setq custom-file "~/.config/emacs-custom.el")
+(setq custom-file "~/.config/emacs/custom.el")
 (load custom-file)
 @end example
 
@@ -390,14 +390,14 @@ Saving Customizations
 @example
 (cond ((< emacs-major-version 22)
        ;; @r{Emacs 21 customization.}
-       (setq custom-file "~/.config/custom-21.el"))
+       (setq custom-file "~/.config/emacs/custom-21.el"))
       ((and (= emacs-major-version 22)
             (< emacs-minor-version 3))
        ;; @r{Emacs 22 customization, before version 22.3.}
-       (setq custom-file "~/.config/custom-22.el"))
+       (setq custom-file "~/.config/emacs/custom-22.el"))
       (t
        ;; @r{Emacs version 22.3 or later.}
-       (setq custom-file "~/.config/emacs-custom.el")))
+       (setq custom-file "~/.config/emacs/custom.el")))
 
 (load custom-file)
 @end example
@@ -2215,28 +2215,30 @@ Init File
 @cindex init file
 @cindex .emacs file
 @cindex ~/.emacs file
-@cindex ~/.config/emacs file
+@cindex ~/.config/emacs/init.el file
 @cindex Emacs initialization file
 @cindex startup (init file)
 
   When Emacs is started, it normally tries to load a Lisp program from
 an @dfn{initialization file}, or @dfn{init file} for short.  This
 file, if it exists, specifies how to initialize Emacs for you.  Emacs
-looks for your init file using the filenames
-@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
-@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
-@file{~/.emacs.d/init.el}; you can choose to use any one of these
-names (@pxref{Find Init}).  Here, @file{~/} stands for your home
-directory.
+looks for your init file using the filenames @file{~/.emacs} or
+@file{~/.emacs.el}.  Here, @file{~/} stands for your home directory.
+Alternatively, you may wish to group all things Emacs-related in one
+place in the Emacs configuration directory.  Emacs looks for
+@file{$XDG_CONFIG_HOME/emacs/init.el}, using @file{~/.config} for
+@env{XDG_CONFIG_HOME} if it's not set.  If
+@file{$XDG_CONFIG_HOME/emacs/} doesn't exist, Emacs will fall back to
+@file{~/.emacs.d/} and look for @file{~/.emacs.d/init.el} instead
+(@pxref{Find Init}).
 
   While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations
 are backward-compatible to older Emacs versions, and the rest of this
-chapter will use them to name your initialization file, it is better practice
-to group all of your dotfiles under @file{.config} so that if you have
-to troubleshoot a problem that might be due to a bad init file, or
-archive a collection of them, it can be done by renaming or
-copying that directory.  Note that the @file{.config} versions
-don't have a leading dot on the basename part of the file.
+chapter will use them to name your initialization file, it is better
+practice to group all of your dotfiles under @file{~/.config} so that
+if you have to troubleshoot a problem that might be due to a bad init
+file, or archive a collection of them, it can be done by renaming or
+copying that directory.
 
   You can use the command line switch @samp{-q} to prevent loading
 your init file, and @samp{-u} (or @samp{--user}) to specify a
@@ -2642,13 +2644,14 @@ Terminal Init
 @node Find Init
 @subsection How Emacs Finds Your Init File
 
-  Normally Emacs uses your home directory to find
-@file{~/.config/emacs} or @file{~/.emacs}; that's what @samp{~} means
-in a file name.  @xref{General Variables, HOME}.  If none of
-@file{~/.config/emacs}, @file{~/.emacs}, @file{~/.config/emacs.el} nor
+  Normally Emacs uses your home directory to find @file{~/.emacs}
+(@samp{~} refers to the user's home directory in a file name).
+@xref{General Variables, HOME}.  If neither @file{~/.emacs} nor
 @file{~/.emacs.el} is found, Emacs looks for
-@file{~/.config/emacs.d/init.el} or @file{~/.emacs.d/init.el} (these,
-like @file{~/.emacs.el}, can be byte-compiled).
+@file{$XDG_CONFIG_HOME/emacs/init.el}, substituting @file{~/.config}
+for @env{XDG_CONFIG_HOME} if it's not set.  If neither of these exist,
+Emacs will look for @file{~/.emacs.d/init.el}.  These, like
+@file{~/.emacs.el}, can be byte-compiled.
 
   However, if you run Emacs from a shell started by @code{su}, Emacs
 tries to find your own initialization files, not that of the user you are
@@ -2702,16 +2705,19 @@ Early Init File
 @cindex early init file
 
   Most customizations for Emacs should be put in the normal init file,
-@file{.config/emacs} or @file{~/.config/emacs.d/init.el}.  However, it is sometimes desirable
-to have customizations that take effect during Emacs startup earlier than the
-normal init file is processed.  Such customizations can be put in the early
-init file, @file{~/.config/emacs.d/early-init.el} or @file{~/.emacs.d/early-init.el}.  This file is loaded before the
-package system and GUI is initialized, so in it you can customize variables
-that affect frame appearance as well as the package initialization process,
-such as @code{package-enable-at-startup}, @code{package-load-list}, and
-@code{package-user-dir}.  Note that variables like @code{package-archives}
-which only affect the installation of new packages, and not the process of
-making already-installed packages available, may be customized in the regular
+@file{~/.emacs} or @file{$XDG_CONFIG_HOME/emacs/init.el}.  However, it
+is sometimes desirable to have customizations that take effect during
+Emacs startup earlier than the normal init file is processed.  Such
+customizations can be put in the early init file,
+@file{$XDG_CONFIG_HOME/emacs/early-init.el} or
+@file{~/.emacs.d/early-init.el}.  This file is loaded before the
+package system and GUI is initialized, so in it you can customize
+variables that affect frame appearance as well as the package
+initialization process, such as @code{package-enable-at-startup},
+@code{package-load-list}, and @code{package-user-dir}.  Note that
+variables like @code{package-archives} which only affect the
+installation of new packages, and not the process of making
+already-installed packages available, may be customized in the regular
 init file.  @xref{Package Installation}.
 
   We do not recommend that you move into @file{early-init.el}
diff --git a/etc/NEWS b/etc/NEWS
index f358a211a5..09a5e7a8aa 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -24,6 +24,12 @@ When you add a new item, use the appropriate mark if you are sure it applies,
 \f
 * Installation Changes in Emacs 27.1
 
+** Emacs now supports XDG Base Directory specification
+Emacs now uses "$XDG_CONFIG_HOME/emacs/" for 'user-emacs-directory' if
+it exists, including for the init and early init files.  If
+"$XDG_CONFIG_HOME" is not set, Emacs will use "~/.config/emacs/" if it
+exists, and will otherwise fall back to "~/.emacs.d/".
+
 ** Emacs now uses GMP, the GNU Multiple Precision library.
 By default, if 'configure' does not find a suitable libgmp, it
 arranges for the included mini-gmp library to be built and used.
diff --git a/lisp/startup.el b/lisp/startup.el
index 90046389d1..49b44fbae3 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1,4 +1,4 @@
-;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
+;;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985-1986, 1992, 1994-2019 Free Software Foundation,
 ;; Inc.
@@ -971,15 +971,6 @@ startup--load-user-init-file
     (when debug-on-error-should-be-set
       (setq debug-on-error debug-on-error-from-init-file))))
 
-(defun find-init-path (fn)
-  "Look in ~/.config/FOO or ~/.FOO for the dotfile or dot directory FOO.
-It is expected that the output will undergo ~ expansion.  Implements the
-XDG convention for dotfiles."
-  (let* ((xdg-path (concat "~" init-file-user "/.config/" fn))
-        (oldstyle-path (concat "~" init-file-user "/." fn))
-        (found-path (if (file-exists-p xdg-path) xdg-path oldstyle-path)))
-    found-path))
-
 (defun command-line ()
   "A subroutine of `normal-top-level'.
 Amongst another things, it parses the command-line arguments."
@@ -1180,8 +1171,7 @@ command-line
       ;; with the .el extension, if the file doesn't exist, not just
       ;; "early-init" without an extension, as it does for ".emacs".
       "early-init.el"
-      (file-name-as-directory
-       (find-init-path "emacs.d")))))
+      (file-name-as-directory user-emacs-directory))))
   (setq early-init-file user-init-file)
 
   ;; If any package directory exists, initialize the package system.
@@ -1322,7 +1312,7 @@ command-line
         ((eq system-type 'ms-dos)
          (concat "~" init-file-user "/_emacs"))
         ((not (eq system-type 'windows-nt))
-         (find-init-path "emacs"))
+         (concat "~" init-file-user "/.emacs"))
         ;; Else deal with the Windows situation.
         ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
          ;; Prefer .emacs on Windows.
@@ -1339,8 +1329,7 @@ command-line
      (lambda ()
        (expand-file-name
         "init"
-        (file-name-as-directory
-         (find-init-path "emacs.d"))))
+        (file-name-as-directory user-emacs-directory)))
      (not inhibit-default-init))
 
     (when (and deactivate-mark transient-mark-mode)
diff --git a/lisp/subr.el b/lisp/subr.el
index 73031a2a9f..dc2a4d8373 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2924,7 +2924,11 @@ user-emacs-directory
   (if (eq system-type 'ms-dos)
       ;; MS-DOS cannot have initial dot.
       "~/_emacs.d/"
-    "~/.emacs.d/")
+    (let ((config-dir (or (getenv "XDG_CONFIG_HOME")
+                          (concat "~" init-file-user "/.config"))))
+      (if (file-exists-p config-dir)
+          (concat config-dir "/emacs/")
+        (concat "~" init-file-user "/.emacs.d/"))))
   "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.21.0


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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.)
  2019-06-09  7:01       ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Amin Bandali
@ 2019-06-09  8:10         ` Eli Zaretskii
  2019-06-09 18:59         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory Stefan Monnier
  2019-06-13 11:34         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Stefan Kangas
  2 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-06-09  8:10 UTC (permalink / raw)
  To: Amin Bandali; +Cc: monnier, emacs-devel

> From: Amin Bandali <bandali@gnu.org>
> Cc: Eli Zaretskii <eliz@gnu.org>,  Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Sun, 09 Jun 2019 03:01:22 -0400
> 
> > Would someone like to suggest changes to fix the problems in this
> > commit?  If so, please show the proposed changes, and let's discuss
> > them.  Failing that, I will revert that commit in a couple of days.
> 
> I’ve attached my first try at this.  At first it was only concerned with
> lisp/startup.el—like ESR’s change—but then I thought it would be even
> nicer to do it at the user-emacs-directory itself.  It’s not quite there
> yet—as it tries to use things in lisp/subr.el before they’re actually
> defined/loaded—but it lays out what I have in mind.

Thanks.

> Feedback and help appreciated.

Below.

> diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
> index 982cea1f21..b582601cae 100644
> --- a/doc/emacs/custom.texi
> +++ b/doc/emacs/custom.texi
> @@ -380,7 +380,7 @@ Saving Customizations
>  file.  For example:
>  
>  @example
> -(setq custom-file "~/.config/emacs-custom.el")
> +(setq custom-file "~/.config/emacs/custom.el")
>  (load custom-file)
>  @end example

I question the need to modify the examples in this chapter of the
manual.  They are not directly related to the issue at hand.  If
Eric's changeset modified these parts, I'd rather just revert to what
the text said before.

>    When Emacs is started, it normally tries to load a Lisp program from
>  an @dfn{initialization file}, or @dfn{init file} for short.  This
>  file, if it exists, specifies how to initialize Emacs for you.  Emacs
> -looks for your init file using the filenames
> -@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
> -@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
> -@file{~/.emacs.d/init.el}; you can choose to use any one of these
> -names (@pxref{Find Init}).  Here, @file{~/} stands for your home
> -directory.
> +looks for your init file using the filenames @file{~/.emacs} or
> +@file{~/.emacs.el}.  Here, @file{~/} stands for your home directory.
> +Alternatively, you may wish to group all things Emacs-related in one
> +place in the Emacs configuration directory.  Emacs looks for
> +@file{$XDG_CONFIG_HOME/emacs/init.el}, using @file{~/.config} for
> +@env{XDG_CONFIG_HOME} if it's not set.  If
> +@file{$XDG_CONFIG_HOME/emacs/} doesn't exist, Emacs will fall back to
> +@file{~/.emacs.d/} and look for @file{~/.emacs.d/init.el} instead
> +(@pxref{Find Init}).

This text is slightly confusing: the part which begins with "Emacs
looks for @file{$XDG_CONFIG_HOME/emacs/init.el}" should tell whether
Emacs looks for the XDG tree before or after looking for ~/.emacs and
~/.emacs.el, otherwise I as a user cannot figure out how to make Emacs
find my init files regardless of whether I want or don't want to go
the XDG way.  Also missing is an explanation of what happens if
XDG_CONFIG_HOME is defined, but the Emacs directory does not exist
there.  the last sentence, which talks about ~/.emacs.d/init.el, adds
more to the confusion, because again the order of examining all these
possibilities is left largely unspecified or at least not entirely
clear.  Maybe arranging the description as an ordered itemized list
would help.

Markup-wise, "@file{$XDG_CONFIG_HOME/emacs/init.el}" uses the Unix
shell $FOO notation, something that we avoid in the manuals.  I
suggest to say something like

  Emacs looks for @file{@var{xdg-home}/emacs/init.el}, where
  @var{xdg-home} is the value of the environment variable
  @env{XDG_CONFIG_HOME} or @file{~/.config} if that variable is not
  defined.

>    While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations
>  are backward-compatible to older Emacs versions, and the rest of this
> -chapter will use them to name your initialization file, it is better practice
> -to group all of your dotfiles under @file{.config} so that if you have
> -to troubleshoot a problem that might be due to a bad init file, or
> -archive a collection of them, it can be done by renaming or
> -copying that directory.  Note that the @file{.config} versions
> -don't have a leading dot on the basename part of the file.
> +chapter will use them to name your initialization file, it is better
> +practice to group all of your dotfiles under @file{~/.config} so that

I cannot say I like the "better" qualification here.  This is in the
eyes of the beholder.  I think we should say that "modern Posix
platforms prefer to group all of your dotfiles under
@file{~/.config}..." and leave the judgmental part out of the text.
(as an aside, why say ~/.config here and not the directory pointed to
by XDG_CONFIG_HOME?)

> +  Normally Emacs uses your home directory to find @file{~/.emacs}
> +(@samp{~} refers to the user's home directory in a file name).

The last part should reorder words:

  (@samp{~} in a file name refers to the user's home directory)

> +@xref{General Variables, HOME}.  If neither @file{~/.emacs} nor
>  @file{~/.emacs.el} is found, Emacs looks for
> -@file{~/.config/emacs.d/init.el} or @file{~/.emacs.d/init.el} (these,
> -like @file{~/.emacs.el}, can be byte-compiled).
> +@file{$XDG_CONFIG_HOME/emacs/init.el}, substituting @file{~/.config}
> +for @env{XDG_CONFIG_HOME} if it's not set.  If neither of these exist,
> +Emacs will look for @file{~/.emacs.d/init.el}.  These, like
> +@file{~/.emacs.el}, can be byte-compiled.

Similar comments here, although this description is somewhat more
clear regarding the order of looking for init files.

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -24,6 +24,12 @@ When you add a new item, use the appropriate mark if you are sure it applies,
>  \f
>  * Installation Changes in Emacs 27.1
>  
> +** Emacs now supports XDG Base Directory specification

The header line should end in a period.

> +Emacs now uses "$XDG_CONFIG_HOME/emacs/" for 'user-emacs-directory' if

Again, let's not use $FOO notation in documentation.

> diff --git a/lisp/subr.el b/lisp/subr.el
> index 73031a2a9f..dc2a4d8373 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -2924,7 +2924,11 @@ user-emacs-directory
>    (if (eq system-type 'ms-dos)
>        ;; MS-DOS cannot have initial dot.
>        "~/_emacs.d/"
> -    "~/.emacs.d/")
> +    (let ((config-dir (or (getenv "XDG_CONFIG_HOME")
> +                          (concat "~" init-file-user "/.config"))))
> +      (if (file-exists-p config-dir)
> +          (concat config-dir "/emacs/")
> +        (concat "~" init-file-user "/.emacs.d/"))))
>    "Directory beneath which additional per-user Emacs-specific files are placed.

user-emacs-directory is a defconst, so calling getenv to compute its
value will record the value of the environment variable at Emacs build
time, which is not what we want, AFAIU.  Moreover, init-file-user is
most probably also not yet computed, and definitely doesn't correspond
to the user who will run the dumped Emacs, right?  So I think this
should be rethought: if you want user-emacs-directory to absorb these
changes, it cannot be computed at build time, and cannot be a
defconst.

Also, there are quite a few places in our sources which mention
user-emacs-directory; they need to be audited to determine whether
redirecting the value to XDG_CONFIG_HOME/emacs will do what the users
expect (as I understand XDG_CONFIG_HOME is a per-session setting that
can change for the next session).



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-09  7:01       ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Amin Bandali
  2019-06-09  8:10         ` Eli Zaretskii
@ 2019-06-09 18:59         ` Stefan Monnier
  2019-06-09 19:16           ` Eli Zaretskii
  2019-06-13 11:34         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Stefan Kangas
  2 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier @ 2019-06-09 18:59 UTC (permalink / raw)
  To: emacs-devel; +Cc: Eli Zaretskii

> I’ve attached my first try at this.  At first it was only concerned with
> lisp/startup.el—like ESR’s change—but then I thought it would be even
> nicer to do it at the user-emacs-directory itself.

I think conceptually, this is indeed the better way to go.
Eli's comments already pointed out some technical difficulties you'll
have to overcome, so I'll limit myself to one more comment:

> * lisp/subr.el (user-emacs-directory): Use "$XDG_CONFIG_HOME/emacs/"
>   if XDG_CONFIG_HOME is set and has an "emacs/" subdirectory.
>   Otherwise, try "~/.config/emacs/" before falling back to
>   "~/.emacs.d/".

I think for simple reasons of backward compatibility, if both
"$XDG_CONFIG_HOME/emacs/" and "~/.emacs.d/" exist, we should use
"~/.emacs.d/".


        Stefan




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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-09 18:59         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory Stefan Monnier
@ 2019-06-09 19:16           ` Eli Zaretskii
  2019-06-09 20:16             ` Noam Postavsky
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-06-09 19:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Eli Zaretskii <eliz@gnu.org>
> Date: Sun, 09 Jun 2019 14:59:44 -0400
> 
> I think for simple reasons of backward compatibility, if both
> "$XDG_CONFIG_HOME/emacs/" and "~/.emacs.d/" exist, we should use
> "~/.emacs.d/".

I agree, but maybe we should also have an opt-in defcustom to prefer
the other way around.  IME, sometimes ~/.emacs.d is created due to
some random experiments people do, which are unrelated to their
routine operations, or due to some (buggy) packages that hard-code
~/.emacs.d.  We should give such users a fire escape.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-09 19:16           ` Eli Zaretskii
@ 2019-06-09 20:16             ` Noam Postavsky
  2019-06-10 16:22               ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Noam Postavsky @ 2019-06-09 20:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Monnier, Emacs developers

On Sun, 9 Jun 2019 at 15:17, Eli Zaretskii <eliz@gnu.org> wrote:

> > I think for simple reasons of backward compatibility, if both
> > "$XDG_CONFIG_HOME/emacs/" and "~/.emacs.d/" exist, we should use
> > "~/.emacs.d/".
>
> I agree, but maybe we should also have an opt-in defcustom to prefer
> the other way around.  IME, sometimes ~/.emacs.d is created due to
> some random experiments people do, which are unrelated to their
> routine operations, or due to some (buggy) packages that hard-code
> ~/.emacs.d.  We should give such users a fire escape.

But where would the defcustom setting be read from? Seems like a bit
of a bootstrapping problem.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-09 20:16             ` Noam Postavsky
@ 2019-06-10 16:22               ` Eli Zaretskii
  2019-06-10 18:55                 ` Noam Postavsky
  2019-07-02 16:55                 ` Noam Postavsky
  0 siblings, 2 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-06-10 16:22 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: monnier, emacs-devel

> From: Noam Postavsky <npostavs@gmail.com>
> Date: Sun, 9 Jun 2019 16:16:22 -0400
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, Emacs developers <emacs-devel@gnu.org>
> 
> > I agree, but maybe we should also have an opt-in defcustom to prefer
> > the other way around.  IME, sometimes ~/.emacs.d is created due to
> > some random experiments people do, which are unrelated to their
> > routine operations, or due to some (buggy) packages that hard-code
> > ~/.emacs.d.  We should give such users a fire escape.
> 
> But where would the defcustom setting be read from? Seems like a bit
> of a bootstrapping problem.

You are right, but then I think this feature will be an endless
source of confusion and bug reports.  Sigh...




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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-10 16:22               ` Eli Zaretskii
@ 2019-06-10 18:55                 ` Noam Postavsky
  2019-06-10 19:21                   ` Lars Ingebrigtsen
  2019-07-02 16:55                 ` Noam Postavsky
  1 sibling, 1 reply; 30+ messages in thread
From: Noam Postavsky @ 2019-06-10 18:55 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Monnier, Emacs developers

On Mon, 10 Jun 2019 at 12:22, Eli Zaretskii <eliz@gnu.org> wrote:
>>> IME, sometimes ~/.emacs.d is created due to some random experiments
>>> people do, which are unrelated to their routine operations, or due
>>> to some (buggy) packages that hard-code ~/.emacs.d.
>>
>> But where would the defcustom setting be read from? Seems like a bit
>> of a bootstrapping problem.
>
> You are right, but then I think this feature will be an endless
> source of confusion and bug reports.  Sigh...

Would it be okay to only use ~/.emacs.d as user-emacs-directory if
~/.emacs.d/init.el exists?



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-10 18:55                 ` Noam Postavsky
@ 2019-06-10 19:21                   ` Lars Ingebrigtsen
  2019-06-10 19:26                     ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-10 19:21 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Eli Zaretskii, Stefan Monnier, Emacs developers

Noam Postavsky <npostavs@gmail.com> writes:

> Would it be okay to only use ~/.emacs.d as user-emacs-directory if
> ~/.emacs.d/init.el exists?

I've got an ~/.emacs.d directory where all the different Emacs packages
store their data, but I don't have an ~/.emacs.d/init.el.  Instead I
have an ~/.emacs, and that's probably not an unusual configuration...

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



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-10 19:21                   ` Lars Ingebrigtsen
@ 2019-06-10 19:26                     ` Eli Zaretskii
  0 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-06-10 19:26 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel, npostavs, monnier

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: Eli Zaretskii <eliz@gnu.org>,  Stefan Monnier <monnier@iro.umontreal.ca>,  Emacs developers <emacs-devel@gnu.org>
> Date: Mon, 10 Jun 2019 21:21:25 +0200
> 
> Noam Postavsky <npostavs@gmail.com> writes:
> 
> > Would it be okay to only use ~/.emacs.d as user-emacs-directory if
> > ~/.emacs.d/init.el exists?
> 
> I've got an ~/.emacs.d directory where all the different Emacs packages
> store their data, but I don't have an ~/.emacs.d/init.el.  Instead I
> have an ~/.emacs, and that's probably not an unusual configuration...

This is in fact identical to what I have here.

So maybe Stefan is right and we should unconditionally prefer ~/.emacs
and ~/.emacs.d to the XDG stuff, if the former exist.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.)
  2019-06-09  7:01       ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Amin Bandali
  2019-06-09  8:10         ` Eli Zaretskii
  2019-06-09 18:59         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory Stefan Monnier
@ 2019-06-13 11:34         ` Stefan Kangas
  2 siblings, 0 replies; 30+ messages in thread
From: Stefan Kangas @ 2019-06-13 11:34 UTC (permalink / raw)
  To: emacs-devel; +Cc: Eli Zaretskii, Amin Bandali, Stefan Monnier

Amin Bandali <bandali@gnu.org> writes:
> I’ve attached my first try at this.

Thanks for working on this.

I would add bug#583 to the commit message, and remember to close that
bug once this is all done and merged.

Thanks,
Stefan Kangas



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-06-10 16:22               ` Eli Zaretskii
  2019-06-10 18:55                 ` Noam Postavsky
@ 2019-07-02 16:55                 ` Noam Postavsky
  2019-07-02 17:26                   ` Eli Zaretskii
  1 sibling, 1 reply; 30+ messages in thread
From: Noam Postavsky @ 2019-07-02 16:55 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Monnier, Emacs developers

On Mon, 10 Jun 2019 at 12:22, Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Noam Postavsky <npostavs@gmail.com>
> > Date: Sun, 9 Jun 2019 16:16:22 -0400
> > Cc: Stefan Monnier <monnier@iro.umontreal.ca>, Emacs developers <emacs-devel@gnu.org>
> >
> > > I agree, but maybe we should also have an opt-in defcustom to prefer
> > > the other way around.  IME, sometimes ~/.emacs.d is created due to
> > > some random experiments people do, which are unrelated to their
> > > routine operations, or due to some (buggy) packages that hard-code
> > > ~/.emacs.d.  We should give such users a fire escape.
> >
> > But where would the defcustom setting be read from? Seems like a bit
> > of a bootstrapping problem.
>
> You are right, but then I think this feature will be an endless
> source of confusion and bug reports.  Sigh...

Perhaps we could revisit Bug#15539 which allows setting
user-emacs-directory via EMACS_USER_DIRECTORY environment variable? It
was marked as wontfix, mainly (as far as I can tell) based on the
potential bugs that letting user-emacs-directory be different than
$HOME/.emacs.d could bring, but it looks like we've basically decided
that is acceptable here anyway.

https://debbugs.gnu.org/15539



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-02 16:55                 ` Noam Postavsky
@ 2019-07-02 17:26                   ` Eli Zaretskii
  2019-07-23 14:36                     ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-02 17:26 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: monnier, emacs-devel

> From: Noam Postavsky <npostavs@gmail.com>
> Date: Tue, 2 Jul 2019 12:55:21 -0400
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, Emacs developers <emacs-devel@gnu.org>
> 
> > > > I agree, but maybe we should also have an opt-in defcustom to prefer
> > > > the other way around.  IME, sometimes ~/.emacs.d is created due to
> > > > some random experiments people do, which are unrelated to their
> > > > routine operations, or due to some (buggy) packages that hard-code
> > > > ~/.emacs.d.  We should give such users a fire escape.
> > >
> > > But where would the defcustom setting be read from? Seems like a bit
> > > of a bootstrapping problem.
> >
> > You are right, but then I think this feature will be an endless
> > source of confusion and bug reports.  Sigh...
> 
> Perhaps we could revisit Bug#15539 which allows setting
> user-emacs-directory via EMACS_USER_DIRECTORY environment variable? It
> was marked as wontfix, mainly (as far as I can tell) based on the
> potential bugs that letting user-emacs-directory be different than
> $HOME/.emacs.d could bring, but it looks like we've basically decided
> that is acceptable here anyway.

Maybe use an environment variable only to override the default
preference order between XDG and ~/.emacs.d, i.e. as that "fire
escape" I had in mind?



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-02 17:26                   ` Eli Zaretskii
@ 2019-07-23 14:36                     ` Eli Zaretskii
  2019-07-27  2:58                       ` Amin Bandali
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-23 14:36 UTC (permalink / raw)
  To: Amin Bandali; +Cc: emacs-devel, npostavs, monnier

> > From: Noam Postavsky <npostavs@gmail.com>
> > Date: Tue, 2 Jul 2019 12:55:21 -0400
> > Cc: Stefan Monnier <monnier@iro.umontreal.ca>, Emacs developers <emacs-devel@gnu.org>
> > 
> > > > > I agree, but maybe we should also have an opt-in defcustom to prefer
> > > > > the other way around.  IME, sometimes ~/.emacs.d is created due to
> > > > > some random experiments people do, which are unrelated to their
> > > > > routine operations, or due to some (buggy) packages that hard-code
> > > > > ~/.emacs.d.  We should give such users a fire escape.
> > > >
> > > > But where would the defcustom setting be read from? Seems like a bit
> > > > of a bootstrapping problem.
> > >
> > > You are right, but then I think this feature will be an endless
> > > source of confusion and bug reports.  Sigh...
> > 
> > Perhaps we could revisit Bug#15539 which allows setting
> > user-emacs-directory via EMACS_USER_DIRECTORY environment variable? It
> > was marked as wontfix, mainly (as far as I can tell) based on the
> > potential bugs that letting user-emacs-directory be different than
> > $HOME/.emacs.d could bring, but it looks like we've basically decided
> > that is acceptable here anyway.
> 
> Maybe use an environment variable only to override the default
> preference order between XDG and ~/.emacs.d, i.e. as that "fire
> escape" I had in mind?

Amin, are you still working on this?  If so, do you have an updated
patch, which takes in account the review comments?  If not, can we
please get back to fixing this?

I'd like to fix the possible breakage that the original changeset
might cause.

TIA



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-23 14:36                     ` Eli Zaretskii
@ 2019-07-27  2:58                       ` Amin Bandali
  2019-07-27  7:55                         ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Amin Bandali @ 2019-07-27  2:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: npostavs, monnier, emacs-devel

Hi Eli, all,

Eli Zaretskii <eliz@gnu.org> writes:

[...]

>
> Amin, are you still working on this?  If so, do you have an updated
> patch, which takes in account the review comments?  If not, can we
> please get back to fixing this?
>
> I'd like to fix the possible breakage that the original changeset
> might cause.
>
> TIA
>
>

Sorry for going AWOL on this.  After reading all the feedback I did some
experiments on my local checkout, but I wasn’t able to work out anything
worthy of sharing with the list.  It’d be great if you or Stefan could
pick this up and change the code to behave more properly, such as what
was proposed earlier on the thread.  Otherwise, and if this is not a
priority, then I suppose the right thing to do would be to just revert
ESR’s changes for the time being.

Thanks, and sorry for the disappointment,
amin



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-27  2:58                       ` Amin Bandali
@ 2019-07-27  7:55                         ` Eli Zaretskii
  2019-07-27 18:46                           ` Paul Eggert
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-27  7:55 UTC (permalink / raw)
  To: Amin Bandali; +Cc: npostavs, monnier, emacs-devel

> From: Amin Bandali <bandali@gnu.org>
> Cc: emacs-devel@gnu.org,  npostavs@gmail.com,  monnier@iro.umontreal.ca
> Date: Fri, 26 Jul 2019 22:58:23 -0400
> 
> Sorry for going AWOL on this.  After reading all the feedback I did some
> experiments on my local checkout, but I wasn’t able to work out anything
> worthy of sharing with the list.  It’d be great if you or Stefan could
> pick this up and change the code to behave more properly, such as what
> was proposed earlier on the thread.  Otherwise, and if this is not a
> priority, then I suppose the right thing to do would be to just revert
> ESR’s changes for the time being.

Thanks.

I myself don't have time to work on this, and don't consider myself
enough of an expert on the XDG stuff anyway.  So I will wait for a
couple of weeks for someone to pick up the gauntlet, and if no one
steps in, I will revert that commit.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-27  7:55                         ` Eli Zaretskii
@ 2019-07-27 18:46                           ` Paul Eggert
  2019-07-27 21:22                             ` Basil L. Contovounesios
  2019-07-28 14:48                             ` Eli Zaretskii
  0 siblings, 2 replies; 30+ messages in thread
From: Paul Eggert @ 2019-07-27 18:46 UTC (permalink / raw)
  To: emacs-devel

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

Eli Zaretskii wrote:
> I myself don't have time to work on this, and don't consider myself
> enough of an expert on the XDG stuff anyway.  So I will wait for a
> couple of weeks for someone to pick up the gauntlet

I'll give it a whirl. Proposed patch attached. This reflects the comments so 
far, except that it prefers the new (XDG-style) directory if it exists, as that 
gives the user a simple escape hatch. They can set XDG_CONFIG_DIR to /nowhere to 
go back to the old way, as an emergency fix to get Emacs up and running well 
enough to fix their configuration. In practice it appears that XDG_CONFIG_DIR is 
rarely if ever set, so this should be adequate as an escape hatch.

[-- Attachment #2: 0001-Use-XDG-conventions-more-consistently.patch --]
[-- Type: text/x-patch, Size: 14950 bytes --]

From 05d573e312b840cb26fa5353cc6d74e5e3b5afd7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 27 Jul 2019 11:38:16 -0700
Subject: [PATCH] Use XDG conventions more consistently

* doc/emacs/custom.texi (Init File, Init Syntax, Find Init):
* doc/lispref/files.texi (Standard File Names):
* doc/lispref/os.texi (Init File):
* doc/misc/url.texi (Customization):
* etc/NEWS:
Adjust accordingly.
* lisp/startup.el (startup--load-user-init-file):
If init-file-name is nil, do not load from it; instead
just use the alt-file.
(find-init-path): Remove; no longer used.
(command-line): Don't check twice for XDG.
Look at XDG_CONFIG_HOME instead of assuming it's ~/.config.
Prefer XDG configuration if it exists; the user can disable
this by setting XDG_CONFIG_HOME to some other place.
* lisp/subr.el (user-emacs-directory):
Prefer XDG configuration if it exists.
---
 doc/emacs/custom.texi  | 52 ++++++++++++++++++++++--------------------
 doc/lispref/files.texi |  5 ++--
 doc/lispref/os.texi    |  7 ++++--
 doc/misc/url.texi      |  3 ++-
 etc/NEWS               |  8 +++++++
 lisp/startup.el        | 48 +++++++++++++++++++++-----------------
 lisp/subr.el           | 13 +++++++----
 7 files changed, 81 insertions(+), 55 deletions(-)

diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index adea9351ea..d0c3b67f07 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -2219,28 +2219,33 @@ Init File
 @cindex init file
 @cindex .emacs file
 @cindex ~/.emacs file
-@cindex ~/.config/emacs file
+@cindex ~/.config/emacs/init.el file
 @cindex Emacs initialization file
 @cindex startup (init file)
+@cindex XDG_CONFIG_HOME
 
   When Emacs is started, it normally tries to load a Lisp program from
 an @dfn{initialization file}, or @dfn{init file} for short.  This
-file, if it exists, specifies how to initialize Emacs for you.  Emacs
-looks for your init file using the filenames
-@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
-@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
-@file{~/.emacs.d/init.el}; you can choose to use any one of these
-names (@pxref{Find Init}).  Here, @file{~/} stands for your home
+file, if it exists, specifies how to initialize Emacs for you.
+If the directory @file{@var{xdghome}/.config/emacs} exists, Emacs uses
+@file{@var{xdghome}/.config/emacs/init.el} as the init file.  Here,
+@var{xdghome} stands for the value of the environment variable
+@env{XDG_CONFIG_HOME}, or for @file{~/.config} if
+@env{XDG_CONFIG_HOME} is unset; @file{~/} stands for your home
 directory.
 
-  While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations
-are backward-compatible to older Emacs versions, and the rest of this
-chapter will use them to name your initialization file, it is better practice
-to group all of your dotfiles under @file{.config} so that if you have
+  If @file{~/.config/emacs} does not exist, Emacs looks for your init
+file using the filenames @file{~/.emacs}, @file{~/.emacs.el}, or
+@file{~/.emacs.d/init.el}; you can choose to use any one of these
+names (@pxref{Find Init}).  Although this is backward-compatible
+with older Emacs versions, modern POSIX platforms prefer putting your
+initialization files under @file{.config} so that if you have
 to troubleshoot a problem that might be due to a bad init file, or
 archive a collection of them, it can be done by renaming or
 copying that directory.  Note that the @file{.config} versions
 don't have a leading dot on the basename part of the file.
+For convenience the rest of this section assumes @env{XDG_CONFIG_HOME}
+is unset or has a value equivalent to @file{~/.config}.
 
   You can use the command line switch @samp{-q} to prevent loading
 your init file, and @samp{-u} (or @samp{--user}) to specify a
@@ -2312,17 +2317,17 @@ Init Syntax
 
   You can set any Lisp variable with @code{setq}, but with certain
 variables @code{setq} won't do what you probably want in the
-@file{.emacs} file.  Some variables automatically become buffer-local
-when set with @code{setq}; what you want in @file{.emacs} is to set
+init file.  Some variables automatically become buffer-local
+when set with @code{setq}; what you want in the init file is to set
 the default value, using @code{setq-default}.  Some customizable minor
 mode variables do special things to enable the mode when you set them
 with Customize, but ordinary @code{setq} won't do that; to enable the
-mode in your @file{.emacs} file, call the minor mode command.  The
+mode in your init file, call the minor mode command.  The
 following section has examples of both of these methods.
 
   The second argument to @code{setq} is an expression for the new
 value of the variable.  This can be a constant, a variable, or a
-function call expression.  In @file{.emacs}, constants are used most
+function call expression.  In the init file, constants are used most
 of the time.  They can be:
 
 @table @asis
@@ -2645,15 +2650,12 @@ Terminal Init
 @node Find Init
 @subsection How Emacs Finds Your Init File
 
-  Normally Emacs uses your home directory to find
-@file{~/.config/emacs} or @file{~/.emacs}; that's what @samp{~} means
-in a file name.  @xref{General Variables, HOME}.  If none of
-@file{~/.config/emacs}, @file{~/.emacs}, @file{~/.config/emacs.el} nor
-@file{~/.emacs.el} is found, Emacs looks for
-@file{~/.config/emacs.d/init.el} or @file{~/.emacs.d/init.el} (these,
-like @file{~/.emacs.el}, can be byte-compiled).
+  Emacs normally finds your init file in a location under your home
+directory, e.g., @file{~/.config/emacs/init.el} or
+@file{~/.emacs.d/init.el}.  @xref{Init File}.
 
-  However, if you run Emacs from a shell started by @code{su}, Emacs
+  However, if you run Emacs from a shell started by @code{su} and
+@env{XDG_CONFIG_HOME} is not set in your environment, Emacs
 tries to find your own initialization files, not that of the user you are
 currently pretending to be.  The idea is that you should get your own
 editor customizations even if you are running as the super user.
@@ -2704,8 +2706,8 @@ Early Init File
 @subsection The Early Init File
 @cindex early init file
 
-  Most customizations for Emacs should be put in the normal init file,
-@file{.config/emacs} or @file{~/.config/emacs.d/init.el}.  However, it is sometimes desirable
+  Most customizations for Emacs should be put in the normal init file.
+@xref{Init File}.  However, it is sometimes desirable
 to have customizations that take effect during Emacs startup earlier than the
 normal init file is processed.  Such customizations can be put in the early
 init file, @file{~/.config/emacs.d/early-init.el} or @file{~/.emacs.d/early-init.el}.  This file is loaded before the
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 6be5a52837..d53fed4ee8 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2822,8 +2822,9 @@ Standard File Names
 name for a particular use---typically, to hold configuration data
 specified by the current user.  Usually, such files should be located
 in the directory specified by @code{user-emacs-directory}, which is
-@file{~/.emacs.d} by default (@pxref{Init File}).  For example, abbrev
-definitions are stored by default in @file{~/.emacs.d/abbrev_defs}.
+@file{~/.config/emacs} or @file{~/.emacs.d} by default (@pxref{Init
+File}).  For example, abbrev definitions are stored by default in
+@file{~/.config/emacs/abbrev_defs} or @file{~/.emacs.d/abbrev_defs}.
 The easiest way to specify such a file name is to use the function
 @code{locate-user-emacs-file}.
 
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index fef954eb7a..a0615004a8 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -475,8 +475,11 @@ Init File
 @end defvar
 
 @defvar user-emacs-directory
-This variable holds the name of the @file{.emacs.d} directory.  It is
-@file{~/.emacs.d} on all platforms but MS-DOS.
+This variable holds the name of the Emacs default directory.
+It is @file{@var{xdghome}/emacs/} if that directory exists, otherwise
+@file{~/.emacs.d/} on all platforms but MS-DOS.  Here, @var{xdghome}
+stands for the value of the environment variable @env{XDG_CONFIG_HOME}
+if that variable is set, and for @file{~/.config} otherwise.
 @end defvar
 
 @node Terminal-Specific
diff --git a/doc/misc/url.texi b/doc/misc/url.texi
index 0cdfcac24e..bad7701daf 100644
--- a/doc/misc/url.texi
+++ b/doc/misc/url.texi
@@ -1267,7 +1267,8 @@ Customization
 
 The default value specifies a subdirectory named @file{url/} in the
 standard Emacs user data directory specified by the variable
-@code{user-emacs-directory} (normally @file{~/.emacs.d}).  However,
+@code{user-emacs-directory} (normally @file{~/.config/emacs}
+or @file{~/.emacs.d}).  However,
 the old default was @file{~/.url}, and this directory is used instead
 if it exists.
 @end defopt
diff --git a/etc/NEWS b/etc/NEWS
index d876c95e68..7703fc1e79 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -135,6 +135,14 @@ builds respectively.
 \f
 * Startup Changes in Emacs 27.1
 
++++
+** Emacs now uses the XDG convention for init files.
+For example, it looks for init.el in ~/.config/emacs/init.el.
+Emacs continues to look for init files in their traditional locations
+if ~/.config/emacs does not exist.  The XDG_CONFIG_HOME environment
+variable (default ~/.config) specifies the parent directory of these
+configuration files.
+
 +++
 ** Emacs can now be configured using an early init file.
 The file is called 'early-init.el', in 'user-emacs-directory'.  It is
diff --git a/lisp/startup.el b/lisp/startup.el
index 564428580b..4d584a0cb5 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1,4 +1,4 @@
-;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
+;;; startup.el --- process Emacs shell arguments  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1985-1986, 1992, 1994-2019 Free Software Foundation,
 ;; Inc.
@@ -906,16 +906,19 @@ startup--load-user-init-file
               ;; the name of the file that it loads into
               ;; `user-init-file'.
               (setq user-init-file t)
-              (load (if (equal (file-name-extension init-file-name)
-                               "el")
-                        (file-name-sans-extension init-file-name)
-                      init-file-name)
-                    'noerror 'nomessage)
+	      (when init-file-name
+		(load (if (equal (file-name-extension init-file-name)
+				 "el")
+			  (file-name-sans-extension init-file-name)
+			init-file-name)
+		      'noerror 'nomessage))
 
               (when (and (eq user-init-file t) alternate-filename-function)
                 (let ((alt-file (funcall alternate-filename-function)))
                   (and (equal (file-name-extension alt-file) "el")
                        (setq alt-file (file-name-sans-extension alt-file)))
+		  (unless init-file-name
+		    (setq init-file-name alt-file))
                   (load alt-file 'noerror 'nomessage)))
 
               ;; If we did not find the user's init file, set
@@ -971,18 +974,10 @@ startup--load-user-init-file
     (when debug-on-error-should-be-set
       (setq debug-on-error debug-on-error-from-init-file))))
 
-(defun find-init-path (fn)
-  "Look in ~/.config/FOO or ~/.FOO for the dotfile or dot directory FOO.
-It is expected that the output will undergo ~ expansion.  Implements the
-XDG convention for dotfiles."
-  (let* ((xdg-path (concat "~" init-file-user "/.config/" fn))
-        (oldstyle-path (concat "~" init-file-user "/." fn))
-        (found-path (if (file-exists-p xdg-path) xdg-path oldstyle-path)))
-    found-path))
-
 (defun command-line ()
   "A subroutine of `normal-top-level'.
 Amongst another things, it parses the command-line arguments."
+ (let (xdg-dir startup-init-directory)
   (setq before-init-time (current-time)
 	after-init-time nil
         command-line-default-directory default-directory)
@@ -1171,6 +1166,18 @@ command-line
                                    init-file-user))
                          :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
+    (let* ((dir (concat (or (getenv "XDG_CONFIG_HOME")
+			    (concat "~" init-file-user "/.config"))
+			"/emacs/")))
+      (if (file-exists-p dir) dir)))
+  (setq startup-init-directory
+	(or xdg-dir (concat "~" init-file-user "/.emacs.d/")))
+
   ;; Load the early init file, if found.
   (startup--load-user-init-file
    (lambda ()
@@ -1180,8 +1187,7 @@ command-line
       ;; with the .el extension, if the file doesn't exist, not just
       ;; "early-init" without an extension, as it does for ".emacs".
       "early-init.el"
-      (file-name-as-directory
-       (find-init-path "emacs.d")))))
+      startup-init-directory)))
   (setq early-init-file user-init-file)
 
   ;; If any package directory exists, initialize the package system.
@@ -1319,10 +1325,11 @@ command-line
     (startup--load-user-init-file
      (lambda ()
        (cond
+	(xdg-dir nil)
         ((eq system-type 'ms-dos)
          (concat "~" init-file-user "/_emacs"))
         ((not (eq system-type 'windows-nt))
-         (find-init-path "emacs"))
+         (concat "~" init-file-user "/.emacs"))
         ;; Else deal with the Windows situation.
         ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
          ;; Prefer .emacs on Windows.
@@ -1339,8 +1346,7 @@ command-line
      (lambda ()
        (expand-file-name
         "init"
-        (file-name-as-directory
-         (find-init-path "emacs.d"))))
+        startup-init-directory))
      (not inhibit-default-init))
 
     (when (and deactivate-mark transient-mark-mode)
@@ -1456,7 +1462,7 @@ command-line
   (if (and (boundp 'x-session-previous-id)
            (stringp x-session-previous-id))
       (with-no-warnings
-	(emacs-session-restore x-session-previous-id))))
+	(emacs-session-restore x-session-previous-id)))))
 
 (defun x-apply-session-resources ()
   "Apply X resources which specify initial values for Emacs variables.
diff --git a/lisp/subr.el b/lisp/subr.el
index eea4e045dd..8b50748a59 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2930,10 +2930,15 @@ temp-buffer-setup-hook
 mode.")
 
 (defconst user-emacs-directory
-  (if (eq system-type 'ms-dos)
-      ;; MS-DOS cannot have initial dot.
-      "~/_emacs.d/"
-    "~/.emacs.d/")
+  (let ((config-dir (concat (or (getenv-internal "XDG_CONFIG_HOME")
+				"~/.config")
+			    "/emacs/")))
+    (if (file-exists-p config-dir)
+	config-dir
+      (if (eq system-type 'ms-dos)
+	  ;; MS-DOS cannot have initial dot.
+	  "~/_emacs.d/"
+	"~/.emacs.d/")))
   "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] 30+ messages in thread

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-27 18:46                           ` Paul Eggert
@ 2019-07-27 21:22                             ` Basil L. Contovounesios
  2019-07-28 14:41                               ` Eli Zaretskii
  2019-07-28 14:48                             ` Eli Zaretskii
  1 sibling, 1 reply; 30+ messages in thread
From: Basil L. Contovounesios @ 2019-07-27 21:22 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

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

> Eli Zaretskii wrote:
>> I myself don't have time to work on this, and don't consider myself
>> enough of an expert on the XDG stuff anyway.  So I will wait for a
>> couple of weeks for someone to pick up the gauntlet
>
> I'll give it a whirl. Proposed patch attached.

My only question is whether any of the new logic can be shared with
lisp/xdg.el or vice versa, and my only comment that perhaps the log
entry should mention bug#583 as Stefan K. suggested:

https://lists.gnu.org/archive/html/emacs-devel/2019-06/msg00307.html

Thanks for working on this,

-- 
Basil



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-27 21:22                             ` Basil L. Contovounesios
@ 2019-07-28 14:41                               ` Eli Zaretskii
  2019-07-28 15:21                                 ` Basil L. Contovounesios
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-28 14:41 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: eggert, emacs-devel

> From: "Basil L. Contovounesios" <contovob@tcd.ie>
> Date: Sat, 27 Jul 2019 22:22:01 +0100
> Cc: emacs-devel@gnu.org
> 
> My only question is whether any of the new logic can be shared with
> lisp/xdg.el or vice versa

I'm not sure I see how.  xdg.el includes a lot of stuff that is not
needed in every Emacs session, whereas the changes discussed here must
be in preloaded code.  Is your suggestion to move some of the code in
xdg.el to startup.el/subr.el and leave the rest in xdg.el?  If so,
which part(s) would you suggest to move?

In general, I feel that xdg.el is currently too Freedesktop-specific,
and "needs work" if we want to make it a portable mainstream package
useful on all the supported platforms.  (There's also a strange
comment about Emacs "not having a notion of l10n/i18n", which is
simply wrong, so support for localestring could/should also be
improved.)  Patches welcome.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-27 18:46                           ` Paul Eggert
  2019-07-27 21:22                             ` Basil L. Contovounesios
@ 2019-07-28 14:48                             ` Eli Zaretskii
  2019-07-29  1:00                               ` Elias Mårtenson
  2019-08-25  8:46                               ` Eli Zaretskii
  1 sibling, 2 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-28 14:48 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Sat, 27 Jul 2019 11:46:31 -0700
> 
> I'll give it a whirl. Proposed patch attached.

Thanks.

> They can set XDG_CONFIG_DIR to /nowhere to go back to the old way,
> as an emergency fix to get Emacs up and running well enough to fix
> their configuration.

I think we should mention this part in NEWS.

> --- a/doc/emacs/custom.texi
> +++ b/doc/emacs/custom.texi
> @@ -2219,28 +2219,33 @@ Init File
>  @cindex init file
>  @cindex .emacs file
>  @cindex ~/.emacs file
> -@cindex ~/.config/emacs file
> +@cindex ~/.config/emacs/init.el file
>  @cindex Emacs initialization file
>  @cindex startup (init file)
> +@cindex XDG_CONFIG_HOME
>  
>    When Emacs is started, it normally tries to load a Lisp program from
>  an @dfn{initialization file}, or @dfn{init file} for short.  This
> -file, if it exists, specifies how to initialize Emacs for you.  Emacs
> -looks for your init file using the filenames
> -@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
> -@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
> -@file{~/.emacs.d/init.el}; you can choose to use any one of these
> -names (@pxref{Find Init}).  Here, @file{~/} stands for your home
> +file, if it exists, specifies how to initialize Emacs for you.
> +If the directory @file{@var{xdghome}/.config/emacs} exists, Emacs uses
> +@file{@var{xdghome}/.config/emacs/init.el} as the init file.  Here,
> +@var{xdghome} stands for the value of the environment variable
> +@env{XDG_CONFIG_HOME}, or for @file{~/.config} if
> +@env{XDG_CONFIG_HOME} is unset; @file{~/} stands for your home
>  directory.
>  
> -  While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations
> -are backward-compatible to older Emacs versions, and the rest of this
> -chapter will use them to name your initialization file, it is better practice
> -to group all of your dotfiles under @file{.config} so that if you have
> +  If @file{~/.config/emacs} does not exist, Emacs looks for your init
> +file using the filenames @file{~/.emacs}, @file{~/.emacs.el}, or
> +@file{~/.emacs.d/init.el}; you can choose to use any one of these
> +names (@pxref{Find Init}).  Although this is backward-compatible
> +with older Emacs versions, modern POSIX platforms prefer putting your
> +initialization files under @file{.config} so that if you have
>  to troubleshoot a problem that might be due to a bad init file, or
>  archive a collection of them, it can be done by renaming or
>  copying that directory.  Note that the @file{.config} versions
>  don't have a leading dot on the basename part of the file.
> +For convenience the rest of this section assumes @env{XDG_CONFIG_HOME}
> +is unset or has a value equivalent to @file{~/.config}.

I think the test which describes in detail how Emacs finds the init
file should be in the section by that name; otherwise it makes no
sense to have that section in the first place.  The "Init File"
section should just mention the possible places and refer to that
other section for the details.

> diff --git a/etc/NEWS b/etc/NEWS
> index d876c95e68..7703fc1e79 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -135,6 +135,14 @@ builds respectively.
>  \f
>  * Startup Changes in Emacs 27.1
>  
> ++++
> +** Emacs now uses the XDG convention for init files.
> +For example, it looks for init.el in ~/.config/emacs/init.el.
> +Emacs continues to look for init files in their traditional locations
> +if ~/.config/emacs does not exist.  The XDG_CONFIG_HOME environment
> +variable (default ~/.config) specifies the parent directory of these
> +configuration files.

As mentioned above, I think we should tell here how to get back the
old behavior.

> diff --git a/lisp/subr.el b/lisp/subr.el
> index eea4e045dd..8b50748a59 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -2930,10 +2930,15 @@ temp-buffer-setup-hook
>  mode.")
>  
>  (defconst user-emacs-directory
> -  (if (eq system-type 'ms-dos)
> -      ;; MS-DOS cannot have initial dot.
> -      "~/_emacs.d/"
> -    "~/.emacs.d/")
> +  (let ((config-dir (concat (or (getenv-internal "XDG_CONFIG_HOME")
> +				"~/.config")
> +			    "/emacs/")))
> +    (if (file-exists-p config-dir)
> +	config-dir

Can this be a defconst?  It probes the existence of an environment
variable and a directory, so it must be done at run time, not at build
time, I think.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-28 14:41                               ` Eli Zaretskii
@ 2019-07-28 15:21                                 ` Basil L. Contovounesios
  2019-07-28 16:34                                   ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Basil L. Contovounesios @ 2019-07-28 15:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: eggert, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: "Basil L. Contovounesios" <contovob@tcd.ie>
>> Date: Sat, 27 Jul 2019 22:22:01 +0100
>> Cc: emacs-devel@gnu.org
>> 
>> My only question is whether any of the new logic can be shared with
>> lisp/xdg.el or vice versa
>
> I'm not sure I see how.  xdg.el includes a lot of stuff that is not
> needed in every Emacs session, whereas the changes discussed here must
> be in preloaded code.

Right, and the new XDG-related code looks too startup-specific to be
useful for xdg.el, really.

> Is your suggestion to move some of the code in xdg.el to
> startup.el/subr.el and leave the rest in xdg.el?  If so, which part(s)
> would you suggest to move?

I was just thinking aloud that IWBNI definitions and/or environment
lookup code could be shared, but on second look that would be overkill
and not entirely applicable here.

> In general, I feel that xdg.el is currently too Freedesktop-specific,
> and "needs work" if we want to make it a portable mainstream package
> useful on all the supported platforms.  (There's also a strange
> comment about Emacs "not having a notion of l10n/i18n", which is
> simply wrong, so support for localestring could/should also be
> improved.)  Patches welcome.

What kind of non-Freedesktop-specific portability do you envision?

Thanks,

-- 
Basil



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-28 15:21                                 ` Basil L. Contovounesios
@ 2019-07-28 16:34                                   ` Eli Zaretskii
  0 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-28 16:34 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: eggert, emacs-devel

> From: "Basil L. Contovounesios" <contovob@tcd.ie>
> Cc: eggert@cs.ucla.edu,  emacs-devel@gnu.org
> Date: Sun, 28 Jul 2019 16:21:10 +0100
> 
> > In general, I feel that xdg.el is currently too Freedesktop-specific,
> > and "needs work" if we want to make it a portable mainstream package
> > useful on all the supported platforms.  (There's also a strange
> > comment about Emacs "not having a notion of l10n/i18n", which is
> > simply wrong, so support for localestring could/should also be
> > improved.)  Patches welcome.
> 
> What kind of non-Freedesktop-specific portability do you envision?

The fallback directory names are Unix-specific; the assumption that
all the settings are necessarily in a file which has a very particular
format is specific to Freedesktop; The file associations are only > 
supported in XDG way of their definitions; etc.

Of course, one could argue that this package supports the XDG spec and
nothing else, and that is completely legitimate.  But in that case
using it for general-purpose Emacs features like finding our files and
directories is questionable, and should IMO be restricted to the
absolute minimum -- more or less what Paul proposed in his patch.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-28 14:48                             ` Eli Zaretskii
@ 2019-07-29  1:00                               ` Elias Mårtenson
  2019-07-29  2:36                                 ` Eli Zaretskii
  2019-08-25  8:46                               ` Eli Zaretskii
  1 sibling, 1 reply; 30+ messages in thread
From: Elias Mårtenson @ 2019-07-29  1:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, emacs-devel

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

On Sun, 28 Jul 2019, 22:49 Eli Zaretskii, <eliz@gnu.org> wrote:

> > From: Paul Eggert <eggert@cs.ucla.edu>
> > Date: Sat, 27 Jul 2019 11:46:31 -0700
> >
> > I'll give it a whirl. Proposed patch attached.
>
> >    When Emacs is started, it normally tries to load a Lisp program from
> >  an @dfn{initialization file}, or @dfn{init file} for short.  This
> > -file, if it exists, specifies how to initialize Emacs for you.  Emacs
> > -looks for your init file using the filenames
> > -@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
> > -@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
> > -@file{~/.emacs.d/init.el}; you can choose to use any one of these
> > -names (@pxref{Find Init}).  Here, @file{~/} stands for your home
> > +file, if it exists, specifies how to initialize Emacs for you.
> > +If the directory @file{@var{xdghome}/.config/emacs} exists, Emacs uses
> > +@file{@var{xdghome}/.config/emacs/init.el} as the init file.  Here,
> > +@var{xdghome} stands for the value of the environment variable
> > +@env{XDG_CONFIG_HOME}, or for @file{~/.config} if
> > +@env{XDG_CONFIG_HOME} is unset; @file{~/} stands for your home
> >  directory.
>

The above quote explains the meaning of the ~ symbol twice. Is that
necessary, or is it the result of an incorrect copy and paste?

Regards,
Elias

>

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

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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-29  1:00                               ` Elias Mårtenson
@ 2019-07-29  2:36                                 ` Eli Zaretskii
  2019-07-29  4:24                                   ` Elias Mårtenson
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-29  2:36 UTC (permalink / raw)
  To: Elias Mårtenson; +Cc: eggert, emacs-devel

> From: Elias Mårtenson <lokedhs@gmail.com>
> Date: Mon, 29 Jul 2019 09:00:12 +0800
> Cc: Paul Eggert <eggert@cs.ucla.edu>, emacs-devel <emacs-devel@gnu.org>
> 
>  > From: Paul Eggert <eggert@cs.ucla.edu>
>  > Date: Sat, 27 Jul 2019 11:46:31 -0700
>  > 
>  > I'll give it a whirl. Proposed patch attached.
> 
>  >    When Emacs is started, it normally tries to load a Lisp program from
>  >  an @dfn{initialization file}, or @dfn{init file} for short.  This
>  > -file, if it exists, specifies how to initialize Emacs for you.  Emacs
>  > -looks for your init file using the filenames
>  > -@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
>  > -@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
>  > -@file{~/.emacs.d/init.el}; you can choose to use any one of these
>  > -names (@pxref{Find Init}).  Here, @file{~/} stands for your home
>  > +file, if it exists, specifies how to initialize Emacs for you.
>  > +If the directory @file{@var{xdghome}/.config/emacs} exists, Emacs uses
>  > +@file{@var{xdghome}/.config/emacs/init.el} as the init file.  Here,
>  > +@var{xdghome} stands for the value of the environment variable
>  > +@env{XDG_CONFIG_HOME}, or for @file{~/.config} if
>  > +@env{XDG_CONFIG_HOME} is unset; @file{~/} stands for your home
>  >  directory.
> 
> The above quote explains the meaning of the ~ symbol twice. Is that necessary, or is it the result of an
> incorrect copy and paste? 

I admit that I don't see the duplication.  Can you point it out
explicitly?



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-29  2:36                                 ` Eli Zaretskii
@ 2019-07-29  4:24                                   ` Elias Mårtenson
  2019-07-29 14:21                                     ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Elias Mårtenson @ 2019-07-29  4:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, emacs-devel

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

Hello Eli,

I am sorry for the confusion caused. I was reading it on the phone, and due
to the way the lines were broken up, I didn't notice that some of the lines
were prefixed with a minus, indicating that they were removed.

Please ignore my comment.

Regards,
Elias

On Mon, 29 Jul 2019 at 10:36, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Elias Mårtenson <lokedhs@gmail.com>
> > Date: Mon, 29 Jul 2019 09:00:12 +0800
> > Cc: Paul Eggert <eggert@cs.ucla.edu>, emacs-devel <emacs-devel@gnu.org>
> >
> >  > From: Paul Eggert <eggert@cs.ucla.edu>
> >  > Date: Sat, 27 Jul 2019 11:46:31 -0700
> >  >
> >  > I'll give it a whirl. Proposed patch attached.
> >
> >  >    When Emacs is started, it normally tries to load a Lisp program
> from
> >  >  an @dfn{initialization file}, or @dfn{init file} for short.  This
> >  > -file, if it exists, specifies how to initialize Emacs for you.  Emacs
> >  > -looks for your init file using the filenames
> >  > -@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
> >  > -@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
> >  > -@file{~/.emacs.d/init.el}; you can choose to use any one of these
> >  > -names (@pxref{Find Init}).  Here, @file{~/} stands for your home
> >  > +file, if it exists, specifies how to initialize Emacs for you.
> >  > +If the directory @file{@var{xdghome}/.config/emacs} exists, Emacs
> uses
> >  > +@file{@var{xdghome}/.config/emacs/init.el} as the init file.  Here,
> >  > +@var{xdghome} stands for the value of the environment variable
> >  > +@env{XDG_CONFIG_HOME}, or for @file{~/.config} if
> >  > +@env{XDG_CONFIG_HOME} is unset; @file{~/} stands for your home
> >  >  directory.
> >
> > The above quote explains the meaning of the ~ symbol twice. Is that
> necessary, or is it the result of an
> > incorrect copy and paste?
>
> I admit that I don't see the duplication.  Can you point it out
> explicitly?
>

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

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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-29  4:24                                   ` Elias Mårtenson
@ 2019-07-29 14:21                                     ` Eli Zaretskii
  0 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-07-29 14:21 UTC (permalink / raw)
  To: Elias Mårtenson; +Cc: eggert, emacs-devel

> From: Elias Mårtenson <lokedhs@gmail.com>
> Date: Mon, 29 Jul 2019 12:24:02 +0800
> Cc: Paul Eggert <eggert@cs.ucla.edu>, emacs-devel <emacs-devel@gnu.org>
> 
> I am sorry for the confusion caused. I was reading it on the phone, and due to the way the lines were broken
> up, I didn't notice that some of the lines were prefixed with a minus, indicating that they were removed.

Nothing to apologize about, this happens to me all the time.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-07-28 14:48                             ` Eli Zaretskii
  2019-07-29  1:00                               ` Elias Mårtenson
@ 2019-08-25  8:46                               ` Eli Zaretskii
  2019-08-27 21:50                                 ` Paul Eggert
  1 sibling, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2019-08-25  8:46 UTC (permalink / raw)
  To: eggert; +Cc: emacs-devel

Ping!  This seems to have stalled.  Can we please revive it and make
the changes in the repository?

TIA

> Date: Sun, 28 Jul 2019 17:48:34 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> CC: emacs-devel@gnu.org
> 
> > From: Paul Eggert <eggert@cs.ucla.edu>
> > Date: Sat, 27 Jul 2019 11:46:31 -0700
> > 
> > I'll give it a whirl. Proposed patch attached.
> 
> Thanks.
> 
> > They can set XDG_CONFIG_DIR to /nowhere to go back to the old way,
> > as an emergency fix to get Emacs up and running well enough to fix
> > their configuration.
> 
> I think we should mention this part in NEWS.
> 
> > --- a/doc/emacs/custom.texi
> > +++ b/doc/emacs/custom.texi
> > @@ -2219,28 +2219,33 @@ Init File
> >  @cindex init file
> >  @cindex .emacs file
> >  @cindex ~/.emacs file
> > -@cindex ~/.config/emacs file
> > +@cindex ~/.config/emacs/init.el file
> >  @cindex Emacs initialization file
> >  @cindex startup (init file)
> > +@cindex XDG_CONFIG_HOME
> >  
> >    When Emacs is started, it normally tries to load a Lisp program from
> >  an @dfn{initialization file}, or @dfn{init file} for short.  This
> > -file, if it exists, specifies how to initialize Emacs for you.  Emacs
> > -looks for your init file using the filenames
> > -@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
> > -@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
> > -@file{~/.emacs.d/init.el}; you can choose to use any one of these
> > -names (@pxref{Find Init}).  Here, @file{~/} stands for your home
> > +file, if it exists, specifies how to initialize Emacs for you.
> > +If the directory @file{@var{xdghome}/.config/emacs} exists, Emacs uses
> > +@file{@var{xdghome}/.config/emacs/init.el} as the init file.  Here,
> > +@var{xdghome} stands for the value of the environment variable
> > +@env{XDG_CONFIG_HOME}, or for @file{~/.config} if
> > +@env{XDG_CONFIG_HOME} is unset; @file{~/} stands for your home
> >  directory.
> >  
> > -  While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations
> > -are backward-compatible to older Emacs versions, and the rest of this
> > -chapter will use them to name your initialization file, it is better practice
> > -to group all of your dotfiles under @file{.config} so that if you have
> > +  If @file{~/.config/emacs} does not exist, Emacs looks for your init
> > +file using the filenames @file{~/.emacs}, @file{~/.emacs.el}, or
> > +@file{~/.emacs.d/init.el}; you can choose to use any one of these
> > +names (@pxref{Find Init}).  Although this is backward-compatible
> > +with older Emacs versions, modern POSIX platforms prefer putting your
> > +initialization files under @file{.config} so that if you have
> >  to troubleshoot a problem that might be due to a bad init file, or
> >  archive a collection of them, it can be done by renaming or
> >  copying that directory.  Note that the @file{.config} versions
> >  don't have a leading dot on the basename part of the file.
> > +For convenience the rest of this section assumes @env{XDG_CONFIG_HOME}
> > +is unset or has a value equivalent to @file{~/.config}.
> 
> I think the test which describes in detail how Emacs finds the init
> file should be in the section by that name; otherwise it makes no
> sense to have that section in the first place.  The "Init File"
> section should just mention the possible places and refer to that
> other section for the details.
> 
> > diff --git a/etc/NEWS b/etc/NEWS
> > index d876c95e68..7703fc1e79 100644
> > --- a/etc/NEWS
> > +++ b/etc/NEWS
> > @@ -135,6 +135,14 @@ builds respectively.
> >  \f
> >  * Startup Changes in Emacs 27.1
> >  
> > ++++
> > +** Emacs now uses the XDG convention for init files.
> > +For example, it looks for init.el in ~/.config/emacs/init.el.
> > +Emacs continues to look for init files in their traditional locations
> > +if ~/.config/emacs does not exist.  The XDG_CONFIG_HOME environment
> > +variable (default ~/.config) specifies the parent directory of these
> > +configuration files.
> 
> As mentioned above, I think we should tell here how to get back the
> old behavior.
> 
> > diff --git a/lisp/subr.el b/lisp/subr.el
> > index eea4e045dd..8b50748a59 100644
> > --- a/lisp/subr.el
> > +++ b/lisp/subr.el
> > @@ -2930,10 +2930,15 @@ temp-buffer-setup-hook
> >  mode.")
> >  
> >  (defconst user-emacs-directory
> > -  (if (eq system-type 'ms-dos)
> > -      ;; MS-DOS cannot have initial dot.
> > -      "~/_emacs.d/"
> > -    "~/.emacs.d/")
> > +  (let ((config-dir (concat (or (getenv-internal "XDG_CONFIG_HOME")
> > +				"~/.config")
> > +			    "/emacs/")))
> > +    (if (file-exists-p config-dir)
> > +	config-dir
> 
> Can this be a defconst?  It probes the existence of an environment
> variable and a directory, so it must be done at run time, not at build
> time, I think.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-08-25  8:46                               ` Eli Zaretskii
@ 2019-08-27 21:50                                 ` Paul Eggert
  2019-08-28  5:59                                   ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Paul Eggert @ 2019-08-27 21:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii wrote:
> Ping!  This seems to have stalled.  Can we please revive it and make
> the changes in the repository?

Done, with further tweaks to NEWS along the lines you suggested.



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

* Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
  2019-08-27 21:50                                 ` Paul Eggert
@ 2019-08-28  5:59                                   ` Eli Zaretskii
  0 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2019-08-28  5:59 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

> Cc: emacs-devel@gnu.org
> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Tue, 27 Aug 2019 14:50:40 -0700
> 
> Eli Zaretskii wrote:
> > Ping!  This seems to have stalled.  Can we please revive it and make
> > the changes in the repository?
> 
> Done, with further tweaks to NEWS along the lines you suggested.

Thanks!



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

end of thread, other threads:[~2019-08-28  5:59 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190525172356.30070.65317@vcs0.savannah.gnu.org>
     [not found] ` <20190525172357.86D4F207F5@vcs0.savannah.gnu.org>
2019-05-26 22:40   ` [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config Stefan Monnier
2019-06-03  2:32     ` Eli Zaretskii
2019-06-09  7:01       ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Amin Bandali
2019-06-09  8:10         ` Eli Zaretskii
2019-06-09 18:59         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory Stefan Monnier
2019-06-09 19:16           ` Eli Zaretskii
2019-06-09 20:16             ` Noam Postavsky
2019-06-10 16:22               ` Eli Zaretskii
2019-06-10 18:55                 ` Noam Postavsky
2019-06-10 19:21                   ` Lars Ingebrigtsen
2019-06-10 19:26                     ` Eli Zaretskii
2019-07-02 16:55                 ` Noam Postavsky
2019-07-02 17:26                   ` Eli Zaretskii
2019-07-23 14:36                     ` Eli Zaretskii
2019-07-27  2:58                       ` Amin Bandali
2019-07-27  7:55                         ` Eli Zaretskii
2019-07-27 18:46                           ` Paul Eggert
2019-07-27 21:22                             ` Basil L. Contovounesios
2019-07-28 14:41                               ` Eli Zaretskii
2019-07-28 15:21                                 ` Basil L. Contovounesios
2019-07-28 16:34                                   ` Eli Zaretskii
2019-07-28 14:48                             ` Eli Zaretskii
2019-07-29  1:00                               ` Elias Mårtenson
2019-07-29  2:36                                 ` Eli Zaretskii
2019-07-29  4:24                                   ` Elias Mårtenson
2019-07-29 14:21                                     ` Eli Zaretskii
2019-08-25  8:46                               ` Eli Zaretskii
2019-08-27 21:50                                 ` Paul Eggert
2019-08-28  5:59                                   ` Eli Zaretskii
2019-06-13 11:34         ` [PATCH] Implement XDG Base Directory specification for user-emacs-directory (was: [Emacs-diffs] master d68ed15: Implement and document XDG-style startup files under ~/.config.) Stefan Kangas

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