Skip to content

Commit 2953dc4

Browse files
committed
Document the inline macrostep flow
1 parent f759352 commit 2953dc4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

doc/modules/ROOT/pages/debugging/macroexpansion.adoc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,60 @@ namespaces in the macroexpansion buffer. It can be set to one of the following:
5353

5454
The option `cider-macroexpansion-print-metadata` controls whether to print the var metadata
5555
in the macroexpansion buffer. It's set to `nil` by default.
56+
57+
== Inline macroexpansion
58+
59+
As an alternative to the separate buffer, `cider-macrostep-expand` expands
60+
macros *in place* in the source buffer, in the spirit of the
61+
https://github.com/joddie/macrostep[macrostep] package. Place point right after
62+
a form (as with kbd:[C-x C-e]) and run `M-x cider-macrostep-expand`: the form is
63+
replaced by its one-step expansion and you enter a transient, read-only
64+
`cider-macrostep-mode` with these keybindings:
65+
66+
|===
67+
| Keyboard shortcut | Description
68+
69+
| kbd:[e] +
70+
kbd:[=] +
71+
kbd:[RET]
72+
| Expand the form before point one step further. Inside an existing expansion, put point after a nested form to step into it.
73+
74+
| kbd:[a]
75+
| Fully expand the form before point in one step (`macroexpand-all`), instead of stepping level by level.
76+
77+
| kbd:[c] +
78+
kbd:[u] +
79+
kbd:[DEL]
80+
| Collapse the innermost expansion at point, restoring the original form.
81+
82+
| kbd:[n] +
83+
kbd:[p]
84+
| Move to the next/previous further-expandable sub-form.
85+
86+
| kbd:[q]
87+
| Collapse every expansion and leave `cider-macrostep-mode`.
88+
|===
89+
90+
Each expansion remembers the exact text it replaced, so collapsing restores the
91+
original verbatim and nested expansions peel back in order. The operators of
92+
sub-forms that can be expanded further (those that resolve to a macro) are
93+
underlined so you can see what's left to expand, and kbd:[n]/kbd:[p] jump
94+
between them. The gensyms a macro introduces (e.g. `x__42__auto__`) are each
95+
given their own color, so a binding can be tracked through the expansion.
96+
97+
NOTE: The expandable-head highlighting and gensym coloring rely on the
98+
`cider/classify-symbols` nREPL op, available in cider-nrepl 0.60 and newer.
99+
Without it the stepping still works, just without those visual aids.
100+
101+
=== Configuration
102+
103+
* `cider-macrostep-display-namespaces` - how namespaces are displayed in the
104+
expansion (`tidy`, `qualified` or `none`), as for the separate-buffer flow.
105+
* `cider-macrostep-highlight-expansion` - briefly pulse a freshly inserted
106+
expansion (on by default).
107+
* `cider-macrostep-highlight-expandable` - underline the operators of
108+
further-expandable sub-forms (on by default).
109+
* `cider-macrostep-color-gensyms` - colorize the gensyms introduced by an
110+
expansion (on by default).
111+
* `cider-macrostep-gensym-colors` - the palette cycled through when coloring
112+
gensyms.

0 commit comments

Comments
 (0)