all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Eli Barzilay <eli@barzilay.org>,
	emacs-devel@gnu.org, monnier@iro.umontreal.ca,
	20202-done@debbugs.gnu.org, 20484@debbugs.gnu.org,
	phillip.lord@russet.org.uk
Subject: Re: EMACS=t Joy and Happiness
Date: Sat, 26 May 2018 13:54:46 -0700	[thread overview]
Message-ID: <e81387b2-4135-573c-c839-cf0972bfd56c@cs.ucla.edu> (raw)
In-Reply-To: <831sdyanny.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

Eli Zaretskii wrote:

> I like it because it is future proof, and makes our burden of
> remembering this issue easier.
> 
> Thanks.

You're welcome. Stefan privately emailed me some helpful comments that improved 
the patch (thanks!), and I installed the attached into master. In the hope that 
this has laid Bug#20202 to rest (at least on modern GNU systems running Bash 4.4 
or later), I'm boldly closing the bug report.

[-- Attachment #2: 0001-Don-t-set-EMACS-t-if-Bash-is-4.4-or-newer.txt --]
[-- Type: text/plain, Size: 3257 bytes --]

From 6fcab83600317e94ea7b915da7730a8c7e50226d Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 26 May 2018 13:29:06 -0700
Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20set=20EMACS=3Dt=20if=20Bash=20i?=
 =?UTF-8?q?s=204.4=20or=20newer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

(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.
---
 lisp/term.el | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/lisp/term.el b/lisp/term.el
index 017b022..19e68dd 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -1489,6 +1489,31 @@ term-termcap-format
   ;; 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 @@ term-exec-1
 	   (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 @@ term-exec-1
 	;; 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;\
-- 
2.7.4


  parent reply	other threads:[~2018-05-26 20:54 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-24 20:46 EMACS=t Joy and Happiness Phillip Lord
2018-05-24 20:52 ` Stefan Monnier
2018-05-24 20:52 ` bug#20202: " Stefan Monnier
2018-05-24 22:03 ` Paul Eggert
2018-05-24 22:03 ` Paul Eggert
2018-05-25  2:25   ` bug#20202: " Van L
2018-05-25  6:11     ` Ricardo Wurmus
2018-05-25  7:12       ` Van L
2018-05-25  6:11     ` bug#20202: " Ricardo Wurmus
2018-05-25  6:11     ` bug#20484: " Ricardo Wurmus
2018-05-25 17:59     ` bug#20202: " Paul Eggert
2018-05-25 17:59     ` bug#20484: " Paul Eggert
2018-05-25 17:59     ` Paul Eggert
2018-05-26  0:17       ` Van L
2018-05-26  7:41         ` Eli Zaretskii
2018-05-26 10:07           ` Van L
2018-05-26 10:57             ` Eli Zaretskii
2018-05-26  0:43       ` Van L
2018-05-25  6:16   ` Eli Zaretskii
2018-05-25  7:28     ` bug#20484: " Van L
2018-05-25  7:28     ` Van L
2018-05-25  8:02       ` bug#20484: " Eli Zaretskii
2018-05-25  8:02       ` Eli Zaretskii
2018-05-26  0:01         ` Van L
2018-05-25  8:02       ` bug#20202: " Eli Zaretskii
2018-05-25  7:28     ` Van L
2018-05-25 17:50     ` Paul Eggert
2018-05-25  6:16   ` bug#20202: " Eli Zaretskii
2018-05-25  6:16   ` bug#20484: " Eli Zaretskii
2018-05-25 22:34   ` Phillip Lord
2018-05-24 22:03 ` Paul Eggert
2018-05-25 20:36 ` Paul Eggert
2018-05-25 22:49   ` bug#20202: " Phillip Lord
2018-05-26  7:20   ` bug#20484: " Eli Zaretskii
2018-05-26 20:54     ` bug#20202: " Paul Eggert
2018-05-26 20:54     ` bug#20484: " Paul Eggert
2018-05-26 20:54     ` Paul Eggert [this message]
2018-05-31 21:07       ` bug#20202: " Phillip Lord
2018-05-31 23:45         ` Paul Eggert
2018-06-01  1:56           ` bug#20484: " Stefan Monnier
2018-06-01  1:56           ` bug#20202: " Stefan Monnier
2018-06-01  1:56           ` Stefan Monnier
2018-06-01  7:04           ` Eli Zaretskii
2018-06-01 14:08             ` Paul Eggert
2018-06-01 14:14               ` bug#20484: " Eli Zaretskii
2018-06-14 20:54                 ` bug#20202: " Paul Eggert
2018-06-14 20:54                 ` Paul Eggert
2018-06-14 20:54                 ` bug#20484: " Paul Eggert
2018-06-01 14:08             ` bug#20202: " Paul Eggert
2018-06-01 14:08             ` bug#20484: " Paul Eggert
2018-06-01  7:04           ` Eli Zaretskii
2018-06-01  7:04           ` bug#20202: " Eli Zaretskii
2018-05-31 23:45         ` bug#20484: " Paul Eggert
2018-05-31 23:45         ` bug#20202: " Paul Eggert
2018-05-25 20:36 ` bug#20484: " Paul Eggert
2018-05-25 20:36 ` bug#20202: " Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e81387b2-4135-573c-c839-cf0972bfd56c@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=20202-done@debbugs.gnu.org \
    --cc=20484@debbugs.gnu.org \
    --cc=eli@barzilay.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=phillip.lord@russet.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.