3

Feature

There is a nice built-in Emacs feature to colorize strings with ANSI color escape sequences. So evaluating the following Elisp code, will insert the "Test text" at the point with proper colors.

(require 'ansi-color)
(insert (ansi-color-apply "^[[33mTest text^[[0m"))

enter image description here

Problem

I tried to use the ansi-color-apply function to colorize the results of my Org Babel code blocks using :post with the following filter block.

#+name:ansi-colorize
#+begin_src emacs-lisp :var input="[33mTest text[0m" :results raw

    (ansi-color-apply input)

#+end_src

#+RESULTS: ansi-colorize
Test text

Which only removes the color escape sequences, but the inserted text has no proper face attributes.:

enter image description here

Notes:

Since ansi-color-apply is a pure function, therefore does its job right and returns with:

#("Test text" 0 9 (font-lock-face (foreground-color . "#E6DB74")))

Which does not have the expected effect when the result is inserted by Org Babel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.