-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
add exit/quit hint #21362
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
add exit/quit hint #21362
Conversation
""" | ||
quit() = exit() | ||
|
||
# hint for people who forget parentheses |
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.
Can this be more repl specific?
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.
Probably, but I still don't really understand how display
works...
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.
I'm actually talking about something more integrated into the REPL (since that's where we need this) instead of modifying how some functions are displayed.
Something like
diff --git a/base/REPL.jl b/base/REPL.jl
index 7a4eb61b46..5ac8261dfc 100644
--- a/base/REPL.jl
+++ b/base/REPL.jl
@@ -138,7 +138,9 @@ function print_response(errio::IO, val::ANY, bt, show_value::Bool, have_color::B
errio, QuoteNode(val), bt))))
iserr, lasterr = false, ()
else
- if val !== nothing && show_value
+ if (val === exit || val === quit) && show_value && specialdisplay === nothing
+ println("Use exit(), quit() or Ctrl-D to exit")
+ elseif val !== nothing && show_value
try
if specialdisplay === nothing
eval(Main, Expr(:body, Expr(:return, Expr(:call, display, QuoteNode(val)))))
This gives;
julia> exit
Use exit(), quit() or Ctrl-D to exit
julia> quit
Use exit(), quit() or Ctrl-D to exit
julia> print(exit)
exit
julia> display(exit)
exit (generic function with 2 methods)
julia> display(quit)
quit (generic function with 1 method)
Ideally we may want to do this only when the input is just quit
and exit
.
When trying this I realized that this will make it harder to see how many methods are defined for the two function. Hopefully it's fine...
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.
I completely agree --- this should only be an interactive feature, if anything, not something that prevents you from normally show
ing certain functions.
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.
This is one of the rare cases where you might want to overload display
:
Base.display(d::Base.REPL.REPLDisplay, ::Union{typeof(exit),typeof(quit)}) = display(d, Text("Use exit(), quit(), or Ctrl-D to exit"))
will work and should only affect output in the REPL, and doesn't require hacking REPL internals.
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.
I didn't overload display
because this way we can probably pass in additional information and only show it on certain inputs.
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.
This should not affect how the object is shown, it should only affect the exact input exit
, not e.g. fs = [exit]; fs[1]
.
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.
Yeah, agree. print_response
is just easier to find then the input handling ;-p
processes completed successfully. | ||
""" | ||
exit(n) = ccall(:jl_exit, Void, (Int32,), n) | ||
exit() = exit(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.
Is there a reason we're not doing exit(n=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.
Probably this function pre-dates optional arguments.
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.
I hate special cases like this, but could maybe tolerate it if it were REPL-only. 👎
closed in favor of #38522 |
By changing the
show
method, we can provide more useful hints (this idea is gratuitously stolen from Python):