Skip to content

Commit 7266705

Browse files
committed
add support for bracket functionality when that lands in Julia
1 parent 93a960c commit 7266705

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

ext/REPLExt/REPLExt.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ include("compat.jl")
2828
# REPL mode creation #
2929
######################
3030

31+
const BRACKET_INSERT_SUPPORTED = isdefined(LineEdit, :bracket_insert_keymap) &&
32+
hasfield(REPL.Options, :auto_insert_closing_bracket)
33+
3134
struct PkgCompletionProvider <: LineEdit.CompletionProvider end
3235

3336
function LineEdit.complete_line(c::PkgCompletionProvider, s; hint::Bool = false)
@@ -183,8 +186,11 @@ function create_mode(repl::REPL.AbstractREPL, main::LineEdit.Prompt)
183186

184187
b = Dict{Any, Any}[
185188
skeymap, repl_keymap, mk, prefix_keymap, LineEdit.history_keymap,
186-
LineEdit.default_keymap, LineEdit.escape_defaults,
187189
]
190+
if BRACKET_INSERT_SUPPORTED && repl.options.auto_insert_closing_bracket
191+
push!(b, LineEdit.bracket_insert_keymap)
192+
end
193+
push!(b, LineEdit.default_keymap, LineEdit.escape_defaults)
188194
pkg_mode.keymap_dict = LineEdit.keymap(b)
189195
return pkg_mode
190196
end
@@ -195,14 +201,18 @@ function repl_init(repl::REPL.LineEditREPL)
195201
push!(repl.interface.modes, pkg_mode)
196202
keymap = Dict{Any, Any}(
197203
']' => function (s, args...)
198-
return if isempty(s) || position(LineEdit.buffer(s)) == 0
204+
if isempty(s) || position(LineEdit.buffer(s)) == 0
199205
buf = copy(LineEdit.buffer(s))
200-
LineEdit.transition(s, pkg_mode) do
206+
return LineEdit.transition(s, pkg_mode) do
201207
LineEdit.state(s, pkg_mode).input_buffer = buf
202208
end
203209
else
204-
LineEdit.edit_insert(s, ']')
205-
LineEdit.check_show_hint(s)
210+
if BRACKET_INSERT_SUPPORTED && repl.options.auto_insert_closing_bracket
211+
return LineEdit.bracket_insert_keymap[']'](s, args...)
212+
else
213+
LineEdit.edit_insert(s, ']')
214+
return LineEdit.check_show_hint(s)
215+
end
206216
end
207217
end
208218
)

0 commit comments

Comments
 (0)