From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Sven Joachim Newsgroups: gmane.emacs.bugs Subject: bug#583: Use XDG basedir spec for configuration files? Date: Wed, 11 Sep 2019 11:21:12 +0200 Message-ID: <87impzmbnb.fsf@turtle.gmx.de> References: <09f0b6af-213f-cc04-336b-00850ba0f3bf@cs.ucla.edu> <8ad91615-e621-7a10-72e2-03277676bd3a@cs.ucla.edu> <35285a0c-e43f-c74e-06da-52ef8475b0aa@cs.ucla.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="138218"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: ferkiwi@gmail.com, 583@debbugs.gnu.org To: Paul Eggert Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 11 11:24:10 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1i7yrC-000Zqf-8B for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Sep 2019 11:24:10 +0200 Original-Received: from localhost ([::1]:48824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7yrB-0000rW-0c for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Sep 2019 05:24:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41162) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7ypA-0006rW-3H for bug-gnu-emacs@gnu.org; Wed, 11 Sep 2019 05:22:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7yp8-0000Bk-NZ for bug-gnu-emacs@gnu.org; Wed, 11 Sep 2019 05:22:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33201) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7yp8-0000Bd-II for bug-gnu-emacs@gnu.org; Wed, 11 Sep 2019 05:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i7yp8-0005om-DM for bug-gnu-emacs@gnu.org; Wed, 11 Sep 2019 05:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Sven Joachim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Sep 2019 09:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 583 X-GNU-PR-Package: emacs Original-Received: via spool by 583-submit@debbugs.gnu.org id=B583.156819370222337 (code B ref 583); Wed, 11 Sep 2019 09:22:02 +0000 Original-Received: (at 583) by debbugs.gnu.org; 11 Sep 2019 09:21:42 +0000 Original-Received: from localhost ([127.0.0.1]:42022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i7yon-0005oA-HU for submit@debbugs.gnu.org; Wed, 11 Sep 2019 05:21:41 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:56573) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i7yol-0005ny-M4 for 583@debbugs.gnu.org; Wed, 11 Sep 2019 05:21:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1568193677; bh=Y+eafjOrtYeOdQFBlgSFotQuMTSa8w7GT0ZPSs0c0+4=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=NX02fA6y5YyQgi3NzVG8QUOm6fr6j0/5gHxuENQZ7tkOHWES7X9e4sfyoTBoGk8Kw 33IlkJ4wZWJhpRDBrOk0iGxShvX/pX7l8WVdGpj4kV2w0K3Hp3nuxcSQdIYSuSrKDC Rplq6fVKMaQKRWxVaO/zd2BfHqdD4V25rDTzUwGU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from localhost.localdomain ([79.223.36.122]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LnkiR-1icL1H41yp-00hxhP; Wed, 11 Sep 2019 11:21:17 +0200 Original-Received: by localhost.localdomain (Postfix, from userid 1000) id 503F7800B8; Wed, 11 Sep 2019 11:21:12 +0200 (CEST) In-Reply-To: <35285a0c-e43f-c74e-06da-52ef8475b0aa@cs.ucla.edu> (Paul Eggert's message of "Sat, 31 Aug 2019 14:51:55 -0700") X-Provags-ID: V03:K1:g6EsF/em83qFgpaHCtEJJASZ75yobdHpGCcBmzcRxbRIexHa7Yu s/cnL9fy+2ukbQsgC9EEPxyJ10DxHnM3OFVvbcKz538G45fuU1lm2X9DlgYTY7lWiFpRbF3 RLruLWy3aRsfNk8u7JJ8oPbCGAfawgd2I0hLxRYpOK/UOcy7DMHgvH0jO5H+1GkOVIvX+u6 /QZ2tFS0Y++a30/wWlIwQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:3Iyjfoc7zGs=:i/YGt/R2vOvgURot7cktJe OK9uemZMaE94ernFGyNx6bAeZVCaoKl1YhOa5MrUD6fMCEreEv2qwIFu0WGbl91Cwdlt7kWWe mwM2Gwxpnmj4pWMhTlYU2X42L1qoGADHSF2rDgXdNUMKUtQgzcb97DGhtlNQxJe0HGWdjAuAC p/Vqdg56GGy5ONUf3CG00w3VXHpnENjd1fwIxxtvx7k6Vwl5uxqwgID2xc5DX1U9nXorq2AXy JILAkjF0IisJu1irXtbZm4Eu9XOWYGXIsygGACQd6MSFw/utUzRfbkZwiDHZxWDizwTe3azLI 3dPLXjSvJyT4TMm3NWDu8GIivySY3SHzIPTo/kA5ITkq1ZUOTi/vRJIs8X4PVOUy+VlkKxlq5 e8JAGahAW0pBZBPgeWCMSNgJ4TFK9LPRFuL+9zRYvam6X8pw+bOFotQ+PfsV5SIbFZWJK0z2n 7QQJySSWmMvpdZtelKD9MBQp0YMWJudwJQUskhoZaqEmGS2sSGx+KRk+1fYd9ub3yzZ19VR5q k0pWVtRUCM5/avu1RQYl3y0TJebqAJkRw4dSJ4+gsD8H0DvT+qq3JA+x2hXJ+RV9am53G/WeB Lnz1qC015Pj7TrH6bL1/vd9g20q0VVmX4Z2yPmVPni4fT4PNGZKh2ukgMQ9H+7Gg2bPtLVIHM K4RPe5U7tsY1JQ2jCtnLNP7CHNmA40RVoflqQDF7H41NPB8mQgas0SPyL9vlC0wISlprUvmYZ uV4DssLMrWokJ8fqVcW1q83mim41SAa6COjhn/OxNvui7u4ZBTgfFqjzzJG6cKtrx8ZUH7Mx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:166353 Archived-At: On 2019-08-31 14:51 -0700, Paul Eggert wrote: > Glenn Morris wrote: >> I guess user-emacs-directory is being set at build time, not run time. > > Thanks for reporting that. I installed the attached to fix it. I plan > to follow up soon on the other issues raised here. FWIW, this patch broke auto-save-list-file-prefix, at least when user-emacs-directory is "~/.emacs.d/". See bug #37354. ,---- | auto-save-list-file-prefix is a variable defined in =E2=80=98startup.el= =E2=80=99. | Its value is "auto-save-list/.saves-" | Original value was | "~/.emacs.d/auto-save-list/.saves-" `---- Cheers, Sven > From 2befb4f0a1494f699f56215d5f28ba055663d881 Mon Sep 17 00:00:00 2001 > From: Paul Eggert > Date: Sat, 31 Aug 2019 14:47:04 -0700 > Subject: [PATCH] Calculate user-emacs-directory on startup > > Problem reported by Glenn Morris (Bug#583#56). > * lisp/startup.el (startup--xdg-config-default): New constant. > (startup--xdg-config-home-emacs): New var. > (startup--xdg-or-homedot): New function. > (normal-top-level): Use it to set user-emacs-directory early on. > (command-line): Also use it to determine the startup init directory. > * lisp/subr.el (user-emacs-directory): Just initialize to nil. > --- > lisp/startup.el | 51 +++++++++++++++++++++++++++++++++++++------------ > lisp/subr.el | 14 ++------------ > 2 files changed, 41 insertions(+), 24 deletions(-) > > diff --git a/lisp/startup.el b/lisp/startup.el > index c1e429b8db..a16db242da 100644 > --- a/lisp/startup.el > +++ b/lisp/startup.el > @@ -490,6 +490,27 @@ normal-top-level-add-to-load-path > (when tail > (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))= )) >=20=20 > +;; The default location for XDG-convention Emacs init files. > +(defconst startup--xdg-config-default "~/.config/emacs/") > +;; The location for XDG-convention Emacs init files. > +(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. > +(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 (file-exists-p emacs-d-dir) > + emacs-d-dir > + xdg-dir)))) > + > (defun normal-top-level () > "Emacs calls this function when it first starts up. > It sets `command-line-processed', processes the command-line, > @@ -499,6 +520,14 @@ normal-top-level > (message internal--top-level-message) > (setq command-line-processed t) >=20=20 > + (setq startup--xdg-config-home-emacs > + (let ((xdg-config-home (getenv-internal "XDG_CONFIG_HOME"))) > + (if xdg-config-home > + (concat xdg-config-home "/emacs/") > + startup--xdg-config-default))) > + (setq user-emacs-directory > + (startup--xdg-or-homedot startup--xdg-config-home-emacs nil)) > + > ;; Look in each dir in load-path for a subdirs.el file. If we > ;; find one, load it, which will add the appropriate subdirs of > ;; that dir into load-path. This needs to be done before setting > @@ -1167,19 +1196,17 @@ command-line > :error)))) >=20=20 > ;; 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 (concat (or (getenv "XDG_CONFIG_HOME") > - (concat "~" init-file-user "/.config")) > - "/emacs/")) > + ;; This is typically ~INIT-FILE-USER/.config/emacs unless the user > + ;; is following the ~INIT-FILE-USER/.emacs.d convention. > + (setq xdg-dir startup--xdg-config-home-emacs) > (setq startup-init-directory > - (if (file-exists-p xdg-dir) > - xdg-dir > - (let ((emacs-d-dir (concat "~" init-file-user "/.emacs.d/"))) > - (if (file-exists-p emacs-d-dir) > - emacs-d-dir > - xdg-dir)))) > + (if (or (zerop (length init-file-user)) > + (and (eq xdg-dir user-emacs-directory) > + (not (eq xdg-dir startup--xdg-config-default)))) > + user-emacs-directory > + ;; The name is not obvious, so access more directories to calculate i= t. > + (setq xdg-dir (concat "~" init-file-user "/.config/emacs/")) > + (startup--xdg-or-homedot xdg-dir init-file-user))) >=20=20 > ;; Load the early init file, if found. > (startup--load-user-init-file > diff --git a/lisp/subr.el b/lisp/subr.el > index 566a3fc758..cf6fb108e9 100644 > --- a/lisp/subr.el > +++ b/lisp/subr.el > @@ -2938,18 +2938,8 @@ temp-buffer-setup-hook > mode.") >=20=20 > (defconst user-emacs-directory > - (let ((config-dir (concat (or (getenv-internal "XDG_CONFIG_HOME") > - "~/.config") > - "/emacs/"))) > - (if (file-exists-p config-dir) > - config-dir > - (let ((emacs-d-dir (if (eq system-type 'ms-dos) > - ;; MS-DOS cannot have initial dot. > - "~/_emacs.d/" > - "~/.emacs.d/"))) > - (if (file-exists-p emacs-d-dir) > - emacs-d-dir > - config-dir)))) > + ;; The value does not matter since Emacs sets this at startup. > + nil > "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. > --=20 > 2.17.1