Using emacs in batch mode to upload syntax highlighted file?

I would like to use emacs in some kind of batch mode to just display the file with syntax highlighting and output. In particular, I want to flush the buffer with the buffer using ANSI escape codes so that it looks syntactically allocated enough on my terminal. Is there any way to do this?

The ansi-lpr.el library seems similar to what I want, but the result is not colored, I can’t figure out how to overcome this last hurdle - there are many modules to digest ANSI escape codes in Emacs text properties (for example, ansi- color.el ), but I did not find anything that would do the opposite. If someone can point me to something that does, I think I can put it all together.

As an alternative, I saw some hacker approaches, such as this answer (using scriptand fixing the output), but in my experiments this approach would hardly be useful - you get tons of unwanted control sequences mixed with the selected text.

The general motivation here is to use emacs in the channel $LESSOPENto get syntax highlighting when working with page files. In case you say that, I tried and "just page files in Emacs" is not suitable for me.

+4
source share
1 answer

I am pleased to announce the new e2ansi package which (hopefully) does what you requested.

The package provides a command-line tool e2ansi-catthat launches Emacs in batch mode, opens files, the syntax selects them (using font lock) and creates versions of the syntax highlighted by ANSI.

You can integrate this into lessby setting the following variables, for example:

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

:

Example

, , , Emacs.

e2ansi https://github.com/Lindydancer/e2ansi

, e2ansi.

+4

Source: https://habr.com/ru/post/1545391/


All Articles