Commit graph

229 commits

Author SHA1 Message Date
Henrik Lissner
5a5195b84d
fix: add :depth field to modules
This introduces a depth field for modules so that they may dictate their
load order explicitly, it also treats depths <= -100 or >= 100 as
special depths, which will be loaded early, before their respective
doom-{before,after}-module-{init,config}-hook. This permits psuedo
modules like :core and :user modules to be treated as normal modules
without too many special cases.

This also fixes a module load order issue on Emacs 29 (#6813), caused by
emacs-mirror/emacs@4311bd0bd7, which changed the return value order of
hash-table-{keys,values} causing modules to be loaded in reverse order;
resulting in the loss of evil keybinds, among other things.

Other notable changes:
- Changes the data structure for module data caches from a list to a
  vector. Uses less memory and permits faster lookups. Also adds two
  depth fields to the front of it.
- Changes the signature of doom-module-list and doom-package-list.
- Renames doom--read-packages -> doom-packages--read for consistency
  with naming convention.
- Add doom-module-depth function.
- Adds a temporary doom-core-dir/init.el file, which is responsible for
  loading doom-*.el.

Fix: #6813
Ref: emacs-mirror/emacs@4311bd0bd7
2022-09-24 18:46:21 +02:00
Henrik Lissner
772f9f26d9
fix: prevent error on tagless doom-version
This would throw an error when we eventually drop the -pre tag in
doom-version.
2022-09-24 11:52:38 +02:00
Henrik Lissner
19f9e1fdd7
fix: doom-module-locate-path: try load-suffixes 2022-09-24 11:52:34 +02:00
Henrik Lissner
fef7c27bbc
feat: add doom-module-locate-paths function
This is a common idiom within Doom's internals, to create a list
of (existing) module files in any desired order.
2022-09-23 18:03:31 +02:00
Henrik Lissner
028de9483f
fix: load compiled module files, if available
Not that they'll be compiled anytime soon, but just in case.
2022-09-20 17:32:00 +02:00
Henrik Lissner
b7b66e6202
fix: $DOOMDIR loading twice and too early
An unintended change snuck into 2c14eff. The :core and :user virtual
modules are no longer stripped from the module list before iterating
through (and loading) them. This meant that Doom would load these two
like regular modules (and first, since these two are always at the start
of the list).

This is harmless for :core, because it has no init.el or config.el, but
:user does! This means $DOOMDIR/{init,config}.el would be loaded
twice (once before all other modules and again afterwards), causing load
order issues (like #6818).

Fix: #6818
Amend: 2c14eff7f1
2022-09-20 13:03:47 +02:00
Henrik Lissner
c5de95f722
perf: defer init for frame's buffer-predicate
Ensures that it doesn't pull in the buffer library so early in the
startup process, or gets called prematurely.
2022-09-20 02:29:14 +02:00
Henrik Lissner
7a81b0252f
fix(lib): doom/help-search-{load-path,loaded-files}
And updates them to reflect upstream changes to the consult--grep API.

Ref: c994e3ed59
2022-09-20 02:29:08 +02:00
Henrik Lissner
024048dd5e
perf: disable autoload-compute-prefixes & optimize var cache
- Batch more variables in Doom's autoloads files.
- Remove all the register-definition-prefixes calls generated in
  autoloads files (for both modules' and packages' autoloads). These
  don't serve much purpose, and only incur added cost growing a large
  hash table.
2022-09-20 01:43:33 +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
46d99917ba
fix(cli): debug output despite no debug-mode
Let's not fall back on original `message` function, at the end of
`with-output-to!`s advice stack.
2022-09-19 17:33:25 +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
b65da762b8
fix(cli): 'Profiles not initialized' error
Due to $DOOMPROFILE being set to an empty string when persisting Doom
CLI sessions, which would affect any case where a CLI command restarts
the session (e.g. when the :config literate module tangles a config or
'doom --debug ...' restarts to set DEBUG=1).
2022-09-19 00:01:03 +02:00
Henrik Lissner
f9de598daa
tweak(lib): doom-info: split byte-compiled-config trait into 3
What used to be a `byte-compiled-config` trait, displayed in your `M-x
doom/info`, is now `compiled-user-config`, `compiled-core`, and
`compiled-modules`, for more helpful granularity for debugging possible
byte-code issues.
2022-09-18 14:01:52 +02:00
Henrik Lissner
231fc9cf53
fix(cli): link $XDG_*_HOME to fake $HOME for doom run
Due to a technical limitation of Emacs <=28, launching Emacs out of a
non-standard location is non-trivial, and `doom run` tries to promise
that it can do so on demand. Emacs 29 does introduce a --init-directory
switch that would make this easy, but it'll be some time before we can
rely on it.

So 'doom run' creates a fake $HOME in /tmp/doom.run/ and writes a
bootloader there to load your Doom config remotely. But there's a
problem: in this fake $HOME, none of the user's config, cache, data, or
binscript directories are available, so I symlink them there. This
should at least resolve the most trivial incompatibilities (like the
lack of all-the-icons fonts, which typically get installed to
$HOME/.local/share/fonts/ -- see #6807), but there may be yet more edge
cases. Still, this is a good enough compromise for now.

Fix: #6807
2022-09-18 13:55:47 +02:00
Henrik Lissner
e2ce4345d2
bump: :lang org
abo-abo/org-download@947ca22364 -> abo-abo/org-download@19e166f0a8
alf/ob-restclient.el@3ac834b02b -> alf/ob-restclient.el@1b021ce1c6
emacs-straight/org-mode@00adad9357 -> emacs-straight/org-mode@86c4635dba
emacsmirror/org-contrib@39e2abc562 -> emacsmirror/org-contrib@0740bd3fe6
hakimel/reveal.js@e219184f37 -> hakimel/reveal.js@c1c4145240
org-roam/org-roam@7f453f3fff -> org-roam/org-roam@d95d25615e

Close: #6692
Fix: #6691
2022-09-18 13:10:49 +02:00
Henrik Lissner
8fd7e8bed0
fix(lib): doom/reload to reflect recent changes
Fix: #6806
2022-09-18 13:10:49 +02:00
Henrik Lissner
195359cf99
fix: properly disable tooltip-mode
In 4a25375, it seemed that only setting the variables to nil early
enough would be sufficient, but this turned out not to be the case.
There's no avoiding calling the mode to disable it.

Ref: 58c0de6841
Amend: 4a253757cb
2022-09-18 10:36:00 +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
7fd6cd4398
refactor: remove redundant server-auth-dir setting
And move server-name setter to :config.
2022-09-18 00:54:10 +02:00
Henrik Lissner
f99cf0ccc8
feat(cli): introduce DOOMPROFILELOAD{FILE,PATH} envvars
- Adds $DOOMPROFILELOADFILE: Controls where to read and write the
  profile loader. Changing this may be helpful for users on nix/guix,
  who have deployed Doom to a read-only location. This sets
  `doom-profile-load-file`.
- Changed profile load file's default location (used to be
  $EMACSDIR/profiles/init.el, is now $EMACSDIR/profiles/load.el). The
  gitignore was updated to reflect this.
- Adds $DOOMPROFILELOADPATH: A colon-delimited list of profile config
  files and directories (semi-colon on Windows) which dictate what Doom
  reads in order to discover your profiles. Config files are required to
  have an *.el extension. This sets `doom-profile-load-path`.
- Changes the nomenclature around this loader script. I used to refer to
  it as the profile bootstrapper. I'll now refer to it as the profile
  load file, and I've renamed `doom-profiles-bootstrap-file` to
  `doom-profile-load-file` to reflect this.
- The variables `doom-profile-dirs` and `doom-profile-config-files` were
  merged into doom-profile-load-path.
- Both envvars have also been documented in `doom help` (and
  $DOOMPROFILE's has been updated).

Ref: #6794
2022-09-18 00:28:13 +02:00
Henrik Lissner
dc107e4a15
refactor: restore doom-profile-default
And throw errors if a profile has the same name as the default (_).
2022-09-17 21:41:43 +02:00
Henrik Lissner
21f2ad58b5
fix(cli): ensure doom envvars are set for post-script sessions
Particularly DOOMPROFILE, without which the --profile switch wasn't
actually doing anything, and profile sessions would (silently) use the
default user-emacs-directory and doom-user-dir.
2022-09-17 21:41:42 +02:00
Henrik Lissner
6dffa09c71
refactor(profiles): bootstrap script
- Swap out the funcall+alist lookup for a pcase (which is expanded to a
  cond, which is is faster and easier to read).
- Wrap bootstrap file to $EMACSDIR/profiles/init.el, but byte-compile it
  to $EMACSDIR/profiles/init.X.el where X is emacs-major-version.
- Make doom-profiles-save's second argument optional (defaults to
  doom-profiles-bootstrap-file).
- Make doom-profiles-save throw a error if byte-compilation fails for
  some reason.
- Rename the tempvars to include 'doom' in their name, so debuggers know
  where they originate.
2022-09-17 21:41:42 +02:00
Henrik Lissner
09d24cd68a
fix(cli): type error trying to split a cons cell
doom-profile was changed to a cons cell in 18cd2eb.

Amend: 18cd2eb483
2022-09-17 21:41:42 +02:00
Henrik Lissner
a726ba33b9
tweak: use doom-profile-*-dir for core dir/file vars
In this commit I start using doom-profile-*-dir vars, though it will
make no difference to the default Doom install (only to profiles, and in
the future, in v3, where we'll drop $EMACSDIR/.local entirely).
2022-09-17 21:41:42 +02:00
Henrik Lissner
25bc9c9765
fix: defconst->defvar for more doom-*-dir vars
So they can be changed before doom.el is loaded (e.g. by profiles).
2022-09-17 21:41:42 +02:00
Henrik Lissner
4a3654d666
refactor(cli): read $DEBUG in early-init.el instead
This opens up $DEBUG as an alternative to --debug-init, and allows more
of the startup process to react to it.
2022-09-17 21:41:42 +02:00
Henrik Lissner
7fec2cf5bb
tweak(profiles): regen profiles if generator version changed
The profile bootstrap file's first form is the doom-version it was
generated with. If this has changed, it should be considered outdated,
even if the user's profiles haven't changed.
2022-09-17 21:41:42 +02:00
Henrik Lissner
36a9637e79
fix(profiles): no bootstrap file for non-bootloaders
If Doom doesn't live in ~/.emacs.d or ~/.config/emacs, then it cannot
play the role of bootloader, so opt out of generating the profile
bootstrappper in this case.

That said, don't disable the profile system entirely; it can still be
useful for internal, noninteractive, and sandbox use.
2022-09-17 15:29:17 +02:00
Henrik Lissner
753b479ea6
feat(cli): add --reload switch to 'profiles sync'
So 'doom profiles sync' can be relied on to forcibly regenerate the
profile init by default.
2022-09-17 15:11:48 +02:00
Henrik Lissner
edf54a398b
tweak(profiles): suppress profile init compilation warnings
It's not useful information, but should still be emitted if debug mode
is on.
2022-09-17 15:11:47 +02:00
Henrik Lissner
750d75a45b
refactor(profiles): simplify profile init file
So that the resulting file expands to less code and doesn't apply too
magic to file paths (it may be unwanted).

And don't try to unintern a lexical binding.
2022-09-17 15:11:47 +02:00
Henrik Lissner
329d65d0d4
fix(profiles): unexpanded paths in implicit profiles
Fixes two issues with implicit profiles:

1. Where user-emacs-directory (and sometimes doom-user-dir) would be
   unexpanded in the profile init file (generated by 'doom profiles
   sync'), which would be ineffective at runtime.
2. Where an implicit profile with a .doomprofile that lacks a
   user-emacs-directory setting would not have any user-emacs-directory
   set for it at all. Instead, it should fall back to that profile's
   location.
2022-09-17 15:11:47 +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
00e8f6b72a
fix: don't require doom-local-dir end with a slash 2022-09-17 11:00:08 +02:00
Henrik Lissner
811c18ca68
fix(cli): remove redundant comp-effective-async-max-jobs advice
Amend: 51a9745f38
2022-09-16 19:20:45 +02:00
Henrik Lissner
fe602fe9cd
fix(lib): suppress 'Function X is already compiled'
Emitted from `byte-compile`.
2022-09-16 19:19:55 +02:00
Henrik Lissner
51a9745f38
perf: native-comp: use 1/4 of your cores instead of 1/2
The sudden spike in CPU and memory utilization alarms people, so I've
reduced how many cores native-comp will use. In non-interactive
sessions, it will use all of them, however (that is, when I later
introduce an AOT switch).

You can still override this by setting native-comp-async-jobs-number or
comp-num-cpus yourself.

I use advice instead of setting comp-num-cpus so that users to avoid
trampling on default behavior, or attempts by the user to change them.
2022-09-16 19:09:34 +02:00
Henrik Lissner
0694be43ee
fix(cli): reference to free variable id
Fix: #6791
2022-09-16 19:09:34 +02:00
Henrik Lissner
3ba56eb008
fix(lib): ignore doom-compile-functions failures
It really isn't important if this function succeeds or not, but it seems
its stability is highly variable, dependent on your specific build and
version of Emacs. Since there are a lot of 29 Doom users, best to be
more permissive and simply fall back to byte-compilation if native-comp
fails.
2022-09-16 19:09:28 +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
9121100bb4
fix(cli): remove redundant doom-env-file
Causing the envvar file to be generated to wrong place, and thus never
be updated/properly loaded at runtime.

This new setting is for later, where I'll integrate the envvar generate
into the profile generator proper.
2022-09-16 17:06:49 +02:00
Henrik Lissner
732d87ac3e
nit: minor comment revision and refactors 2022-09-16 17:01:57 +02:00
Henrik Lissner
c5e88d229f
fix(lib): doom-compile-function throwing native-compiler-error 2022-09-16 16:15:07 +02:00
Henrik Lissner
3f866983e5
refactor(lib): doom-load 2022-09-16 13:07:28 +02:00
Henrik Lissner
b804a2f34f
refactor(lib): convert cli/autoloads.el to lib 2022-09-16 13:07:28 +02:00
Henrik Lissner
7ea4b21953
fix(cli): remove vestigial doom-initialize-modules calls
Fix: #6784
2022-09-16 13:07:28 +02:00