Avoid `user-init-file' being set to an eln file (bug#59334)

* lisp/startup.el (startup--load-user-init-file): If possible,
point `user-init-file' to the source file if the init file was
native-compiled.
This commit is contained in:
Juanma Barranquero 2022-11-18 13:57:00 +01:00
parent f7ee6609ae
commit c116d9f74c

View file

@ -1063,19 +1063,27 @@ init-file, or to a default value if loading is not possible."
;; If we loaded a compiled file, set `user-init-file' to
;; the source version if that exists.
(when (equal (file-name-extension user-init-file)
"elc")
(let* ((source (file-name-sans-extension user-init-file))
(alt (concat source ".el")))
(setq source (cond ((file-exists-p alt) alt)
((file-exists-p source) source)
(t nil)))
(when source
(when (file-newer-than-file-p source user-init-file)
(message "Warning: %s is newer than %s"
source user-init-file)
(sit-for 1))
(setq user-init-file source))))
(if (equal (file-name-extension user-init-file) "elc")
(let* ((source (file-name-sans-extension user-init-file))
(alt (concat source ".el")))
(setq source (cond ((file-exists-p alt) alt)
((file-exists-p source) source)
(t nil)))
(when source
(when (file-newer-than-file-p source user-init-file)
(message "Warning: %s is newer than %s"
source user-init-file)
(sit-for 1))
(setq user-init-file source)))
;; Else, perhaps the user init file was compiled
(when (equal (file-name-extension user-init-file) "eln")
(if-let (source (gethash (file-name-nondirectory user-init-file)
comp-eln-to-el-h))
;; source exists or the .eln file would not load
(setq user-init-file source)
(message "Warning: unknown source file for init file %S"
user-init-file)
(sit-for 1))))
(when (and load-defaults
(not inhibit-default-init))