Update bazel's emacs check for 25.1's INSIDE_EMACS move.
History in
https://github.com/emacs-mirror/emacs/blo[]f125aa3de06fa0180a83ec7b5a26970309eeeb6/etc/NEWS#L1769-L1773
RELNOTES: Emacs' [C-x `], a.k.a. next-error, works again in emacsen >= 25.1
--
MOS_MIGRATED_REVID=131851164
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 3c5bdab..1af27f2 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -224,15 +224,25 @@
return unlink(file_path.c_str()) == 0;
}
+bool IsEmacsTerminal() {
+ string emacs = getenv("EMACS") == nullptr ? "" : getenv("EMACS");
+ string inside_emacs =
+ getenv("INSIDE_EMACS") == nullptr ? "" : getenv("INSIDE_EMACS");
+ // GNU Emacs <25.1 (and ~all non-GNU emacsen) set EMACS=t, but >=25.1 doesn't
+ // do that and instead sets INSIDE_EMACS=<stuff> (where <stuff> can look like
+ // e.g. "25.1.1,comint"). So we check both variables for maximum
+ // compatibility.
+ return emacs == "t" || inside_emacs != "";
+}
+
// Returns true iff both stdout and stderr are connected to a
// terminal, and it can support color and cursor movement
// (this is computed heuristically based on the values of
// environment variables).
bool IsStandardTerminal() {
string term = getenv("TERM") == nullptr ? "" : getenv("TERM");
- string emacs = getenv("EMACS") == nullptr ? "" : getenv("EMACS");
if (term == "" || term == "dumb" || term == "emacs" || term == "xterm-mono" ||
- term == "symbolics" || term == "9term" || emacs == "t") {
+ term == "symbolics" || term == "9term" || IsEmacsTerminal()) {
return false;
}
return isatty(STDOUT_FILENO) && isatty(STDERR_FILENO);
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 68fd9bb..0472ddc 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -64,6 +64,9 @@
// Returns true on success. In case of failure sets errno.
bool UnlinkPath(const string &file_path);
+// Returns true iff the current terminal is running inside an Emacs.
+bool IsEmacsTerminal();
+
// Returns true iff the current terminal can support color and cursor movement.
bool IsStandardTerminal();
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index 2119d45..87560b8 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -443,8 +443,7 @@
}
command_arguments_.push_back("--client_cwd=" + blaze::ConvertPath(cwd));
- const char *emacs = getenv("EMACS");
- if (emacs != NULL && strcmp(emacs, "t") == 0) {
+ if (IsEmacsTerminal()) {
command_arguments_.push_back("--emacs");
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java
index f322394..60e8741 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java
@@ -112,8 +112,9 @@
@Option(name = "emacs",
defaultValue = "false",
category = "undocumented",
- help = "A system-generated parameter which is true iff EMACS=t in the environment of "
- + "the client. This option controls certain display features.")
+ help = "A system-generated parameter which is true iff EMACS=t or INSIDE_EMACS is set "
+ + "in the environment of the client. This option controls certain display "
+ + "features.")
public boolean runningInEmacs;
@Option(name = "show_timestamps",