Skip to content

Commit

Permalink
Update bazel's emacs check for 25.1's INSIDE_EMACS move.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Googler authored and aehlig committed Sep 1, 2016
1 parent 099059e commit 957f374
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/main/cpp/blaze_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,25 @@ bool UnlinkPath(const string &file_path) {
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);
Expand Down
3 changes: 3 additions & 0 deletions src/main/cpp/blaze_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ bool WriteFile(const string &content, const string &filename);
// 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();

Expand Down
3 changes: 1 addition & 2 deletions src/main/cpp/option_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ void OptionProcessor::AddRcfileArgsAndOptions(bool batch, const string& cwd) {
}
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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public static class Options extends OptionsBase {
@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",
Expand Down

0 comments on commit 957f374

Please sign in to comment.