: Learning GNU Emacs, 3rd Edition

5.3 Printing from Emacs

5.3 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 M-x print-buffer Enter. This command sends the buffer to pr (a program that does simple formatting for listings), followed by lpr (which sends the listing to the printer). If you want to print the file directly, without the headers and page numbers that pr provides, give the command M-x lpr-buffer Enter. 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 M-x print-region Enter (or M-x lpr-region Enter).

The lpr-buffer and lpr-region commands always check the variable lpr-switches to determine whether any options should be passed to the Unix lpr command. These options are used to request a particular printer and for many other purposes; see the manpage for 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; see Chapter 11 for more details.

You can also print from Dired. To print the file the cursor is on, type P. Emacs puts the default printing command in the minibuffer, and you can modify it.

Emacs also includes commands to print a buffer as a PostScript file. If you have formatted text in the file, you can print the buffer with those attributes by typing M-x ps-print-buffer-with-faces.

Table 5-3 provides a summary of commands for printing.

Table5-3.Printing commands

Keystrokes Action
M-x print-buffer File ? Print Buffer Print the buffer (similar to Unix pr | lpr).
M-x print-region File ? Print Region Print the region (similar to Unix pr | lpr).
M-x lpr-buffer Print buffer with no page numbers (similar to Unix lpr).
M-x lpr-region Print region with no page numbers (similar to Unix lpr).
P Operate ? Print From Dired, put the default print command in the minibuffer; you can change it or press Enter to execute it.
M-x ps-print-buffer-with-faces File ? Postscript Print Buffer Print the buffer with text attributes.
M-x ps-print-region-with-faces File ? Postscript Print Region Print the region with text attributes.

: 0.778. /Cache: 3 / 0