Commit Graph

39 Commits

Author SHA1 Message Date
Henrik Lissner
82e0641bf7
refactor: remove redundant auto-mode-alist entries
Also removes the *.{hex,nes} entry because it's far too niche to be a
global default.
2024-04-05 12:06:18 -04:00
Henrik Lissner
4be265ead7
fix: doom-incremental-first-idle-timer: type error when nil (part 2)
Amend: 2bce9dbc1a
Ref: #7710
2024-03-11 03:59:37 -04:00
Henrik Lissner
c6063de439
nit: revise and reformat comments 2024-03-11 00:53:44 -04:00
Henrik Lissner
2bce9dbc1a
fix: doom-incremental-first-idle-timer: type error when nil
If the user uses the doom-load-packages-incrementally function directly,
and has set doom-incremental-first-idle-timer set to nil, it will throw
a type error.

Close: #7710
2024-03-11 00:53:43 -04:00
Henrik Lissner
659f7bfc71
refactor!: deprecate IS-* OS constants
BREAKING CHANGE: This deprecates the IS-(MAC|WINDOWS|LINUX|BSD) family
of global constants in favor of a native `featurep` check:

  IS-MAC      ->  (featurep :system 'macos)
  IS-WINDOWS  ->  (featurep :system 'windows)
  IS-LINUX    ->  (featurep :system 'linux)
  IS-BSD      ->  (featurep :system 'bsd)

The constants will stick around until the v3 release so folks can still
use it -- and there are still some modules that use it, but I'll phase
those uses out gradually.

Fix: #7479
2024-02-04 17:54:29 -05:00
Henrik Lissner
1cd2a287f5
nit: comment revision, spellcheck, & reformatting
Close: #7262
Co-authored-by: emergenz <emergenz@users.noreply.github.com>
2023-07-22 19:01:35 +02:00
Henrik Lissner
61b799d062
fix: s/permanant-local/permanent-local
Fix: #7123
Amend: 8d578cad76
2023-03-13 12:50:31 -04:00
Henrik Lissner
8d578cad76
fix: s/permenant-local/permanent-local
Fix: #7123
2023-03-11 19:53:26 -05:00
Henrik Lissner
f9201eb218
refactor: introduce doom-context
Introduces a system to announce what execution contexts are active, so I
can react appropriately, emit more helpful logs/warnings in the case of
issues, and throw more meaningful errors.

* bin/doom: load module CLIs in the 'modules' context.
* lisp/cli/doctor.el: load package files in 'packages' context.
* lisp/doom-cli.el:
  - (doom-before-init-hook, doom-after-init-hook): trigger hooks at the
    correct time. This may increase startup load time, as the benchmark
    now times more of the startup process.
  - (doom-cli-execute, doom-cli-context-execute,
    doom-cli-context-restore, doom-cli-context-parse,
    doom-cli--output-benchmark-h, doom-cli-call, doom-cli--restart,
    doom-cli-load, run!): remove redundant context prefix in debug logs,
    it's now redundant with doom-context, which doom-log now prefixes
    them with.
* lisp/doom-lib.el (doom-log): prefix doom-context to doom-log output,
  unless it starts with :.
* lisp/doom-packages.el (package!, doom-packages--read): throw error if
  not used in a packages.el file or in the context of our package
  manager.
* lisp/doom-profiles.el (doom-profile--generate-init-vars,
  doom-profile--generate-load-modules): use modules doom-context instead
  of doom-init-time to detect startup.
* lisp/doom-start.el (doom-load-packages-incrementally-h): move function
  closer to end of doom-after-init-hook.
* lisp/doom.el:
  - (doom-before-init-hook, doom--set-initial-values-h,
    doom--begin-init-h): rename doom--set-initial-values-h to
    doom--begin-init-h and ensure it runs as late in
    doom-before-init-hook as possible, as that is the point where Doom's
    "initialization" formally begins.
  - (doom-after-init-hook): don't trigger at the end of command-line-1
    in non-interactive sessions. This will be triggered manually in
    doom-cli.el's run!.
* lisp/lib/config.el (doom/reload, doom/reload-autoloads,
  doom/reload-env): use 'reload' context for reload commands.
* modules/lang/emacs-lisp/autoload.el (+emacs-lisp-eval): use 'eval'
  context.
* modules/lang/org/config.el: remove doom-reloading-p; check for
  'reload' doom context instead.
2022-09-24 22:09:05 +02:00
Henrik Lissner
1c4217aa27
refactor: minor refactors & commentary revision
* lisp/doom-cli.el:
  - reference backport source commit.
  - doom-cli--restart: a type check is all we need here. This is a
    programmer error, not a user error.
* lisp/doom-editor.el (recentf): mention recentf-show-abbreviated (added in
  emacs-mirror/emacs@32906819ad)
* lisp/doom-keybinds.el (doom-init-leader-keys-h): move to
  doom-after-init-hook, in case the user customizes leader variables in
  a previous hook (like emacs-startup-hook or after-init-hook).
* lisp/doom-start.el: use eval-when! to compile out the section on
  non-macOS systems (when Doom gets around to compiling its core files,
  later).
* modules/config/literate/autoload.el (+literate-config-file): use
  file-name-concat instead of string concat. This relaxes the
  requirement that doom-user-dir end in a /; a requirement I intend to
  fully phase out.
* modules/lang/emacs-lisp/autoload.el (+emacs-lisp-non-package): remove
  empty map! macro in flycheck-emacs-lisp-check-form. The macro already
  no-ops at compile-time/in noninteractive sessions since b480ed51a3.
* modules/ui/hl-todo/config.el (hl-todo-keyword-faces): revise
  commentary for default hl-todo keywords.

Ref: emacs-mirror/emacs@32906819ad
Ref: b480ed51a3
2022-09-24 20:31:34 +02:00
Henrik Lissner
6c76b98dbb
refactor: use doom-module-*-file variables; add two
- Adds doom-module-packages-file and doom-module-metadata-file.
- Uses them and the other doom-module-*-file variables where they were
  previously hardcoded.
- Add .el extension to doom-module-{init,config}-file; it is now the
  consumer's responsibility to strip/change/keep the extension as they
  see fit.
2022-09-24 20:31:34 +02:00
Henrik Lissner
a3a275624e
refactor: record doom-init-time in doom-after-init-hook 2022-09-24 18:46:21 +02:00
Henrik Lissner
e61441af52
refactor: use defcustom to define doom-first-*-hook
This will soon be done by convention for variables Doom expects users to
customize.
2022-09-24 18:46:21 +02:00
Henrik Lissner
16469f1f9d
perf: defer local-vars hooks until after-init-hook
Any buffers created before after-init-hook could trigger these hooks,
which may house expensive functions, but never anything that is
important at startup time.

However, it must not occur later than after-init-hook (which triggers
before file arguments are processed and file buffers are created).
2022-09-20 01:40:59 +02:00
Henrik Lissner
7a75b63959
fix: incorrect user-init-file set
Prior to this, it would incorrectly be set to
$EMACSDIR/.local/etc/@/init.el.el.
2022-09-20 01:40:59 +02:00
Henrik Lissner
2c14eff7f1
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:40:59 +02:00
Henrik Lissner
869852aed9
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
Henrik Lissner
9d52ba2747
fix: envvar file not loading
This is because display-graphic-p returns nil so early in the startup
process.

Fix: #6802
2022-09-18 01:08:27 +02:00
Henrik Lissner
fd61150f60
refactor: local-vars: don't intern unneeded symbols
If the hook doesn't exist, it hasn't been bound to, and doom-run-hooks
will no-op if passed a nil. Saves a tiny bit on memory usage.
2022-09-17 12:12:11 +02:00
Henrik Lissner
58c0de6841
fix: menu-bar not disabled in some instances
It seems unsetting menu-bar-mode is enough on *some* builds of Emacs,
but not all. Best we cover all the bases.

Amend: 4a253757cb
Fix: #6790
2022-09-16 18:27:04 +02:00
Henrik Lissner
354d71566a
fix: inhibit-null-byte-detection = t at startup 2022-09-16 03:08:29 +02:00
Henrik Lissner
41051f4761
fix: disable UI elements earlier
Moves this from doom-ui to doom-start, since there is more savings to be
had if this is done early.

Also moves the menu-bar fix for macos out of the :os macos module into
doom-start, because it is a fix (and for a Doom optimization) and not a
feature, so it shouldn't be behind a module.
2022-09-16 01:14:23 +02:00
Henrik Lissner
b914830403
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-16 01:14:23 +02:00
Henrik Lissner
4a253757cb
refactor: how UI elements are disabled at startup
The default-frame-alist properties are only necessary for the scrollbar.
The variables are enough for the rest. Also, no need to set
x-gtk-use-symtem-tooltips if we're turning off tooltips anyway.

Also moves the UI config that snuck its way into doom-start back to
doom-ui.
2022-09-16 01:14:23 +02:00
Henrik Lissner
0d7c3eaf24
feat: add doom-{before,after}-init-hook
doom-before-init-hook runs before $DOOMDIR/init.el is loaded.

doom-after-init-hook runs at the *very* end of the Emacs startup
process (after window-setup-hook).
2022-09-16 01:14:23 +02:00
Henrik Lissner
57a91235bd
perf: add additional startup optimizations
Also switches `expand-file-name` calls with the much faster
`file-name-concat` where possible.
2022-09-16 01:14:22 +02:00
Henrik Lissner
42d88421ba
refactor: move startup optimizations to doom.el
I move our hackiest and least offensive startup optimizations to core,
so they're easy for me to keep track of (they'll likely change often,
between major Emacs releases), to keep them from affecting non-Doom
profiles, and make it easy for readers to use as a reference.
2022-09-16 01:14:22 +02:00
Henrik Lissner
6ddaed5cdd
nit: comment revision and formatting
For clarity, to enforce conventions, and explain the unexplained.
2022-09-16 01:14:22 +02:00
Henrik Lissner
07d22adb4a
nit: revise comments, reformat config sections 2022-09-16 01:14:21 +02:00
Henrik Lissner
6a83079d2e
refactor: move core optimizations to doom-start
These only benefit interactive sessions, and doom-start's responsibility
is to configure interactive sessions; it doesn't make sense to keep
these in core.
2022-09-16 01:14:20 +02:00
Henrik Lissner
6cac7b05b6
refactor(lib): tidy doom-log output
This commit reduces the debug log noise, makes it easier to
read/parse/search, and soft-introduces a convention for doom-log
messages, where they are prefixed with a unique identifier loosely named
after it's running context or calling function.

I haven't enforced it everywhere doom-log is used yet, but this is a
start.
2022-09-12 16:01:43 +02:00
Henrik Lissner
0c43c769ef
refactor!: replace doom-incremental-load-immediately var
BREAKING CHANGE: This removes the doom-incremental-load-immediately
variable. Instead, set doom-incremental-first-idle-timer to 0 to force
all iloaded packages be eagerly loaded at startup. This is already the
default behavior for daemon sessions.
2022-09-12 15:59:29 +02:00
Henrik Lissner
46e23f37ba
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@e13509468b)
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: b7f84bdd01
2022-09-10 01:38:58 +02:00
Henrik Lissner
7e65329289
refactor: move gcmh config to doom-start
Configuration for interactive sessions ought to live in doom-start.

Ref: 3ce4b38c3d92
2022-09-06 22:55:47 +02:00
Henrik Lissner
1a639b7341
feat: add auto-mode-alist entries for future doom dotfiles 2022-09-06 22:55:47 +02:00
Henrik Lissner
6cf0e04de0
refactor: move doom-first-*-hook to doom-start
doom-start is responsible for configuring an interactive session, so
variables associated with interactive sessions ought to live there.
2022-09-06 22:55:47 +02:00
Henrik Lissner
b7f84bdd01
perf: defer incremental loading for nativecomp users
It'd be detrimental to runtime performance to incrementally load more
packages as Emacs is natively compiling others, so hold off on it a bit
longer.
2022-09-06 22:55:47 +02:00
Henrik Lissner
9b8ed397e8
feat!(cli): load project .doomrc instead of ci.el
BREAKING CHANGE: Before, 'doom ci' would load
$GIT_WORKING_TREE/.github/ci.el, to give users/projects an opportunity
to provide project-local configuration for bin/doom (mainly for CI/CD).
Now, this ci.el file is no longer loaded and instead, *all* bin/doom
sessions will walk up the file tree and load the first .doomrc it finds.

This gives bin/doom users a more general place configure all of its
commands, and not just 'doom ci' commands.

Extras:
- Adds .doomrc to auto-mode-alist (so that it starts in
  emacs-lisp-mode).
2022-08-07 19:43:28 +02:00
Henrik Lissner
b9933e6637
refactor!: restructure Doom core
BREAKING CHANGE: This restructures the project in preparation for Doom
to be split into two repos. Users that have reconfigured Doom's CLI
stand a good chance of seeing breakage, especially if they've referred
to any core-* feature, e.g.

  (after! core-cli-ci ...)

To fix it, simply s/core-/doom-/, i.e.

  (after! doom-cli-ci ...)

What this commit specifically changes is:
- Renames all core features from core-* to doom-*
- Moves core/core-* -> lisp/doom-*
- Moves core/autoloads/* -> lisp/lib/*
- Moves core/templates -> templates/

Ref: #4273
2022-07-30 22:41:13 +02:00