summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-05-26 13:29:06 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2018-05-26 13:44:37 -0700
commit6fcab83600317e94ea7b915da7730a8c7e50226d (patch)
tree50435cb25915bc578e8c493d0ee0239a2f9c943e
parent7dcfdf5b14325ae7996f272f14c72810d7c84944 (diff)
downloademacs-6fcab83600317e94ea7b915da7730a8c7e50226d.tar.gz
Don’t set EMACS=t if Bash is 4.4 or newer
(Thanks to Stefan Monnier for improvements to this patch.) * lisp/term.el (term--bash-needs-EMACS-status): New var. (term--bash-needs-EMACSp): New function. (term-exec-1): Use it instead of always setting EMACS.
-rw-r--r--lisp/term.el34
1 files changed, 28 insertions, 6 deletions
diff --git a/lisp/term.el b/lisp/term.el
index 017b0221ecb..19e68ddb49e 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -1489,6 +1489,31 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.")
;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\
"Termcap capabilities supported.")
+;; This private hack is for backwards compatibility with Bash 4.3 and earlier.
+;; It can be useful even when running a program other than Bash, as the
+;; program might invoke Bash as an interactive subshell. See this thread:
+;; https://lists.gnu.org/r/emacs-devel/2018-05/msg00670.html
+;; Remove this hack and its uses once Bash 4.4-or-later is reasonably
+;; universal, because it slows down execution slightly when
+;; term--bash-needs-EMACSp is first called.
+(defvar term--bash-needs-EMACS-status nil
+ "43 if Bash is so old that it needs EMACS set.
+Some other integer if Bash is new or not in use.
+Nil if unknown.")
+(defun term--bash-needs-EMACSp ()
+ "t if Bash is old, nil if it is new or not in use."
+ (eq 43
+ (or term--bash-needs-EMACS-status
+ (setf
+ term--bash-needs-EMACS-status
+ (let ((process-environment
+ (cons "BASH_ENV" process-environment)))
+ (condition-case nil
+ (call-process
+ "bash" nil nil nil "-c"
+ "case $BASH_VERSION in [0123].*|4.[0123].*) exit 43;; esac")
+ (error 0)))))))
+
;; This auxiliary function cranks up the process for term-exec in
;; the appropriate environment.
@@ -1506,12 +1531,6 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.")
(format term-termcap-format "TERMCAP="
term-term-name term-height term-width)
- ;; This is for backwards compatibility with Bash 4.3 and earlier.
- ;; Remove this hack once Bash 4.4-or-later is common, because
- ;; it breaks './configure' of some packages that expect it to
- ;; say where to find EMACS.
- (format "EMACS=%s (term:%s)" emacs-version term-protocol-version)
-
(format "INSIDE_EMACS=%s,term:%s" emacs-version term-protocol-version)
(format "LINES=%d" term-height)
(format "COLUMNS=%d" term-width))
@@ -1523,6 +1542,9 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.")
;; escape codes, so we need to see the raw output. We will have to
;; do the decoding by hand on the parts that are made of chars.
(coding-system-for-read 'binary))
+ (when (term--bash-needs-EMACSp)
+ (push (format "EMACS=%s (term:%s)" emacs-version term-protocol-version)
+ process-environment))
(apply 'start-process name buffer
"/bin/sh" "-c"
(format "stty -nl echo rows %d columns %d sane 2>/dev/null;\