diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 8eeddf20b12..1591cbd7be0 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi @@ -93,6 +93,11 @@ if requested by environment variables such as @env{LANG}. @item It does some basic parsing of the command-line arguments. +@item +It loads the library @file{site-start}, if it exists. This is not +done if the options @samp{-Q} or @samp{--no-site-file} were specified. +@cindex @file{site-start.el} + @item It loads your early init file (@pxref{Early Init File,,, emacs, The GNU Emacs Manual}). This is not done if the options @samp{-q}, @@ -150,11 +155,6 @@ rather than build-time, context. @c @item @c It registers the colors available for tty frames. -@item -It loads the library @file{site-start}, if it exists. This is not -done if the options @samp{-Q} or @samp{--no-site-file} were specified. -@cindex @file{site-start.el} - @item It loads your init file (@pxref{Init File}). This is not done if the options @samp{-q}, @samp{-Q}, or @samp{--batch} were specified. If @@ -432,9 +432,9 @@ loading of this file with the option @samp{--no-site-file}. @defopt site-run-file This variable specifies the site-customization file to load before the -user's init file. Its normal value is @code{"site-start"}. The only -way you can change it with real effect is to do so before dumping -Emacs. +user's early init file and regular init file. Its normal value is +@code{"site-start"}. The only way you can change it with real effect is +to do so before dumping Emacs. @c So why even mention it here. I imagine it is almost never changed. @end defopt diff --git a/etc/NEWS b/etc/NEWS index f7aebdf538f..836b16620cc 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -61,6 +61,13 @@ OS selection instead of terminal-specific keybindings. You can keep the old behavior by putting '(xterm-mouse-mode -1)' in your init file. ++++ +** 'site-start.el' is now loaded before the user's early init file. +Previously the order was early-init.el, site-start.el and then the +user's regular init file, but now site-start.el comes first. This +allows site administrators to customize things that can normally only be +done from early-init.el, such as adding to 'package-directory-list'. + * Changes in Emacs 31.1 diff --git a/lisp/startup.el b/lisp/startup.el index 3d38f68098b..030139b3c53 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -361,7 +361,8 @@ This file is loaded at run-time before `user-init-file'. It contains inits that need to be in place for the entire site, but which, due to their higher incidence of change, don't make sense to put into Emacs's dump file. Thus, the run-time load order is: 1. file described in -this variable, if non-nil; 2. `user-init-file'; 3. `default.el'. +this variable, if non-nil; 2. `early-init-file', 3. `user-init-file'; +4. `default.el'. Don't use the `site-start.el' file for things some users may not like. Put them in `default.el' instead, so that users can more easily @@ -1426,6 +1427,21 @@ please check its value") (setq xdg-dir (concat "~" init-file-user "/.config/emacs/")) (startup--xdg-or-homedot xdg-dir init-file-user))) + ;; Run the site-start library if it exists. + ;; This used to come after the early init file, but was moved here to + ;; make it possible for sites to do early init things on behalf of + ;; their users, such as adding to `package-directory-list'. + ;; This certainly has to come before loading the regular init file. + ;; Note that `user-init-file' is nil at this point. Code that might + ;; be loaded from `site-run-file' and wants to test if -q was given + ;; should check `init-file-user' instead, since that is already set. + ;; See cus-edit.el for an example. + (when site-run-file + ;; Sites should not disable the startup screen. + ;; Only individuals may disable the startup screen. + (let ((inhibit-startup-screen inhibit-startup-screen)) + (load site-run-file t t))) + ;; Load the early init file, if found. (startup--load-user-init-file (lambda () @@ -1537,20 +1553,7 @@ please check its value") (let ((old-scalable-fonts-allowed scalable-fonts-allowed) (old-face-ignored-fonts face-ignored-fonts)) - ;; Run the site-start library if it exists. The point of this file is - ;; that it is run before .emacs. There is no point in doing this after - ;; .emacs; that is useless. - ;; Note that user-init-file is nil at this point. Code that might - ;; be loaded from site-run-file and wants to test if -q was given - ;; should check init-file-user instead, since that is already set. - ;; See cus-edit.el for an example. - (if site-run-file - ;; Sites should not disable the startup screen. - ;; Only individuals should disable the startup screen. - (let ((inhibit-startup-screen inhibit-startup-screen)) - (load site-run-file t t))) - - ;; Load that user's init file, or the default one, or none. + ;; Load the user's init file, or the default one, or none. (startup--load-user-init-file (lambda () (cond