2022-09-12 18:05:14 +02:00
|
|
|
;;; lisp/doom-start.el --- bootstraps interactive sessions -*- lexical-binding: t; -*-
|
2022-06-18 15:04:12 +02:00
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
|
2022-09-06 19:58:33 +02:00
|
|
|
;;
|
2022-09-12 18:05:14 +02:00
|
|
|
;;; Custom hooks
|
2022-09-06 19:58:33 +02:00
|
|
|
|
2022-09-23 19:32:34 +02:00
|
|
|
(defcustom doom-first-input-hook ()
|
|
|
|
"Transient hooks run before the first user input."
|
|
|
|
:type 'hook
|
|
|
|
:local 'permenant-local
|
|
|
|
:group 'doom)
|
|
|
|
|
|
|
|
(defcustom doom-first-file-hook ()
|
|
|
|
"Transient hooks run before the first interactively opened file."
|
|
|
|
:type 'hook
|
|
|
|
:local 'permenant-local
|
|
|
|
:group 'doom)
|
|
|
|
|
|
|
|
(defcustom doom-first-buffer-hook ()
|
|
|
|
"Transient hooks run before the first interactively opened buffer."
|
|
|
|
:type 'hook
|
|
|
|
:local 'permenant-local
|
|
|
|
:group 'doom)
|
2022-09-06 19:58:33 +02:00
|
|
|
|
|
|
|
|
2022-09-12 00:42:15 +02:00
|
|
|
;;
|
2022-09-12 18:05:14 +02:00
|
|
|
;;; Reasonable defaults for interactive sessions
|
2022-09-12 00:42:15 +02:00
|
|
|
|
2022-09-12 18:05:14 +02:00
|
|
|
;;; Runtime optimizations
|
2022-09-13 18:19:56 +02:00
|
|
|
;; PERF: A second, case-insensitive pass over `auto-mode-alist' is time wasted.
|
2022-09-12 00:42:15 +02:00
|
|
|
(setq auto-mode-case-fold nil)
|
|
|
|
|
2022-09-13 18:19:56 +02:00
|
|
|
;; PERF: Disable bidirectional text scanning for a modest performance boost.
|
|
|
|
;; I've set this to `nil' in the past, but the `bidi-display-reordering's docs
|
|
|
|
;; say that is an undefined state and suggest this to be just as good:
|
2022-09-12 00:42:15 +02:00
|
|
|
(setq-default bidi-display-reordering 'left-to-right
|
|
|
|
bidi-paragraph-direction 'left-to-right)
|
|
|
|
|
2022-09-13 18:19:56 +02:00
|
|
|
;; PERF: Disabling BPA makes redisplay faster, but might produce incorrect
|
|
|
|
;; reordering of bidirectional text with embedded parentheses (and other
|
|
|
|
;; bracket characters whose 'paired-bracket' Unicode property is non-nil).
|
2022-09-12 00:42:15 +02:00
|
|
|
(setq bidi-inhibit-bpa t) ; Emacs 27+ only
|
|
|
|
|
|
|
|
;; Reduce rendering/line scan work for Emacs by not rendering cursors or regions
|
|
|
|
;; in non-focused windows.
|
|
|
|
(setq-default cursor-in-non-selected-windows nil)
|
|
|
|
(setq highlight-nonselected-windows nil)
|
|
|
|
|
|
|
|
;; More performant rapid scrolling over unfontified regions. May cause brief
|
|
|
|
;; spells of inaccurate syntax highlighting right after scrolling, which should
|
|
|
|
;; quickly self-correct.
|
|
|
|
(setq fast-but-imprecise-scrolling t)
|
|
|
|
|
|
|
|
;; Don't ping things that look like domain names.
|
|
|
|
(setq ffap-machine-p-known 'reject)
|
|
|
|
|
|
|
|
;; Emacs "updates" its ui more often than it needs to, so slow it down slightly
|
|
|
|
(setq idle-update-delay 1.0) ; default is 0.5
|
|
|
|
|
|
|
|
;; Font compacting can be terribly expensive, especially for rendering icon
|
|
|
|
;; fonts on Windows. Whether disabling it has a notable affect on Linux and Mac
|
|
|
|
;; hasn't been determined, but do it anyway, just in case. This increases memory
|
|
|
|
;; usage, however!
|
|
|
|
(setq inhibit-compacting-font-caches t)
|
|
|
|
|
|
|
|
;; PGTK builds only: this timeout adds latency to frame operations, like
|
|
|
|
;; `make-frame-invisible', which are frequently called without a guard because
|
|
|
|
;; it's inexpensive in non-PGTK builds. Lowering the timeout from the default
|
|
|
|
;; 0.1 should make childframes and packages that manipulate them (like `lsp-ui',
|
|
|
|
;; `company-box', and `posframe') feel much snappier. See emacs-lsp/lsp-ui#613.
|
|
|
|
(eval-when! (boundp 'pgtk-wait-for-event-timeout)
|
|
|
|
(setq pgtk-wait-for-event-timeout 0.001))
|
|
|
|
|
|
|
|
;; Increase how much is read from processes in a single chunk (default is 4kb).
|
|
|
|
;; This is further increased elsewhere, where needed (like our LSP module).
|
|
|
|
(setq read-process-output-max (* 64 1024)) ; 64kb
|
|
|
|
|
|
|
|
;; Introduced in Emacs HEAD (b2f8c9f), this inhibits fontification while
|
|
|
|
;; receiving input, which should help a little with scrolling performance.
|
|
|
|
(setq redisplay-skip-fontification-on-input t)
|
|
|
|
|
|
|
|
;; Performance on Windows is considerably worse than elsewhere. We'll need
|
|
|
|
;; everything we can get.
|
|
|
|
(eval-when! (boundp 'w32-get-true-file-attributes)
|
|
|
|
(setq w32-get-true-file-attributes nil ; decrease file IO workload
|
|
|
|
w32-pipe-read-delay 0 ; faster IPC
|
2022-09-13 18:19:56 +02:00
|
|
|
w32-pipe-buffer-size (* 64 1024))) ; read more at a time (was 4K)
|
2022-09-12 00:42:15 +02:00
|
|
|
|
2022-09-12 18:05:14 +02:00
|
|
|
;; The GC introduces annoying pauses and stuttering into our Emacs experience,
|
|
|
|
;; so we use `gcmh' to stave off the GC while we're using Emacs, and provoke it
|
|
|
|
;; when it's idle. However, if the idle delay is too long, we run the risk of
|
|
|
|
;; runaway memory usage in busy sessions. If it's too low, then we may as well
|
|
|
|
;; not be using gcmh at all.
|
|
|
|
(setq gcmh-idle-delay 'auto ; default is 15s
|
|
|
|
gcmh-auto-idle-delay-factor 10
|
|
|
|
gcmh-high-cons-threshold (* 16 1024 1024)) ; 16mb
|
|
|
|
(add-hook 'doom-first-buffer-hook #'gcmh-mode)
|
|
|
|
|
|
|
|
|
2022-09-15 19:02:26 +02:00
|
|
|
;;; Disable UI elements early
|
|
|
|
;; PERF,UI: Doom strives to be keyboard-centric, so I consider these UI elements
|
|
|
|
;; clutter. Initializing them also costs a morsel of startup time. Whats more,
|
|
|
|
;; the menu bar exposes functionality that Doom doesn't endorse. Perhaps one
|
|
|
|
;; day Doom will support these, but today is not that day.
|
|
|
|
;;
|
|
|
|
;; HACK: I intentionally avoid calling `menu-bar-mode', `tool-bar-mode', and
|
|
|
|
;; `scroll-bar-mode' because they do extra work to manipulate frame variables
|
|
|
|
;; that isn't necessary this early in the startup process.
|
2022-09-16 18:27:04 +02:00
|
|
|
(push '(menu-bar-lines . 0) default-frame-alist)
|
|
|
|
(push '(tool-bar-lines . 0) default-frame-alist)
|
2022-09-15 19:02:26 +02:00
|
|
|
(push '(vertical-scroll-bars) default-frame-alist)
|
2022-09-16 18:27:04 +02:00
|
|
|
;; And set these to nil so users don't have to toggle the modes twice to
|
|
|
|
;; reactivate them.
|
|
|
|
(setq menu-bar-mode nil
|
|
|
|
tool-bar-mode nil
|
|
|
|
scroll-bar-mode nil)
|
2022-09-15 19:02:26 +02:00
|
|
|
;; FIX: On MacOS, disabling the menu bar makes MacOS treat Emacs as a
|
|
|
|
;; non-application window -- which means it doesn't automatically capture
|
|
|
|
;; focus when it is started, among other things, so enable the menu-bar for
|
|
|
|
;; GUI frames, but keep it disabled in terminal frames because there it
|
|
|
|
;; activates an ugly, in-frame menu bar.
|
2022-09-24 11:01:49 +02:00
|
|
|
(eval-when! IS-MAC
|
2022-09-15 19:02:26 +02:00
|
|
|
(add-hook! '(window-setup-hook after-make-frame-functions)
|
|
|
|
(defun doom-restore-menu-bar-in-gui-frames-h (&optional frame)
|
|
|
|
(when-let (frame (or frame (selected-frame)))
|
|
|
|
(when (display-graphic-p frame)
|
|
|
|
(set-frame-parameter frame 'menu-bar-lines 1))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Encodings
|
2022-09-12 00:42:15 +02:00
|
|
|
;; Contrary to what many Emacs users have in their configs, you don't need more
|
|
|
|
;; than this to make UTF-8 the default coding system:
|
|
|
|
(set-language-environment "UTF-8")
|
|
|
|
;; ...but `set-language-environment' also sets `default-input-method', which is
|
|
|
|
;; a step too opinionated.
|
|
|
|
(setq default-input-method nil)
|
|
|
|
;; ...And the clipboard on Windows could be in a wider encoding (UTF-16), so
|
|
|
|
;; leave Emacs to its own devices.
|
|
|
|
(eval-when! IS-WINDOWS
|
|
|
|
(setq selection-coding-system 'utf-8))
|
|
|
|
|
|
|
|
|
2022-09-14 23:11:04 +02:00
|
|
|
;;; Support for more file extensions
|
2022-09-12 18:05:14 +02:00
|
|
|
;; Add support for additional file extensions.
|
|
|
|
(dolist (entry '(("/\\.doom\\(?:rc\\|project\\|module\\|profile\\)\\'" . emacs-lisp-mode)
|
|
|
|
("/LICENSE\\'" . text-mode)
|
|
|
|
("\\.log\\'" . text-mode)
|
|
|
|
("rc\\'" . conf-mode)
|
|
|
|
("\\.\\(?:hex\\|nes\\)\\'" . hexl-mode)))
|
|
|
|
(push entry auto-mode-alist))
|
|
|
|
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;;; MODE-local-vars-hook
|
|
|
|
|
|
|
|
;; File+dir local variables are initialized after the major mode and its hooks
|
|
|
|
;; have run. If you want hook functions to be aware of these customizations, add
|
|
|
|
;; them to MODE-local-vars-hook instead.
|
|
|
|
(defvar doom-inhibit-local-var-hooks nil)
|
|
|
|
|
|
|
|
(defun doom-run-local-var-hooks-h ()
|
|
|
|
"Run MODE-local-vars-hook after local variables are initialized."
|
|
|
|
(unless (or doom-inhibit-local-var-hooks delay-mode-hooks)
|
|
|
|
(setq-local doom-inhibit-local-var-hooks t)
|
2022-09-17 12:12:11 +02:00
|
|
|
(doom-run-hooks (intern-soft (format "%s-local-vars-hook" major-mode)))))
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
;; If the user has disabled `enable-local-variables', then
|
|
|
|
;; `hack-local-variables-hook' is never triggered, so we trigger it at the end
|
|
|
|
;; of `after-change-major-mode-hook':
|
|
|
|
(defun doom-run-local-var-hooks-maybe-h ()
|
|
|
|
"Run `doom-run-local-var-hooks-h' if `enable-local-variables' is disabled."
|
|
|
|
(unless enable-local-variables
|
|
|
|
(doom-run-local-var-hooks-h)))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Incremental lazy-loading
|
|
|
|
|
|
|
|
(defvar doom-incremental-packages '(t)
|
|
|
|
"A list of packages to load incrementally after startup. Any large packages
|
|
|
|
here may cause noticeable pauses, so it's recommended you break them up into
|
|
|
|
sub-packages. For example, `org' is comprised of many packages, and can be
|
|
|
|
broken up into:
|
|
|
|
|
|
|
|
(doom-load-packages-incrementally
|
|
|
|
'(calendar find-func format-spec org-macs org-compat
|
|
|
|
org-faces org-entities org-list org-pcomplete org-src
|
|
|
|
org-footnote org-macro ob org org-clock org-agenda
|
|
|
|
org-capture))
|
|
|
|
|
|
|
|
This is already done by the lang/org module, however.
|
|
|
|
|
|
|
|
If you want to disable incremental loading altogether, either remove
|
|
|
|
`doom-load-packages-incrementally-h' from `emacs-startup-hook' or set
|
|
|
|
`doom-incremental-first-idle-timer' to nil. Incremental loading does not occur
|
|
|
|
in daemon sessions (they are loaded immediately at startup).")
|
|
|
|
|
2022-09-11 00:00:55 +02:00
|
|
|
(defvar doom-incremental-first-idle-timer (if (daemonp) 0 2.0)
|
2022-06-18 15:04:12 +02:00
|
|
|
"How long (in idle seconds) until incremental loading starts.
|
|
|
|
|
2022-09-11 00:00:55 +02:00
|
|
|
Set this to nil to disable incremental loading.
|
|
|
|
Set this to 0 to load all incrementally deferred packages immediately at
|
|
|
|
`emacs-startup-hook'.")
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
(defvar doom-incremental-idle-timer 0.75
|
|
|
|
"How long (in idle seconds) in between incrementally loading packages.")
|
|
|
|
|
|
|
|
(defun doom-load-packages-incrementally (packages &optional now)
|
|
|
|
"Registers PACKAGES to be loaded incrementally.
|
|
|
|
|
|
|
|
If NOW is non-nil, load PACKAGES incrementally, in `doom-incremental-idle-timer'
|
|
|
|
intervals."
|
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.
The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b7c)
are unaffected.
It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:
Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:
(run-with-idle-timer
2 nil (lambda ()
(run-with-idle-timer 1 nil (lambda () (message "hi")))))
I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.
By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.
Amend: b7f84bdd0105
2022-09-10 01:01:28 +02:00
|
|
|
(let ((gc-cons-threshold most-positive-fixnum))
|
|
|
|
(if (not now)
|
|
|
|
(cl-callf append doom-incremental-packages packages)
|
2022-09-06 19:22:43 +02:00
|
|
|
(while packages
|
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.
The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b7c)
are unaffected.
It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:
Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:
(run-with-idle-timer
2 nil (lambda ()
(run-with-idle-timer 1 nil (lambda () (message "hi")))))
I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.
By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.
Amend: b7f84bdd0105
2022-09-10 01:01:28 +02:00
|
|
|
(let ((req (pop packages))
|
|
|
|
idle-time)
|
|
|
|
(if (featurep req)
|
2022-09-11 20:12:22 +02:00
|
|
|
(doom-log "start:iloader: Already loaded %s (%d left)" req (length packages))
|
2022-09-06 19:22:43 +02:00
|
|
|
(condition-case-unless-debug e
|
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.
The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b7c)
are unaffected.
It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:
Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:
(run-with-idle-timer
2 nil (lambda ()
(run-with-idle-timer 1 nil (lambda () (message "hi")))))
I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.
By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.
Amend: b7f84bdd0105
2022-09-10 01:01:28 +02:00
|
|
|
(and
|
|
|
|
(or (null (setq idle-time (current-idle-time)))
|
|
|
|
(< (float-time idle-time) doom-incremental-first-idle-timer)
|
|
|
|
(not
|
|
|
|
(while-no-input
|
2022-09-11 20:12:22 +02:00
|
|
|
(doom-log "start:iloader: Loading %s (%d left)" req (length packages))
|
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.
The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b7c)
are unaffected.
It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:
Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:
(run-with-idle-timer
2 nil (lambda ()
(run-with-idle-timer 1 nil (lambda () (message "hi")))))
I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.
By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.
Amend: b7f84bdd0105
2022-09-10 01:01:28 +02:00
|
|
|
;; If `default-directory' doesn't exist or is
|
|
|
|
;; unreadable, Emacs throws file errors.
|
|
|
|
(let ((default-directory doom-emacs-dir)
|
|
|
|
(inhibit-message t)
|
|
|
|
(file-name-handler-alist
|
|
|
|
(list (rassq 'jka-compr-handler file-name-handler-alist))))
|
|
|
|
(require req nil t)
|
|
|
|
t))))
|
|
|
|
(push req packages))
|
2022-09-06 19:22:43 +02:00
|
|
|
(error
|
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.
The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b7c)
are unaffected.
It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:
Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:
(run-with-idle-timer
2 nil (lambda ()
(run-with-idle-timer 1 nil (lambda () (message "hi")))))
I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.
By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.
Amend: b7f84bdd0105
2022-09-10 01:01:28 +02:00
|
|
|
(message "Error: failed to incrementally load %S because: %s" req e)
|
|
|
|
(setq packages nil)))
|
|
|
|
(if (null packages)
|
2022-09-11 20:12:22 +02:00
|
|
|
(doom-log "start:iloader: Finished!")
|
fix: memory leak & freezes on native-comp+pgtk builds
b7f84bd introduced a nasty regression that caused an infinite loop and
runaway memory usage on some pgtk+native-comp builds of Emacs when it
attempted to perform deferred native compilation of your packages. This
would make Emacs unusable and, if left alone, could even crash your
system.
The only Emacs builds I'm certain are affected are derived from
flatwhatson/emacs (like emacs-pgtk-native-comp on Guix and Arch Linux in
particular). 28.1 stable and master (on emacs-mirror/emacs@e13509468b7c)
are unaffected.
It appears that some, earlier pgtk builds stack idle timers differently.
I'm not entirely sure how, because it doesn't manifest in more recent
builds of Emacs, and I'm already burnt out on debugging this, but here's
how Doom encountered it:
Doom has an incremental package loader; it loads packages, piecemeal,
after Emacs has been idle for 2s, then again every 0.75s until it
finishes or the user sends input (then it waits another 2s before
starting again). However, if at any time the iloader detected that
native-compilation is in progress, it waits 2s before trying
again (repeat, until native-comp is done). But here's the catch, given
the following:
(run-with-idle-timer
2 nil (lambda ()
(run-with-idle-timer 1 nil (lambda () (message "hi")))))
I had assumed "hi" would be emitted after 3 seconds (once idle), but
instead it is emitted after 2. Like this, Doom's iloader would elapse
one idle timer directly into another, ad infinitum, until Emacs was
forcibly killed.
By switching to run-at-time and employing my own rudimentary idle timer,
I avoid this issue. Also, the iloader no longer needs to be considerate
of native-comp, because the latter does its own rate-limiting controlled
by native-comp-async-jobs-number.
Amend: b7f84bdd0105
2022-09-10 01:01:28 +02:00
|
|
|
(run-at-time (if idle-time
|
|
|
|
doom-incremental-idle-timer
|
|
|
|
doom-incremental-first-idle-timer)
|
|
|
|
nil #'doom-load-packages-incrementally
|
|
|
|
packages t)
|
2022-09-06 19:22:43 +02:00
|
|
|
(setq packages nil))))))))
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
(defun doom-load-packages-incrementally-h ()
|
|
|
|
"Begin incrementally loading packages in `doom-incremental-packages'.
|
|
|
|
|
|
|
|
If this is a daemon session, load them all immediately instead."
|
2022-09-11 00:00:55 +02:00
|
|
|
(when (numberp doom-incremental-first-idle-timer)
|
|
|
|
(if (zerop doom-incremental-first-idle-timer)
|
|
|
|
(mapc #'require (cdr doom-incremental-packages))
|
2022-06-18 15:04:12 +02:00
|
|
|
(run-with-idle-timer doom-incremental-first-idle-timer
|
|
|
|
nil #'doom-load-packages-incrementally
|
|
|
|
(cdr doom-incremental-packages) t))))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
2022-09-12 18:05:14 +02:00
|
|
|
;;; Benchmark
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
(defun doom-display-benchmark-h (&optional return-p)
|
|
|
|
"Display a benchmark including number of packages and modules loaded.
|
|
|
|
|
|
|
|
If RETURN-P, return the message as a string instead of displaying it."
|
|
|
|
(funcall (if return-p #'format #'message)
|
|
|
|
"Doom loaded %d packages across %d modules in %.03fs"
|
|
|
|
(- (length load-path) (length (get 'load-path 'initial-value)))
|
|
|
|
(hash-table-count doom-modules)
|
2022-09-23 22:03:38 +02:00
|
|
|
doom-init-time))
|
2022-06-18 15:04:12 +02:00
|
|
|
|
|
|
|
|
2022-09-13 18:19:56 +02:00
|
|
|
;;
|
|
|
|
;;; Let 'er rip!
|
|
|
|
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
;;; Load core modules and set up their autoloads
|
|
|
|
(require 'doom-modules)
|
|
|
|
(autoload 'doom-initialize-packages "doom-packages")
|
|
|
|
;; TODO (autoload 'doom-profiles-initialize "doom-profiles")
|
|
|
|
;; TODO (autoload 'doom-packages-initialize "doom-packages")
|
2022-06-18 15:04:12 +02:00
|
|
|
|
2022-09-13 18:19:56 +02:00
|
|
|
;; UX: There's a chance the user will later use package.el or straight in this
|
|
|
|
;; interactive session. If they do, make sure they're properly initialized
|
|
|
|
;; when they do.
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
(with-eval-after-load 'package (require 'doom-packages))
|
|
|
|
(with-eval-after-load 'straight (doom-initialize-packages))
|
2022-09-13 14:06:56 +02:00
|
|
|
|
2022-09-14 19:01:57 +02:00
|
|
|
;; A last ditch opportunity to undo dodgy optimizations or do extra
|
|
|
|
;; configuration before the session is complicated by user config and packages.
|
|
|
|
(doom-run-hooks 'doom-before-init-hook)
|
2022-06-18 15:04:12 +02:00
|
|
|
|
2022-09-18 01:08:27 +02:00
|
|
|
;;; Load envvar file
|
|
|
|
;; 'doom env' generates an envvar file. This is a snapshot of your shell
|
|
|
|
;; environment, which Doom loads here. This is helpful in scenarios where Emacs
|
|
|
|
;; is launched from an environment detached from the user's shell environment.
|
|
|
|
(when (and (or initial-window-system
|
|
|
|
(daemonp))
|
|
|
|
doom-env-file)
|
|
|
|
(doom-load-envvars-file doom-env-file 'noerror))
|
|
|
|
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
;;; Last minute setup
|
|
|
|
(add-hook 'doom-after-init-hook #'doom-load-packages-incrementally-h)
|
|
|
|
(add-hook 'doom-after-init-hook #'doom-display-benchmark-h 110)
|
|
|
|
(doom-run-hook-on 'doom-first-buffer-hook '(find-file-hook doom-switch-buffer-hook))
|
|
|
|
(doom-run-hook-on 'doom-first-file-hook '(find-file-hook dired-initial-position-hook))
|
|
|
|
(doom-run-hook-on 'doom-first-input-hook '(pre-command-hook))
|
2022-09-20 01:32:26 +02:00
|
|
|
;; PERF: Activate these later, otherwise they'll fire for every buffer created
|
|
|
|
;; between now and the end of startup.
|
|
|
|
(add-hook! 'after-init-hook
|
|
|
|
(defun doom-init-local-var-hooks-h ()
|
|
|
|
;; These fire `MAJOR-MODE-local-vars-hook' hooks, which is a Doomism. See
|
|
|
|
;; the `MODE-local-vars-hook' section above.
|
|
|
|
(add-hook 'after-change-major-mode-hook #'doom-run-local-var-hooks-h 100)
|
|
|
|
(add-hook 'hack-local-variables-hook #'doom-run-local-var-hooks-h)))
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
|
|
|
|
;;; Load $DOOMDIR/init.el early
|
|
|
|
;; TODO: Catch errors
|
2022-09-24 10:45:50 +02:00
|
|
|
(load! (string-remove-suffix ".el" doom-module-init-file) doom-user-dir t)
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
|
|
|
|
;;; Load the rest of $DOOMDIR + modules if noninteractive
|
|
|
|
;; If the user is loading this file from a batch script, let's assume they want
|
|
|
|
;; to load their userland config as well.
|
|
|
|
(when noninteractive
|
|
|
|
(doom-require 'doom-profiles)
|
|
|
|
(let ((init-file (doom-profile-init-file)))
|
|
|
|
(unless (file-exists-p init-file)
|
|
|
|
(user-error "Profile init file hasn't been generated. Did you forgot to run 'doom sync'?"))
|
|
|
|
(let (kill-emacs-query-functions
|
|
|
|
kill-emacs-hook)
|
|
|
|
;; Loads modules, then $DOOMDIR/config.el
|
|
|
|
(doom-load init-file 'noerror)
|
|
|
|
(doom-initialize-packages))))
|
|
|
|
|
|
|
|
;;; Entry point
|
|
|
|
;; HACK: This advice hijacks Emacs' initfile loader to accomplish the following:
|
|
|
|
;;
|
|
|
|
;; 1. Load the profile init file directory (generated on `doom sync`)
|
|
|
|
;; 2. Ignore initfiles we don't care about (like $EMACSDIR/init.el, ~/.emacs,
|
|
|
|
;; and ~/_emacs) -- and spare us the IO of searching for them, and allows
|
|
|
|
;; savvy hackers to use $EMACSDIR as their $DOOMDIR, if they wanted.
|
|
|
|
;; 3. Cut down on unnecessary logic in Emacs' bootstrapper.
|
|
|
|
;; 4. Offer a more user-friendly error state/screen, especially for errors
|
|
|
|
;; emitted from Doom's core or the user's config.
|
refactor: startup--load-user-init-file@init-doom advice
- Since its arguments aren't used, make the advice n-arity, to future
proof the advice.
- Add commentary on load's side-effect on user-init-file.
- Add NOSUFFIX arg to load call, to spare Emacs the file IO of searching
for init.%d.elc{.{so{,.gz},elc{,.gz},el{,.gz},,gz}}.
2022-09-19 00:02:58 +02:00
|
|
|
(define-advice startup--load-user-init-file (:override (&rest _) init-doom 100)
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
(let ((debug-on-error-from-init-file nil)
|
|
|
|
(debug-on-error-should-be-set nil)
|
2022-09-16 03:08:29 +02:00
|
|
|
(debug-on-error-initial (if (eq init-file-debug t) 'startup init-file-debug))
|
|
|
|
;; The init file might contain byte-code with embedded NULs, which can
|
|
|
|
;; cause problems when read back, so disable nul byte detection. (Bug
|
|
|
|
;; #52554)
|
|
|
|
(inhibit-null-byte-detection t))
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
(let ((debug-on-error debug-on-error-initial))
|
|
|
|
(condition-case-unless-debug error
|
|
|
|
(when init-file-user
|
|
|
|
(let ((init-file-name
|
|
|
|
;; This dynamically generated init file stores a lot of
|
|
|
|
;; precomputed information, such as module and package
|
|
|
|
;; autoloads, and values for expensive variables like
|
|
|
|
;; `doom-modules', `doom-disabled-packages', `load-path',
|
|
|
|
;; `auto-mode-alist', and `Info-directory-list'. etc.
|
|
|
|
;; Compiling them in one place is a big reduction in startup
|
|
|
|
;; time, and by keeping a history of them, you get a snapshot
|
|
|
|
;; of your config in time.
|
fix: freezing+side-effects on `M-x` or `C-h {f,v}`
To understand this issue, you have to understand these two things:
1. Doom builds an init file which combines all its autoloads (for
packages and modules), and Doom's bootstrapper (which loads modules,
$DOOMDIR, etc). This init file is byte-compiled.
2. When Emacs byte-compiles elisp, docstrings are lazy-loaded (by
embedding them in the elc as commented text to be retrieved later).
This is generally done to save on memory.
Now the issue: when these lazy-loaded docstrings are retrieved, Emacs
may evaluate the whole file to find it, including Doom's bootstrap
process, reloading all its files, the user's config files, and running
all its startup hooks. Not only is this terribly expensive, reloading
these files may have disastrous effects.
One such effect is compounded by Marginalia, which invokes this
docstring fetch process (by calling the `documentation` function in
`marginalia--function-doc`) for *each* symbol in the `M-x` or `C-h
{v,f}` completion lists, which means Doom re-bootstraps multiple times
and rapidly, causing Emacs to totally lock up.
The solution is to simply gate the expensive part of the initfile so it
doesn't run more than once, at startup, and when `doom/reload` is
called. The rest of the file loads instantly.
Still, this is a bit flimsy. I'll think of a more elegant solution
later.
2022-09-20 01:09:37 +02:00
|
|
|
(file-name-concat
|
2022-09-23 22:03:38 +02:00
|
|
|
doom-profile-dir (format "init.%d.elc" emacs-major-version))))
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
;; If `user-init-file' is t, then `load' will store the name of
|
2022-09-20 01:27:37 +02:00
|
|
|
;; the next file it loads into `user-init-file'.
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
(setq user-init-file t)
|
|
|
|
(when init-file-name
|
refactor: startup--load-user-init-file@init-doom advice
- Since its arguments aren't used, make the advice n-arity, to future
proof the advice.
- Add commentary on load's side-effect on user-init-file.
- Add NOSUFFIX arg to load call, to spare Emacs the file IO of searching
for init.%d.elc{.{so{,.gz},elc{,.gz},el{,.gz},,gz}}.
2022-09-19 00:02:58 +02:00
|
|
|
(load init-file-name 'noerror 'nomessage 'nosuffix))
|
2022-09-20 01:27:37 +02:00
|
|
|
;; If it's still `t', then it failed to load the profile initfile.
|
|
|
|
;; This likely means the user has forgotten to run `doom sync'!
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
(when (eq user-init-file t)
|
refactor: startup--load-user-init-file@init-doom advice
- Since its arguments aren't used, make the advice n-arity, to future
proof the advice.
- Add commentary on load's side-effect on user-init-file.
- Add NOSUFFIX arg to load call, to spare Emacs the file IO of searching
for init.%d.elc{.{so{,.gz},elc{,.gz},el{,.gz},,gz}}.
2022-09-19 00:02:58 +02:00
|
|
|
(signal 'doom-nosync-error (list init-file-name)))
|
|
|
|
;; If we loaded a compiled file, set `user-init-file' to the
|
|
|
|
;; source version if that exists.
|
|
|
|
(setq user-init-file
|
2022-09-20 01:27:37 +02:00
|
|
|
(concat (string-remove-suffix ".elc" user-init-file)
|
refactor: startup--load-user-init-file@init-doom advice
- Since its arguments aren't used, make the advice n-arity, to future
proof the advice.
- Add commentary on load's side-effect on user-init-file.
- Add NOSUFFIX arg to load call, to spare Emacs the file IO of searching
for init.%d.elc{.{so{,.gz},elc{,.gz},el{,.gz},,gz}}.
2022-09-19 00:02:58 +02:00
|
|
|
".el"))))
|
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:
- Doom now fully and dynamically generates (and byte-compiles) your
profile and its init files, which includes your autoloads, loading
your init files and modules, and then some. This replaces
doom-initialize-modules, doom-initialize-core-modules, and
doom-module-loader, which have been removed. This has also improved
startup time by a bit, but if you use these functions in your CLIs,
for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
run whenever you change them, or when you up/downgrade Emacs across
major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
any of doom-{ui,keybinds,editor,projects}, before any autoloads are
loaded, and before your load-path has been populated with your
packages. It now runs in the context of early-init.el, giving users
freer range over what they can affect, but a more minimalistic
environment to do it in.
If you must have some logic run when all that is set up, add it to one
of the module hooks added in e08f68b or 283308a.
This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:
1. Adds a new `doom profiles sync` command. This will forcibly resync
your profiles, while `doom sync` will only do so if your profiles
have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
user-init-file, which includes loading all your init files, modules,
and custom-file. This replaces the job of doom-initialize-modules,
doom-initialize-core-modules, and doom-module-loader, which have been
removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
changes.
2022-09-15 18:53:06 +02:00
|
|
|
;; TODO: Add safe-mode profile.
|
|
|
|
;; (error
|
|
|
|
;; ;; HACK: This is not really this variable's intended purpose, but it
|
|
|
|
;; ;; doesn't mind what value its set to, only that its non-nil, so I'm
|
|
|
|
;; ;; exploiting its dynamic scope to pass the error to the profile.
|
|
|
|
;; (setq init-file-had-error error)
|
|
|
|
;; (load (file-name-concat doom-emacs-dir "profiles" "safe-mode" "init.el")
|
|
|
|
;; nil 'nomessage 'nosuffix))
|
|
|
|
(error
|
|
|
|
(display-warning
|
|
|
|
'initialization
|
|
|
|
(format-message "\
|
|
|
|
An error occurred while loading `%s':\n\n%s%s%s\n\n\
|
|
|
|
To ensure normal operation, you should investigate and remove the
|
|
|
|
cause of the error in your initialization file. Start Emacs with
|
|
|
|
the `--debug-init' option to view a complete error backtrace."
|
|
|
|
user-init-file
|
|
|
|
(get (car error) 'error-message)
|
|
|
|
(if (cdr error) ": " "")
|
|
|
|
(mapconcat (lambda (s) (prin1-to-string s t))
|
|
|
|
(cdr error) ", "))
|
|
|
|
:warning)
|
|
|
|
(setq init-file-had-error t)))
|
|
|
|
;; If we can tell that the init file altered debug-on-error, arrange to
|
|
|
|
;; preserve the value that it set up.
|
|
|
|
(or (eq debug-on-error debug-on-error-initial)
|
|
|
|
(setq debug-on-error-should-be-set t
|
|
|
|
debug-on-error-from-init-file debug-on-error)))
|
|
|
|
(when debug-on-error-should-be-set
|
|
|
|
(setq debug-on-error debug-on-error-from-init-file))))
|
2022-06-18 15:04:12 +02:00
|
|
|
|
2022-07-30 21:49:00 +02:00
|
|
|
(provide 'doom-start)
|
|
|
|
;;; doom-start.el ends here
|