Skip to content

Commit 8714338

Browse files
committed
Revert "Merge branch 'c42f-c42f/fixed-world-age'"
This reverts commit 056c328, reversing changes made to 1e17c65.
1 parent 056c328 commit 8714338

7 files changed

+81
-108
lines changed

src/BracketInserter.jl

+1
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,5 @@ function insert_into_keymap!(D::Dict)
166166
end
167167
end
168168

169+
insert_into_keymap!(OhMyREPL.Prompt.NEW_KEYBINDINGS)
169170
end # module
+6-49
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
1-
import REPL
2-
import REPL.LineEdit
1+
32
using Crayons
43
import Markdown
54

6-
function _refresh_line(s::REPL.LineEdit.BufferLike)
7-
LineEdit.refresh_multi_line(s)
8-
OhMyREPL.Prompt.rewrite_with_ANSI(s)
9-
end
10-
11-
function _REPL_display(d::REPL.REPLDisplay, mime::MIME"text/plain", @nospecialize(x))
12-
x = Ref{Any}(x)
13-
REPL.with_repl_linfo(d.repl) do io
14-
if isdefined(REPL, :active_module)
15-
mod = REPL.active_module(d)::Module
16-
else
17-
mod = Main
18-
end
19-
io = IOContext(io, :limit => true, :module => mod)
20-
if OUTPUT_PROMPT !== nothing
21-
output_prompt = OUTPUT_PROMPT isa String ? OUTPUT_PROMPT : OUTPUT_PROMPT()
22-
write(io, OUTPUT_PROMPT_PREFIX)
23-
write(io, output_prompt, "\e[0m")
24-
end
25-
get(io, :color, false) && write(io, REPL.answer_color(d.repl))
26-
if isdefined(d.repl, :options) && isdefined(d.repl.options, :iocontext)
27-
# this can override the :limit property set initially
28-
io = foldl(IOContext, d.repl.options.iocontext, init=io)
29-
end
30-
show(io, mime, x[])
31-
println(io)
32-
end
33-
return nothing
34-
end
5+
import .OhMyREPL.Passes.SyntaxHighlighter.SYNTAX_HIGHLIGHTER_SETTINGS
6+
import .OhMyREPL.HIGHLIGHT_MARKDOWN
357

368
split_lines(s::AbstractString) = isdefined(Markdown, :lines) ? Markdown.lines(s) : split(s, '\n')
379

38-
function _Markdown_term(io::IO, md::Markdown.Code, columns)
10+
function Markdown.term(io::IO, md::Markdown.Code, columns)
3911
code = md.code
4012
# Want to remove potential.
4113
lang = md.language == "" ? "" : first(split(md.language))
@@ -65,11 +37,11 @@ function _Markdown_term(io::IO, md::Markdown.Code, columns)
6537
push!(outputs, "")
6638
end
6739

68-
if do_syntax && OhMyREPL.HIGHLIGHT_MARKDOWN[]
40+
if do_syntax && HIGHLIGHT_MARKDOWN[]
6941
for (i, (sourcecode, output)) in enumerate(zip(sourcecodes, outputs))
7042
tokens = collect(tokenize(sourcecode))
7143
crayons = fill(Crayon(), length(tokens))
72-
OhMyREPL.Passes.SyntaxHighlighter.SYNTAX_HIGHLIGHTER_SETTINGS(crayons, tokens, 0, sourcecode)
44+
SYNTAX_HIGHLIGHTER_SETTINGS(crayons, tokens, 0, sourcecode)
7345
buff = IOBuffer()
7446
if lang == "jldoctest" || lang == "julia-repl"
7547
print(buff, Crayon(foreground = :red, bold = true), "julia> ", Crayon(reset = true))
@@ -100,18 +72,3 @@ function _Markdown_term(io::IO, md::Markdown.Code, columns)
10072
end
10173
end
10274
end
103-
104-
_refresh_line_hook = _refresh_line
105-
106-
function activate_hooks()
107-
@eval begin
108-
LineEdit.refresh_line(s::REPL.LineEdit.BufferLike) =
109-
_refresh_line_hook(s)
110-
Markdown.term(io::IO, md::Markdown.Code, columns) =
111-
_Markdown_term(io, md, columns)
112-
end
113-
if !isdefined(REPL, :IPython)
114-
@eval REPL.display(d::REPL.REPLDisplay, mime::MIME"text/plain", x) =
115-
_REPL_display(d, mime, x)
116-
end
117-
end

src/OhMyREPL.jl

+23-34
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,12 @@ export colorscheme!, colorschemes, enable_autocomplete_brackets, enable_highligh
1717

1818
const SUPPORTS_256_COLORS = !(Sys.iswindows() && VERSION < v"1.5.3")
1919

20-
# Wrap the function `f` so that it's always invoked in the given `world_age`
21-
function fix_world_age(f, world_age)
22-
if world_age == typemax(UInt)
23-
function (args...; kws...)
24-
Base.invokelatest(f, args...; kws...)
25-
end
26-
else
27-
function (args...; kws...)
28-
Base.invoke_in_world(world_age, f, args...; kws...)
29-
end
30-
end
31-
end
32-
3320
include("repl_pass.jl")
3421
include("repl.jl")
3522
include("passes/Passes.jl")
3623

3724
include("BracketInserter.jl")
3825
include("prompt.jl")
39-
include("hooks.jl")
4026

4127
import .BracketInserter.enable_autocomplete_brackets
4228

@@ -105,47 +91,50 @@ const ENABLE_FZF = Ref(true)
10591
enable_fzf(v::Bool) = ENABLE_FZF[] = v
10692

10793
using Pkg
108-
function reinsert_after_pkg(repl, world_age)
94+
function reinsert_after_pkg()
95+
repl = Base.active_repl
10996
mirepl = isdefined(repl,:mi) ? repl.mi : repl
11097
main_mode = mirepl.interface.modes[1]
11198
m = first(methods(main_mode.keymap_dict[']']))
11299
if m.module == Pkg.REPLMode
113-
Prompt.insert_keybindings(repl, world_age)
100+
Prompt.insert_keybindings()
114101
end
115102
end
116103

117-
function setup_repl(repl, world_age)
118-
if !isdefined(repl, :interface)
119-
repl.interface = REPL.setup_interface(repl)
120-
end
121-
Prompt.insert_keybindings(repl, world_age)
122-
@async begin
123-
sleep(0.25)
124-
reinsert_after_pkg(repl, world_age)
125-
end
126-
update_interface(repl.interface)
127-
128-
global _refresh_line_hook = fix_world_age(_refresh_line, world_age)
129-
end
130-
131104
function __init__()
132105
options = Base.JLOptions()
133-
world_age = Base.get_world_counter()
134106
# command-line
135107
if (options.isinteractive != 1) && options.commands != C_NULL
136108
return
137109
end
138110

139111
if isdefined(Base, :active_repl)
140-
setup_repl(Base.active_repl, world_age)
112+
if !isdefined(Base.active_repl, :interface)
113+
Base.active_repl.interface = REPL.setup_interface(Base.active_repl)
114+
end
115+
Prompt.insert_keybindings()
116+
@async begin
117+
sleep(0.25)
118+
reinsert_after_pkg()
119+
end
141120
else
142121
atreplinit() do repl
143-
setup_repl(Base.active_repl, world_age)
122+
if !isdefined(repl, :interface)
123+
repl.interface = REPL.setup_interface(repl)
124+
end
125+
Prompt.insert_keybindings()
126+
@async begin
127+
sleep(0.25)
128+
reinsert_after_pkg()
129+
end
130+
update_interface(repl.interface)
144131
end
145132
end
146133

147134
if ccall(:jl_generating_output, Cint, ()) == 0
148-
activate_hooks()
135+
include(joinpath(@__DIR__, "refresh_lines.jl"))
136+
include(joinpath(@__DIR__, "output_prompt_overwrite.jl"))
137+
include(joinpath(@__DIR__, "MarkdownHighlighter.jl"))
149138
end
150139
end
151140

src/output_prompt_overwrite.jl

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import REPL
2+
3+
if !isdefined(REPL, :IPython)
4+
function REPL.display(d::REPL.REPLDisplay, mime::MIME"text/plain", x)
5+
x = Ref{Any}(x)
6+
REPL.with_repl_linfo(d.repl) do io
7+
if isdefined(REPL, :active_module)
8+
mod = REPL.active_module(d)::Module
9+
else
10+
mod = Main
11+
end
12+
io = IOContext(io, :limit => true, :module => mod)
13+
if OUTPUT_PROMPT !== nothing
14+
output_prompt = OUTPUT_PROMPT isa String ? OUTPUT_PROMPT : OUTPUT_PROMPT()
15+
write(io, OUTPUT_PROMPT_PREFIX)
16+
write(io, output_prompt, "\e[0m")
17+
end
18+
get(io, :color, false) && write(io, REPL.answer_color(d.repl))
19+
if isdefined(d.repl, :options) && isdefined(d.repl.options, :iocontext)
20+
# this can override the :limit property set initially
21+
io = foldl(IOContext, d.repl.options.iocontext, init=io)
22+
end
23+
show(io, mime, x[])
24+
println(io)
25+
end
26+
return nothing
27+
end
28+
end

src/precompile.jl

-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ precompile(Tuple{OhMyREPL.Passes.SyntaxHighlighter.SyntaxHighlighterSettings, Ar
55
precompile(Tuple{OhMyREPL.Passes.BracketHighlighter.BracketHighlighterSettings, Array{Crayons.Crayon, 1}, Array{JuliaSyntax.Token, 1}, Int64, String})
66
precompile(Tuple{OhMyREPL.Passes.RainbowBrackets.RainbowBracketsSettings, Array{Crayons.Crayon, 1}, Array{JuliaSyntax.Token, 1}, Int64, String})
77
precompile(Tuple{typeof(OhMyREPL.untokenize_with_ANSI), Base.IOContext{Base.GenericIOBuffer{Array{UInt8, 1}}}, OhMyREPL.PassHandler, Array{JuliaSyntax.Token, 1}, String, Int64})
8-
precompile(_refresh_line, (REPL.LineEdit.ModeState,))
9-
precompile(_refresh_line, (REPL.LineEdit.MIState,))
10-
precompile(_refresh_line, (REPL.LineEdit.IOBuffer,))
11-
precompile(_REPL_display, (REPL.REPLDisplay, MIME"text/plain", String))
12-
precompile(_Markdown_term, (IO, Markdown.Code, Int))

src/refresh_lines.jl

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import REPL.LineEdit
2+
3+
function LineEdit.refresh_line(s::REPL.LineEdit.BufferLike)
4+
LineEdit.refresh_multi_line(s)
5+
OhMyREPL.Prompt.rewrite_with_ANSI(s)
6+
end

src/repl.jl

+17-20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import REPL.Terminals: raw!, width, height, cmove, getX, TerminalBuffer,
1717
getY, clear_line, beep, disable_bracketed_paste, enable_bracketed_paste
1818

1919
using OhMyREPL
20-
import OhMyREPL: untokenize_with_ANSI, apply_passes!, PASS_HANDLER, fix_world_age
20+
import OhMyREPL: untokenize_with_ANSI, apply_passes!, PASS_HANDLER
2121

2222
if VERSION > v"1.3"
2323
import JLFzf
@@ -89,7 +89,8 @@ function rewrite_with_ANSI(s, cursormove::Bool = false)
8989
end
9090
end
9191

92-
function create_keybindings(prefix_hist_prompt, world_age)
92+
93+
function create_keybindings()
9394
D = Dict{Any, Any}()
9495
D['\b'] = (s, data, c) -> if LineEdit.edit_backspace(s, true)
9596
rewrite_with_ANSI(s)
@@ -288,33 +289,29 @@ function create_keybindings(prefix_hist_prompt, world_age)
288289
LineEdit.enter_search(s, p, true)
289290
end
290291
end
291-
292-
# Up Arrow
293-
D["\e[A"] = (s,o...)-> begin
294-
LineEdit.edit_move_up(buffer(s)) || LineEdit.enter_prefix_search(s, prefix_hist_prompt, true)
295-
Prompt.rewrite_with_ANSI(s)
296-
end
297-
# Down Arrow
298-
D["\e[B"] = (s,o...)-> begin
299-
LineEdit.edit_move_down(buffer(s)) || LineEdit.enter_prefix_search(s, prefix_hist_prompt, false)
300-
Prompt.rewrite_with_ANSI(s)
301-
end
302-
303-
OhMyREPL.BracketInserter.insert_into_keymap!(D)
304-
305-
return Dict(k=>fix_world_age(f, world_age) for (k,f) in D)
292+
return D
306293
end
294+
NEW_KEYBINDINGS = create_keybindings()
307295

308-
function insert_keybindings(repl, world_age)
296+
function insert_keybindings(repl = Base.active_repl)
309297
mirepl = (isdefined(repl,:mistate) && !isnothing(repl.mistate)) ? repl.mistate : repl
310298
interface_modes = mirepl.interface.modes
311299
main_mode = interface_modes[1]
312300
php_idx = findfirst(Base.Fix2(isa, LineEdit.PrefixHistoryPrompt), interface_modes)
313301
p = interface_modes[php_idx]
314302

315-
keybinds = create_keybindings(p, world_age)
303+
# Up Arrow
304+
NEW_KEYBINDINGS["\e[A"] = (s,o...)-> begin
305+
LineEdit.edit_move_up(buffer(s)) || LineEdit.enter_prefix_search(s, p, true)
306+
Prompt.rewrite_with_ANSI(s)
307+
end
308+
# Down Arrow
309+
NEW_KEYBINDINGS["\e[B"] = (s,o...)-> begin
310+
LineEdit.edit_move_down(buffer(s)) || LineEdit.enter_prefix_search(s, p, false)
311+
Prompt.rewrite_with_ANSI(s)
312+
end
316313

317-
main_mode.keymap_dict = LineEdit.keymap(Dict{Any, Any}[keybinds, main_mode.keymap_dict])
314+
main_mode.keymap_dict = LineEdit.keymap(Dict{Any, Any}[NEW_KEYBINDINGS, main_mode.keymap_dict])
318315
end
319316

320317
function _commit_line(s, data, c)

0 commit comments

Comments
 (0)