Strange error output with emacs eshell (possibly related to zsh?)

134 views Asked by At

I'm new to Emacs and am trying to use eshell. Unfortunately, when I have errors in a C file, for example, I receive some odd error output (this is just an example; the particular error isn't important):

^[[1m2-2.c:18:18: ^[[0m^[[0;1;31merror: ^[[0m^[[1mexpected ';' after expression^[[0m
    c = getchar()
^[[0;1;32m                 ^
^[[0m^[[0;32m                 ;
^[[0m^[[1m2-2.c:21:5: ^[[0m^[[0;1;31merror: ^[[0m^[[1muse of undeclared identifier 's'^[[0m
    s[i] = c;
^[[0;1;32m    ^
^[[0m2 errors generated.

I'm not sure what all of this means. I'm using zsh, rather than normal bash, so maybe that has something to do with it?

If I run the same file in my normal terminal, of course I still receive errors, but it is readable.

2

There are 2 answers

0
shakurov On

This is your compiler trying to be nice and format the output using color and things like bold font face. What's strange is that it should work just fine out of the box. Try inspecting the eshell-output-filter-functions variable:

C-h v eshell-output-filter-functions

For me, the value of the variable is

(eshell-postoutput-scroll-to-bottom eshell-handle-control-codes eshell-handle-ansi-color eshell-watch-for-password-prompt)

If you miss some of those elements from the list, try adding them manually:

(add-to-list 'eshell-output-filter-functions 'eshell-handle-ansi-color)
(add-to-list 'eshell-output-filter-functions 'eshell-handle-control-codes)

If you're using an older version of Emacs, there will be no functions like eshell-handle-control-codes and you will have to define them yourself. See this wiki page for an example.

PS. This is probably unrelated, but you should give compilation mode a try. M-x compile.

0
Tim X On

What you are seeing are ansi escape sequences. Most terminal emulators will interpret these as different text properties, such as bold, various colours etc.

Emacs is usually pretty good at handling this and by default, there should be an output filter which is able to handle these control codes. Either your running an old version of emacs or for some reason, the output filters in eshell have been changed.

Try running emacs with the -q switch and open eshell and run your compilation. If you still see the control characters, then you need to try setting the eshell output filter functions to add ansi-colour support. If you don't see the control codes, then something in your init file is either removing or breaking the output filters.

This is vary unlikely to be related to zsh. In fact, you will probably find that emacs is using sh or bash 'under the ood' anyway. Note also that emacs has more sophisticated support for building programs. Have a look at Compiling and Testing Programs in the Emacs info manual. Depending on your language, you can streamline your compilation process to make compiling programs more interactive with easy ways to trigger re-compile and jump between compiler errors and your code etc. It can take a little bit of work initially, especially if your compiler or language is soemthing emacs does not understand 'out of the box', but it is well worth it. You can even do some really funky things like edit code locally and compile the changes on remote servers etc.

Finally, if you just want to get going and not spend more time tweaking emacs right now, you can look at the compiler options. Most compilers will have a way to disable the control codes. Look for things like 'turn off colours' or error message formatting etc.