diff options
| author | Paul Eggert | 2018-05-26 13:29:06 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-06-14 13:50:31 -0700 |
| commit | b635c548c681532335b89b39e0642ecdf7bf1d9c (patch) | |
| tree | 530ff8f52368c710c18f5785b565cb4d0242da1d | |
| parent | a933ebef57cde64c90fd6d92ae34eabd705f100a (diff) | |
| download | emacs-b635c548c681532335b89b39e0642ecdf7bf1d9c.tar.gz emacs-b635c548c681532335b89b39e0642ecdf7bf1d9c.zip | |
Don’t set EMACS=t if Bash is 4.4 or newer
(Backport from master.)
(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.el | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/lisp/term.el b/lisp/term.el index 60cd547f93d..b7f5b0e7f20 100644 --- a/lisp/term.el +++ b/lisp/term.el | |||
| @@ -1520,6 +1520,31 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") | |||
| 1520 | ;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\ | 1520 | ;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\ |
| 1521 | "Termcap capabilities supported.") | 1521 | "Termcap capabilities supported.") |
| 1522 | 1522 | ||
| 1523 | ;; This private hack is for backwards compatibility with Bash 4.3 and earlier. | ||
| 1524 | ;; It can be useful even when running a program other than Bash, as the | ||
| 1525 | ;; program might invoke Bash as an interactive subshell. See this thread: | ||
| 1526 | ;; https://lists.gnu.org/r/emacs-devel/2018-05/msg00670.html | ||
| 1527 | ;; Remove this hack and its uses once Bash 4.4-or-later is reasonably | ||
| 1528 | ;; universal, because it slows down execution slightly when | ||
| 1529 | ;; term--bash-needs-EMACSp is first called. | ||
| 1530 | (defvar term--bash-needs-EMACS-status nil | ||
| 1531 | "43 if Bash is so old that it needs EMACS set. | ||
| 1532 | Some other integer if Bash is new or not in use. | ||
| 1533 | Nil if unknown.") | ||
| 1534 | (defun term--bash-needs-EMACSp () | ||
| 1535 | "t if Bash is old, nil if it is new or not in use." | ||
| 1536 | (eq 43 | ||
| 1537 | (or term--bash-needs-EMACS-status | ||
| 1538 | (setf | ||
| 1539 | term--bash-needs-EMACS-status | ||
| 1540 | (let ((process-environment | ||
| 1541 | (cons "BASH_ENV" process-environment))) | ||
| 1542 | (condition-case nil | ||
| 1543 | (call-process | ||
| 1544 | "bash" nil nil nil "-c" | ||
| 1545 | "case $BASH_VERSION in [0123].*|4.[0123].*) exit 43;; esac") | ||
| 1546 | (error 0))))))) | ||
| 1547 | |||
| 1523 | ;; This auxiliary function cranks up the process for term-exec in | 1548 | ;; This auxiliary function cranks up the process for term-exec in |
| 1524 | ;; the appropriate environment. | 1549 | ;; the appropriate environment. |
| 1525 | 1550 | ||
| @@ -1537,12 +1562,6 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") | |||
| 1537 | (format term-termcap-format "TERMCAP=" | 1562 | (format term-termcap-format "TERMCAP=" |
| 1538 | term-term-name term-height term-width) | 1563 | term-term-name term-height term-width) |
| 1539 | 1564 | ||
| 1540 | ;; This is for backwards compatibility with Bash 4.3 and earlier. | ||
| 1541 | ;; Remove this hack once Bash 4.4-or-later is common, because | ||
| 1542 | ;; it breaks './configure' of some packages that expect it to | ||
| 1543 | ;; say where to find EMACS. | ||
| 1544 | (format "EMACS=%s (term:%s)" emacs-version term-protocol-version) | ||
| 1545 | |||
| 1546 | (format "INSIDE_EMACS=%s,term:%s" emacs-version term-protocol-version) | 1565 | (format "INSIDE_EMACS=%s,term:%s" emacs-version term-protocol-version) |
| 1547 | (format "LINES=%d" term-height) | 1566 | (format "LINES=%d" term-height) |
| 1548 | (format "COLUMNS=%d" term-width)) | 1567 | (format "COLUMNS=%d" term-width)) |
| @@ -1554,6 +1573,9 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") | |||
| 1554 | ;; escape codes, so we need to see the raw output. We will have to | 1573 | ;; escape codes, so we need to see the raw output. We will have to |
| 1555 | ;; do the decoding by hand on the parts that are made of chars. | 1574 | ;; do the decoding by hand on the parts that are made of chars. |
| 1556 | (coding-system-for-read 'binary)) | 1575 | (coding-system-for-read 'binary)) |
| 1576 | (when (term--bash-needs-EMACSp) | ||
| 1577 | (push (format "EMACS=%s (term:%s)" emacs-version term-protocol-version) | ||
| 1578 | process-environment)) | ||
| 1557 | (apply 'start-process name buffer | 1579 | (apply 'start-process name buffer |
| 1558 | "/bin/sh" "-c" | 1580 | "/bin/sh" "-c" |
| 1559 | (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\ | 1581 | (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\ |