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, 25 Aug 2019 11:46:51 +0300 Message-ID: <83r259hbt0.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> <83ef2akyf1.fsf@gnu.org> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="178228"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: eggert@cs.ucla.edu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 25 10:47:26 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 1i1oBJ-000kFy-UA for ged-emacs-devel@m.gmane.org; Sun, 25 Aug 2019 10:47:26 +0200 Original-Received: from localhost ([::1]:41376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1oBI-0008Mu-4n for ged-emacs-devel@m.gmane.org; Sun, 25 Aug 2019 04:47:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40588) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1oAo-0008Mn-GS for emacs-devel@gnu.org; Sun, 25 Aug 2019 04:46:55 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:46365) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1i1oAn-0004OV-S2; Sun, 25 Aug 2019 04:46:53 -0400 Original-Received: from [176.228.60.248] (port=3171 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1i1oAl-00038v-Vy; Sun, 25 Aug 2019 04:46:53 -0400 In-reply-to: <83ef2akyf1.fsf@gnu.org> (message from Eli Zaretskii on Sun, 28 Jul 2019 17:48:34 +0300) 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:239547 Archived-At: 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 > CC: emacs-devel@gnu.org > > > 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.