Printing from Emacs

Emacs offers several commands for printing buffers and regions. To print a buffer with page numbers and headers for the filename, type ESC x print-buffer RETURN or select Print Buffer from the Tools menu. This command takes the entire buffer and sends it to pr (a program that does simple formatting for listings), followed by lpr (which sends the listing to the printer). [33] If you want to print the file directly, without the headers and page numbers that pr provides, give the command ESC x lpr-buffer RETURN. You can also use these commands to print a selected portion of a file. First define a region by setting a mark at one end and moving the cursor to the other end. Then give the command ESC x print-region RETURN (or ESC x lpr-region RETURN) or select Print Region from the Tools menu.

The lpr-buffer and lpr-region commands always check the variable lpr-switches to determine if there are any options that should be passed to the UNIX lpr command. These options are used to request a particular printer and for many other purposes; see the UNIX reference manual’s discussion of lpr for more information. For example, if you want to use the printer named “lpt1” whenever you print from Emacs, you would want to set lpr-switches to “-Plpt1.” To do so, add the following line to your .emacs file:

(setq lpr-switches '("-Plpt1"))

Note the single quote preceding, and the parentheses surrounding, the string <">-Plpt1<">. This is just weird-but-necessary LISP syntax; ...

Get Learning GNU Emacs, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.