I'm using the *compilation* buffer to build a C++ application on Centos 5 and Centos 6. The buffer shows the build and includes references to files that are part of the build. However, I'm getting control characters like ^[ appear in the output and it is hard to read and emacs is getting corrupted filenames when you click one in the output. I think these characters are some kind of coloring or other annotation on the compiler output but I don't know where they are coming from. Here is sample output:

^[[01m^[[K../machind/lmcrypt.c:^[[m^[[K In function  ^[[01m^[[Kmain^[[m^[[K :
^[[01m^[[K../machind/lmcrypt.c:156:47:^[[m^[[K ^[[01;35m^[[Kwarning: ^[[m^[[Kcast to pointer from integer of different size [-Wint-to-pointer-cast]
     lc_set_attr(lm_job, LM_A_MAX_LICENSE_LEN, (LM_A_VAL_TYPE)max);
^[[01;32m^[[K                                               ^^[[m^[[K

How can I get rid of the non-text output in my compilation buffer?

  • 2
    Those look like VT100 Color and formatting escapes. You might try disabling colors by passing -fdiagnostics-color=never to gcc (assuming that gcc is your cc)
    – PythonNut
    Feb 10, 2015 at 21:24
  • As the ansi-color-apply-on-region could be slow, I have written up this snippet few weeks back: de-ansi.el. I did not intend it to be a package and so it has dependencies on the key-chords package and on my temporary minor mode temp-mode.el. You also need to be on emacs 24.4 or later for the file-notify feature. Feb 10, 2015 at 21:49

1 Answer 1


These are indeed escape sequences which the terminal should interpret as orders to change the text color. Normally they shouldn't be used when the compiler is invoked from Emacs (the terminal type should be set to dumb, which should cause the compiler to refrain from using any escape sequence). There may be something wrong in your configuration that causes colors to be used when they shouldn't. But you can make Emacs recognize the escape sequences with the ansi-color package.

Something like this should make compilation buffers handle ANSI escape sequences instead of displaying them as raw strings.

(require 'ansi-color)
(defun my/ansi-colorize-buffer ()
  (let ((buffer-read-only nil))
    (ansi-color-apply-on-region (point-min) (point-max))))
(add-hook 'compilation-filter-hook 'my/ansi-colorize-buffer)
  • 2
    Extremely useful. Works in Emacs 26.1.
    – Lalylulelo
    Nov 30, 2018 at 10:36
  • 1
    This re-colors the whole buffer each time it runs (and resulted in coloring all text to the last foreground color for me). This hook sets "compilation-filter-start" to the start of the region inserted with point moved to the end. So I would use those instead of (point-min) and (point-max).
    – gct
    Jan 28, 2019 at 17:26
  • Good stuff, thank you! Together with compilation-filter-start and (point) it works for me.
    – M-x
    Nov 14, 2023 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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