You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
This issue on Cursive has a lot of potentially helpful discussion about problems that might be encountered in the process of implementing this behavior.
The :clojure/expand-macro and :clojure/collapse-macro actions, respectively, can be used to expand and collapse the form under the cursor.
Macros are always expanded as with macroexpand, rather than macroexpand-1 – all possible macroexpansions are performed on the selected form.
Macroexpanded subtrees are styled with the .macroexpanded CSS class.
All navigation, editing, etc. actions are permitted within macroexpanded forms. Any changes made within the expanded subtree will be lost when the subtree is collapsed.
Possible changes to consider for the future:
Unify the :clojure/{collapse,expand}-macros actions into a single :clojure/toggle-macroexpansion action (or similar) that makes the appropriate changes in context.
Implement similar actions that use macroexpand-1 rather than macroexpand.
Implement similar actions that use macroexpand-all, recursively macroexpanding all subforms of the selected form as well as the form itself.
Somehow make the level of macroexpansion scrubbable, i.e. present a slider whose leftmost value corresponds to the unexpanded macro form and whose rightmost value corresponds to the full expansion as with 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.The text was updated successfully, but these errors were encountered: