Skip to content

Commit

Permalink
Fix compilation of init file during startup
Browse files Browse the repository at this point in the history
`startup--load-user-init-file' binds `user-init-file' to t, and then
calls `load', which (due to that special value) sets that variable to
the file it loads.

`auto-compile-on-load' calls `byte-compile-file', which in this case
causes other files to be loaded.  We have to suspend the special
`user-init-file' value, or the first of them thinks it is loaded the
init file and sets thus sets `user-init-file' to the file it loaded.

Closes #33.
  • Loading branch information
tarsius committed Mar 4, 2024
1 parent 3899157 commit 6c698d6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions auto-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,15 @@ Also see the related `auto-compile-on-save-mode'."
If `auto-compile-on-load-mode' isn't enabled, then do nothing.
It needs recompilation if it is newer than the byte-code file.
Without this advice the outdated source file would get loaded."
(when auto-compile-on-load-mode
(auto-compile-on-load file nosuffix)))
(cond ((not auto-compile-on-load-mode))
((eq user-init-file t)
;; We are loading the init file during startup. If we have to
;; compile it, then that would load additional files. Prevent
;; the first recursive `load' invocation from believing it is
;; loading the init file, by suspending the special value.
(let ((user-init-file nil))
(auto-compile-on-load file nosuffix)))
((auto-compile-on-load file nosuffix))))

(define-advice require
(:before (feature &optional filename _noerror) auto-compile)
Expand Down

0 comments on commit 6c698d6

Please sign in to comment.