Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GAP REPL mode - WIP #225

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"
[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
4 changes: 4 additions & 0 deletions src/GAP.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module GAP

include(abspath(joinpath(@__DIR__, "..", "deps", "deps.jl")))
include( "repl.jl" )

"""
FFE
Expand Down Expand Up @@ -107,6 +108,9 @@ function __init__()
if ! isdefined(Main, :__GAPINTERNAL_LOADED_FROM_GAP) || Main.__GAPINTERNAL_LOADED_FROM_GAP != true
run_it(GAPROOT, error_handler_func)
end
if isdefined(Base, :active_repl)
run_gap_repl()
end
end

end
65 changes: 65 additions & 0 deletions src/repl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import REPL
import REPL: LineEdit, REPLCompletions

function CreateGAPREPL(; prompt = "gap> ", name = :gap, repl = Base.active_repl, main_mode = repl.interface.modes[1])
mirepl = isdefined(repl,:mi) ? repl.mi : repl
# Setup GAP panel
panel = LineEdit.Prompt(prompt;
# Copy colors from the prompt object
prompt_prefix=Base.text_colors[:blue],
prompt_suffix=Base.text_colors[:red],
on_enter = REPL.return_callback)
#on_enter = s->isExpressionComplete(C,push!(copy(LineEdit.buffer(s).data),0)))

panel.on_done = REPL.respond(repl,panel; pass_empty = false) do line
if !isempty(line)
:(GAP.EvalString($line) )
else
:( )
end
end

main_mode == mirepl.interface.modes[1] &&
push!(mirepl.interface.modes,panel)

# 0.7 compat
if isdefined(main_mode, :repl)
panel.repl = main_mode.repl
end

hp = main_mode.hist
hp.mode_mapping[name] = panel
panel.hist = hp

search_prompt, skeymap = LineEdit.setup_search_keymap(hp)
mk = REPL.mode_keymap(main_mode)

b = Dict{Any,Any}[skeymap, mk, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults]
panel.keymap_dict = LineEdit.keymap(b)

panel
end

global function run_gap_repl(; prompt = "gap> ", name = :gap, key = '$')
repl = Base.active_repl
mirepl = isdefined(repl,:mi) ? repl.mi : repl
main_mode = mirepl.interface.modes[1]

panel = CreateGAPREPL(; prompt=prompt, name=name, repl=repl)

# Install this mode into the main mode
gap_keymap = Dict{Any,Any}(
key => function (s,args...)
if isempty(s) || position(LineEdit.buffer(s)) == 0
buf = copy(LineEdit.buffer(s))
LineEdit.transition(s, panel) do
LineEdit.state(s, panel).input_buffer = buf
end
else
LineEdit.edit_insert(s,key)
end
end
)
main_mode.keymap_dict = LineEdit.keymap_merge(main_mode.keymap_dict, gap_keymap);
nothing
end