1

I would like to use emacs to "render" text to an output file.

Is there a way to export the buffer with all font-locking to a file?

(The exact format may not matter HTML or terminal-escaped colors would both be fine).

Some options I'm aware of but aren't quite what I'm after.


  • Cairo SVG screenshot...

    • Being a screenshot makes this less useful for writing a whole text buffer, although in theory and off screen buffer could be made very tall I suppose.
    • SVG isn't so easy to manipulate (search, convert into other text format).
  • Terminal screenshot...

    • Again, it's limited to a "screen", not so convenient to dump an entire buffer.

.. Of course it's possible to do tricks like capturing regions and joining them together, this can work but isn't trivial and seems like a last resort.


Are there any solutions that export the entire buffer as it's displayed on-screen?

ideasman42
  • 8,375
  • 1
  • 28
  • 105

1 Answers1

3

There are several packages for this, including:

  • ps-print -- Renders a buffer as postscript for printing (standard package)
  • htmlfontify -- Convert a buffer to html (standard package)
  • htmlize -- Another package for converting a buffer to html. Even though this is not included in the standard Emacs distribution, it is widely used.
  • e2ansi -- Renders a buffer using ANSI sequences for display in a terminal (useful in batch mode, e.g. as highlighter for more).

If you plan to write your own package that export it to another format you can base it on face-explorer (which was developed as part of the e2ansi project). It handles all the hairy low-level details, and works in batch mode.

Note: I'm the author of e2ansi and face-explorer.

Lindydancer
  • 6,095
  • 1
  • 13
  • 25