Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My emacs lists strange escape characters in shell buffers:

me@ubuntu:~//configuration.template/hooks$ 
me@ubuntu:~//configuration.template/hooks$ ls
[0m[01;32mpost-commit[0m  [01;32mpost-commit~[0m  [01;32mpost-update[0m  
[01;32mpost-update~[0m  [01;32mpre-commit[0m  [01;32mpre-commit~[0m  [01;32mupdate[0m      update~

Anyone knows how I can fix that?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

These characters are color-changing control sequences. These sequences don't work in emacs *shell* buffers: instead they are displayed almost directly.

You should change your shell startup file (probably ~/.bashrc) so that ls uses colors only in terminals that support them. In practice, this is likely to mean on every terminal type other than dumb (which is the terminal type provided in *shell* buffers). The terminal type is indicated in the TERM environment variable, so you can do something like this:

if [ "$TERM" != "dumb" ]; then
  alias ls='ls --color=auto'
fi
share|improve this answer

"ansi-color-for-comint-mode" handles some color in shells. It is not perfect, but it helps. To turn it on, go to your shell and do [M-x]ansi-color-for-comint-mode-on[RET].

-John

share|improve this answer
    
cool, this helps –  zedoo Oct 23 '10 at 13:16

On a related note, if you are seeing this problem with the emacs grep command enter this at the command's prompt:

grep --color=NEVER -nH -e "searchstring" *
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.