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

@niceexpand #124

Open
oxinabox opened this issue Sep 2, 2019 · 2 comments
Open

@niceexpand #124

oxinabox opened this issue Sep 2, 2019 · 2 comments

Comments

@oxinabox
Copy link
Member

oxinabox commented Sep 2, 2019

I have this code that I use for expanding things.
I think it is like prettify but when I tried using prettify
it engaged animal names,
which (unlike gensym_ids) removes the names of things that were created via gensym(:meaningful)

Not sure what to do with it, but it is handy.
Would a PR be useful?

using MacroTools
macro niceexpand(code)
    code = Base.macroexpand(Main, code, recursive=false)
    code = MacroTools.postwalk(MacroTools.unblock, code)
    code = MacroTools.postwalk(code) do x
        isexpr(x, :escape) ? x.args[1] : x
    end
    code = MacroTools.gensym_ids(code)
    code = MacroTools.striplines(code)
    return QuoteNode(code)
end
@MikeInnes
Copy link
Member

You can ask prettify not to alias like that via a kwarg. That's probably less necessary now that gensyms are printed in a sensible way.

goretkin added a commit to goretkin/MacroTools.jl that referenced this issue Jul 3, 2020
@cstjean
Copy link
Collaborator

cstjean commented Nov 13, 2020

I've got a very similar macro on my side. Maybe we should name it @prettyexpand for consistency, and change prettify accordingly.

The animal names are definitely prettier, but they're losing variable name information. I would replace the gensyms like var"#3#elapsedtime" with ¤elapsedtime, or some similar Unicode character that Julia won't var.

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

No branches or pull requests

3 participants