Skip to content

jkrumbiegel/PrettyMacroExpand.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrettyMacroExpand

Stable Dev Build Status

PrettyMacroExpand has macros that expand other macros to more readable code using JuliaFormatter and MacroTools.prettify.

There are four macros, @prettyexpand, @prettyexpand1, @prettyexpand_md and @prettyexpand1_md. The 1 versions correspond to @macroexpand1 and only expand the first macro layer, the md versions return markdown objects which leads to nicer code formatting, e.g. in Documenter blocks.

Here is an example using @prettyexpand1 on itself compared to @macroexpand1:

julia> PrettyMacroExpand.@prettyexpand1 @prettyexpand1 x + y
PrettyMacroExpand.print(
    PrettyMacroExpand.format_text(
        PrettyMacroExpand.string(
            PrettyMacroExpand.prettify(
                @macroexpand1(x + y),
                alias = PrettyMacroExpand.alias[],
            ),
        );
        margin = PrettyMacroExpand.margin[],
    ),
)

julia> @macroexpand1 @prettyexpand1 x + y
quote
    #= /Users/username/.julia/dev/PrettyMacroExpand/src/PrettyMacroExpand.jl:20 =#
    PrettyMacroExpand.print(begin
            #= /Users/username/.julia/dev/PrettyMacroExpand/src/PrettyMacroExpand.jl:43 =#
            PrettyMacroExpand.format_text(PrettyMacroExpand.string(PrettyMacroExpand.prettify(#= /Users/username/.julia/dev/PrettyMacroExpand/src/PrettyMacroExpand.jl:46 =# @macroexpand1(x + y), alias = PrettyMacroExpand.alias[])); margin = PrettyMacroExpand.margin[])
        end)
end

You can change the preferred code width with PrettyMacroExpand.margin[] = 70 and turn of animal name aliasing of temporary variables with PrettyMacroExpand.alias[] = false.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages