Subject: bug#21041: 24.3; emacsclient doesn't discover ansi-term correctly

From: Noam Postavsky <[email-masked]>
Date: Mon, 23 Jul 2018 21:20:09 -0400

merge 21041 22639
tags 21041 + patch
quit

Philipp Stephani <[email-masked]> writes:

> M-x ansi-term RET RET
> emacsclient -t
>
> Expected: emacsclient shows an error message
> Actual: Emacs frame opened inside ansi-term

And then gets stuck, as described in Bug#22639.

> term.el sets TERM to eterm-color, but emacsclient.c checks only for
> eterm (exact match).  I'd suggest to introduce more defensive checks in
> emacsclient.c:  abort whenever either TERM starts with eterm (prefix
> match) or INSIDE_EMACS is set.

I think "or" is too aggressive, "and" makes more sense.  "eterm" is
somewhat generic, there used to be a non-Emacs related terminal emulator
called that.

>From d9d779ebe7d62e9ea928ead61a7c345f8eb2058a Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Mon, 23 Jul 2018 21:01:01 -0400
Subject: [PATCH] Fix emacsclient check for term.el buffer (Bug#21041)

* lib-src/emacsclient.c (find_tty): Check for any TERM value with
prefix of "eterm", not just "eterm" itself.  Also check for ",term:"
in INSIDE_EMACS value.
---
 lib-src/emacsclient.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index b139b2fe3f..b0243f99c2 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1114,7 +1114,9 @@ find_tty (const char **tty_type, const char **tty_name, int noabort)
 	}
     }
 
-  if (strcmp (type, "eterm") == 0)
+  const char *inside_emacs = egetenv ("INSIDE_EMACS");
+  if (inside_emacs && strstr (inside_emacs, ",term:")
+      && strprefix ("eterm", type))
     {
       if (noabort)
 	return 0;
-- 
2.11.0