Skip to content
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

make Meta-M with a empty prompt return the contextual module to Main #51616

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Standard library changes

* Tab complete hints now show in lighter text while typing in the repl. To disable
set `Base.active_repl.options.hint_tab_completes = false` ([#51229])
* Meta-M with an empty prompt now returns the contextual module of the REPL to `Main`.

#### SuiteSparse

Expand Down
6 changes: 3 additions & 3 deletions stdlib/REPL/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ Main

It is possible to change this contextual module via the function
`REPL.activate(m)` where `m` is a `Module` or by typing the module in the REPL
and pressing the keybinding Alt-m (the cursor must be on the module name). The
active module is shown in the prompt:
and pressing the keybinding Alt-m (the cursor must be on the module name). The `Main` module can be "activated" with an empty prompt plus the keybinding. The
active module is shown in the prompt (unless it is `Main`):

```julia-repl
julia> using REPL
Expand All @@ -598,7 +598,7 @@ julia> Core<Alt-m> # using the keybinding to change module

(Core) julia>

(Core) julia> Main<Alt-m> # going back to Main via keybinding
(Core) julia> <Alt-m> # going back to Main via keybinding

julia>
```
Expand Down
20 changes: 14 additions & 6 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1475,14 +1475,22 @@ current_word_with_dots(s::MIState) = current_word_with_dots(buffer(s))

function activate_module(s::MIState)
word = current_word_with_dots(s);
isempty(word) && return beep(s)
try
mod = Base.Core.eval(Base.active_module(), Base.Meta.parse(word))
REPL.activate(mod)
edit_clear(s)
catch
mod = if isempty(word)
edit_insert(s, ' ') # makes the `edit_clear` below actually update the prompt
Main
else
try
Base.Core.eval(Base.active_module(), Base.Meta.parse(word))
catch
nothing
end
end
if !(mod isa Module)
beep(s)
return
end
REPL.activate(mod)
edit_clear(s)
end

history_prev(::EmptyHistoryProvider) = ("", false)
Expand Down