From 8ed529f0f300487600ac49cff22cce09c45db94b Mon Sep 17 00:00:00 2001 From: Allen Li Date: Fri, 15 Dec 2017 11:30:25 +0200 Subject: [PATCH] Add option to configure comint TERM * lisp/comint.el (comint-terminfo-terminal): New defcustom. (comint-term-environment): New function for setting terminal options (comint-exec-1): Use comint-term-environment. (Bug#29583) * lisp/progmodes/compile.el (compilation-start): Use comint-term-environment. * etc/NEWS: * doc/emacs/misc.texi (Shell Options): Document the new option. --- doc/emacs/misc.texi | 9 +++++++++ etc/NEWS | 7 +++++++ lisp/comint.el | 35 ++++++++++++++++++++++------------- lisp/progmodes/compile.el | 8 +------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 6ad5fbafdd6..b6b396af8f5 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1396,6 +1396,15 @@ directory stack if they are not already on it (@code{shell-pushd-dunique}). The values you choose should match the underlying shell, of course. +@vindex comint-terminfo-terminal +Comint mode sets the @env{TERM} environment variable to a safe default +value, but this value disables some useful features. For example, +color is disabled for applications that use @env{TERM} to determine if +color is supported. Therefore, Emacs provides an option +@code{comint-terminfo-terminal}, which you can set to a terminal that +is present in your system's terminfo database, in order to take +advantage of advanced features of that terminal. + @node Terminal emulator @subsection Emacs Terminal Emulator @findex term diff --git a/etc/NEWS b/etc/NEWS index 6151543ee4e..784c608041b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -812,6 +812,13 @@ whose content matches a regexp; bound to '% g'. *** New user option 'comint-move-point-for-matching-input' to control where to place point after 'C-c M-r' and 'C-c M-s'. ++++ +*** New user option 'comint-terminfo-terminal'. +This option allows control of the value of the TERM environment +variable Emacs puts into the environment of the Comint mode and its +derivatives, such as Shell mode and Compilation Shell minor-mode. The +default is "dumb", for compatibility with previous behavior. + ** Compilation mode --- diff --git a/lisp/comint.el b/lisp/comint.el index dcf1ff794f9..7c56c259c49 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -459,6 +459,11 @@ executed once when the buffer is created." :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: @@ -817,19 +822,7 @@ series of processes in the same Comint buffer. The hook (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 @@ -858,6 +851,22 @@ series of processes in the same Comint buffer. The hook (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 4cce47e5d8c..c68001d2366 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1746,13 +1746,7 @@ Returns the compilation buffer created." (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.39.2