Open mkremins opened 10 years ago
This issue on Cursive has a lot of potentially helpful discussion about problems that might be encountered in the process of implementing this behavior.
As of https://github.com/mkremins/flense/commit/773377ce38f4dbb03ff272c62ebcc1b99a9acd02:
:clojure/expand-macro
and :clojure/collapse-macro
actions, respectively, can be used to expand and collapse the form under the cursor.macroexpand
, rather than macroexpand-1
– all possible macroexpansions are performed on the selected form..macroexpanded
CSS class.Possible changes to consider for the future:
:clojure/{collapse,expand}-macros
actions into a single :clojure/toggle-macroexpansion
action (or similar) that makes the appropriate changes in context.macroexpand-1
rather than macroexpand
.macroexpand-all
, recursively macroexpanding all subforms of the selected form as well as the form itself.macroexpand
.Leaving this issue open for now to collect future thoughts and research, even though the current implementation of macroexpansion is probably good enough for the time being.
Using Stilts, it should be possible to display the expanded form of any macro which can be defined as an ordinary CLJS function operating on forms.
Important considerations: how to handle the expanded form from an editing perspective? Should it be treated as a read-only subtree of the entire document, a completely opaque node that merely happens to be rendered in a way that resembles Clojure code, or something else entirely? Allowing the user to hand-edit the expanded form seems nonsensical: editing would break the 1:1 relationship between the macro's output and the underlying original code.
There definitely ought to be a way to collapse the expanded form back to the original code from which it was expanded. As such, the data representation of an expanded form should include some sort of reference to the underlying code.
Note the differences between
macroexpand-1
andmacroexpand
. Separate actions should probably be provided for each to keep the distinction clear.