Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down