emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Implement XDG Base Directory specification for user-emacs-di


From: Eli Zaretskii
Subject: Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory
Date: Sun, 28 Jul 2019 17:48:34 +0300

> From: Paul Eggert <address@hidden>
> 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.
>  
>  * 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]