Commit graph

96 commits

Author SHA1 Message Date
Henrik Lissner
422baedad7
refactor(cli): load cli libs from doom.el
This simplifies the entry point for loading Doom (and/or its CLI
framework).
2022-08-07 19:43:28 +02:00
Henrik Lissner
06db69bf76
fix(emacs-lisp): suppress popup warnings from flycheck
Typically caused by partial syntax errors in Doom Emacs (e.g. while
you're writing code in $EMACSDIR or $DOOMDIR, and haven't typed the
closing parenthesis yet).
2022-08-05 00:49:17 +02:00
Henrik Lissner
1f8bf7accb
merge: rewrite-docs
I've omitted docs/*.org from this merge, as there is still work left to
do there, but I am pushing the module docs early so folks can benefit
from the new docs sooner.
2022-08-03 03:27:50 +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
a4aab45656
fix(emacs-lisp): flycheck false positives in Doom configs 2022-06-22 23:04:00 +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
6c5537b487
fix(emacs-lisp): eval forms from within the current buffer
This fix ensures that functions/macros that are evaluated with +eval/*
et co will remember where they were defined (if possible), so you don't
have to see this in their documentation again:

  FUNCTION is a function without a source file.

Ref: https://github.com/doomemacs/doomemacs/pull/6444#issuecomment-1159457888
2022-06-18 18:19:39 +02:00
Henrik Lissner
9fde385cdc
fix(emacs-lisp): void-function lisp--local-defform-body-p
I was too hasty adding this function in 15432cf. This function wasn't
introduced until Emacs 29.

Amend: 15432cf9d2
2022-06-18 16:57:17 +02:00
Henrik Lissner
15432cf9d2
fix(emacs-lisp): update custom lisp-indent-function
To reflect Emacs 28+ changes to the function it is
replacing (lisp-indent-function).
2022-06-17 21:58:05 +02:00
tecosaur
f0f414ac67
fix(eval): type error in +emacs-lisp-eval
When evaluating from a buffer not visiting any file, file-truename would
error out since the argument it was fed is nil.

Fix: #6181
Close: #6404
Ref: 7290f85cfd
Co-authored-by: Yoav Marco <ymarco@users.noreply.github.com>
2022-06-17 18:36:10 +02:00
Henrik Lissner
97155412a9
fix(emacs-lisp): missing package cookies in imenu 2022-03-21 03:57:03 +01:00
Henrik Lissner
7290f85cfd feat(eval): set load-true-file-name & buffer-file-truename
So they are available in evaluated contexts.
2022-01-27 03:50:52 +01:00
Henrik Lissner
0aad1399cc refactor(file-templates): doom readme templates
Including readme template for categories.
2021-11-21 20:04:28 +01:00
Colin Woodbury
c3d237c3f5 fix(emacs-lisp): quiet doc lints in org src blocks
Opening an Org src block with `SPC m '` creates a minibuffer with no
associated file name, hence the check for `buffer-file-name`.
2021-09-23 11:37:18 +02:00
Henrik Lissner
3bedae38dd dev: transition to 12c long hashes
In bumps, in :pin's, and in our git conventions. We have no rules for
the commit linter for it yet, though.
2021-08-02 22:07:13 -04:00
Henrik Lissner
3ba364ae10 Minor refactoring across the board 2021-05-23 22:09:07 -04:00
Jan Felix Langenbach
acb0399424 Reimplement +emacs-lisp--module-at-point 2021-04-26 00:39:55 +02:00
Henrik Lissner
7e1f5da169 lang/emacs-lisp: respect lexical-binding in eval handler 2021-03-08 10:25:09 -05:00
Nikita Bloshchanevich
e05d804f1f Restore the old buffer when using `ivy-call'
Without `deferred', the file selected in the `counsel-find-file' will
only remain the current buffer afterwards when pressing RET on an item,
not just `ivy-call'.
2021-02-26 22:06:41 +01:00
Nikita Bloshchanevich
65dfdd5c4a [4415] remove FIXME comment
Due to `ivy-call' still causing files to be opened in the
background (which is not a bug in `ivy'),
`+emacs-lisp-lookup-definition' still needs to return `deferred' for
modules. The comment is as such misleading and needs to be removed (it
has been resolved).
2020-12-15 14:28:19 +01:00
Nikita Bloshchanevich
621cb60e75 Workaround: fix goto definition on modules
`+emacs-lisp-lookup-definition' does not work when browsing the directory of a
module, because, due to a possible bug in `counsel', the visited buffer is not
immediately visible after calling `counsel-find-file' (unlike with `find-file').
As such, the backend should return `deferred' for that case.

See abo-abo/swiper#2752. This should be removed once that PR is merged.
2020-12-12 13:21:26 +01:00
Henrik Lissner
d1effe2ddd
Fix keyword highlighting in Emacs 28+
Because they now satisfy special-variable-p.
2020-10-21 22:05:58 -04:00
Henrik Lissner
6a64f37435
Minor refactors & revision across the board 2020-07-31 01:39:24 -04:00
Henrik Lissner
99d5cd1fba
Check +emacs-lisp-disable-flycheck-in-dirs against default-directory
Instead of buffer-file-name, which could be nil in some buffers.
2020-07-25 16:55:54 -04:00
Henrik Lissner
946852fe6b
Fix #3545: overzealous :pin truncation 2020-07-13 15:51:28 -04:00
Henrik Lissner
8bf902d5f4
General refactors & reformatting across the board 2020-06-04 20:13:28 -04:00
Henrik Lissner
ada4110730
Refactor :lang emacs-lisp 2020-05-25 03:43:40 -04:00
Henrik Lissner
037345cfd9
lang/emacs-lisp: reformat autoloads 2020-05-11 03:00:08 -04:00
Henrik Lissner
cacc4a0ff7
Only trigger property indent correction in plists
Before

  (defcli! :main
           ()
           ...)

After

  (defcli! :main
    ()
    ...)
2020-05-05 03:31:43 -04:00
Henrik Lissner
03ecfed1a7
Fix RET indent of elisp forms following properties
Only affects newline-and-indent, not reindent commands.

Before:

  (list :a 1
    :b 2
    :c 3)

After:

  (list :a 1
        :b 2
        :c 3)

This could use some refactoring...
2020-05-01 02:18:26 -04:00
Henrik Lissner
a634e2c812
Indent elisp plists more sensibly 2020-04-30 15:54:36 -04:00
Henrik Lissner
106f3324e8
Fix over-aggressive pin truncation
Would truncate the rest of the buffer in some cases.
2020-04-30 02:31:51 -04:00
Henrik Lissner
45cdfb1258
Bump :core
spudlyo/clipetty@7ee3f9c -> spudlyo/clipetty@01b3904
bbatsov/projectile@eec569d -> bbatsov/projectile@5cd261d
noctuid/general.el@14ad4c8 -> noctuid/general.el@42e3803

We're also transitioning from abbreviated SHA1 hashes to full ones,
because underlying git machinery in future updates of straight will
require it (e.g. to obtain shallow clones of pinned packages).
2020-04-29 23:48:21 -04:00
Henrik Lissner
bd944634bc
Fix defadvice! functions omitted from elisp imenu 2020-02-21 10:42:33 -05:00
Henrik Lissner
1910453e29
The byte-compiler ate my baby 2020-02-06 16:55:27 -05:00
Henrik Lissner
d47bc06ab4
Fix K on modules with no readme 2020-01-12 22:35:03 -05:00
Henrik Lissner
29250133e8
Replace doom/describe-symbol w/ helpful-symbol
And helpful-at-point.
2020-01-11 17:21:35 -05:00
Henrik Lissner
e5fa19ea2d
lang/emacs-lisp: fix wrong-num-args error on doc lookup 2019-12-27 04:44:20 -05:00
Henrik Lissner
fe1642e854
Add special goto def/docs support in doom! blocks
- Pressing gd on a module in your doom! block will now browse that
  module's directory.
- Pressing K on a module will jump to that module's documentation, if any.
- Pressing K on a module flag will jump to that flag's description
  within that module's documenation.
- This is now explained in init.example.el

Closes #2249
2019-12-26 01:41:45 -05:00
Henrik Lissner
5623b8b9ba
lang/emacs-lisp: refactor +emacs-lisp-eval 2019-11-24 19:40:00 -05:00
Henrik Lissner
768d5b718c
Fix #2111: +eval/buffer not capturing whole elisp buffer 2019-11-24 16:50:46 -05:00
Henrik Lissner
ccf7197acf
lang/emacs-lisp: print string repr of evaluated result
This makes the return type of the evaluated result clearer at a glance.
2019-10-26 23:44:29 -04:00
Henrik Lissner
84a063ca78
tools/eval: add +overlay feature
Now, inline evaluation will display results in an overlay next to the
cursor, rather than in the minibuffer (unless it gets too big, in which
case it'll use a popup buffer).
2019-10-26 02:12:58 -04:00
Henrik Lissner
e6094f262f
lang/emacs-lisp: don't resize non-output windows 2019-10-23 18:30:03 -04:00
Henrik Lissner
373d920715
lang/emacs-lisp: resize eval popup to fit contents 2019-10-22 19:57:57 -04:00
Henrik Lissner
e31f51e0ba
lang/emacs-lisp: recreate output popup on eval
If we don't, the popup doesn't resize itself if the contents shrink or
grow.
2019-10-22 00:34:16 -04:00
Henrik Lissner
2485cac2e0
lang/emacs-lisp: refactor eval handler
pp-eval-expression does much of what +emacs-lisp-eval used to do.
2019-10-17 02:53:44 -04:00
Rudi Grinberg
1ffaa699f8 Fix naming convention
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
2019-09-19 23:01:08 +09:00
Rudi Grinberg
46c0ec0f11 [emacs lisp] Add bindings for debugging defuns
`, d f` - turn on debugging for defun
`, d F` - turn off debugging for defun

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
2019-09-19 13:58:16 +09:00
Henrik Lissner
31ccd9be78
Replace vestigial references to def-package!
def-package! is deprecated and is replaced with use-package! to reduce
confusion about its purpose and connection to use-package.
2019-09-13 22:00:34 -04:00