Commit graph

69 commits

Author SHA1 Message Date
Henrik Lissner
adfa438487
fix: --profile switch in noninteractive sessions
This fixes command-line-args getting prematurely cleared out just before
being scanned for a --profile switch.

Fix: #7457
Co-authored-by: hpfr <hpfr@users.noreply.github.com>
2024-05-21 17:16:43 +02:00
Henrik Lissner
7aa87eb019
fix(profiles): not loading $EMACSDIR/init.el
`startup--load-user-init-file` persists its original
user-emacs-directory in a lexical binding that we cannot affect from
early-init.el, and uses it to find init.el. This prevents non-Doom
profiles' init.el files from being loaded.

A way around this is to have our own $EMACSDIR/init.el that loads
{user-emacs-directory}/init.el, but that's unnecessary work and ruins
our users' ability to use their $EMACSDIR as their $DOOMDIR, so I opted
for advice instead, to force it to recognize the changed
user-emacs-directory.

Fix: https://discourse.doomemacs.org/t/3251
2022-10-02 18:46:37 +02:00
Henrik Lissner
9c72b0e81f
nit: early-init: update commentary 2022-09-25 13:28:29 +02:00
Henrik Lissner
fa345fcc62
refactor: early-init: distinguish failure/fallthrough states
If lisp/doom.el does not exist, then we assume the user isn't loading a
Doom config and fall through to $EMACSDIR/early-init.el, if it exists.
However, `load`'s NOERROR argument suppresses more than just
file-missing errors -- it suppress permissions errors and other
legitimate IO errors that I want to treat as error states, not
fall-through states. This commit fixes that.

* early-init.el (gc-cons-threshold): Set a reasonable more default for
  gc-cons-threshold for non-Doom configs (16mb), instead of
  most-positive-fixnum, which would eventually cause
  freezing/stuttering for non-Doom profiles.
2022-09-25 13:25:15 +02:00
Henrik Lissner
e61af32307
fix: early-init: wrong-type-argument stringp nil
early-init-file is nil in most cases, at this point, so use
user-init-file instead.
2022-09-25 13:08:11 +02:00
Henrik Lissner
55c27a0ae9
fix(cli): avoid misinterpreted switches in argv
If early-init.el is loaded by another doomscript that uses
--init-directory or --profile for its own purposes, then they could
unintentionally alter user-emacs-directory. Lets only respect the
envvars in noninteractive sessions.
2022-09-18 00:46:52 +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
b8cca048c4
refactor: only process --init-directory w/o --profile
Using them both makes no sense, so don't process --init-directory if
--profile is given.
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
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
3a4233582b
perf: add MUST-SUFFIX when loading profile bootstrapper 2022-09-17 21:41:42 +02:00
Henrik Lissner
f748a5d15d
fix(cli): inability to find user-emacs-directory (part 2)
I misunderstood the issue in 1081588. `user-emacs-directory` is never
nil, even in batch sessions. Instead, it is simply set to the wrong path
in cases where Doom is deployed to a non-standard location. It's needed
to change it there, but never in interactive sessions.

Fix: #6777
Amend: 108158876c
2022-09-17 15:29:18 +02:00
Henrik Lissner
1a6524cecc
nit: mention file-name-handler-alist optimization in lisp/doom.el 2022-09-17 15:29:18 +02:00
Henrik Lissner
108158876c
fix(cli): inability to find user-emacs-directory
user-emacs-directory is nil in batch sessions, which early-init.el
wasn't expecting, which caused bin/doom to refuse to run out of a
non-standard location.

Fix: #6777
2022-09-16 17:01:57 +02:00
Henrik Lissner
405f6cdd1e
fix: load-file-suffixes not being restored
This setting (along with load-file-rep-suffixes) is simplified at
startup to optimize file IO at startup, but it was supposed to be undone
at the end of doom-start (in doom-before-init-hook). Unfortunately, the
restoration hook was not reaching their top-level bindings, causing
dynamic modules (like vterm-modules.so) to fail to load.
2022-09-16 13:07:28 +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
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
07d22adb4a
nit: revise comments, reformat config sections 2022-09-16 01:14:21 +02:00
Henrik Lissner
2396262cfa
nit: revise commentary in early-init.el 2022-09-06 23:28:39 +02:00
Henrik Lissner
89506983fe
refactor: early-init comments, loaders, & recursion guards 2022-09-06 22:55:48 +02:00
Henrik Lissner
c05e61536e
refactor: make early-init.el Doom's universal bootstrapper
This centralizes Doom's core startup optimizations and, as a
side-effect, reduces the runtime of bin/doom commands substantially.
This also simplifies the user story for loading Doom remotely (for batch
sessions or doomscripts).
2022-09-06 22:55:47 +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
efa3e9791f
fix: remove inhibit-redisplay hack
If an error occurs before this is restored, this can leave Emacs in a
state where it appears frozen and won't redraw. This can be overcome by
hooking into the debugger, but I'll try that another day.
2022-09-06 22:55:46 +02:00
Henrik Lissner
3a5e34d67b
fix: premature doom init in doom sub-profiles
Ensures that Doom doesn't prematurely initialize itself if a non-Doom
config tries to load Doom.
2022-08-02 20:22:31 +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
Henrik Lissner
44f169740e
tweak: more debug output at startup
Particularly to do with profiles, in case the user starts Emacs with
--debug or --debug-init.
2022-07-28 12:01:02 +02:00
Henrik Lissner
48e3603dfe
fix: envvars in profiles.el not being set 2022-07-28 12:01:02 +02:00
Henrik Lissner
5af38fb08e
feat: make bin/doom profile aware
- Fixes Doom's former inability to (trivially) juggle multiple profiles
  based on the same EMACSDIR (see #6593).
- Adds '--profile NAME' switch to bin/doom (also recognized
  $DOOMPROFILE).
- Adds new doom-profile* variables. These will eventually replace
  doom-{local,etc,cache}-dir and doom-{autoloads,env}-file.

This is intentionally messy to ensure backwards compatibility for a
little while longer. This will be fixed over the next couple weeks.

Ref: #6593
2022-07-28 12:01:02 +02:00
Henrik Lissner
1ecb5c7b9b
fix: fall back to $EMACSDIR/profiles/*
Formerly, profiles.el and $EMACSDIR/profiles/* were mutually exclusive.
I.e. if the file existed, it'd never check the directory. Now, it will
check the directory if the requested profile isn't in profiles.el, or
the file didn't exist.

Amend: 5b6b204bcb
2022-07-27 13:54:12 +02:00
Henrik Lissner
fbc5fd7f8a
nit: revise comments in early-init.el 2022-07-27 12:11:51 +02:00
Henrik Lissner
5b6b204bcb
feat: allow Doom be used as a config bootloader
This allows users to use Doom core to switch between Emacs configs (they
don't have to be Doom configs either). Taking after Chemacs, these
configs (called "profiles") can be declared in $EMACSDIR/profiles.el or
implicitly as directories under $EMACSDIR/profiles/ (symlinks work too).
Launch a profile with `emacs --profile foo` or by setting $DOOMPROFILE:
`DOOMPROFILE=foo emacs`.

An example profiles.el looks like this:

   ((doomemacs (user-emacs-directory . "~/.config/emacs")
               (env ("DOOMDIR" . "~/.config/doom")))
    (spacemacs (user-emacs-directory . "~/.config/spacemacs"))
    (prelude   (user-emacs-directory . "~/.config/prelude"))
    (altdoom   (user-emacs-directory . "~/.config/doomemacs")
               (env ("DOOMDIR" . "~/.config/doomprivate1")))
    (altdoom2  (user-emacs-directory . "~/.config/doomemacs")
               (env ("DOOMDIR" . "~/.config/doomprivate2"))))

Chemacs users will find the format of this file familiar; the biggest
differences are:

- Keys are symbols, not strings
- There is no, special "default" profile. The fallback profile is the
  Doom Emacs config doing the bootloading, living in ~/.config/emacs or
  ~/.emacs.d. If you don't like that, set $DOOMPROFILE in your dotfiles
  to the name of another profile.

WARNING: bin/doom does not understand --profile or $DOOMPROFILE yet. To
sync a particular profile, you'll have to run its bin/doom directly,
e.g.

To sync the "global" doom:
  ~/.config/emacs/bin/doom sync
To sync your "altdoom" (and "altdoom2") profiles:
  ~/.config/doomemacs/bin/doom sync
2022-07-27 12:11:51 +02:00
Henrik Lissner
5108ffc44d
feat: backport --init-directory for 27/28 users
--init-directory was added in Emacs 29. This backports it for 27/28
users, so users can trivially load an Emacs config living in another
directory (will be necessary for future versions of Doom's sandbox).
However, for this to work, Doom needs to live in ~/.emacs.d or
~/.config/emacs.

Ref: emacs-mirror/emacs@8eaf04de83
2022-07-27 11:16:54 +02:00
Henrik Lissner
1402db5129
refactor: how Doom starts up
Restructures Doom's primary core files and entry points to prepare for
backports (from the new CLI) coming soon.

- Removes $EMACSDIR/init.el.
- Doom configures Emacs to ignore ~/.emacs and ~/_emacs files.
- Doom's bootstrapper for interactive sessions was moved out of core.el
  and doom-initialize into doom-start.el. This change is preparation for
  Doom's new profile system (coming soon™️), where this bootstrapper
  will be dynamically generated.
- core.el and early-init.el have been reorganized, comment headers moved
  around, and comments updated to reflect these changes.
2022-06-18 16:54:45 +02:00
Henrik Lissner
a831946afb
feat: no startup optimizations if debug mode is on 2022-02-17 21:14:27 +01:00
Henrik Lissner
e5e301b3e4 refactor: remove redundant load-file advice
A mistake that snuck into 55c1cac while backporting some code from the
CLI rewrite. It was harmless and likely had no side effects, however.

Amend: 55c1cac43f
2022-01-08 18:55:02 +01:00
Henrik Lissner
55c1cac43f tweak: suppress redisplays cause by site-lisp at startup 2021-12-12 22:43:40 +01:00
Henrik Lissner
68ed4e6298 tweak: suppress 'Loading X...' messages at startup
From site-files, particularly. This *might* fix the white flash while
Emacs is starting up in some scenarios.
2021-11-25 01:22:58 +01:00
Itai Y. Efrat
98f44a006a fix: unset default-input-method in early-init.el
set-language-environment sets default-input-method, which is unwanted.

Fix: #5046
2021-11-04 01:08:43 +01:00
Henrik Lissner
0ab6aba056 perf: inhibit redisplay/echo area at startup
Unnecessary redraws can add 0.2-0.4s to startup times in some cases,
especially where site-files are involved (which spam *Messages* with
"Loading X..." messages; which force redraws).

May also indirectly fix #5643 by deferring redisplay (and therefore
window-buffer-change-functions, which triggers doom-init-ui-hook, which
triggers both Doom's dashboard and persp-mode).

Also removes a redundant set-language-environment call.

Ref #5643
2021-10-18 01:15:09 +02:00
Henrik Lissner
68d8364aea refactor: adopt CalVer and reorganize core.el
Doom is adopting CalVer (starting at 21.12) and, later, I'll move Doom's
core out to a separate repo, where it'll stay with SemVer (starting at
3.0).
2021-10-10 18:36:46 +02:00
Henrik Lissner
d79cea2e4c Minor refactors, reformatting, & comment revision 2021-07-11 17:52:08 -04:00
Henrik Lissner
6ad4f0698e Fix #4995: adapt to more renamed comp-* symbols
Two more variables were renamed upstream.
2021-05-11 19:03:18 -04:00
Henrik Lissner
ea389b8eb2 Restore file-name-handler-alist a little sooner
Too late, and we risk read encoding issues when loading compressed elisp
files.
2021-05-07 02:32:51 -04:00
Henrik Lissner
e2a11d24fd core: minor refactors and comment revisions 2021-05-06 18:36:32 -04:00
Henrik Lissner
bddb2b2a2d Refactor early-init.el 2021-04-21 21:45:04 -04:00
Henrik Lissner
5da3641aad
Move init.el to early-init.el
Our first step toward dropping 26.x support. Allows our optimizations to
reach a little further into the startup.
2021-01-09 02:55:08 -05:00
Henrik Lissner
29d8f44254
Add comments 2020-11-16 19:27:39 -05:00
Henrik Lissner
6a82eedeea
Respect Xresources
This was disabled because of configs, but I'll leave it to the user to
resolve those issues.
2020-10-30 19:09:31 -04:00
Henrik Lissner
b857566239
Minor refactors 2020-10-20 16:52:39 -04:00
Henrik Lissner
b245abfe72
Set comp-deferred-compilation in early-init.el
Seems it's necessary for some and not others.

The emacs experience(TM).
2020-10-06 14:38:32 -04:00