Created
November 28, 2021 23:29
-
-
Save digital-carver/7fec89a2bb19e07066ad64abbb75c870 to your computer and use it in GitHub Desktop.
Quick and dirty macro/function to show some source code of a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro showsource(ex0...) | |
InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :showsource, ex0) | |
end | |
showsource(f, @nospecialize t; kwargs...) = showsource(functionloc(f,t)...; kwargs...) | |
function showsource(file::AbstractString, line::Integer; nlines = 10) | |
run(pipeline(`tail -n +$(line) $file`, `head -n $(nlines)`)) | |
nothing | |
end | |
#Usage: @showsource nlines=30 sin(1.) | |
# by default, nlines is 10 if not specified |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment