mkremins / flense

Edit trees, not text
MIT License
101 stars 3 forks source link

Inline macroexpansion #10

Open mkremins opened 10 years ago

mkremins commented 10 years ago

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 and macroexpand. Separate actions should probably be provided for each to keep the distinction clear.

mkremins commented 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.

mkremins commented 10 years ago

As of https://github.com/mkremins/flense/commit/773377ce38f4dbb03ff272c62ebcc1b99a9acd02:

Possible changes to consider for the future:

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.