From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#583: Use XDG basedir spec for configuration files? Date: Sat, 31 Aug 2019 14:51:55 -0700 Organization: UCLA Computer Science Department Message-ID: <35285a0c-e43f-c74e-06da-52ef8475b0aa@cs.ucla.edu> References: <09f0b6af-213f-cc04-336b-00850ba0f3bf@cs.ucla.edu> <8ad91615-e621-7a10-72e2-03277676bd3a@cs.ucla.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------46389C7EF7420550ED25CBD6" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="156052"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Cc: ferkiwi@gmail.com, 583@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 31 23:53:14 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 1i4BJ4-000eRT-2e for geb-bug-gnu-emacs@m.gmane.org; Sat, 31 Aug 2019 23:53:14 +0200 Original-Received: from localhost ([::1]:46488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i4BJ2-0005K7-Bt for geb-bug-gnu-emacs@m.gmane.org; Sat, 31 Aug 2019 17:53:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43857) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i4BIt-0005Jj-Vv for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2019 17:53:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i4BIs-0007Mk-Mi for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2019 17:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i4BIs-0007MZ-J6 for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2019 17:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i4BIs-000337-F2 for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2019 17:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Aug 2019 21:53: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.156728832611642 (code B ref 583); Sat, 31 Aug 2019 21:53:02 +0000 Original-Received: (at 583) by debbugs.gnu.org; 31 Aug 2019 21:52:06 +0000 Original-Received: from localhost ([127.0.0.1]:56026 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i4BHx-00031i-QZ for submit@debbugs.gnu.org; Sat, 31 Aug 2019 17:52:06 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:58730) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i4BHv-00031E-JT for 583@debbugs.gnu.org; Sat, 31 Aug 2019 17:52:04 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D95C916008F; Sat, 31 Aug 2019 14:51:57 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id K-g3aYMsFxfs; Sat, 31 Aug 2019 14:51:56 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9FBD81600A3; Sat, 31 Aug 2019 14:51:56 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pCdeUYwoh2Pl; Sat, 31 Aug 2019 14:51:56 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 3416C16008F; Sat, 31 Aug 2019 14:51:56 -0700 (PDT) In-Reply-To: Content-Language: en-US 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:166125 Archived-At: This is a multi-part message in MIME format. --------------46389C7EF7420550ED25CBD6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------46389C7EF7420550ED25CBD6 Content-Type: text/x-patch; name="0001-Calculate-user-emacs-directory-on-startup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Calculate-user-emacs-directory-on-startup.patch" >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)))))) +;; 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) + (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)))) ;; 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 it. + (setq xdg-dir (concat "~" init-file-user "/.config/emacs/")) + (startup--xdg-or-homedot xdg-dir init-file-user))) ;; 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.") (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. -- 2.17.1 --------------46389C7EF7420550ED25CBD6--