diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 7932031..299bae4 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -4710,6 +4710,13 @@ custom-group-state-update ;;; Reading and writing the custom file. +;;;###autoload +(defcustom custom-file-load-p t + "Load `custom-file' if it is not nil. +Set this variable to `nil' if you want to define `custom-file' but not load it. +This was possible. As per the old definition,someone could just define the variable +and not load the file.") + ;;;###autoload (defcustom custom-file nil "File used for storing customization information. @@ -4722,10 +4729,12 @@ custom-file something like the following in your init file: (setq custom-file \"~/.config/emacs-custom.el\") -(load custom-file) -Note that both lines are necessary: the first line tells Custom to -save all customizations in this file, but does not load it. +This will load `custom-file' after the `user-init-file' if +a) the file exists, +b) `custom-file-load-p' is `t', and +c) it was not loaded before explicitly with + (load-file custom-file). When you change this variable outside Custom, look in the previous custom file (usually your init file) for the diff --git a/lisp/startup.el b/lisp/startup.el index 9f0b23c..472e5f7 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1494,6 +1494,17 @@ command-line (when (featurep 'native-compile) (startup--update-eln-cache)) + ;; Load the `custom-file' if it was not loaded before (see documentation) + + ;; if the user defined the custom-file and didn't reset `custom-file-load-p' + (when (and custom-file custom-file-load-p) + ;; make sure that you get the expanded custom-file name + ;; because that's what appears in `load-history' + (let ((real-custom-file (expand-file-name custom-file))) + ;; if it was loaded, assoc will return non-nil + (unless (assoc real-custom-file load-history) + (load real-custom-file)))) + (when (and deactivate-mark transient-mark-mode) (with-current-buffer (window-buffer) (deactivate-mark)))