From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Implement XDG Base Directory specification for user-emacs-directory Date: Sun, 28 Jul 2019 17:48:34 +0300 Message-ID: <83ef2akyf1.fsf@gnu.org> References: <20190525172356.30070.65317@vcs0.savannah.gnu.org> <20190525172357.86D4F207F5@vcs0.savannah.gnu.org> <835zpnv1o4.fsf@gnu.org> <87lfybw8cd.fsf_-_@fencepost.gnu.org> <83d0jmbmcs.fsf@gnu.org> <8336khbeas.fsf@gnu.org> <83woh0cppu.fsf@gnu.org> <83r26gq0lt.fsf@gnu.org> <87blxg6v5c.fsf@fencepost.gnu.org> <837e83nc87.fsf@gnu.org> <49b51848-c390-eff6-b2e1-be75f67ba620@cs.ucla.edu> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="8981"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 28 16:49:12 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hrkU1-0002Ax-GT for ged-emacs-devel@m.gmane.org; Sun, 28 Jul 2019 16:49:09 +0200 Original-Received: from localhost ([::1]:45490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrkU0-0006Du-HI for ged-emacs-devel@m.gmane.org; Sun, 28 Jul 2019 10:49:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47926) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrkTj-0006Dk-FV for emacs-devel@gnu.org; Sun, 28 Jul 2019 10:48:52 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:57297) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hrkTi-0001X2-Ut; Sun, 28 Jul 2019 10:48:51 -0400 Original-Received: from [176.228.60.248] (port=1279 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hrkTi-00060T-Cy; Sun, 28 Jul 2019 10:48:50 -0400 In-reply-to: <49b51848-c390-eff6-b2e1-be75f67ba620@cs.ucla.edu> (message from Paul Eggert on Sat, 27 Jul 2019 11:46:31 -0700) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238967 Archived-At: > From: Paul Eggert > 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.