diff options
Diffstat (limited to 'lisp/startup.el')
-rw-r--r-- | lisp/startup.el | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/lisp/startup.el b/lisp/startup.el index 564428580b1..4d584a0cb59 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1,4 +1,4 @@ -;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*- +;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*- ;; Copyright (C) 1985-1986, 1992, 1994-2019 Free Software Foundation, ;; Inc. @@ -906,16 +906,19 @@ init-file, or to a default value if loading is not possible." ;; the name of the file that it loads into ;; `user-init-file'. (setq user-init-file t) - (load (if (equal (file-name-extension init-file-name) - "el") - (file-name-sans-extension init-file-name) - init-file-name) - 'noerror 'nomessage) + (when init-file-name + (load (if (equal (file-name-extension init-file-name) + "el") + (file-name-sans-extension init-file-name) + init-file-name) + 'noerror 'nomessage)) (when (and (eq user-init-file t) alternate-filename-function) (let ((alt-file (funcall alternate-filename-function))) (and (equal (file-name-extension alt-file) "el") (setq alt-file (file-name-sans-extension alt-file))) + (unless init-file-name + (setq init-file-name alt-file)) (load alt-file 'noerror 'nomessage))) ;; If we did not find the user's init file, set @@ -971,18 +974,10 @@ the `--debug-init' option to view a complete error backtrace." (when debug-on-error-should-be-set (setq debug-on-error debug-on-error-from-init-file)))) -(defun find-init-path (fn) - "Look in ~/.config/FOO or ~/.FOO for the dotfile or dot directory FOO. -It is expected that the output will undergo ~ expansion. Implements the -XDG convention for dotfiles." - (let* ((xdg-path (concat "~" init-file-user "/.config/" fn)) - (oldstyle-path (concat "~" init-file-user "/." fn)) - (found-path (if (file-exists-p xdg-path) xdg-path oldstyle-path))) - found-path)) - (defun command-line () "A subroutine of `normal-top-level'. Amongst another things, it parses the command-line arguments." + (let (xdg-dir startup-init-directory) (setq before-init-time (current-time) after-init-time nil command-line-default-directory default-directory) @@ -1171,6 +1166,18 @@ please check its value") init-file-user)) :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 + (let* ((dir (concat (or (getenv "XDG_CONFIG_HOME") + (concat "~" init-file-user "/.config")) + "/emacs/"))) + (if (file-exists-p dir) dir))) + (setq startup-init-directory + (or xdg-dir (concat "~" init-file-user "/.emacs.d/"))) + ;; Load the early init file, if found. (startup--load-user-init-file (lambda () @@ -1180,8 +1187,7 @@ please check its value") ;; with the .el extension, if the file doesn't exist, not just ;; "early-init" without an extension, as it does for ".emacs". "early-init.el" - (file-name-as-directory - (find-init-path "emacs.d"))))) + startup-init-directory))) (setq early-init-file user-init-file) ;; If any package directory exists, initialize the package system. @@ -1319,10 +1325,11 @@ please check its value") (startup--load-user-init-file (lambda () (cond + (xdg-dir nil) ((eq system-type 'ms-dos) (concat "~" init-file-user "/_emacs")) ((not (eq system-type 'windows-nt)) - (find-init-path "emacs")) + (concat "~" init-file-user "/.emacs")) ;; Else deal with the Windows situation. ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$") ;; Prefer .emacs on Windows. @@ -1339,8 +1346,7 @@ please check its value") (lambda () (expand-file-name "init" - (file-name-as-directory - (find-init-path "emacs.d")))) + startup-init-directory)) (not inhibit-default-init)) (when (and deactivate-mark transient-mark-mode) @@ -1456,7 +1462,7 @@ Consider using a subdirectory instead, e.g.: %s" (if (and (boundp 'x-session-previous-id) (stringp x-session-previous-id)) (with-no-warnings - (emacs-session-restore x-session-previous-id)))) + (emacs-session-restore x-session-previous-id))))) (defun x-apply-session-resources () "Apply X resources which specify initial values for Emacs variables. |