Skip to content

Commit

Permalink
Fix early-init.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Oct 22, 2022
1 parent 1007018 commit ca353af
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
11 changes: 5 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,14 @@ let
src = doomSrc;

patches = [
(substituteAll {
src = ./patches/early-init.patch;
doom = src;
})
./patches/early-init.patch
./patches/move-doom-dir-paths-to-HOME.patch
];

buildPhase = ''
patchShebangs bin
# Remove the windows wrapper for the CLI so the build doesn't fail
rm bin/doom.cmd
patchShebangs bin
'';
installPhase = ''
mkdir -p $out
Expand Down Expand Up @@ -247,7 +244,9 @@ let
# startup performance
emacs-dir = runCommand "emacs-dir" { } ''
mkdir -p $out
cp ${doom-emacs}/early-init.el $out
cat > $out/early-init.el << EOF
(load "${doom-emacs}/early-init.el")
EOF
cat > $out/init.el << EOF
(load "default.el")
EOF
Expand Down
44 changes: 41 additions & 3 deletions patches/early-init.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/early-init.el b/early-init.el
index c6e6b4d68..16d99a785 100644
index c6e6b4d68..4d34ab0a9 100644
--- a/early-init.el
+++ b/early-init.el
@@ -60,20 +60,7 @@
@@ -60,20 +60,8 @@
(profile (or (cadr (member "--profile" command-line-args))
(getenv-internal "DOOMPROFILE"))))
(if (null profile)
Expand All @@ -20,7 +20,45 @@ index c6e6b4d68..16d99a785 100644
- ;; FIX: To prevent "invalid option" errors later.
- (push (cons "--init-directory" (lambda (_) (pop argv))) command-switch-alist)
- (setq user-emacs-directory (expand-file-name init-dir))))
+ (setq user-emacs-directory "@doom@")
+ (setq user-emacs-directory
+ (file-name-directory (file-truename load-file-name)))
;; FIX: Discard the switch to prevent "invalid option" errors later.
(push (cons "--profile" (lambda (_) (pop argv))) command-switch-alist)
;; Running 'doom sync' or 'doom profile sync' (re)generates a light
@@ -105,34 +93,8 @@
;; I avoid `load's NOERROR argument because other, legitimate errors
;; (like permission or IO errors) should not be suppressed or
;; interpreted as "this is not a Doom config".
- (condition-case _
- ;; Load the heart of Doom Emacs.
- (load (expand-file-name "lisp/doom" user-emacs-directory)
- nil (not init-file-debug) nil 'must-suffix)
- ;; Failing that, assume that we're loading a non-Doom config.
- (file-missing
- ;; HACK: `startup--load-user-init-file' resolves $EMACSDIR from a
- ;; lexically bound `startup-init-directory', which means changes
- ;; to `user-emacs-directory' won't be respected when loading
- ;; $EMACSDIR/init.el, so I force it to:
- (define-advice startup--load-user-init-file (:filter-args (args) reroute-to-profile)
- (list (lambda () (expand-file-name "init.el" user-emacs-directory))
- nil (nth 2 args)))
- ;; Set `user-init-file' for the `load' call further below, and do so
- ;; here while our `file-name-handler-alist' optimization is still
- ;; effective (benefits `expand-file-name'). BTW: Emacs resets
- ;; `user-init-file' and `early-init-file' after this file is loaded.
- (setq user-init-file (expand-file-name "early-init" user-emacs-directory))
- ;; COMPAT: I make no assumptions about the config we're going to
- ;; load, so undo this file's global side-effects.
- (setq load-prefer-newer t)
- ;; PERF: But make an exception for `gc-cons-threshold', which I
- ;; think all Emacs users and configs will benefit from. Still,
- ;; setting it to `most-positive-fixnum' is dangerous if downstream
- ;; does not reset it later to something reasonable, so I use 16mb
- ;; as a best fit guess. It's better than Emacs' 80kb default.
- (setq gc-cons-threshold (* 16 1024 1024))
- nil)))
+ (load (expand-file-name "lisp/doom" user-emacs-directory)
+ nil (not init-file-debug) nil 'must-suffix))
;; ...But if Doom loaded then continue as normal.
(doom-require (if noninteractive 'doom-cli 'doom-start))))

0 comments on commit ca353af

Please sign in to comment.