Commit graph

45 commits

Author SHA1 Message Date
Henrik Lissner
8352562b2c
fix(lib): appease byte-compiler-sama
Silences some byte-compiler warnings about:

- 'nreverse on constant list' on add-hook! calls.
- inhibit-changing-match-data deprecation warning.
- unescaped quotes in docstring in some doom-*-dir variables.
- Variable non-essential should be quoted (though it isn't referring to
  a variable).
- CONTEXT -> CONTEXTS to match argument name.
2024-01-24 12:38:41 -05:00
Henrik Lissner
986573a4a2
perf(lib): dir!: unset file-name-handler-alist
file-name-directory consults this variable for alternative strategies,
which is unnecessary work. (file!) won't (and should never be used in
any context where it could) return anything but a simple file path.
2023-02-21 03:30:51 -05:00
Henrik Lissner
7bf5938c66
fix: relative paths for add-load-path!
Because (dir!) was being expanded too early (at macro expansion time)
rather than runtime.
2023-02-18 15:27:47 -05:00
Henrik Lissner
f93003a9a2
refactor!(lib): remove eval-when-compile!
BREAKING CHANGE: Removes the eval-when-compile! macro. I recently
discovered cl-eval-when and it serves this macro's purpose well
enough (and is autoloaded+built-in).

This macro wasn't used anywhere in (published) Doom code, however, and
users shouldn't really be using it, so its removal is unlikely to cause
any actual breakage.
2022-10-03 14:12:33 +02:00
Henrik Lissner
ff9602ef75
fix(lib): revert add-transient-hook! refactor
a4b5831 removed this let-binding because I expected the function to
capture it, which seems to be the case in general, except for #6865.
Since add-transient-hook! could conceivably be used in an elisp file
with lexical-binding off, I'll take fewer chances and live with a little
redundancy.

Amend: a4b58311da
Fix: #6865
2022-10-02 19:08:53 +02:00
Henrik Lissner
a6f0bf3123
fix(lib): infinite recursion in doom-first-*-hook
It's possible for these hooks to be triggered recursively, such as in
the case of emojify's "Emoji images not available should I download them
now?" prompt (reported upstream).

Fix: iqbalansari/emacs-emojify#100
2022-10-01 17:09:15 +02:00
Henrik Lissner
1c32e317cc
tweak(lib): log calling hook from doom-run-hook
Makes it easier to trace hooks through logs.
2022-09-24 22:10:02 +02:00
Henrik Lissner
4efaf6837b
refactor: introduce doom-module-context
Where f9201eb introduced a general context system, this one introduces
one for modules, to simplify our let-bind game when interacting with
modules, and to more efficiently expose module state to modulep! (which
gets called at runtime a great deal, so its performance is important).

* lisp/doom-lib.el (doom-log): simplify macro and introduce
  doom-inhibit-log variable.
* lisp/doom-modules.el (modulep!): fix reported file path if modulep!
  fails to find the local module.
* lisp/lib/debug.el (doom-debug-variables): disable doom-inhibit-log
  when debug mode is on.

Ref: f9201eb218
2022-09-24 22:09:46 +02: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
f0431b6fac
fix(lib): setq!: use set-default-toplevel-value
This is more correct, as we never want to use this to set buffer-local
variables.
2022-09-24 20:31:34 +02:00
Henrik Lissner
eda2e30721
fix(lib): doom-load: use doom-profile-error
...for errors emitted from the profile directory (basically just the
init file).
2022-09-24 20:31:34 +02:00
Henrik Lissner
a4b58311da
refactor(lib): simplify fn!, add-transient-hook!
* lisp/doom-lib.el:
  - (fn!): unroll the loop into a single, fast setplist that
    doesn't require a cl-lib macro (autoloading which seems to throw an
    error on flatpak/snap builds; still investigating that one).
  - (add-transient-hook!): Removes a redundant let-bind.  `sym` is
    already lexically bound outside the function. This will break
    anywhere lexical-binding is nil though. Not sure if I should cater
    to that scenario...
2022-09-24 20:31:34 +02:00
Henrik Lissner
d33478dc79
feat(lib): backport file-name-with-extension 2022-09-24 18:46:22 +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
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
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
d552dbc878
fix(lib): resolve relative paths in doom-load errors
And don't forward file-missing errors, as this would convolute them.
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
18cd2eb483
refactor: reformat doom.el and use doom-lib
Move startup optimizations after core globals, so we can employ
doom-lib's API.
2022-09-16 01:14:23 +02:00
Henrik Lissner
701f51c3d6
refactor(lib): use uninterned symbols for transient/chained hooks
The debugger appears to display uninterned symbols properly, and since
these symbols should never be touched/referenced by users, there's no
reason to pollute the obarray with these transient symbols.
2022-09-16 01:14:21 +02:00
Henrik Lissner
3fe1641937
feat(lib): add doom-compile-function
To be used in some autoloaded libraries, in case they haven't been
byte-compiled and contain especially expensive functions.
2022-09-16 01:14:20 +02:00
Henrik Lissner
f49953ab56
feat(lib): add versionp! macro
A convenience macro for Emacs' version API, for performing compound
version checks in less code.
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
3505e666a8
fix: failure to load doom libs on 27.x
Emacs 27.x does not collapse consecutive slashes in a file path when
trying to load them, and instead discards everything before it and
treats the rest as an absolute path, e.g. "~/some//path/foo/" ->
"/path/foo". This is not the case in 28.1, but Doom's backport of
file-name-concat did not take this into account, so it's been modified
to trim trailing slashes.

Fix: #6766
Amend: 433c9e344d
2022-09-10 18:33:02 +02:00
Henrik Lissner
eb80d461df
fix(lib): void-function macroexp-file-name error
This function was introduced in Emacs 28.1, so 7e0c2ed was a breaking
change for 27.x users.

Fix: #6766
Amend: 7e0c2ed8a3
2022-09-10 13:03:53 +02:00
Henrik Lissner
f3e85afc7e
fix(lib): ensure after! body gets expanded
Relying on eval-after-load's compiler-macro magic (after 8b4f722) can
cause scope issues with nested macros (like file! and dir! running in
the context of a temp buffer), so best we use with-eval-after-load
directly.

Ref: 8b4f722fa3
2022-09-10 11:59:48 +02:00
Henrik Lissner
7e0c2ed8a3
fix(lib): convert file! and dir! to macros
To ensure that they're expanded at a file's top-level, while expanded,
where they're used. It also fixes a few inlined uses of the file!
macro (e.g. in `load!`, as reported in #6764), which was prematurely
committed ahead of this change.

Close: #6764
Amend: a179b8d262
2022-09-10 11:59:17 +02:00
Henrik Lissner
a179b8d262
feat(lib): add doom-{require,load}
These functions are light wrappers around require and load, such that
Doom will catch (and decorate) any errors from the target file, and is
also capable of loading Doom's subfeatures.
2022-09-07 23:19:37 +02:00
Henrik Lissner
0a51fdff53
refactor(lib): move doom-log to doom-lib
This is such an essential macro that it should be universally available,
and not stowed away in the print library.
2022-09-06 23:46:42 +02:00
Henrik Lissner
4009509db5
feat(lib): add eval-when-compile! macro
Unlike eval-when-compile, the body of this macro's calls will only be
evaluated while byte-compiling.
2022-09-06 22:55:48 +02:00
Henrik Lissner
338f59c456
feat(lib): backport bol & eol from 29
Ref: emacs-mirror/emacs@f117b5df4d
2022-09-06 22:55:46 +02:00
Henrik Lissner
2b01166d1d
feat(lib): backport with-memoization from 29
Ref: emacs-mirror/emacs@3c972723e4
2022-09-06 22:55:46 +02:00
Henrik Lissner
edaa887bd9
refactor(lib): add + use defbackport! macro
In the future, doom-lib (among other things) will be byte-compiled as
part of 'doom sync'. To spare runtime the overhead of checking for these
functions, I've wrapped these in a macro. It also makes their
definitions a tad simpler.
2022-09-06 22:55:46 +02:00
Henrik Lissner
5ebc2528d8
perf(lib): use symbol plist for fn! lookup table
A good deal faster than alists at this scale.
2022-09-06 22:55:46 +02:00
Henrik Lissner
65c86ea3ff
feat(lib): backport with-environment-variables from 28.1
And alias letenv! to it. Not sure if I want to deprecate it though,
given the length of the macro it's linked to...
2022-09-06 22:55:46 +02:00
ivanbrennan
c44bc81a05 fix(lib): defer-feature! fallback FNS
If defer-feature! was called with one argument (as is the case in the
:lang common-lisp module), FNS defaulted to an empty list. As a result,
FEATURE was deferred but never re-added to the features list, and after!
blocks were never triggered.

Instead of defaulting to an empty list, fallback to a singleton list
containing just (FEATURE). This aligns with the behavior this macro had
prior to 5b8b04f0c8, which generalized FNS
to support a list of functions rather than just one.
2022-08-19 11:24:34 +02:00
Henrik Lissner
8b4f722fa3
docs(lib): update after! to reflect changes upstream
It used to be that after! suppressed macro expansion, but at some point
around 28.1, the elisp interpreter started recognizing the
compiler-macro hint in eval-after-load's definition; implicitly wrapping
quoted forms in a function. Therefore, we can no longer rely on
eval-after-load to hide macros from the byte-compiler. Instead, modules
will need to take care to wrap macro calls in `eval` or similar, on a
case-by-case basis.
2022-08-18 16:27:57 +02:00
Henrik Lissner
050624d475
fix(lib): nested interpolation & order of args for fn! macro
This fixes a couple bugs with this macro:

- Nested %-refs (in nested fn!'s) were interpolated as arguments of the
  outer-most fn!. E.g. (fn! (fn! %2)) would expand to:

  Before this fix:

    (lambda (_%1 %2)
      (lambda (_%1 %2)
        %2))

  After this fix:

    (lambda ()
      (lambda (_%1 %2)
        %2))

- Unused arguments were not only listed in the wrong order, they were
  off-by-one. E.g.

    (fn! %3 %5) expands to (lambda (_%4 _%3 %3 _%1 %5) %3 %5)

  This never caused any actual issues, but it was unexpected.

I've also moved the lookup table to `fn!`, and removed unnecessary
entries from it.
2022-08-15 22:12:45 +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
b763c5b992
fix: file-name-handler-alist ignoring user changes
Unsetting file-name-handler-alist around a `load` call prevents any
change to this variable from surviving that file's evaluation (e.g. by
packages loaded therein). Since the user's config files are loaded with
this macro, this affects users' configs, which is unacceptable.

Since this optimization is already done in early-init.el, we can get
away with being more selective here.
2022-08-08 22:20:11 +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
433c9e344d
feat(lib): backport file-name-concat from 28.1
May replace doom-path in the future.
2022-08-05 17:35:46 +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
Renamed from core/core-lib.el (Browse further)