From: Paul Eggert <eggert@cs.ucla.edu>
To: Glenn Morris <rgm@gnu.org>
Cc: ferkiwi@gmail.com, 583@debbugs.gnu.org
Subject: bug#583: Use XDG basedir spec for configuration files?
Date: Sat, 31 Aug 2019 14:51:55 -0700 [thread overview]
Message-ID: <35285a0c-e43f-c74e-06da-52ef8475b0aa@cs.ucla.edu> (raw)
In-Reply-To: <w5tv9zj02p.fsf@fencepost.gnu.org>
[-- Attachment #1: Type: text/plain, Size: 216 bytes --]
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.
[-- Attachment #2: 0001-Calculate-user-emacs-directory-on-startup.patch --]
[-- Type: text/x-patch, Size: 4737 bytes --]
From 2befb4f0a1494f699f56215d5f28ba055663d881 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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
next prev parent reply other threads:[~2019-08-31 21:51 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-21 6:59 bug#583: Use XDG basedir spec for configuration files? Fernando
2012-12-08 12:18 ` bug#583: XDG basedir specification Eric Heintzmann
2012-12-08 19:06 ` Jan Djärv
2012-12-08 19:31 ` Eli Zaretskii
2019-08-27 21:57 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
2019-08-28 16:11 ` Glenn Morris
2019-08-28 16:29 ` Eli Zaretskii
2019-08-28 16:50 ` Glenn Morris
2019-08-28 17:18 ` Eli Zaretskii
2019-08-29 2:17 ` Glenn Morris
2019-08-29 7:03 ` Eli Zaretskii
2019-08-28 18:11 ` Paul Eggert
2019-08-29 2:14 ` Glenn Morris
2019-08-29 6:22 ` Paul Eggert
2019-08-29 8:42 ` Štěpán Němec
2019-08-29 18:30 ` Glenn Morris
2019-08-29 18:35 ` Glenn Morris
2019-08-29 18:53 ` Eli Zaretskii
2019-08-30 8:02 ` Paul Eggert
2019-08-30 16:18 ` Glenn Morris
2019-08-30 17:44 ` Eli Zaretskii
2019-09-01 1:56 ` bug#15539: [PATCH] Setting user-emacs-directory Paul Eggert
2019-09-02 23:45 ` Glenn Morris
2019-09-03 6:29 ` Paul Eggert
2019-09-08 14:54 ` Mike Carifio
2020-08-13 11:06 ` Lars Ingebrigtsen
2019-09-01 2:02 ` bug#583: Use XDG basedir spec for configuration files? Paul Eggert
2019-09-01 14:38 ` Eli Zaretskii
2019-09-01 18:40 ` Paul Eggert
2019-09-01 18:50 ` Eli Zaretskii
2019-09-01 23:01 ` Paul Eggert
2019-08-31 21:51 ` Paul Eggert [this message]
2019-09-11 9:21 ` Sven Joachim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=35285a0c-e43f-c74e-06da-52ef8475b0aa@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=583@debbugs.gnu.org \
--cc=ferkiwi@gmail.com \
--cc=rgm@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).