Commit graph

331 commits

Author SHA1 Message Date
Henrik Lissner
14b2395424
refactor: remove unused core variables
doom-debug-p and doom-interactive-p have always been intentionally
redundant, because changing the variables they replaced had other
side-effects, which made writing tests for them difficult. Since our
new (yet unpublished) tests lean heavily toward integration testing more
than unit testing, this becomes an implementation detail.

And doom-init-p's only use was refactor out at some point in the past,
so it's no longer used.

Also done to reduce Doom's footprint, in general.
2022-06-29 18:14:20 +02:00
Henrik Lissner
66d06261aa
perf(lib): factor seq out of fn! & bake in lookup table
A little more time and space gained by cutting out seq entirely and
pre-generating the argument lookup table. At least, in uncompiled use
cases.

The original implementation used regexp to lookup arguments, which
was (relatively) expensive. By comparison, using `assq` is *much*
faster, especially for datasets this small; and more so when I get
around to byte-compiling Doom's core (assq has its own byte-compiler
opcode).
2022-06-21 23:27:19 +02:00
Henrik Lissner
1583db5983
fix(lib): void-variable x error in fn!
Amend: 72a8485d77
2022-06-21 23:01:13 +02:00
Henrik Lissner
72a8485d77
perf(lib): optimize fn! macro
- Reduces allocations by avoiding copies produced by reverse and seq,
  and by avoiding a closure.
- Reduces runtime by avoiding the overhead of seq's generics.
2022-06-21 22:51:45 +02:00
Henrik Lissner
681d40ab58
refactor(lib): use feature checks for backports
Instead of imprecise version checks.

Fix: #6489
2022-06-21 21:29:08 +02:00
Henrik Lissner
23feb482e9
refactor!(lib): rename fn!->lambda! & fn!!->fn!
BREAKING CHANGE: This renames the fn! macro to lambda! and fn!! to fn!.
I hadn't put much thought into their names when they were added, but now
that they're seeing more use, I've reconsidered.

The reasoning is (and I'll refer to them by their new names):

- If you're using fn!, you care more about the syntax's brevity, than if
  you were using lambda!, so I wanted fn! to have the (even if slightly)
  shorter name.
- lambda! decorates native lambda (with cl-function). Its old name
  did not suggest that connection like other !-macros in Doom's library
  do.
- Their old names implied the two macros were somehow related or that
  one decorated the other. They aren't and don't.
2022-06-21 21:29:08 +02:00
Henrik Lissner
9d1df5f298
nit: minor refactors & comment/docstring revisions 2022-06-21 14:40:15 +02:00
Henrik Lissner
210381bdcf
fix(lib): autoload format-spec on 27.x
This function wasn't autoloaded until 28, causing void-function errors
if it's used.
2022-06-20 03:02:25 +02:00
Henrik Lissner
6c0b7e1530
refactor!(cli): rewrite CLI framework libraries
BREAKING CHANGE: this changes Doom's CLI framework in subtle ways, which
is listed in greater detail below. If you've never extended Doom's CLI,
then this won't affect you, but otherwise it'd be recommended you read
on below.

This commit focuses on the CLI framework itself and backports some
foundational changes to its DSL and how it resolves command line
arguments to CLIs, validates input, displays documentation, and persists
state across sessions -- and more. This is done in preparation for the
final stretch towarding completing the CLI rewrite (see #4273).

This is also an effort to generalize Doom's CLI (both its framework and
bin/doom), to increase it versatility and make it a viable dev tool for
other Doom projects (on our Github org) and beyond.

However, there is a *lot* to cover so I'll try to be brief:

- Refactor: generalize Doom's CLI framework by moving all bin/doom
  specific configuration/commands out of core-cli into bin/doom. This
  makes it easier to use bin/doom as a project-agnostic development
  tool (or for users to write their own).
- Refactor: change the namespace for CLI variables/functions from
  doom-cli-X to doom-X.
- Fix: subcommands being mistaken as arguments. "doom make index" will
  resolve to (defcli! (doom make index)) if it exists,
  otherwise (defcli! (doom make)) with "index" as an argument. Before
  this, it would resolve to the latter no matter what. &rest can
  override this; with (defcli! (doom make) (&rest args)), (defcli! (doom
  make index)) will never be invoked.
- Refactor!: redesign our output library (was core/autoload/output.el,
  is now core/autoload/print.el), and how our CLI framework buffers and
  logs output, and now merges logs across (exit! ...) restarts.
- Feat: add support for :before and :after pseudo commands. E.g.

    (defcli! (:before doom help) () ...)
    (defcli! (:after doom sync) () ...)

  Caveat: unlike advice, only one of each can be defined per-command.
- Feat: option arguments now have rudimentary type validation (see
  `doom-cli-option-arg-types`). E.g.

    (defcli! (doom foo) ((foo ("--foo" num))) ...)

  If NUM is not a numeric, it will throw a validation error.

  Any type that isn't in `doom-cli-option-arg-types` will be treated as a
  wildcard string type. `num` can also be replaced with a specification,
  e.g. "HOST[:PORT]", and can be formatted by using symbol quotes:
  "`HOST'[:`PORT']".
- Feat: it is no longer required that options *immediately* follow the command
  that defines them (but it must be somewhere after it, not before). E.g.
    With:
      (defcli! (:before doom foo) ((foo ("--foo"))) ...)
      (defcli! (doom foo baz) () ...)
    Before:
      FAIL: doom --foo foo baz
      GOOD: doom foo --foo baz
      FAIL: doom foo baz --foo
    After:
      FAIL: doom --foo foo baz
      GOOD: doom foo --foo baz
      GOOD: doom foo baz --foo
- Refactor: CLI session state is now kept in a doom-cli-context struct (which
  can be bound to a CLI-local variable with &context in the arglist):

    (defcli! (doom sync) (&context context)
      (print! "Command: " (doom-cli-context-command context)))

  These contexts are persisted across sessions (when restarted). This is
  necessary to support seamless script restarting (i.e. execve
  emulation) in post-3.0.
- Feat: Doom's CLI framework now understands "--". Everything after it will be
  treated as regular arguments, instead of sub-commands or options.
- Refactor!: the semantics of &rest for CLIs has changed. It used to be "all
  extra literal, non-option arguments". It now means *all* unprocessed
  arguments, and its use will suppress "unrecognized option" errors, and
  tells the framework not to process any further subcommands. Use &args
  if you just want "all literal arguments following this command".
- Feat: add new auxiliary keywords for CLI arglists: &context, &multiple,
  &flags, &args, &stdin, &whole, and &cli.
  - &context SYM: binds the currently running context to SYM (a
    `doom-cli-context` struct). Helpful for introspection or passing
    along state when calling subcommands by hand (with `call!`).
  - &stdin SYM: SYM will be bound to a string containing any input piped
    into the running script, or nil if none. Use
    `doom-cli-context-pipe-p` to detect whether the script has been
    piped into or out of.
  - &multiple OPTIONS...: allows all following OPTIONS to be repeated. E.g. "foo
    -x a -x b -x c" will pass (list ("-x" . "a") ("-x" . "b") ("-x" .
    "c")) as -x's value.
  - &flags OPTIONS...: All options after "&flags" get an implicit --no-* switch
    and cannot accept arguments. Will be set to :yes or :no depending on which flag is
    provided, and nil if the flag isn't provided. Otherwise, a default
    value can be specified in that options' arglist. E.g.

      (defcli! (doom foo) (&flags (foo ("--foo" :no))) ...)

    When called, this command sets FOO to :yes if --foo, :no if --no-foo, and
    defaults to :no otherwise.
  - &args SYM: this replaces what &rest used to be; it binds to SYM a
    list of all unprocessed (non-option) arguments.
  - &rest SYM: now binds SYM to a list of all unprocessed arguments, including
    options. This also suppresses "unrecognized option" errors, but will render
    any sub-commands inaccessible. E.g.

      (defcli! (doom make) (&rest rest) ...)
      ;; These are now inaccessible!
      (defcli! (doom make foo) (&rest rest) ...)
      (defcli! (doom make bar) (&rest rest) ...)
  - &cli SYM: binds SYM to the currently running `doom-cli` struct. Can also be
    obtained via `(doom-cli-get (doom-cli-context-command context))`. Possibly
    useful for introspection.
- feat: add defobsolete! macro for quickly defining obsolete commands.
- feat: add defalias! macro for quickly defining alias commands.
- feat: add defautoload! macro for defining an autoloaded command (won't
  be loaded until it is called for).
- refactor!: rename defcligroup! to defgroup! for consistency.
- fix: CLIs will now recursively inherit plist properties from parent
  defcli-group!'s (but will stack :prefix).
- refactor!: remove obsolete 'doom update':
- refactor!: further generalize 'doom ci'
  - In an effort to generalize 'doom ci' (so other Doom--or
    non-doom--projects can use it), all its subcommands have been
    changed to operate on the current working directory's repo instead
    of $EMACSDIR.
  - Doom-specific CI configuration was moved to .github/ci.el.
  - All 'doom ci' commands will now preload one of \$CURRENT_REPO_ROOT/ci.el or
    \$DOOMDIR/ci.el before executing.
- refactor!: changed 'doom env'
  - 'doom env {-c,--clear}' is now 'doom env {clear,c}'
  - -r/--reject and -a/--allow may now be specified multiple times
- refactor!: rewrote CLI help framework and error handling to be more
  sophisticated and detailed.
- feat: can now initiate $PAGER on output with (exit! :pager) (or use
  :pager? to only invoke pager is output is longer than the terminal is
  tall).
- refactor!: changed semantics+conventions for global bin/doom options
  - Single-character global options are now uppercased, to distinguish them from
    local options:
    - -d (for debug mode) is now -D
    - -y (to suppress prompts) is now -!
    - -l (to load elisp) is now -L
    - -h (short for --help) is now -?
  - Replace --yes/-y switches with --force/-!
  - -L/--load FILE: now silently ignores file errors.
  - Add --strict-load FILE: does the same as -L/--load, but throws an error if
    FILE does not exist/is unreadable.
  - Add -E/--eval FORM: evaluates arbitrary lisp before commands are processed.
  - -L/--load, --strict-load, and -E/--eval can now be used multiple times in
    one command.
  - Add --pager COMMAND to specify an explicit pager. Will also obey
    $DOOMPAGER envvar. Does not obey $PAGER.
- Fix #3746: which was likely caused by the generated post-script overwriting
  the old mid-execution. By salting the postscript filenames (with both an
  overarching session ID and a step counter).
- Docs: document websites, environment variables, and exit codes in
  'doom --help'
- Feat: add imenu support for def{cli,alias,obsolete}!

Ref: #4273
Fix: #3746
Fix: #3844
2022-06-18 23:53:12 +02:00
Henrik Lissner
4bf49785fd
feat(lib): backport ensure-list from 28+
And deprecate doom-enlist, which it replaces.
2022-06-18 16:57:17 +02:00
Henrik Lissner
a48cd27d79
tweak(lib): always suppress doom-log output
It will still be logged to *Messages*, but won't spam the echo area.
2022-03-31 19:25:50 +02:00
Henrik Lissner
b92c644ad8
docs(lib): clarify setq!'s docstring
Emacs 29+ introduced the setopt macro for setting defcustom variables in
a way that takes setters and type-constraints into account, but it
eagerly pulls in a symbol's dependencies before doing so. To side-step
this silliness, use Doom's setq! macro instead. I'm tempted to alias
setopt to it...
2022-03-21 03:57:03 +01:00
Henrik Lissner
3333eee466
refactor(lib): sharp-quote & minor refactors 2022-03-21 03:57:03 +01:00
Henrik Lissner
0a151f4f13
refactor!(lib): remove obsolete lambda! macros
BREAKING CHANGE: These macros have been deprecated for years. Use
cmd!/cmd!! instead.
2022-03-21 03:57:02 +01:00
Henrik Lissner
17f457edf7
feat(lib): add fn!! macro
With implicit positional arguments. Adapted from
https://git.sr.ht/~tarsius/llama, minus the font-locking, outer function
call, and plus a few minor optimizations.

Ref: https://git.sr.ht/~tarsius/llama
2022-03-21 03:56:59 +01:00
Lele Gaifax
e5213f20e5 nit: fix several documentation typos 2022-01-10 02:21:49 +01:00
Henrik Lissner
9dad26961a fix: envvar file loader processing TZ incorrectly
setenv treats the TZ (and only TZ) envvar especially, so we have to too,
since I'm intentionally avoiding iteratively setenv'ing envvars to avoid
the unnecessary extra work it does.

Fix: #5760
2021-11-24 21:18:39 +01:00
Henrik Lissner
3a669d8daa fix(lib): add-hook! fails when passed a quoted list
Fix: #5779
2021-11-20 00:55:24 +01:00
Henrik Lissner
b35b32273a fix(lib): doom-enlist not wrapping cons cells
While lists are technically cons cells, cons cells don't have all the
properties of lists, so doom-enlist shouldn't treat it as one.

Before:

  (doom-enlist '(a . b))   #=> (a . b)

After:

  (doom-enlist '(a . b))   #=> ((a . b))
2021-10-20 20:18:39 +02:00
Henrik Lissner
8f040b79be fix(lib): fn! error when arglist is a cons cell
Throws a wrong-type-argument error when fn! is given a cons cell in its
arguments, e.g.

  (fn! ((x . y)) ...)
2021-10-19 22:29:08 +02:00
Henrik Lissner
0112319c04 fix(lib): add &allow-other-keys in fn! sub-arglists
Before this fix:

  (fn! (x &key y z))
  ;; implies
  (fn! (&key x &allow-other-keys)).

But

  (fn! (x (&key y) &key z))
  ;; would not imply
  (fn! (x (&key y &allow-other-keys) &key z &allow-other-keys)).
2021-10-18 01:15:54 +02:00
Henrik Lissner
ade96ed515 docs(lib): clarify type of add-hook!'s first arg 2021-10-11 20:25:18 +02:00
Henrik Lissner
f5c1332a31 refactor: minor refactors & nit picks across core 2021-10-10 18:36:46 +02:00
Henrik Lissner
094b4c1023 refactor: move init helpers to core-lib
The functions have more general use-cases and should be considered part
of Doom's stdlib.
2021-10-10 18:36:46 +02:00
Henrik Lissner
91770b66e5 feat(lib): add :depth support to add-hook!
The semantics of add-hook's APPEND argument changed in 27.1: it was
replaced with DEPTH, which controls its exact order of the hook (and is
respected every time a function is added to a hook, throughout its
lifetime).

Includes a general refactor for add-hook! too.
2021-10-10 18:36:46 +02:00
Henrik Lissner
d13816ce3e feat(lib): extend function deftypes in letf! macro
This adds support for two new definition types to the left! convenience
macro: defun* and defadvice.

First, defun* is for defining recursive, local functions (uses
cl-labels under the hood). e.g.

  (letf! (defun* triangle (number)
           (cond ((<= number 0) 0)
                 ((= number 1) 1)
                 ((> number 1)
                  (+ number (triangle (1- number))))))
    ...)

Second, defadvice is for defining temporary advice (which has a global
effect; it can later be improved to limit scope by redefining things
with cl-letf). e.g.

  (letf! (defadvice my-fixed-triangle (fn number)
           :around #'triangle
           (funcall fn (1+ number)))
    ...)
2021-10-01 19:30:56 +02:00
Henrik Lissner
2c5cc752ff fix(lib): preserve package order in after! macro
Prior to this, (after! (a b) ...) would expand to

  (after! b
    (after! a
      ...))

After this, it expands to

  (after! a
    (after! b
      ...))

This fixes load order issues with packages whose deferred configs are
nested, such as org and ob-ditaa.

Ref https://www.reddit.com/r/emacs/comments/pp3sye/hd311nz
2021-09-16 20:20:18 +02:00
Henrik Lissner
f2588b0e90 feat(lib): imply &allow-other-keys in fn! macro 2021-09-16 20:20:08 +02:00
Henrik Lissner
044a1a5f2b Drop Emacs 26.x support
Emacs 27.x has been the stable version of Emacs for nearly a year, and
introduces a litany of bugfixes, performance, and quality-of-life
improvements that significantly reduce Doom's maintenance burden (like
XDG support, early-init.el, image manipulation without imagemagick, a
native JSON library, harfbuzz support, pdumper, and others).

With so many big changes on Doom's horizon, I like having one less (big)
thing to worry about.

Also reverts bb677cf7a (#5232) as it is no longer needed.
2021-07-06 02:31:52 -04:00
Henrik Lissner
060636966f Document :depth in add-hook! docstring 2021-05-16 21:19:30 -04:00
Henrik Lissner
dee20c7585 Remove define-obsolete-*-alias fix
Packages have had enough time to catch up. Also, with 9d3742c0d these
fixes are no longer effective for packages.

Closes #4534
2021-05-15 14:09:08 -04:00
Henrik Lissner
d44c57f01a Add :defer support to add-hook! macro
See add-hook's DEPTH argument (replaces APPEND in Emacs 27+).
2021-05-09 13:06:24 -04:00
Henrik Lissner
b8b51cee7b Simplify after!
The featurep check is redundant. eval-after-load does it too.
2021-02-24 18:28:23 -05:00
Henrik Lissner
76636d4a98 Refactor cmds!!
+ No longer depends on general.el
+ Each branch is now anaphoric (binds `it` to the return value of the
  predicate)
2021-02-11 17:35:48 -05:00
Henrik Lissner
16a495c97d Fix #4548: global TAB overwritten by evil keybind 2021-02-06 06:54:18 -05:00
Henrik Lissner
9446a8f411 Move byte-compile fix to core-packages
So it targets more than just 28.x+ users.
2021-02-06 04:49:28 -05:00
Henrik Lissner
628f0a930f Force straight to byte-compile packages in same session
Straight (on its develop branch) byte compiles packages in a child
process, isolated from the current session. This is a sensible approach
and I applaud it, but there's a problem:

Some packages don't load their compile-time dependencies at
compile-time, causing errors *at* compile-time. They unwittingly rely on
the fact that package.el compiles them in the same session as their
dependencies, which indirectly loads their macros for them. I can't
depend on package authors to do the right thing, but I can force
straight to revert to the old approach.
2021-02-05 22:48:31 -05:00
Henrik Lissner
f5a9dc11ee Update deprecated notices on back (+forward) ports 2021-01-31 04:30:48 -05:00
Henrik Lissner
b91f1607d8 Fix #4532: wrong-number-of-args errors on emacs HEAD
This is a temporary fix. These should be removed once packages have
updated to accommodate the changes to the
define-obsolete-{variable,function,face}-alias macros.
2021-01-31 04:30:48 -05:00
Henrik Lissner
20e74206a8
Merge pull request #4531 from jbampton/fix-spelling
Fix spelling
2021-01-27 02:36:44 -05:00
Henrik Lissner
63929a240c Fix doom-lookup-key
+ Scanning wrong variable for minor mode keymaps (minor-mode-alist ->
  minor-mode-map-alist).
+ Accommodate possibility that emulation-mode-map-alists may contain
  nested alists (#4538).

Closes #4538
2021-01-18 17:45:29 -05:00
John Bampton
583f854298 Fix spelling 2021-01-18 02:16:45 +10:00
Henrik Lissner
da177d58c4
Fix #4457: wrong-type-arg keymapp on C-i keybinds 2021-01-05 01:55:53 -05:00
Henrik Lissner
a567834ff8
Fix #4457: broken key sequences ending with C-i 2021-01-03 22:40:06 -05:00
Henrik Lissner
c987794884
Fix #4478: backport exec-path function from 27.1 2021-01-03 17:40:33 -05:00
Henrik Lissner
4281a772b1
Revise core lib docstrings for clarity 2020-12-11 17:38:59 -05:00
Henrik Lissner
8edabbecfa
Add kbd! alias for general-simulate-key macro 2020-12-11 16:59:47 -05:00
Henrik Lissner
b5e948054c
Refactor & reformat core.el
Backport a bit of core.el from our CLI rewrite.
2020-12-02 17:58:09 -05:00
Henrik Lissner
affd076d53
Minor refactors & reformatting 2020-12-01 13:53:46 -05:00
Akira Baruah
c3001f77aa core-lib: Add docstring for add-hook-trigger! 2020-11-19 00:31:13 -08:00