-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
mention methodtable Ctrl+Q trick in methodshow #35556
mention methodtable Ctrl+Q trick in methodshow #35556
Conversation
c9b0be8
to
e407c53
Compare
Tagging @fredrikekre, since I believed you added this feature in #22007. Could I get a review? |
This is a very nice thing to have for new users. But wouldn't this write the "tips" message into a file if I type |
Should I check for |
I don't think diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl
index 30af00a6cd..be3e14538d 100644
--- a/stdlib/REPL/src/REPL.jl
+++ b/stdlib/REPL/src/REPL.jl
@@ -206,6 +206,7 @@ end
function display(d::REPLDisplay, mime::MIME"text/plain", x)
io = outstream(d.repl)
get(io, :color, false) && write(io, answer_color(d.repl))
+ io = IOContext(io, :interactive => true)
if isdefined(d.repl, :options) && isdefined(d.repl.options, :iocontext)
# this can override the :limit property set initially
io = foldl(IOContext, d.repl.options.iocontext, |
e407c53
to
4dd8acd
Compare
If we go with this direction, should we add Lines 266 to 283 in 65869b1
|
Yes, I think that would be helpful. Should this all go into this PR or would it make more sense to have a dedicated PR for this? |
This patch introduces a new convention in REPL.jl so I think it makes sense to add the documentation here. |
Perhaps |
Ah, that's a very good point. Yes, I wonder if we should just directly overload A bit hacky solution may be something like function display(d::REPLDisplay, mime::MIME"text/plain", x)
backup = copy(Base.LAST_SHOWN_LINE_INFOS)
empty!(Base.LAST_SHOWN_LINE_INFOS)
...
if isempty(Base.LAST_SHOWN_LINE_INFOS)
append!(Base.LAST_SHOWN_LINE_INFOS, backup)
else
print(io, the_hint_message)
end
end |
Hmm... Actually, maybe infos = []
io = IOContext(io, :LAST_SHOWN_LINE_INFOS => infos)
show(io, "text/plain", x)
d.repl.last_shown_line_infos = infos in |
I don't really get, why we would need |
No, it doesn't. My suggestion was to do it the other way around. If we implement this in (However, this is correct only if there is only one I think this is the right way to do it. As you pointed out, this is very specific to REPL. So, I think REPL is the best place to implement it. |
4dd8acd
to
2a32e13
Compare
@tkf I got the same error locally, I just wanted to see whether it was just on my machine. Do you have any idea why it would fail? I don't really know where to start looking into this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it simpler to always use io = IOContext(io, :LAST_SHOWN_LINE_INFOS => infos)
?
Also, current code seems to not update d.repl.last_shown_line_infos
after the second time?
Yes, that makes sense. Originally, I had structured it a bit differently, but doesn't really matter either way. |
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
Bump. Is this good to go? |
It's is rather a radical change in the "philosophy" of how ping @StefanKarpinski |
I don't think I'm the person for this particular review. @JeffBezanson, @stevengj and @vtjnash have more of a history and familiarity with the display system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is rather clever! It's unusual, but I can't see any reason that'd be a problem.
if haskey(io, :LAST_SHOWN_LINE_INFOS) | ||
resize!(io[:LAST_SHOWN_LINE_INFOS], 0) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if haskey(io, :LAST_SHOWN_LINE_INFOS) | |
resize!(io[:LAST_SHOWN_LINE_INFOS], 0) | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to skip resize!
here? What happens when multiple stack traces are shown (via nested errors)? Would IOContext
be reset appropriately?
@@ -373,6 +374,7 @@ show(io::IO, mime::MIME"text/html", mt::Core.MethodTable) = show(io, mime, Metho | |||
|
|||
# pretty-printing of AbstractVector{Method} | |||
function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method}) | |||
LAST_SHOWN_LINE_INFOS = get(io, :LAST_SHOWN_LINE_INFOS, Tuple{String,Int}[]) | |||
resize!(LAST_SHOWN_LINE_INFOS, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resize!(LAST_SHOWN_LINE_INFOS, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need resize!
for something like this?
struct TwoMethodTables
methods1
methods2
end
function Base.show(io::IO, ::MIME"text/plain", two::TwoMethodTables)
println(io, "TwoMethodTables:")
show(io, MIME"text/plain"(), two.methods1)
show(io, MIME"text/plain"(), two.methods2)
end
Currently, I think Ctrl+Q works for numbering in methods2
. If we remove resize!
, it'd refer to the numbering in methods1
(and also in methods2
shifted by length(methods)
).
@@ -240,6 +240,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru | |||
end | |||
n = rest = 0 | |||
local last | |||
LAST_SHOWN_LINE_INFOS = get(io, :LAST_SHOWN_LINE_INFOS, Tuple{String,Int}[]) | |||
|
|||
resize!(LAST_SHOWN_LINE_INFOS, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resize!(LAST_SHOWN_LINE_INFOS, 0) |
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Bumping this again. I thought the |
I merged this as @vtjnash is OK with it at a high-level picture. I'm keeping @vtjnash Let us know if the code around It seems to be better to merge now so that there is more chance to play with the UI in the 1.6-DEV cycle. It's also better to merge this before #36134. (The test failures look like some network glitches.) |
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com> Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Thanks to @oxinabox for pointing me to this trick on Slack. I think this deserves to be mentioned in the MethodTable output.