Commit a4144af9 authored by Paul Eggert's avatar Paul Eggert

Prefer ~/.config/emacs to ~/.emacs.d if neither exists

That way, when Emacs starts in a fresh home directory,
it prefers the new (XDG) convention rather than the old one.
* lisp/files.el (locate-user-emacs-file): Make the parent
directories of user-emacs-directory if needed.  This is useful
if user-emacs-directory is "~/.config/emacs" and "~/.config"
does not yet exist.
* lisp/startup.el (command-line):
* lisp/subr.el (user-emacs-directory):
Prefer XDG_CONFIG_HOME to ~/.emacs.d if neither exists.
parent 462be72f
...@@ -1043,7 +1043,7 @@ directory if it does not exist." ...@@ -1043,7 +1043,7 @@ directory if it does not exist."
(setq errtype "access")) (setq errtype "access"))
(with-file-modes ?\700 (with-file-modes ?\700
(condition-case nil (condition-case nil
(make-directory user-emacs-directory) (make-directory user-emacs-directory t)
(error (setq errtype "create"))))) (error (setq errtype "create")))))
(when (and errtype (when (and errtype
user-emacs-directory-warning user-emacs-directory-warning
......
...@@ -1170,13 +1170,16 @@ please check its value") ...@@ -1170,13 +1170,16 @@ please check its value")
;; This is typically equivalent to ~/.config/emacs if the user is ;; This is typically equivalent to ~/.config/emacs if the user is
;; following the XDG convention, and is ~INIT-FILE-USER/.emacs.d ;; following the XDG convention, and is ~INIT-FILE-USER/.emacs.d
;; on other systems. ;; on other systems.
(setq xdg-dir (setq xdg-dir (concat (or (getenv "XDG_CONFIG_HOME")
(let* ((dir (concat (or (getenv "XDG_CONFIG_HOME")
(concat "~" init-file-user "/.config")) (concat "~" init-file-user "/.config"))
"/emacs/"))) "/emacs/"))
(if (file-exists-p dir) dir)))
(setq startup-init-directory (setq startup-init-directory
(or xdg-dir (concat "~" init-file-user "/.emacs.d/"))) (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))))
;; Load the early init file, if found. ;; Load the early init file, if found.
(startup--load-user-init-file (startup--load-user-init-file
...@@ -1325,7 +1328,7 @@ please check its value") ...@@ -1325,7 +1328,7 @@ please check its value")
(startup--load-user-init-file (startup--load-user-init-file
(lambda () (lambda ()
(cond (cond
(xdg-dir nil) ((eq startup-init-directory xdg-dir) nil)
((eq system-type 'ms-dos) ((eq system-type 'ms-dos)
(concat "~" init-file-user "/_emacs")) (concat "~" init-file-user "/_emacs"))
((not (eq system-type 'windows-nt)) ((not (eq system-type 'windows-nt))
......
...@@ -2943,10 +2943,13 @@ mode.") ...@@ -2943,10 +2943,13 @@ mode.")
"/emacs/"))) "/emacs/")))
(if (file-exists-p config-dir) (if (file-exists-p config-dir)
config-dir config-dir
(if (eq system-type 'ms-dos) (let ((emacs-d-dir (if (eq system-type 'ms-dos)
;; MS-DOS cannot have initial dot. ;; MS-DOS cannot have initial dot.
"~/_emacs.d/" "~/_emacs.d/"
"~/.emacs.d/"))) "~/.emacs.d/")))
(if (file-exists-p emacs-d-dir)
emacs-d-dir
config-dir))))
"Directory beneath which additional per-user Emacs-specific files are placed. "Directory beneath which additional per-user Emacs-specific files are placed.
Various programs in Emacs store information in this directory. Various programs in Emacs store information in this directory.
Note that this should end with a directory separator. Note that this should end with a directory separator.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment