diff options
| author | Paul Eggert | 2018-05-26 13:29:06 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-05-26 13:44:37 -0700 |
| commit | 6fcab83600317e94ea7b915da7730a8c7e50226d (patch) | |
| tree | 50435cb25915bc578e8c493d0ee0239a2f9c943e | |
| parent | 7dcfdf5b14325ae7996f272f14c72810d7c84944 (diff) | |
| download | emacs-6fcab83600317e94ea7b915da7730a8c7e50226d.tar.gz emacs-6fcab83600317e94ea7b915da7730a8c7e50226d.zip | |
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.el | 34 |
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.") | |||
| 1489 | ;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\ | 1489 | ;; don't define :te=\\E[2J\\E[?47l\\E8:ti=\\E7\\E[?47h\ |
| 1490 | "Termcap capabilities supported.") | 1490 | "Termcap capabilities supported.") |
| 1491 | 1491 | ||
| 1492 | ;; This private hack is for backwards compatibility with Bash 4.3 and earlier. | ||
| 1493 | ;; It can be useful even when running a program other than Bash, as the | ||
| 1494 | ;; program might invoke Bash as an interactive subshell. See this thread: | ||
| 1495 | ;; https://lists.gnu.org/r/emacs-devel/2018-05/msg00670.html | ||
| 1496 | ;; Remove this hack and its uses once Bash 4.4-or-later is reasonably | ||
| 1497 | ;; universal, because it slows down execution slightly when | ||
| 1498 | ;; term--bash-needs-EMACSp is first called. | ||
| 1499 | (defvar term--bash-needs-EMACS-status nil | ||
| 1500 | "43 if Bash is so old that it needs EMACS set. | ||
| 1501 | Some other integer if Bash is new or not in use. | ||
| 1502 | Nil if unknown.") | ||
| 1503 | (defun term--bash-needs-EMACSp () | ||
| 1504 | "t if Bash is old, nil if it is new or not in use." | ||
| 1505 | (eq 43 | ||
| 1506 | (or term--bash-needs-EMACS-status | ||
| 1507 | (setf | ||
| 1508 | term--bash-needs-EMACS-status | ||
| 1509 | (let ((process-environment | ||
| 1510 | (cons "BASH_ENV" process-environment))) | ||
| 1511 | (condition-case nil | ||
| 1512 | (call-process | ||
| 1513 | "bash" nil nil nil "-c" | ||
| 1514 | "case $BASH_VERSION in [0123].*|4.[0123].*) exit 43;; esac") | ||
| 1515 | (error 0))))))) | ||
| 1516 | |||
| 1492 | ;; This auxiliary function cranks up the process for term-exec in | 1517 | ;; This auxiliary function cranks up the process for term-exec in |
| 1493 | ;; the appropriate environment. | 1518 | ;; the appropriate environment. |
| 1494 | 1519 | ||
| @@ -1506,12 +1531,6 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") | |||
| 1506 | (format term-termcap-format "TERMCAP=" | 1531 | (format term-termcap-format "TERMCAP=" |
| 1507 | term-term-name term-height term-width) | 1532 | term-term-name term-height term-width) |
| 1508 | 1533 | ||
| 1509 | ;; This is for backwards compatibility with Bash 4.3 and earlier. | ||
| 1510 | ;; Remove this hack once Bash 4.4-or-later is common, because | ||
| 1511 | ;; it breaks './configure' of some packages that expect it to | ||
| 1512 | ;; say where to find EMACS. | ||
| 1513 | (format "EMACS=%s (term:%s)" emacs-version term-protocol-version) | ||
| 1514 | |||
| 1515 | (format "INSIDE_EMACS=%s,term:%s" emacs-version term-protocol-version) | 1534 | (format "INSIDE_EMACS=%s,term:%s" emacs-version term-protocol-version) |
| 1516 | (format "LINES=%d" term-height) | 1535 | (format "LINES=%d" term-height) |
| 1517 | (format "COLUMNS=%d" term-width)) | 1536 | (format "COLUMNS=%d" term-width)) |
| @@ -1523,6 +1542,9 @@ Using \"emacs\" loses, because bash disables editing if $TERM == emacs.") | |||
| 1523 | ;; escape codes, so we need to see the raw output. We will have to | 1542 | ;; escape codes, so we need to see the raw output. We will have to |
| 1524 | ;; do the decoding by hand on the parts that are made of chars. | 1543 | ;; do the decoding by hand on the parts that are made of chars. |
| 1525 | (coding-system-for-read 'binary)) | 1544 | (coding-system-for-read 'binary)) |
| 1545 | (when (term--bash-needs-EMACSp) | ||
| 1546 | (push (format "EMACS=%s (term:%s)" emacs-version term-protocol-version) | ||
| 1547 | process-environment)) | ||
| 1526 | (apply 'start-process name buffer | 1548 | (apply 'start-process name buffer |
| 1527 | "/bin/sh" "-c" | 1549 | "/bin/sh" "-c" |
| 1528 | (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\ | 1550 | (format "stty -nl echo rows %d columns %d sane 2>/dev/null;\ |