Commit graph

52 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
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
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
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
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
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
811c18ca68
fix(cli): remove redundant comp-effective-async-max-jobs advice
Amend: 51a9745f38
2022-09-16 19:20:45 +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
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
Henrik Lissner
00ff149ebe
fix(cli): print-group-if! -> print-group! + :if
Remove some vestigial references to the former, which was replaced with
the latter in b7bd27d.

Amend: b7bd27d22b
2022-09-16 02:42:48 +02:00
Henrik Lissner
7b1ac7cdc1
fix(cli): doom-autoloads-reload -> doom-profile-generate
Remove vestigial references to the former, which was replaced with the
latter in b914830.

Amend: b914830403
2022-09-16 02:42:30 +02:00
Henrik Lissner
cc0e6a61c3
fix(cli): add lisp/cli/profiles.el
I forgot to add the definitions for the 'doom profile{s,}' commands in
b914830, which causes "unrecognized command 'profiles sync'" errors on
'doom {sync,upgrade}'.

My unparalleled brilliance is 4 parallel universes ahead of me, clearly.

Amend: b914830403
2022-09-16 02:26:00 +02:00
Henrik Lissner
c7289da99b
fix(cli): suppress redundant logs from straight-prune-build-cache 2022-09-16 01:14:24 +02:00
Henrik Lissner
cba240f88a
refactor(cli): move native-comp call into guard
Each of these functions have a native-comp guard, which may be overkill,
but for the time being they should be grouped together, to indicate
their relationship.
2022-09-16 01:14:24 +02:00
Henrik Lissner
1be11539e8
refactor(cli): explain! to use print!'s fill function 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
3a0f1aa3ef
refactor: register :core & :user as virtual modules
...that are always enabled. This way, the module API treats them as any
other module.

This also changes doom-module-load-path. If supplied directories,
doom-user-dir will not be the CAR of its return value. If no dirs are
supplied, then doom-core-dir and doom-user-dir are included (and will
always be the first two items in the returned list).
2022-09-16 01:14:22 +02:00
Henrik Lissner
c5188c4388
perf: cache module flags in symbol plists
For small amounts of data, symbol plists are the most efficient (space
and time wise) as data access gets in Emacs. Hash tables, though O(1),
impose a minimum threshold of overhead before it becomes the efficient
option, but this benefit won't be obvious for datasets of at least 60 or
less.

Since modulep! is used *a lot*, and used to determine a module's
state (and state of its flags), there is a benefit to caching it.
Still, this is only a read-only cache, and does not replace the
`doom-modules` hash-table, which will always be the preferred interface
for the rest of the module API.
2022-09-16 01:14:22 +02:00
Henrik Lissner
775ee2f04a
refactor: rethink doom-module-*-path functions
- Rename doom-module-path -> doom-module-expand-path, to better reflect
  its purpose.
- Optimize doom-module-locate-path to try caches and
  locate-file-internal, before looping through doom-modules-dirs.
- Rely on file-name-concat to join paths, rather than string
  concatenation. file-name-concat is more robust for the purpose and
  has lower overhead than expand-file-name.
2022-09-16 01:14:21 +02:00
Henrik Lissner
a5bb50e957
docs: improve emacs version checks and their explanations
- Add a 27.x check, recommending that users upgrade to 28.1.
- Removed the check for <27. Loading doom.el with sub-27 will already
  fail with a detailed error about supported versions.
- Now detects development (.50) and pre-release (.9x) builds of Emacs,
  and warns the user of their dangers.
- Revises the warning for 29+ or .50|.9x users.
2022-09-16 01:14:21 +02:00
Henrik Lissner
07d22adb4a
nit: revise comments, reformat config sections 2022-09-16 01:14:21 +02:00
Henrik Lissner
b7bd27d22b
refactor(cli,lib): print levels & output redirection
This refactors how Doom captures and redirects its output (to stdout and
stderr) into a more general with-output-to! macro, and:

- Simplifies the "print level" system. The various doom-print-*-level
  variables have been removed.
- Adds a new print level: notice, which will be the default level for
  all standard output (from print!, doom-print, prin[ct1], etc).
- Adds a with-output-to! macro for capturing and redirecting
  output to multiple streams (without suppressing it from stdout). It
  can also be nested.
- Changes the following about doom-print:
  - Default :format changed to nil (was t)
  - Default :level changed to t (was `doom-print-level`)
  - No longer no-ops if OUTPUT is only whitespace
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
bcf7a8a554
refactor!(cli): rename cli definers for consistency
BREAKING CHANGE: If anyone is using Doom's CLI framework and are
defining their own CLIs with any of the following macros, they'll need
to be updated to their new names:

- defautoload! -> defcli-autoload!
- defgroup! -> defcli-group!
- defstub! -> defcli-stub!
- defalias! -> defcli-alias!
- defobsolete! -> defcli-obsolete!

These were renamed to make their relationship with CLIs more obvious;
they were too ambiguous otherwise.
2022-09-12 11:45:59 +02:00
Henrik Lissner
7a2fa1e313
fix(cli): doctor warnings about irrelevant bytecode
This would check for stale bytecode across all profiles or even .local*
directories created by shell.nix, which is unnecessary.
2022-09-10 20:03:24 +02:00
Henrik Lissner
45a66cda60
fix: ensure module state is in scope for modulep!
Otherwise, doom-module-from-path (and modulep!) would fail to detect the
module they're in, or at least, modulep! would incorrectly return nil,
even for enabled modules.

This issue is what would've caused the package list or the doctor to
include/consider packages in disabled modules or behind disabled flags.
2022-09-10 19:11:03 +02:00
Henrik Lissner
151300ecce
feat(cli): deny XDG, Wayland, Sway, + socket envvars
Additional envvars that would not be helpful to persist.

Ref: https://discourse.doomemacs.org/t/3088
2022-09-10 18:36:24 +02:00
Henrik Lissner
96ae3f1b04
fix(cli): nativecomp error writing to read-only fs
Occurs when a site-file fails to be natively compiled, and Doom attempts
to write an error file in the same directory. On some systems, the
site-lisp directory is in a read-only tree/mount (like nix and guix).
This should suppress those attempts.
2022-09-10 12:08:16 +02:00
Henrik Lissner
3fe81f4291
fix(cli): wrong-number-of-args error when auto-resolving prompts
E.g. 'doom sync -!' will auto-resolve repo conflicts, but this error was
preventing that.
2022-09-10 01:36:58 +02:00
Henrik Lissner
a0fe199237
fix(cli): void-variable doom-dir on 'doom doctor'
A regression caused by an overaggressive search and replace (for
e986d6b).

Amend: e986d6bef9
2022-09-06 23:31:01 +02:00
Henrik Lissner
cee89a5d3f
refactor!(cli): remove 'doom {refresh,re}'
BREAKING CHANGE: This finally removes 'doom refresh'. It was first
deprecated in 8a77633 and disabled in 8c37928, and has long since been
replaced with 'doom sync'.

Ref: 8c37928de2
Ref: 8a7763337d
2022-09-06 23:08:55 +02:00
Henrik Lissner
e986d6bef9
refactor(lib): deprecate doom-dir
This function never really added much value over doom-path or
file-name-concat, so I'm phasing it out.
2022-09-06 22:55:48 +02:00
Henrik Lissner
1dac4ac37b
refactor: move file-name-handler-alist hack to early-init
In the future, early-init.el (among other parts of Doom) will be
byte-compiled, plus I'd rather keep these optimizations in one place.

Ref: 1d8c61698b
2022-09-06 22:55:46 +02:00
Henrik Lissner
a5c80fcb4b
refactor: deprecate doom-private-dir for doom-user-dir
- Deprecates the doom-private-dir variable in favor of doom-user-dir.
- Renames the pseudo category for the user's module: :private -> :user.
- Renames the doom-private-error error type to doom-user-error.

Emacs uses the term "user" to refer to the "things" in user space (e.g.
user-init-file, user-emacs-directory, user-mail-address, xdg-user-dirs,
package-user-dir, etc), and I'd like to be consistent with that. It also
has the nice side-effect of being slightly shorter. I also hope
'doom-user-error' will be less obtuse to beginners than
'doom-private-error'.
2022-08-14 20:43:35 +02:00
Henrik Lissner
0407621aff
refactor: deprecate EMACS2[89]+, NATIVECOMP, MODULES
To reduce redundancy, remove the maintenance hassle that version
constants would impose later on, and rely on built-in
facilities (featurep) more over global variables or doomisms, these
global constants have been deprecated in favor of Emacs "features":

- EMACS28+   -- replace with (> emacs-major-version 27)
- EMACS29+   -- replace with (> emacs-major-version 28)
- NATIVECOMP -- replace with (featurep 'native-compile)
- MODULES    -- replace with (featurep 'dynamic-modules)

(These constants will be formally removed when v3 is released. The IS-*
constants are likely next, but I haven't decided on their substitutes
yet)

I also decided to follow native-compile's example and provide features
for Emacs' system features (since system-configuration-features' docs
outs itself as a poor method to detect features):

- dynamic-modules
- jansson
- native-compile -- this one already exists, but will instead be removed
  if it's non-functional; i.e. (native-comp-available-p) returns nil.

These are now detectable using featurep, which is fast and built-in.
2022-08-14 20:43:35 +02:00
Henrik Lissner
3239ab8b2e
nit(mu4e): neutralize comments
Some of our comments/docs can come off as disparaging or snide. They're
glimpses of unfiltered frustration or snarky rubber ducking gone too
far, something I can totally sympathize with, as a scatterbrained
tinkerer, unwittingly made responsible for a lot of work that isn't mine
because of Doom's position as a middleman. But now that Doom has a
veritable userbase, I'd like to hold it to a higher standard.

Light-hearted banter and aired grievances in our source code,
documentation, or community are fine if focused on the problem or the
personal/shared experiences of the community (things that offer value or
amusement to others), but it is never acceptable to attack people or
their efforts. Especially not the very people on whose shoulders Doom
stands.

I sincerely apologize if these have offended you.

Amend: b07614037f
2022-08-14 20:36:42 +02:00
Henrik Lissner
12bf6baa21
fix: void-function doom-reset-file-handler-alist-h
A regression introduced in 1d8c61698b. Doom disables its
file-name-handler-alist optimization if in a daemon session or if debug
mode is active.

Fix: #6657
Amend: 1d8c61698b
2022-08-10 17:29:01 +02:00
Henrik Lissner
8191607093
refactor(cli): use more reliable means to assemble paths
Use filesystem to build or check paths, rather than regexps and string
concatenation.
2022-08-10 14:02:47 +02:00
Henrik Lissner
25ac752de2
fix(cli): file-missing error on comp-el-to-eln-filename
If you've moved $EMACSDIR, comp-el-to-eln-filename will throw errors
about missing directories/files, rendering 'doom sync' ineffective and
forcing the user to delete $EMACSDIR and reinstall Doom.
2022-08-10 13:18:34 +02:00
Henrik Lissner
2ff8228133
fix(docs): handle missing autoloads file in core doctor
Instead of a long winded backtrace about a missing autoloads file, let
the user know a 'doom sync' is needed.
2022-08-10 13:18:08 +02:00
Henrik Lissner
1d8c61698b
fix: "symbol's value as variable is void: \213" error (part 2)
See 6f1c0f7cc7 for part 1.

Turns out startup.elc likely exists on most Emacs installations (and,
since it's so integral to Emacs, it likely gets special treatment), so
it was a poor heuristic for this fix. Instead, a more variable target
would be calc-loaddefs.el.

On some systems, only calc-loaddefs.el.gz exists (in which case, we
should turn off the optimization). On others, calc-loaddefs.el
exists (so I'll assume it's safe to leave them on). I won't check for
calc-loaddefs.elc because it doesn't matter; calc.el explicitly
calls (load "calc-loaddefs.el") so it is never loaded.

Of course, you can sidestep the entire issue by building Emacs with
--without-compress-install, but it's not practical for users to
know/want to do that.

Amend: 6f1c0f7cc7
2022-08-08 22:19:18 +02:00
Henrik Lissner
6f1c0f7cc7
fix: "symbol's value as variable is void: \213" error
Some installs of Emacs do not come with byte-compiled versions of its
bundled elisp files, so when loading them, Emacs falls back to loading
its *.el.gz files. This would be fine if it were not for a  startup
optimization Doom employs, where it sets file-name-handler-alist to
nil (and by doing so, robs Emacs of the ability to read compressed
elisp). This causes "symbol's value as variable is void: \213" errors at
startup.

With this commit, Doom now disables this optimization early if it
suspects this applies to your install. But time will tell if it's early
enough.

Ref: https://mail.gnu.org/archive/html/emacs-devel/2022-08/msg00234.html
2022-08-08 18:52:32 +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
50f0cebe92
feat(cli): generalize 'doom make codeowners'
- Adds -o/--file option,
- If -o/--file is passed a dash, print codeowners to stdout,
- Adds --dryrun option,
- Will accept literal string entries in doom-make-codeowners as
  standalone lines (useful for comments).
2022-08-07 19:43:28 +02:00
Henrik Lissner
057e6c531c
refactor: replace doom-enlist with ensure-list
doom-enlist is now a deprecated alias for ensure-list, which is built
into Emacs 28.1+ and is its drop-in replacement. We've already
backported it for 27.x users in doom-lib (in 4bf4978).

Ref: 4bf49785fd
2022-08-07 19:43:13 +02:00
Henrik Lissner
615848e3a7
fix(cli): more future resistant 'doom upgrade'
In the future, should doom-core-dir or {doom-core-dir}/packages.el
change, 'doom upgrade' won't leave the repo in a broken state.
Unfortunately, this cannot retroactively prevent the issue; users will
experience this as soon as they update to b9933e6 or beyond, so users
will have to upgrade manually to overcome it:

  cd ~/.emacs.d
  git reset --hard 35a89bdfa6
  git pull origin master
  doom sync -u

Fix: #6598
Amend: b9933e6637
2022-07-31 00:58:36 +02:00