Skip to content

Commit

Permalink
make Meta-M with a empty prompt return the contextual module to Main (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Oct 24, 2023
1 parent d38348b commit 5e43309
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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

0 comments on commit 5e43309

Please sign in to comment.