Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline macroexpansion #10

Open
mkremins opened this issue Jul 19, 2014 · 2 comments
Open

Inline macroexpansion #10

mkremins opened this issue Jul 19, 2014 · 2 comments

Comments

@mkremins
Copy link
Owner

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
Copy link
Owner Author

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
Copy link
Owner Author

As of 773377c:

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant