diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index 9a9114aed9e3d..9d0481a3fe69a 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -124,7 +124,46 @@ end # Temporary alias until Documenter updates const softscope! = softscope -const repl_ast_transforms = Any[softscope] # defaults for new REPL backends +""" + print_exit_hint(ex) + +Print a hint about how to exit Julia if the user just types "exit" while using the REPL. + +To remove this functionality, use +`filter!(!=(REPL.print_exit_hint), Base.active_repl_backend.ast_transforms)` + +# Example +```julia +julia> exit +suggestion: To exit Julia, use Ctrl-D, or type exit() and press enter. +exit (generic function with 2 methods) + +julia> using REPL + +julia> filter!(!=(REPL.print_exit_hint), Base.active_repl_backend.ast_transforms) +1-element Vector{Any}: + softscope (generic function with 1 method) + +julia> exit +exit (generic function with 2 methods) +``` +""" +function print_exit_hint(@nospecialize ex) + # Look to see if user just typed "exit". ex.args[1] is a LineNumberNode + if ex isa Expr && ex.head === :toplevel && length(ex.args) == 2 && ex.args[2] === :exit + quote + if Main.exit === Base.exit + println("suggestion: To exit Julia, use Ctrl-D, or type exit() and press enter.") + end + # Return the method exit + exit + end + else + return ex + end +end + +const repl_ast_transforms = Any[softscope, print_exit_hint] # defaults for new REPL backends # Allows an external package to add hooks into the code loading. # The hook should take a Vector{Symbol} of package names and