I'd like to run the gprolog interactive interpreter in an Emacs sub-process shell (started with M-x shell).

The interactive interpret starts without a problem, but it does not respond to some keystrokes as expected.

To illustrate the problem, I first show a simple interaction as it occurs when I run gprolog in a "top-level shell" (i.e. not one running as a subprocess of Emacs).

(In the excerpts below, please regard the delimiters << and >> as "markup" to indicate the text I type. In the actual interaction, I don't type any << or >> sequences. Neither do I type the characters, which I'm using only to indicate the position of point. With the exception of the text enclosed by <<...>> and , all text shown in the excerpts below is produced by gprolog.)

Staring from top-level shell

First I type the following query:

| ?- <<member(X, [a,b,c]).>>▮

Then I hit the Enter key (shown below as [RET]):

| ?- <<member(X, [a,b,c]).[RET]>>

X = a ? ▮

Now I hit ; once:

| ?- <<member(X, [a,b,c]).[RET]>>

X = a ? <<;>>

X = b ? ▮

Note that pressing ; was all that I had to do to elicit the next response from gprolog.

Finally I hit ; twice more, thereby exhausting the list of remaining results:

| ?- <<member(X, [a,b,c]).[RET]>>

X = a ? <<;>>

X = b ? <<;>>

X = c ? <<;>>

| ?- ▮

Staring from Emacs sub-process shell

Next I show what an attempt to run the same interaction in an instance of gprolog invoked from an Emacs sub-process shell.

Up to this point, it looks the same as before:

| ?- <<member(X, [a,b,c]).[RET]>>

X = a ? ▮

But now, if when I press ;, the semicolon character gets inserted, but gprolog does not respond:

| ?- <<member(X, [a,b,c]).[RET]>>
X = a ? <<;>>▮

If now I hit Enter, gprolog (basically) prints out one more result and terminates the query (prematurely):

| ?- <<member(X, [a,b,c]).[RET]>>

X = a ? <<;[RET]>>

X = b ? 

| ?- ▮

I encountered a similar problem with swipl (Swiss-Prolog), but found that starting it with the -tty flag made it usable under an Emacs sub-process shell (though the interface behaves a little differently).

I did not find anything like swipl's -tty flag for gprolog.

  • What about using M-x run-prolog instead of M-x shell?
    – npostavs
    Feb 23, 2017 at 16:07
  • @npostavs: That works very nicely, thank you. I'll gladly accept it if you post it as an answer.
    – kjo
    Feb 23, 2017 at 16:27

1 Answer 1


The best way to run an interactive prolog session under Emacs is to use M-x run-prolog. It includes the code needed to send single characters at a time, rather than the line-based interaction of M-x shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.