Printing .cpp file from command line using emacs

command lineemacsprintingsource

The goal is to print a set of *.cpp files on a network printer, but… in a way that the (color) printer prints the files like they appear in the c++ editor including the colors and highlighting. And all of this from the command line.

I succeeded in sending all the files to the network printer but they are (of course) all printed in black and white (text) format.

I used : lp -d 'printername' *.cpp

Is there a way to open the files in something like emacs and pass the print command to emacs from the command line?

BTW: I'm on mac OS X.

Best Answer

I would be highly surprised if you can do such a thing directly with lp. The following is the easiest solution I could think of.

There is a LaTeX package that can help you a lot: minted. You could write a script, that generates a .tex file (probably by \input{}) and uses this package for syntax-highlighting. Then you compile it, to obtain a .pdf with the colors that you wish. Sending it to printer is than the remaining step.

Related Question