Example for Base.edit and Base.less


Could someone please post an example of how to use Base.edit?

julia> f() = rand()*2
f (generic function with 1 method)

julia> f(x) = rand()+x
f (generic function with 2 methods)

julia> edit(f)

also, how do I see the definition of a struct ?


I usually go with the macro form, eg

@edit f(1)

would take me to the definition in the source file. It won’t be able to do that with a function you typed in from the REPL. I find it is best with a workflow based on Revise.jl. Also, you need to set up your editor correctly, eg

ENV["EDITOR"] = "emacsclient"

in your ~/.juliarc.jl.

AFAICT structs are not supported ATM (by the underlying Base.functionloc). See #14356. But you can work around this in many cases by using the constructor, eg

@edit Date(1980, 1, 1)

and hope the struct definition will be somewhere in the vicinity :smile:


thanks, but yikes. seeing or editing would be useful exactly when I had entered a function in the REPL. when it is in a source file, I can just use my external editor on the source.

because neither @less nor @edit works for REPL entered code, is there no way to display my function source? and/or my struct source?