Subject: bug#20484: bug#20202: Considered Harmful 73d213: 'Comint, term, and compile new set Emacs'

From: Paul Eggert <[email-masked]>
Date: Sat, 9 Apr 2016 20:30:50 -0700

Stefan Monnier wrote:
> "Do the trick" to get what, exactly?

It causes the predicate 'current_prolog_flag(emacs_inferior_process, X)' to 
succeed with X=true, and it causes SWI-Prolog to not attempt to put the terminal 
into raw mode. Although the former doesn't seem to do much of anything, latter 
affects the UI, notably the debugger. For example, SWI-Prolog 7.2.3 in Emacs 24 
under M-x run-prolog:

?- trace, member(X, [a,b,c]).
    Call: (8) lists:member(_G2, [a, b, c]) ? a
% Execution Aborted
?-

The same interaction in emacs-25 now:

1 ?- trace, member(X, [a,b,c]).
    Call: (8) lists:member(_G2, [a, b, c]) ? a
abort
% Execution Aborted
2 ?-

I suppose the differences might be annoying to someone who does a lot of Prolog 
debugging. To give some perspective, although I am annoyed whenever I have to 
debug GNU Prolog under Emacs due to gprolog's mishandling of tty modes under 
Emacs, this is something I've never gotten sufficiently annoyed at to fix, even 
though it's been ten years since I first ran afoul of it.

One possible workaround would be something like the attached patch, which relies 
on SWI-Prolog's behavior of assuming GNU Emacs when INFERIOR=yes in the environment.
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index 9ee405b..fffa7cc 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -1374,8 +1374,10 @@ prolog-ensure-process
       ()
     (with-current-buffer (get-buffer-create "*prolog*")
       (prolog-inferior-mode)
-      (apply 'make-comint-in-buffer "prolog" (current-buffer)
-             (prolog-program-name) nil (prolog-program-switches))
+      (let ((process-environment
+             (cons "INFERIOR=yes" process-environment)))
+        (apply 'make-comint-in-buffer "prolog" (current-buffer)
+               (prolog-program-name) nil (prolog-program-switches)))
       (unless prolog-system
         ;; Setup auto-detection.
         (setq-local