From aaf8e4613e9fc0770a62a6bc154140f9a57f5728 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 24 Jun 2025 17:33:39 +0100 Subject: [PATCH] Load site-start.el before early-init.el * lisp/startup.el (command-line): Load site-start.el before early-init.el. (site-run-file): * doc/lispref/os.texi (Startup Summary, Init File): * etc/NEWS: Document the change. (cherry picked from commit 192066d3b92a64a894def9dd9d5bd3040cc257ba) --- doc/lispref/os.texi | 16 ++++++++-------- etc/NEWS | 7 +++++++ lisp/startup.el | 31 +++++++++++++++++-------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 79001e761dc..013c5b72203 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}, @@ -141,11 +146,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 @@ -409,9 +409,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 3bb6b6f7496..83c8271c3da 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -51,6 +51,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 873488312ce..5c28084e9bc 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -321,7 +321,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 @@ -1368,6 +1369,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 () @@ -1461,19 +1477,6 @@ 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. (startup--load-user-init-file (lambda () -- 2.39.5