From 1a947dd65de23e3d4ad1c2da468c5c4e764286a3 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Tue, 5 Dec 2017 13:01:24 -0800 Subject: [PATCH] Add option to configure comint TERM * doc/emacs/misc.texi (Shell Options): Document new option * lisp/comint.el (comint-terminfo-terminal): Add new option (comint-term-environment): Add new function for setting terminal options (comint-exec-1): Use comint-term-environment * lisp/progmodes/compile.el (compilation-start): Use comint-term-environment --- doc/emacs/misc.texi | 8 ++++++++ lisp/comint.el | 35 ++++++++++++++++++++++------------- lisp/progmodes/compile.el | 8 +------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 6ad5fbafdd..1eaa2160c9 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1396,6 +1396,14 @@ Shell Options (@code{shell-pushd-dunique}). The values you choose should match the underlying shell, of course. +@vindex comint-terminfo-terminal +Comint sets the @env{TERM} environment variable to a safe value, but +this value may not reflect the full features of comint. For example, +color is disabled for some applications that use @env{TERM} to +determine if color is supported. On systems that use terminfo, you +can configure @code{comint-terminfo-terminal} to a terminal that is +present in your system's terminfo database. + @node Terminal emulator @subsection Emacs Terminal Emulator @findex term diff --git a/lisp/comint.el b/lisp/comint.el index aa7dab28f3..433eeb1fb2 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -458,6 +458,11 @@ comint-exec-hook :type 'hook :group 'comint) +(defcustom comint-terminfo-terminal "dumb" + "Value to use for TERM when the system uses terminfo." + :type 'string + :group 'comint) + (defvar comint-mode-map (let ((map (make-sparse-keymap))) ;; Keys: @@ -816,19 +821,7 @@ comint-exec (defun comint-exec-1 (name buffer command switches) (let ((process-environment (nconc - ;; If using termcap, we specify `emacs' as the terminal type - ;; because that lets us specify a width. - ;; If using terminfo, we specify `dumb' because that is - ;; a defined terminal type. `emacs' is not a defined terminal type - ;; and there is no way for us to define it here. - ;; Some programs that use terminfo get very confused - ;; if TERM is not a valid terminal type. - ;; ;; There is similar code in compile.el. - (if (and (boundp 'system-uses-terminfo) system-uses-terminfo) - (list "TERM=dumb" "TERMCAP=" - (format "COLUMNS=%d" (window-width))) - (list "TERM=emacs" - (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width)))) + (comint-term-environment) (list (format "INSIDE_EMACS=%s,comint" emacs-version)) process-environment)) (default-directory @@ -857,6 +850,22 @@ comint-exec-1 (set-process-coding-system proc decoding encoding)) proc)) +(defun comint-term-environment () + "Return an environment variable list for terminal configuration." + ;; If using termcap, we specify `emacs' as the terminal type + ;; because that lets us specify a width. + ;; If using terminfo, we default to `dumb' because that is + ;; a defined terminal type. `emacs' is not a defined terminal type + ;; and there is no way for us to define it here. + ;; Some programs that use terminfo get very confused + ;; if TERM is not a valid terminal type. + (if (and (boundp 'system-uses-terminfo) system-uses-terminfo) + (list (format "TERM=%s" comint-terminfo-terminal) + "TERMCAP=" + (format "COLUMNS=%d" (window-width))) + (list "TERM=emacs" + (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))) + (defun comint-nonblank-p (str) "Return non-nil if STR contains non-whitespace syntax." (not (string-match "\\`\\s *\\'" str))) diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 4cce47e5d8..c68001d236 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1746,13 +1746,7 @@ compilation-start (let ((process-environment (append compilation-environment - (if (if (boundp 'system-uses-terminfo);`If' for compiler warning. - system-uses-terminfo) - (list "TERM=dumb" "TERMCAP=" - (format "COLUMNS=%d" (window-width))) - (list "TERM=emacs" - (format "TERMCAP=emacs:co#%d:tc=unknown:" - (window-width)))) + (comint-term-environment) (list (format "INSIDE_EMACS=%s,compile" emacs-version)) (copy-sequence process-environment)))) (set (make-local-variable 'compilation-arguments) -- 2.15.1