Skip to content

Instantly share code, notes, and snippets.

@digital-carver
Created November 28, 2021 23:29
Show Gist options
  • Save digital-carver/7fec89a2bb19e07066ad64abbb75c870 to your computer and use it in GitHub Desktop.
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
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