Use of semicolon during querying inside emacs no longer working

Today I noticed that pressing “;” when running a query no longer seemed to work in emacs and I am sure it used to. It runs fine from the terminal but not after compiling the buffer and being placed into the comint buffer running the session.

Running GTK emacs or emacs in the terminal (emacs -nw) gives me this;

2 ?- ap(X,Y,[a,b,c,d]).
X = [],
Y = [a, b, c, d] ;
;
X = [a],
Y = [b, c, d] .

3 ?-

I was expecting to be able to see four solutions but it stopped after showing the second one AND I had to press RETURN to get the simocolon to be recognised. It feels like the keyboard handling in the comit buffer has somehow broken?

Has a default setting changed?
Thanks.
Sean.

This definitely needs some details. Both the Emacs version as the Prolog mode matter on how they announce themselves and (I think) wish to interact with Prolog and SWI-Prolog’s options to specify terminal interaction and its heuristic to discover it runs under a dumb terminal has changed several times. Possible relevant flags are tty_control and color_term.

Yes, sorry, it was a little light on details!

GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.23.2) both GTK window and terminal.

prolog_flag() for both tty_control and color_term is true from the emacs console session and from within the prolog session in GTK emacs sessino.

I also have this in my ~/.zshrc but I don’t think it’s relevant in this situation:

136 ####
137 ##
138 ## EMACS: If we are in an emacs shell then set TERM=dumb to stop the
139 ## fancy prompts and colors polluting the buffer
140 ##
141 ####
142 if (( ${+INSIDE_EMACS} )); then
143 export TERM=dumb
144 echo “For EMACS, TERM is dumb”
145 fi

Setting tty_control to true or false seems to make no difference to the need to press Return after the semicolon character:

Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- true.

2 ?- prolog_flag(tty_control,false).
false.

3 ?- ap(X,Y,[a,b,c,d]).
X = [],
Y = [a, b, c, d] ;
;
X = [a],
Y = [b, c, d] .

4 ?- prolog_flag(tty_control,true).
true.

5 ?- ap(X,Y,[a,b,c,d]).
X = [],
Y = [a, b, c, d] ;
;
X = [a],
Y = [b, c, d] .

This should be ?- set_prolog_flag(tty_control,false).. prolog_flag/2 is from the SICStus 3 compatibility library. Note that otherwise I know very little about running Prolog under Emacs. I always run it in terminal.

Of course it should!! :man_facepalming:

And…it makes a difference! I still have to press Enter after the semicolon but at leats I get all the results I was expecting to have.

Thanks Jan.

I can only talk about the Prolog side. If tty_control is true the tracer puts the terminal in raw mode to read and react on a single character. When false the terminal stays in cooked mode, the tracer reads a line from the terminal and acts on that.

TERM=dumb should tell SWI-Prolog to disable color output and using raw mode. Possibly that was added after 8.0.3.

Things go badly wrong if Prolog puts the terminal in raw mode and the terminal sends a line, as it will then receive “; RETURN”, use the “;” for the next answer and then the RETURN to stop.

I think that’s what was happening Jan. When I first enter the session though, tty_control is reported as true which is why I couldn’t figure out why it was happening at all.

At least I know it’s an issue on my setup at least.

Thanks again.

When I run swipl in a shell under Emacs (not the *prolog* window but I presume it’s similar to *shell*), I need to specify swipl --no-tty to get semicolon behaving properly. The --no-tty commandline flag is documented as setting tty_control.

[I ran into this up a few years ago: https://groups.google.com/forum/#!topic/swi-prolog/mbC1XfGOmLY ] … Jan replied to me directly: “There is an additional check to detect ediprolog and disabling a pager for help in that case. … Please use swipl --no-tty rather than the deprecated swipl -tty.”]

Interestiing. My normal workflow is to open a file with emacs then C-c C-b to compile the buffer into a new prolog session… I will have to look into how to add the --no-tty option to the prolog command and see if it makes anuy difference, although if it is just the command line equivalent to set_prolog_flag(tty_control,false); then it won’t really help much more than I have already managed to achieve with setting that flag in the source.

Thanks all.

Sean.

It is. I’m also not convinced this is a SWI-Prolog issue. It has these two (cooked,raw) modes the only thing that changed at various times were the default rules to detect which mode to use. Well, AFAIK … Could the Emacs Prolog binding have changed?

Note that another comfortable way to use Prolog is to use the GNU emacs server extension and hook edit/1 to make the Emacs server open the right file at the right location. After editing you simply type `?- make.’ in Prolog. The added value is TAB completion, color output, etc. The downside is that you have two Windows (terminal and Emacs). Personally I like that, other people don’t.

Hi Jan,
I guess something may have changed. I will also try out with emacsclient (I have that set up on my machine anyway) … I also reported a bug to Stefan Bruda recently about his prolog mode so I do seem to be having fun lately! He hasn’t had the time to fixc it yet so I might muster up the courage to see if I can fix it myself, regarding electric indeting adding a space by a percent character but that’s another matter.

OK, wel I can see that I will stick with emacs/ediprolog/prolog.el by stefan for the forseeable future and I guess I’ll find ways to live/work with it…it’s still a great combination…

Thank you all, again!
Sean

As an update, yesterday I installed “ediprolog” and it works just fine for quering all the results in a do-what-I-mean line in the source text.

Presumably beecause the dwim code uis using emacs internal API calls to do it ?!