Commit graph

164 commits

Author SHA1 Message Date
Henrik Lissner
9ea6ea68b0
tweak(lib): show chemacs version in doom-info 2022-07-30 22:41:13 +02:00
Henrik Lissner
510032bcb0
refactor(lib): s/doom--debug-/doom-debug-/
To uphold conventions introduced in 6c0b7e1.

Ref: 6c0b7e1530
2022-07-30 22:41:12 +02:00
Henrik Lissner
442d607ec0
fix: remove outdated uses of user-emacs-directory
Doom changes user-emacs-directory (see 46844b5 for explanation), so
doom-emacs-dir should be used to refer to your $EMACSDIR instead.

Fix: #6530
Ref: 46844b55de
2022-07-04 02:58:11 +02:00
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
23ee89ec08
tweak(lib): advise run-hooks & improve feedback on debug mode 2022-06-21 14:41:21 +02:00
Henrik Lissner
9d1df5f298
nit: minor refactors & comment/docstring revisions 2022-06-21 14:40:15 +02:00
Henrik Lissner
6963b784cc
refactor(cli): extract doom/info renderer
Into doom-info-string, which will wrap its contents to a given column
using the new print library.
2022-06-19 01:31:56 +02:00
Henrik Lissner
23678c52fe
refactor(lib): tidy up doom/version 2022-06-19 01:31:38 +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
336e7f0087
perf(lib): use syntax table instead of major mode
Should speed up doom/info a bit, and reduce potential edge cases caused
by emacs-lisp-mode hooks.
2022-06-18 16:57:17 +02:00
Henrik Lissner
14ebfc02a5
fix(lib): wrong-number-of-args error on doom/info
- Fixes a wrong-number-of-args error, due to outdated interactive
  spec (#6227).
- Fixes a regression (caused by the refactor in dcae7187b4) where the
  doom-info buffer is initially too short (~3 lines tall) to display all
  of its contents.

Fix: #6227
Amend: dcae7187b4
2022-03-31 21:08:31 +02:00
Henrik Lissner
dcae7187b4
refactor(lib): doom-info & remove unused commands
- Simplify doom-info and doom/info.
- Remove doom/copy-buffer-contents (may be moved later, but atm not very
  useful).
- Remove doom/am-i-secure (this will later be replaced with CLI
  commands)
2022-03-30 17:32:47 +02:00
Henrik Lissner
2aeca577c8
refactor: correct version variables
These two variables have been the wrong way around for a while. In
preparation for splitting Doom into separate repos (its core and module
libraries), I've corrected them. doom-modules-version is a placeholder
and will be removed later.

I've also settled on -dev suffix for inter-release versions of Doom,
rather than alpha.
2022-03-21 03:57:31 +01:00
Henrik Lissner
319665bbdc
feat(lib): time stamp *Messages* lines
...when doom-debug-mode is active.
2022-03-21 03:57:03 +01:00
Henrik Lissner
39886536c3 fix(lib): incorrect &user markers in doom-info
M-x doom/info marks modules that live in $DOOMDIR with &user, but what
if the user has moved their ~/.emacs.d into $DOOMDIR? As this seems to
happen often with Chemacs users, I've made this check a little more
procise.
2022-02-10 21:07:20 +01:00
Henrik Lissner
2d7e0c90ba refactor(lib): add Emacs version to doom/version 2022-01-27 03:43:51 +01: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
fe9d45bcf5 Add/Fix doom/{discourse,issue-tracker,report-bug}
Updated their URLs
2021-05-20 21:09:32 -04:00
Henrik Lissner
fdfd60dbad Don't call uname on Windows for doom/info
Mentioned in #5022
2021-05-10 04:46:14 -04:00
Henrik Lissner
5d7526a224 doom-info: rename distro->system & add window-system 2021-05-06 04:27:33 -04:00
Henrik Lissner
45147aace8 Refactor doom-debug-mode
Store intiial value in symbol plist instead. More info in 8ec8b2b.
2021-05-06 04:27:33 -04:00
Henrik Lissner
ff64a9d106 Add doom-run-hooks
Produces more helpful (and harder-to-miss) error messages when a hook
emits an error. Also advises run-hook when doom-debug-mode is active, so
errors in hooks (generally, major mode hooks) don't quietly go
unnoticed.
2021-05-06 04:27:33 -04:00
Henrik Lissner
2ef54eb782 Fix void-variable emacs-repository-branch in doom-info
Seems this var doesn't exist in some Emacs builds?
2021-04-29 17:24:40 -04:00
Henrik Lissner
6e49cb5ce2 Reduce false positive symlinks in doom/info {emacs,doom}dir 2021-04-17 23:26:27 -04:00
Henrik Lissner
233fd93b65 Add custom-file trait & custom-vars list to doom/info
So I can tell if users may have a custom.el where something may be
inadvertently saved.
2021-04-17 23:26:27 -04:00
Henrik Lissner
079feb26e4 Left align fields in doom-info
The leading whitespace can cause issues with some whitespace trimming
clipboard managers and <pre> blocks.
2021-04-14 23:31:13 -04:00
Henrik Lissner
ce65645fb8 Minor refactors & comment revision 2021-03-27 18:27:19 -04:00
Henrik Lissner
ea105b874e Toggle async-debug on doom-debug-mode 2021-03-12 22:58:15 -05:00
Henrik Lissner
2e1c10a6a4 Move sandbox code into own library 2021-03-12 22:58:15 -05:00
Henrik Lissner
abec86310b Fix #4777: wrong-type-argument listp unpin error 2021-03-11 10:57:41 -05:00
Henrik Lissner
ab7710adfd doom-info: fix args-out-of-range error 2021-03-08 10:25:09 -05:00
Henrik Lissner
4192d87dcd Redesign doom/info
+ Focus on the important information and cut down on excess.
+ Prompt the user to open pastebin.com after copying doom-info to
  clipboard.
+ Include timestamp in doom-info.
2021-03-07 00:03:04 -05:00
Henrik Lissner
c5e3f4d632 New autoload/system.el core library 2021-03-01 22:27:17 -05:00
Henrik Lissner
1a7536cbd1 Extend & compact doom/info
+ Output is now a couple lines shorter
+ Now tries to guess Linux distro names and versions
+ Displays symlinked EMACSDIR and DOOMDIR
+ Replaces elc-files segment with 'byte-compiled-config trait
2021-02-11 17:35:48 -05:00
Henrik Lissner
fc184852d0
Only replace usernames in file paths in doom/info 2021-01-11 02:49:00 -05:00
Henrik Lissner
b7f6532e4f
Fix startup hooks not running in vanilla sandbox 2020-12-01 18:16:12 -05:00
Henrik Lissner
affd076d53
Minor refactors & reformatting 2020-12-01 13:53:46 -05:00
Henrik Lissner
2c663ea5d4
Mention current theme and font in doom/info 2020-11-10 18:36:47 -05:00
Henrik Lissner
45179fbf59
Mention current frame type in doom/info 2020-11-10 18:36:47 -05:00
Henrik Lissner
611fdade09
Add doom/copy-buffer-contents command
To make it easier for beginners to copy content from logs or backtrace
windows.
2020-11-04 19:41:57 -05:00
Henrik Lissner
3e0432959a
Set user-init-file in sandbox 2020-11-02 21:03:28 -05:00
Henrik Lissner
fe37a590cc
Set doom--initial-load-path in sandbox
Prevents loaded packages miscount (e.g. -1) in dashboard/log in sandbox
instance.

This occurs because the benchmark line uses a simple heuristic to
determine the loaded packages: length of load-path minus the length of
doom--initial-load-path (to save on more expensive counting methods).
However, in the sandbox, load-path is pre-populated with all packages
right from the get-go, so doom--initial-load-path will be incorrect.
2020-10-26 05:52:30 -04:00
Henrik Lissner
9e1ac0c0be
Reduce active message-log-max; scale in debug mode
8kb of log isn't really necessary. We'll scale it up when debug mode is
on, instead.
2020-10-26 05:51:12 -04:00
Henrik Lissner
9b4fd806bb
Simplify doom/info output 2020-10-20 23:21:11 -04:00
Henrik Lissner
db07304c71
Don't enable explain-pause-mode at startup
When starting Emacs in debug mode, explain-pause-mode is enabled. This
pulls in other packages with it, which can taint results when testing
package load order. Also, explain-pause-mode is for measuring pauses
during interactive use, it isn't very useful for startup benchmarking.

So we only toggle it if doom-debug-mode is toggled interactively.
2020-10-11 16:41:07 -04:00
Henrik Lissner
b29b865d30
Fix #3975: configure native-comp in sandbox 2020-10-06 02:08:17 -04:00
Henrik Lissner
3cb7458d34
Fix #4033: correctly toggle explain-pause-mode
On doom-debug-mode.
2020-10-05 23:02:36 -04:00
Henrik Lissner
ae3a2fa8c2
doom-info: use &nopath prefix for 404'd modules
The alternative is a stringp error.
2020-09-02 14:23:11 -04:00
Henrik Lissner
5c6189fb4e
Simplify doom/version output
Only really needs to output Doom's version and build info.
2020-08-24 23:00:32 -04:00
Henrik Lissner
7e362e8fbd
Redesign doom/info
+ Replace "daemonp" and "windowsys" fields with "traits" field, which
  can now indicate the presence of: Chemacs, exec-path-from-shell,
  symlinked EMACSDIR/DOOMDIR, a running server, the daemon and an envvar
  file.
+ Now replaces $USER in absolute paths with literal "$USER".
+ Reordered fields from most to least general (system -> emacs -> doom)
+ Show "&user" next to modules that are private modules (defined in
  ~/.doom.d/modules/)
2020-08-24 22:27:40 -04:00