diff options
| author | Eric S. Raymond | 2019-05-25 13:22:44 -0400 |
|---|---|---|
| committer | Eric S. Raymond | 2019-05-25 13:23:46 -0400 |
| commit | d68ed152ffe4369b3fe082cf39d631cc5360143b (patch) | |
| tree | f0123dfb8c9e93842b4d2185437fff0d35467092 | |
| parent | cd7a0bd00802b9331229dfe4a70ea9690d2d70fc (diff) | |
| download | emacs-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.3 | 8 | ||||
| -rw-r--r-- | doc/emacs/custom.texi | 46 | ||||
| -rw-r--r-- | lisp/startup.el | 17 |
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 @@ | |||
| 1 | 2019-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 | |||
| 1 | 2019-04-11 Eli Zaretskii <eliz@gnu.org> | 9 | 2019-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 | |||
| 380 | file. For example: | 380 | file. 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 |
| 2222 | an @dfn{initialization file}, or @dfn{init file} for short. This | 2223 | an @dfn{initialization file}, or @dfn{init file} for short. This |
| 2223 | file, if it exists, specifies how to initialize Emacs for you. Emacs | 2224 | file, if it exists, specifies how to initialize Emacs for you. Emacs |
| 2224 | looks for your init file using the filenames @file{~/.emacs}, | 2225 | looks 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}, |
| 2226 | use any one of these three names (@pxref{Find Init}). Here, @file{~/} | 2227 | @file{~/.emacs.el}, @file{~/.config/emacs.d/init.el} or |
| 2227 | stands for your home directory. | 2228 | @file{~/.emacs.d/init.el}; you can choose to use any one of these |
| 2229 | names (@pxref{Find Init}). Here, @file{~/} stands for your home | ||
| 2230 | directory. | ||
| 2231 | |||
| 2232 | While the @file{~/.emacs} and @file{~/.emacs.d/init.el} locations | ||
| 2233 | are backward-compatible to older Emacs versions, and the rest of this | ||
| 2234 | chapter will use them to name your initialization file, it is better practice | ||
| 2235 | to group all of your dotfiles under @file{.config} so that if you have | ||
| 2236 | to troubleshoot a problem that might be due to a bad init file, or | ||
| 2237 | archive a collection of them, it can be done by renaming or | ||
| 2238 | copying that directory. Note that the @file{.config} versions | ||
| 2239 | don'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 |
| 2230 | your init file, and @samp{-u} (or @samp{--user}) to specify a | 2242 | your 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 |
| 2634 | that's what @samp{~} means in a file name. @xref{General Variables, HOME}. | 2646 | @file{~/.config/emacs} or @file{~/.emacs}; that's what @samp{~} means |
| 2635 | If neither @file{~/.emacs} nor @file{~/.emacs.el} is found, Emacs looks for | 2647 | in 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 |
| 2637 | byte-compiled). | 2649 | @file{~/.emacs.el} is found, Emacs looks for |
| 2650 | @file{~/.config/emacs.d/init.el} or @file{~/.emacs.d/init.el} (these, | ||
| 2651 | like @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 |
| 2640 | tries to find your own @file{.emacs}, not that of the user you are | 2654 | tries to find your own initialization files, not that of the user you are |
| 2641 | currently pretending to be. The idea is that you should get your own | 2655 | currently pretending to be. The idea is that you should get your own |
| 2642 | editor customizations even if you are running as the super user. | 2656 | editor 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 |
| 2692 | to have customizations that take effect during Emacs startup earlier than the | 2706 | to have customizations that take effect during Emacs startup earlier than the |
| 2693 | normal init file is processed. Such customizations can be put in the early | 2707 | normal init file is processed. Such customizations can be put in the early |
| 2694 | init file, @file{~/.emacs.d/early-init.el}. This file is loaded before the | 2708 | init file, @file{~/.config/emacs.d/early-init.el} or @file{~/.emacs.d/early-init.el}. This file is loaded before the |
| 2695 | package system and GUI is initialized, so in it you can customize variables | 2709 | package system and GUI is initialized, so in it you can customize variables |
| 2696 | that affect frame appearance as well as the package initialization process, | 2710 | that affect frame appearance as well as the package initialization process, |
| 2697 | such as @code{package-enable-at-startup}, @code{package-load-list}, and | 2711 | such 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. | ||
| 975 | It is expected that the output will undergo ~ expansion. Implements the | ||
| 976 | XDG 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'. |
| 975 | Amongst another things, it parses the command-line arguments." | 984 | Amongst 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) |