Subject: bug#45095: [PATCH] lisp/progmodes/compile.el: only use comint-term-environment under comint

From: Alyssa Ross <[email-masked]>
Date: Mon, 7 Dec 2020 09:04:51 +0000

comint-term-environment is used for configuring the environment for
terminal output under comint.  If compile is being used with a
different major mode, that mode probably can't handle the fancy
terminfo output that comint can, so comint-term-environment should
only be used under comint or a derived mode.

; Tested with emacs -Q as follows:
;
;  (1) Set comint-terminfo-terminal to "dumb-emacs-ansi", provided by
;      recent ncurses:
;
;          (setq comint-terminfo-terminal "dumb-emacs-ansi") C-x C-e
;
;  (2) Verify that no uninterpreted control characters are displayed by
;          (compile "grep --color=auto Emacs README") C-x C-e
;
;  (3) Verify that grep knows it can output color when using comint:
;          (compile "grep --color=auto Emacs README" t) C-x C-e
;
; Prior to this change, grep in (2) would output control characters,
; which would be displayed uninterpreted in the buffer.
---
I haven't got my copyright papers sorted yet, so hopefully this change
is also small enough that that doesn't matter.

 lisp/progmodes/compile.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 787f5d5ef3..b4bcc3f2d2 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -1868,7 +1868,8 @@ compilation-start
       (let ((process-environment
 	     (append
 	      compilation-environment
-              (comint-term-environment)
+              (when (derived-mode-p 'comint-mode)
+                (comint-term-environment))
 	      (list (format "INSIDE_EMACS=%s,compile" emacs-version))
 	      (copy-sequence process-environment))))
 	(set (make-local-variable 'compilation-arguments)
-- 
2.27.0