e2ansi is a package that provides Emacs powered syntax highlighting support for “less” and other command line tools, written by Anders Lindgren.

The package provides a command-line tool e2ansi-cat that starts Emacs in batch mode, opens files, syntax highlight them (using font-lock), and creates ANSI-colored versions of the syntax highlighted files.

You can integrate this into `less` by setting the following variables to, for example:

    export "LESSOPEN=|emacs --batch -Q -l ~/.emacs -l bin/e2ansi-cat %s"
    export "LESS=-R"
    export MORE=$LESS

The end result looks like the following:


You can vary the colors and attributes like bold, underline, and italics by using a suitable Emacs theme.

Getting the package

The e2ansi package is located on Github.