aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond2019-05-25 13:22:44 -0400
committerEric S. Raymond2019-05-25 13:23:46 -0400
commitd68ed152ffe4369b3fe082cf39d631cc5360143b (patch)
treef0123dfb8c9e93842b4d2185437fff0d35467092
parentcd7a0bd00802b9331229dfe4a70ea9690d2d70fc (diff)
downloademacs-d68ed152ffe4369b3fe082cf39d631cc5360143b.tar.gz
emacs-d68ed152ffe4369b3fe082cf39d631cc5360143b.zip
Implement and document XDG-style startup files under ~/.config.
* lisp/startup.el (command-line): Allow XDG-style as well as old style init paths. * doc/startup.texi: Document the above change.
-rw-r--r--ChangeLog.38
-rw-r--r--doc/emacs/custom.texi46
-rw-r--r--lisp/startup.el17
3 files changed, 51 insertions, 20 deletions
diff --git a/ChangeLog.3 b/ChangeLog.3
index e7f4d866326..fbaf8138528 100644
--- a/ChangeLog.3
+++ b/ChangeLog.3
@@ -1,3 +1,11 @@
12019-05-25 Eric S. Raymond <esr@thyrsus.com>
2
3 Implement and document XDG-style startup files under ~/.config.
4
5 * lisp/startup.el (command-line): Allow XDG-style as well as old
6 style paths.
7 * doc/startup.texi: Document the above change.
8
12019-04-11 Eli Zaretskii <eliz@gnu.org> 92019-04-11 Eli Zaretskii <eliz@gnu.org>
2 10
3 Improve documentation of 'read-command' 11 Improve documentation of 'read-command'
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index bdd6decb6b5..982cea1f213 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -380,7 +380,7 @@ lines of code to your initialization file, to set the variable
380file. For example: 380file. For example:
381 381
382@example 382@example
383(setq custom-file "~/.emacs-custom.el") 383(setq custom-file "~/.config/emacs-custom.el")
384(load custom-file) 384(load custom-file)
385@end example 385@end example
386 386
@@ -390,14 +390,14 @@ Emacs versions, like this:
390@example 390@example
391(cond ((< emacs-major-version 22) 391(cond ((< emacs-major-version 22)
392 ;; @r{Emacs 21 customization.} 392 ;; @r{Emacs 21 customization.}
393 (setq custom-file "~/.custom-21.el")) 393 (setq custom-file "~/.config/custom-21.el"))
394 ((and (= emacs-major-version 22) 394 ((and (= emacs-major-version 22)
395 (< emacs-minor-version 3)) 395 (< emacs-minor-version 3))
396 ;; @r{Emacs 22 customization, before version 22.3.} 396 ;; @r{Emacs 22 customization, before version 22.3.}
397 (setq custom-file "~/.custom-22.el")) 397 (setq custom-file "~/.config/custom-22.el"))
398 (t 398 (t
399 ;; @r{Emacs version 22.3 or later.} 399 ;; @r{Emacs version 22.3 or later.}
400 (setq custom-file "~/.emacs-custom.el"))) 400 (setq custom-file "~/.config/emacs-custom.el")))
401 401
402(load custom-file) 402(load custom-file)
403@end example 403@end example
@@ -2215,16 +2215,28 @@ as a function from Lisp programs.
2215@cindex init file 2215@cindex init file
2216@cindex .emacs file 2216@cindex .emacs file
2217@cindex ~/.emacs file 2217@cindex ~/.emacs file
2218@cindex ~/.config/emacs file
2218@cindex Emacs initialization file 2219@cindex Emacs initialization file
2219@cindex startup (init file) 2220@cindex startup (init file)
2220 2221
2221 When Emacs is started, it normally tries to load a Lisp program from 2222 When Emacs is started, it normally tries to load a Lisp program from
2222an @dfn{initialization file}, or @dfn{init file} for short. This 2223an @dfn{initialization file}, or @dfn{init file} for short. This
2223file, if it exists, specifies how to initialize Emacs for you. Emacs 2224file, if it exists, specifies how to initialize Emacs for you. Emacs
2224looks for your init file using the filenames @file{~/.emacs}, 2225looks for your init file using the filenames
2225@file{~/.emacs.el}, or @file{~/.emacs.d/init.el}; you can choose to 2226@file{~/.config/emacs},. @file{~/.emacs}, @file{~/.config/emacs.el},
2226use any one of these three names (@pxref{Find Init}). Here, @file{~/} 2227@file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or
2227stands for your home directory. 2228@file{~/.emacs.d/init.el}; you can choose to use any one of these
2229names (@pxref{Find Init}). Here, @file{~/} stands for your home
2230directory.
2231
2232 While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations
2233are backward-compatible to older Emacs versions, and the rest of this
2234chapter will use them to name your initialization file, it is better practice
2235to group all of your dotfiles under @file{.config} so that if you have
2236to troubleshoot a problem that might be due to a bad init file, or
2237archive a collection of them, it can be done by renaming or
2238copying that directory. Note that the @file{.config} versions
2239don't have a leading dot on the basename part of the file.
2228 2240
2229 You can use the command line switch @samp{-q} to prevent loading 2241 You can use the command line switch @samp{-q} to prevent loading
2230your init file, and @samp{-u} (or @samp{--user}) to specify a 2242your init file, and @samp{-u} (or @samp{--user}) to specify a
@@ -2630,14 +2642,16 @@ library. @xref{Hooks}.
2630@node Find Init 2642@node Find Init
2631@subsection How Emacs Finds Your Init File 2643@subsection How Emacs Finds Your Init File
2632 2644
2633 Normally Emacs uses your home directory to find @file{~/.emacs}; 2645 Normally Emacs uses your home directory to find
2634that's what @samp{~} means in a file name. @xref{General Variables, HOME}. 2646@file{~/.config/emacs} or @file{~/.emacs}; that's what @samp{~} means
2635If neither @file{~/.emacs} nor @file{~/.emacs.el} is found, Emacs looks for 2647in a file name. @xref{General Variables, HOME}. If none of
2636@file{~/.emacs.d/init.el} (which, like @file{~/.emacs.el}, can be 2648@file{~/.config/emacs}, @file{~/.emacs}, @file{~/.config/emacs.el} nor
2637byte-compiled). 2649@file{~/.emacs.el} is found, Emacs looks for
2650@file{~/.config/emacs.d/init.el} or @file{~/.emacs.d/init.el} (these,
2651like @file{~/.emacs.el}, can be byte-compiled).
2638 2652
2639 However, if you run Emacs from a shell started by @code{su}, Emacs 2653 However, if you run Emacs from a shell started by @code{su}, Emacs
2640tries to find your own @file{.emacs}, not that of the user you are 2654tries to find your own initialization files, not that of the user you are
2641currently pretending to be. The idea is that you should get your own 2655currently pretending to be. The idea is that you should get your own
2642editor customizations even if you are running as the super user. 2656editor customizations even if you are running as the super user.
2643 2657
@@ -2688,10 +2702,10 @@ Type @kbd{C-q}, followed by the key you want to bind, to insert @var{char}.
2688@cindex early init file 2702@cindex early init file
2689 2703
2690 Most customizations for Emacs should be put in the normal init file, 2704 Most customizations for Emacs should be put in the normal init file,
2691@file{.emacs} or @file{~/.emacs.d/init.el}. However, it is sometimes desirable 2705@file{.config/emacs} or @file{~/.config/emacs.d/init.el}. However, it is sometimes desirable
2692to have customizations that take effect during Emacs startup earlier than the 2706to have customizations that take effect during Emacs startup earlier than the
2693normal init file is processed. Such customizations can be put in the early 2707normal init file is processed. Such customizations can be put in the early
2694init file, @file{~/.emacs.d/early-init.el}. This file is loaded before the 2708init file, @file{~/.config/emacs.d/early-init.el} or @file{~/.emacs.d/early-init.el}. This file is loaded before the
2695package system and GUI is initialized, so in it you can customize variables 2709package system and GUI is initialized, so in it you can customize variables
2696that affect frame appearance as well as the package initialization process, 2710that affect frame appearance as well as the package initialization process,
2697such as @code{package-enable-at-startup}, @code{package-load-list}, and 2711such as @code{package-enable-at-startup}, @code{package-load-list}, and
diff --git a/lisp/startup.el b/lisp/startup.el
index a88118e3b9a..f853ceccc51 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1,4 +1,4 @@
1;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*- 1;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1985-1986, 1992, 1994-2019 Free Software Foundation, 3;; Copyright (C) 1985-1986, 1992, 1994-2019 Free Software Foundation,
4;; Inc. 4;; Inc.
@@ -970,6 +970,15 @@ the `--debug-init' option to view a complete error backtrace."
970 (when debug-on-error-should-be-set 970 (when debug-on-error-should-be-set
971 (setq debug-on-error debug-on-error-from-init-file)))) 971 (setq debug-on-error debug-on-error-from-init-file))))
972 972
973(defun find-init-path (fn)
974 "Look in ~/.config/FOO or ~/.FOO for the dotfile or dot directory FOO.
975It is expected that the output will undergo ~ expansion. Implements the
976XDG convention for dotfiles."
977 (let* ((xdg-path (concat "~" init-file-user "/.config/" fn))
978 (oldstyle-path (concat "~" init-file-user "/." fn))
979 (found-path (if (file-exists-p xdg-path) xdg-path oldstyle-path)))
980 found-path))
981
973(defun command-line () 982(defun command-line ()
974 "A subroutine of `normal-top-level'. 983 "A subroutine of `normal-top-level'.
975Amongst another things, it parses the command-line arguments." 984Amongst another things, it parses the command-line arguments."
@@ -1171,7 +1180,7 @@ please check its value")
1171 ;; "early-init" without an extension, as it does for ".emacs". 1180 ;; "early-init" without an extension, as it does for ".emacs".
1172 "early-init.el" 1181 "early-init.el"
1173 (file-name-as-directory 1182 (file-name-as-directory
1174 (concat "~" init-file-user "/.emacs.d"))))) 1183 (find-init-path "emacs.d")))))
1175 (setq early-init-file user-init-file) 1184 (setq early-init-file user-init-file)
1176 1185
1177 ;; If any package directory exists, initialize the package system. 1186 ;; If any package directory exists, initialize the package system.
@@ -1312,7 +1321,7 @@ please check its value")
1312 ((eq system-type 'ms-dos) 1321 ((eq system-type 'ms-dos)
1313 (concat "~" init-file-user "/_emacs")) 1322 (concat "~" init-file-user "/_emacs"))
1314 ((not (eq system-type 'windows-nt)) 1323 ((not (eq system-type 'windows-nt))
1315 (concat "~" init-file-user "/.emacs")) 1324 (find-init-path "emacs"))
1316 ;; Else deal with the Windows situation. 1325 ;; Else deal with the Windows situation.
1317 ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$") 1326 ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
1318 ;; Prefer .emacs on Windows. 1327 ;; Prefer .emacs on Windows.
@@ -1330,7 +1339,7 @@ please check its value")
1330 (expand-file-name 1339 (expand-file-name
1331 "init" 1340 "init"
1332 (file-name-as-directory 1341 (file-name-as-directory
1333 (concat "~" init-file-user "/.emacs.d")))) 1342 (find-init-path "emacs.d"))))
1334 (not inhibit-default-init)) 1343 (not inhibit-default-init))
1335 1344
1336 (when (and deactivate-mark transient-mark-mode) 1345 (when (and deactivate-mark transient-mark-mode)