I wrote a simple emacs handler in SWI-Prolog around 2010, which have been working stable based on asynchronous communication start-process. However recently enter key is found not working as was expected. Fortunately I could fix it, though spending much time and efforts. Here is one of bi-products of the fix. Now it can mimic one of Ediprolog mode features. See sample log for samle queries below.
The following codes is added for the new feature. I tried not to use cut (!) in ugly way, but there I had to use destructive non-backtrackable nb_setarg/3. Without that the codes got dirty for my feeling, though perhaps due to my limitation. I appreciate for elegant way of writing prolog codes for such typical “case” sentence.
user:solve_query(H) :-
term_codes(Q, H, [variable_names(Vs)]),
solve_and_answer(ans_count(0), Q, Vs).
%
solve_and_answer(_, Q, []):-!,
( Q -> A = true
; A = false
),
send_text(["\n", A, ".\n"]).
solve_and_answer(F, Q, Vs):-
( Q,
maplist(display_bind, Vs),
nb_setarg(1, F, 1), % destructive non-backtracable setarg
once(ask_next_key(P)),
( P == next -> send_text(";"), fail
; P == stop -> send_text(".\nstop.\n"), !
; send_text("\nstop.\n"), !
)
; arg(1, F, 0) -> send_text("\nfalse.\n")
; send_text("\nno more.\n")
).
%
display_bind(X=_) :- sub_atom(X, 0, 1, _, '_'), !.
display_bind(Pair) :-
format(string(S), "\n~w", [Pair]),
send_text([S]).
%
ask_next_key(P) :-
call_lisp('read-prolog-interaction-event'(), term(P)).
?- member(b, [a,b,c]).
true.
?- member(d, [a,b,c]).
false.
?- member(X, [a,b,c]).
X=a;
X=b;
X=c;
no more.
?- member(X, [a,b,c]).
X=a.
stop.
?- append(X, Y, [a,b,c]).
X=[]
Y=[a,b,c];
X=[a]
Y=[b,c];
X=[a,b]
Y=[c];
X=[a,b,c]
Y=[];
no more.
?- append(X, X, [a,b,c]).
false.