From 49d2c6d7349381a9c43142814941f7ef5986c759 Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Fri, 6 Oct 2023 16:00:54 +0200 Subject: [PATCH 1/2] make Meta-M with a empty prompt return the contextual module to Main --- NEWS.md | 1 + stdlib/REPL/src/LineEdit.jl | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index f4966babc60ae..86fbd23525654 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/stdlib/REPL/src/LineEdit.jl b/stdlib/REPL/src/LineEdit.jl index efe893870d46e..2fdeb707043b0 100644 --- a/stdlib/REPL/src/LineEdit.jl +++ b/stdlib/REPL/src/LineEdit.jl @@ -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) From 48bbdbc90aedd54763bd04eef0bc8d5421a43641 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Tue, 17 Oct 2023 14:03:38 +0200 Subject: [PATCH 2/2] update doc --- stdlib/REPL/docs/src/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/REPL/docs/src/index.md b/stdlib/REPL/docs/src/index.md index d1064d9c063b4..bee94354e57e1 100644 --- a/stdlib/REPL/docs/src/index.md +++ b/stdlib/REPL/docs/src/index.md @@ -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 @@ -598,7 +598,7 @@ julia> Core # using the keybinding to change module (Core) julia> -(Core) julia> Main # going back to Main via keybinding +(Core) julia> # going back to Main via keybinding julia> ```