File tree Expand file tree Collapse file tree 3 files changed +36
-14
lines changed
Expand file tree Collapse file tree 3 files changed +36
-14
lines changed Original file line number Diff line number Diff line change 1818
1919function __init__ ()
2020 pushfirst! (PyVector (pyimport (" sys" )[" path" ]), @__DIR__ )
21- init_repl_if_not ( )
21+ afterreplinit (init_repl )
2222end
Original file line number Diff line number Diff line change 55 using Base: REPL, LineEdit
66end
77
8- # Register keybind '.' in Julia REPL:
8+ """
9+ afterreplinit(f)
910
10- function init_repl_if_not (; _init_repl= init_repl)
11- active_repl = try
12- Base. active_repl
13- catch err
14- err isa UndefVarError || rethrow ()
15- return
11+ Like `atreplinit` but triggers `f` even after REPL is initialized when
12+ it is called.
13+ """
14+ function afterreplinit (f)
15+ # See: https://github.com/JuliaLang/Pkg.jl/blob/v1.0.2/src/Pkg.jl#L338
16+ function wrapper (repl)
17+ if isinteractive () && repl isa REPL. LineEditREPL
18+ f (repl)
19+ end
20+ end
21+ if isdefined (Base, :active_repl )
22+ wrapper (Base. active_repl)
23+ else
24+ atreplinit () do repl
25+ @async begin
26+ wait_repl_interface (repl)
27+ wrapper (repl)
28+ end
29+ end
1630 end
31+ end
1732
18- if isinteractive () && typeof (active_repl) != REPL. BasicREPL
19- _init_repl (active_repl)
33+ function wait_repl_interface (repl)
34+ for _ in 1 : 20
35+ try
36+ repl. interface. modes[1 ]. keymap_dict
37+ return
38+ catch
39+ end
40+ sleep (0.05 )
2041 end
2142end
22- # See: https://github.com/JuliaInterop/RCall.jl/blob/master/src/setup.jl
43+
44+ # Register keybind '.' in Julia REPL:
2345
2446function init_repl (repl)
2547 start = function (s, _... )
Original file line number Diff line number Diff line change 11module TestJuliaREPL
22
33include (" preamble.jl" )
4- using IPython: init_repl, init_repl_if_not , REPL
4+ using IPython: init_repl, afterreplinit , REPL
55
66@static if VERSION >= v " 0.7.0-"
77 using REPL: TextTerminal
1010end
1111
1212
13- @testset " init_repl_if_not " begin
14- repl = init_repl_if_not (; _init_repl = identity)
13+ @testset " afterreplinit " begin
14+ repl = afterreplinit ( identity)
1515 if isinteractive ()
1616 @test repl === Base. active_repl
1717 else
You can’t perform that action at this time.
0 commit comments