all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: eggert@cs.ucla.edu, emacs-devel@gnu.org
Subject: Re: Default emacs init file location confusion
Date: Thu, 16 Jan 2020 08:35:02 +0100	[thread overview]
Message-ID: <m236cfx3a1.fsf@gmail.com> (raw)
In-Reply-To: <83eew04oci.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 15 Jan 2020 19:32:45 +0200")

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

>>>>> On Wed, 15 Jan 2020 19:32:45 +0200, Eli Zaretskii <eliz@gnu.org> said:

    >> From: Robert Pluim <rpluim@gmail.com>
    >> Cc: eggert@cs.ucla.edu,  emacs-devel@gnu.org
    >> Date: Wed, 15 Jan 2020 14:03:53 +0100
    >> 
    >> I found another use of XDG in emacsclient.c that needed fixing. It
    >> works fine in my testing, but Iʼd appreciate another pair of eyeballs.

    Eli> I see no changes in emacsclient.c in the patch you sent...

*sigh* Iʼd updated the commit with the log message, and forgotten to
 do 'git add'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-emacs-prefer-an-existing-.emacs.d-to-an-existin.patch --]
[-- Type: text/x-patch, Size: 10399 bytes --]

From f840c92da8b6dcd0e4f5506c2fea27a8cb4eed5a Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Wed, 15 Jan 2020 12:24:43 +0100
Subject: [PATCH] Make emacs prefer an existing ~/.emacs.d to an existing XDG
 location

* doc/emacs/custom.texi (Find Init): Update description of how Emacs
finds its init file directory and the interaction with
$XDG_CONFIG_HOME
(Early Init File): Correct XDG location of early-init.el

* etc/NEWS: Update description to make it clear the ~/.emacs.d is
preferred, even if the XDG location exists.

* lisp/startup.el: Prefer ~/.emacs.d even if the XDG location exists.

* lib-src/emacsclient.c (open_config): Prefer home directory the XDG
location.
---
 doc/emacs/custom.texi | 45 +++++++++++++++++++++++++++----------------
 etc/NEWS              | 37 +++++++++++++++++------------------
 lib-src/emacsclient.c | 17 ++++++++--------
 lisp/startup.el       | 42 ++++++++++++++++++++--------------------
 4 files changed, 76 insertions(+), 65 deletions(-)

diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 1958a86b92..2e04a6b22d 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -2655,26 +2655,37 @@ Find Init
 
   Emacs normally finds your init file in a location under your home
 directory.  @xref{Init File}.  By default this location is
-@file{~/.config/emacs/init.el} where @file{~/} stands for your home directory.
+@file{~/.emacs.d/init.el} where @file{~/} stands for your home directory.
 This default can be overridden as described below.
 
-  If @env{XDG_CONFIG_HOME} is set in your environment, its
-value replaces @file{~/.config} in the name of the default
-init file.
-
-  If the default init file's parent directory does not exist but the
-directory @file{~/.emacs.d} does exist, Emacs looks for your init file
+Emacs looks for your init file
 using the filenames @file{~/.emacs.el}, @file{~/.emacs}, or
 @file{~/.emacs.d/init.el}; you can choose to use any one of these
 names.  (Note that only the locations directly in your home directory
-have a leading dot in the location's basename.)  Although this is
-backward-compatible with older Emacs versions, modern POSIX platforms
-prefer putting your initialization files under @file{~/.config} so
-that troubleshooting a problem that might be due to a bad init file,
-or archiving a collection of init files, can be done by renaming that
-directory.  To help older Emacs versions find configuration files in
-their current default locations, you can execute the following
-Emacs Lisp code:
+have a leading dot in the location's basename.)
+
+Emacs can also look in an XDG-compatible location for @file{init.el},
+the default is the directory @file{~/.config/emacs}.  This can be
+overriden by setting @env{XDG_CONFIG_HOME} in your environment, its
+value replaces @file{~/.config} in the name of the default XDG init
+file.  However @file{~/.emacs.d} and @file{~/.emacs} are always
+preferred if they exist, which means that you must delete or rename
+them in order to use the XDG location.
+
+Note also that if neither the XDG location nor @file{~/.emacs.d}
+exist, then Emacs will create @file{~/.emacs.d} (and therefore use it
+during subsequent invocations).
+
+Emacs will set @var{user-emacs-directory} to the directory it decides
+to use.
+
+Although this is backward-compatible with older Emacs versions, modern
+POSIX platforms prefer putting your initialization files under
+@file{~/.config} so that troubleshooting a problem that might be due
+to a bad init file, or archiving a collection of init files, can be
+done by renaming that directory.  To help older Emacs versions find
+configuration files in their current default locations, you can
+execute the following Emacs Lisp code:
 
 @example
 (make-symbolic-link ".config/emacs" "~/.emacs.d")
@@ -2694,7 +2705,7 @@ Find Init
 name in the system's data base of users.
 
   For brevity the rest of the Emacs documentation generally uses just
-the current default location @file{~/.config/emacs/init.el} for the
+the current default location @file{~/.emacs.d/init.el} for the
 init file.
 @c  LocalWords:  backtab
 
@@ -2740,7 +2751,7 @@ Early 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
+init file, @file{~/.config/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
diff --git a/etc/NEWS b/etc/NEWS
index cea5d500c7..c247adc285 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -154,25 +154,24 @@ support.
 * 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", and
-similarly for other init files.
-
-The 'XDG_CONFIG_HOME' environment variable (which defaults to "~/.config")
-specifies the parent directory of these and other configuration files,
-and will override their traditional locations (the home directory,
-"~/.emacs.d", etc.).
-
-Emacs will still look for init files in their traditional locations if
-"$XDG_CONFIG_HOME/emacs" does not exist, but "~/.emacs.d" or
-"~/.emacs" does exist, so invoking Emacs with XDG_CONFIG_HOME='/nowhere'
-might be useful if your new-location init files are scrambled, or if
-you want to force Emacs to ignore files under 'XDG_CONFIG_HOME' for
-some other reason.
-
-If neither "$XDG_CONFIG_HOME/emacs" nor "~/.emacs.d" exist, Emacs will
-now default to "$XDG_CONFIG_HOME/emacs", and will create that directory
-and set 'user-emacs-directory' to point to it.
+** Emacs can now use the XDG convention for init files.
+The 'XDG_CONFIG_HOME' environment variable (which defaults to
+"~/.config") specifies the XDG configuration parent directory.  Emacs
+checks for "init.el" and other configuration files inside the "emacs"
+subdirectory of 'XDG_CONFIG_HOME', i.e. "$XDG_CONFIG_HOME/emacs/init.el"
+
+However, Emacs will still initially look for init files in their
+traditional locations if "~/.emacs.d" or "~/.emacs" exist, even if
+"$XDG_CONFIG_HOME/emacs" also exists.  This means that you must delete
+or rename any existing "~/.emacs.d" and "~/.emacs" to enable use of
+the XDG directory.
+
+If "~/.emacs.d" does not exist, and Emacs has decided to use it
+(i.e. "$XDG_CONFIG_HOME/emacs" does not exist), Emacs will create it.
+Emacs will never create "$XDG_CONFIG_HOME/emacs".
+
+Whichever directory Emacs decides to use, it will set
+'user-emacs-directory' to point to it.
 
 +++
 ** Emacs can now be configured using an early init file.
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 645ff04c6d..204064f187 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -924,21 +924,22 @@ open_config (char const *home, char const *xdg, char const *config_file)
   char *configname = xmalloc (max (xdgsubdirsize, homesubdirsizemax)
 			      + strlen (config_file));
   FILE *config;
-  if (xdg || home)
+
+  if (home)
     {
-      strcpy ((xdg
-	       ? stpcpy (stpcpy (configname, xdg), "/emacs/server/")
-	       : stpcpy (stpcpy (configname, home), "/.config/emacs/server/")),
-	      config_file);
+      strcpy (stpcpy (stpcpy (configname, home), "/.emacs.d/server/"),
+              config_file);
       config = fopen (configname, "rb");
     }
   else
     config = NULL;
 
-  if (! config && home)
+  if (! config && (xdg || home))
     {
-      strcpy (stpcpy (stpcpy (configname, home), "/.emacs.d/server/"),
-	      config_file);
+      strcpy ((xdg
+               ? stpcpy (stpcpy (configname, xdg), "/emacs/server/")
+               : stpcpy (stpcpy (configname, home), "/.config/emacs/server/")),
+              config_file);
       config = fopen (configname, "rb");
     }
 
diff --git a/lisp/startup.el b/lisp/startup.el
index 2a85c004da..1f545c6692 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -497,28 +497,28 @@ startup--xdg-config-default
 (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.
+;; 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 only if the .emacs.d location does not 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 (or (file-exists-p emacs-d-dir)
-	      (if (eq system-type 'windows-nt)
-                  (if (file-directory-p (concat "~" user-name))
-                      (directory-files (concat "~" user-name) nil
-                                       "\\`[._]emacs\\(\\.elc?\\)?\\'"))
-		(file-exists-p (concat "~" init-file-user
-				       (if (eq system-type 'ms-dos)
-					   "/_emacs"
-					 "/.emacs")))))
-	  emacs-d-dir
-	xdg-dir))))
+  (let ((emacs-d-dir (concat "~" user-name
+                             (if (eq system-type 'ms-dos)
+                                 "/_emacs.d/"
+                               "/.emacs.d/"))))
+    (cond
+     ((or (file-exists-p emacs-d-dir)
+          (if (eq system-type 'windows-nt)
+              (if (file-directory-p (concat "~" user-name))
+                  (directory-files (concat "~" user-name) nil
+                                   "\\`[._]emacs\\(\\.elc?\\)?\\'"))
+            (file-exists-p (concat "~" init-file-user
+                                   (if (eq system-type 'ms-dos)
+                                       "/_emacs"
+                                     "/.emacs")))))
+      emacs-d-dir)
+     ((file-exists-p xdg-dir)
+      xdg-dir)
+     (t emacs-d-dir))))
 
 (defun normal-top-level ()
   "Emacs calls this function when it first starts up.
-- 
2.23.0


  reply	other threads:[~2020-01-16  7:35 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-07  2:51 Default emacs init file location confusion Elias Mårtenson
2020-01-07  3:32 ` Eli Zaretskii
2020-01-07  3:40   ` Elias Mårtenson
2020-01-07  4:40     ` Eli Zaretskii
2020-01-07 14:43       ` Lawrence Liu
2020-01-07 15:26         ` Robert Pluim
2020-01-07 16:12           ` Eli Zaretskii
2020-01-07 16:25             ` Robert Pluim
2020-01-07 17:04               ` Eli Zaretskii
2020-01-07 17:11                 ` Elias Mårtenson
2020-01-07 17:21                   ` Eli Zaretskii
2020-01-07 17:33                     ` Elias Mårtenson
2020-01-07 17:37                       ` Eli Zaretskii
2020-01-08  5:28                         ` Mingde (Matthew) Zeng
2020-01-08  5:33                           ` Elias Mårtenson
2020-01-08  7:22                             ` Eli Zaretskii
2020-01-08 10:05                               ` Elias Mårtenson
     [not found]                               ` <m2eewajram.fsf@gmail.com>
2020-01-08 10:05                                 ` Eli Zaretskii
2020-01-08 10:13                                   ` Elias Mårtenson
2020-01-08 10:22                                   ` Robert Pluim
2020-01-08 10:49                                     ` Eli Zaretskii
2020-01-08 12:37                                       ` Robert Pluim
2020-01-08 13:51                                         ` Stefan Monnier
2020-01-08 15:58                                           ` Eli Zaretskii
2020-01-08 16:28                                             ` Stefan Monnier
2020-01-08 16:32                                               ` Eli Zaretskii
2020-01-08 16:41                                                 ` Mingde (Matthew) Zeng
2020-01-08 16:49                                                   ` Robert Pluim
2020-01-08 17:01                                                     ` Eli Zaretskii
2020-01-08 17:25                                                       ` Robert Pluim
2020-01-08 17:35                                                         ` Eli Zaretskii
2020-01-08 17:44                                                           ` Robert Pluim
2020-01-08 17:56                                                             ` Yuan Fu
2020-01-08 18:03                                                               ` Robert Pluim
2020-01-09  2:27                                                                 ` Yuan Fu
2020-01-08 18:07                                                             ` Eli Zaretskii
2020-01-08 18:12                                                               ` Robert Pluim
2020-01-08 18:19                                                                 ` Eli Zaretskii
2020-01-08 19:45                                                                   ` Stefan Monnier
2020-01-08 20:03                                                                     ` Eli Zaretskii
2020-01-10 16:57                                                     ` Eli Zaretskii
2020-01-11  1:46                                                       ` Paul Eggert
2020-01-11  7:58                                                         ` Eli Zaretskii
2020-01-11 15:43                                                         ` Drew Adams
2020-01-11 16:16                                                         ` Stefan Monnier
2020-01-11 18:08                                                           ` Eli Zaretskii
2020-01-13  7:53                                                         ` Robert Pluim
2020-01-13 14:36                                                           ` Robert Pluim
2020-01-13 15:27                                                             ` Colin Baxter
2020-01-13 15:37                                                               ` Robert Pluim
2020-01-13 15:58                                                                 ` Colin Baxter
2020-01-13 16:05                                                                   ` Robert Pluim
2020-01-13 16:42                                                                   ` Eli Zaretskii
2020-01-13 16:59                                                                     ` Colin Baxter
2020-01-13 17:06                                                                       ` Robert Pluim
2020-01-13 17:21                                                                         ` Colin Baxter
2020-01-13 16:15                                                             ` Eli Zaretskii
2020-01-13 16:39                                                               ` Robert Pluim
2020-01-14 14:00                                                                 ` Robert Pluim
2020-01-14 16:05                                                                   ` Eli Zaretskii
2020-01-15 13:03                                                                     ` Robert Pluim
2020-01-15 17:32                                                                       ` Eli Zaretskii
2020-01-16  7:35                                                                         ` Robert Pluim [this message]
2020-01-16 15:02                                                                           ` Eli Zaretskii
2020-01-16 15:08                                                                             ` Robert Pluim
2020-01-13 16:52                                                             ` Stefan Kangas
2020-01-13 16:17                                                           ` Eli Zaretskii
2020-01-13 16:29                                                             ` Robert Pluim
2020-01-08 23:26                                           ` chad
2020-01-08 23:32                                             ` Stefan Monnier
2020-01-09  3:34                                               ` Eli Zaretskii
2020-01-09  1:26                                             ` HaiJun Zhang
2020-01-09  5:07                                               ` 황병희
2020-01-08 11:03                                   ` Mario Lang
2020-01-08 15:56                                     ` Eli Zaretskii
2020-01-08  8:04                             ` Robert Pluim
2020-01-07 17:57                     ` Stefan Monnier
2020-01-07 18:08                       ` Stefan Monnier
2020-01-07 18:09                       ` Eli Zaretskii
2020-01-07 18:41                         ` Stefan Monnier
2020-01-07 18:57                           ` Yuan Fu
2020-01-07 19:15                             ` Greg Farough
2020-01-07 20:11                               ` Andrea Corallo
2020-01-07 18:53                         ` Yuan Fu
2020-01-07 17:12                 ` Yuan Fu
2020-01-07 17:26                   ` Elias Mårtenson
2020-01-07  3:46   ` Mingde (Matthew) Zeng
2020-01-07  3:50     ` Elias Mårtenson
2020-01-07  3:43 ` VanL
2020-01-07  3:51   ` Elias Mårtenson

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=m236cfx3a1.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.