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 prprovides, 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-bufferand lpr-regioncommands always check the variable lpr-switchesto determine whether any options should be passed to the Unix lprcommand. These options are used to request a particular printer and for many other purposes; see the manpage for lprfor more information. For example, if you want to use the printer named lpt1 whenever you print from Emacs, you would want to set lpr-switchesto -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 11for 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-3provides a summary of commands for printing.
Table 5-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 Enterto 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. |
5.4 Reading Manpages in Emacs
You can read Unix online documentation (called manpages ) from within Emacs by typing M-x manor by selecting Manfrom the Helpmenu. [30]This command creates a buffer with a formatted manpage in it, which you can scroll through (or copy from) using Emacs commands. Simply type: M-x man Enter Unix-command-name Enter.
For the Unix command name, you can use either a simple name, like ls, or a manpage section name like ttytab(5).
The advantage of using the mancommand is that you can scroll through the manpage easier than you can in some terminal applications or shell windows. Also, if you try to view manpages in shell mode, they may come out garbled if the settings aren't right, whereas mangives you clean text.
5.5 Using Time Management Tools
Emacs is a natural place to organize all your work. It won't replace your Palm or other handheld, but ongoing work in this area may help you sync your favorite device with your Emacs-based schedule. Here we cover the main features that Emacs itself offers—the calendar and the diary.
5.5.1 Displaying the Calendar
To display the calendar, type M-x calendar. Emacs displays a calendar window with three months: last month, this month, and next month.
Type: M-x calendar

Emacs puts the cursor on today's date and displays the date on the mode line. There's no room to write on the calendar; that's what the diary is for, which we'll discuss shortly.
By default, weeks start on Sunday. If you'd like them to start on Monday instead, type M-x set-variable calendar-week-start Enter 1 Enter. You enter the calendar again to have this take effect. If you'd like to have the calendar always start on Monday, add this line to your .emacs file:
(setq calendar-week-start-day 1)
If you'd like to see the calendar each time you start Emacs, you can add this line to your .emacs file:
(calendar)
5.5.1.1 Moving in the calendar
When you're in the calendar, Emacs sensibly moves by day rather than by character. C-fmoves you to the next day; C-bmoves you to the previous day. C-nmoves you to the same day of the next week; C-pmoves you back a week. The arrow keys work the same way. M-}and M-{move forward and backward by month, and C-x [and C-x ]move forward and backward by year. C-vscrolls forward by three months; M-vscrolls back three months.
The movement commands just discussed move you relative to the cursor position. If you're on Tuesday and you press C-n, you'll move to next Tuesday. If you're on January 25 and press M-}you'll move to February 25. If you're on August 15, 2004 and press C-x [, you'll move to August 15, 2003.
Other commands move to the beginning or the end of the week, month, or year. C-aand C-emove to the beginning and end of the week, M-amoves to the beginning of the month, and M-<moves to the beginning of the year. Table 5-4summarizes these calendar movement commands.
To go to a particular date, press g d. Emacs asks for the year, then the month, and then the day. Emacs moves you to the day selected (this command is well-suited for answering that all-important question, "On what day of the week does my birthday fall in 2020?").
Table 5-4. Calendar movement commands
Keystrokes |
Command name |
Action |
(none) Tools → Display Calendar |
calendar |
Display the calendar. |
. Goto → Today |
calendar-goto-today |
Move to today's date. |
C-f |
calendar-forward-day |
Move forward a day. |
C-b |
calendar-backward-day |
Move backward a day. |
C-n |
calendar-forward-week |
Move forward a week. |
C-p |
calendar-backward-week |
Move backward a week. |
M-} |
calendar-forward-month |
Move forward one month. |
M-{ |
calendar-backward-month |
Move backward a month. |
C-x ] Scroll → Forward 1 Year |
calendar-forward-year |
Move forward a year. |
C-x [ Scroll → Backward 1 Year |
calendar-backward-year |
Move backward a year. |
C-a Goto → Beginning of Week |
calendar-beginning-of-week |
Move to the beginning of the week. |
C-e Goto → End of Week |
calendar-end-of-week |
Move to the end of the week. |
M-a Goto → Beginning of Month |
calendar-beginning-of-month |
Move to the beginning of the month. |
M-e Goto → End of Month |
calendar-end-of-month |
Move to the end of the month. |
M-< Goto → Beginning of Year |
calendar-beginning-of-year |
Move to the beginning of the year. |
M-> Goto → End of Year |
calendar-end-of-year |
Move to the end of the year. |
g d Goto → Other Date |
calendar-goto-date |
Go to the specified date. |
o |
calendar-other-month |
Put the specified month in the middle of the display. |
C-x < Scroll → Forward 1 Month |
scroll-calendar-left |
Scroll forward one month. |
C-x > Scroll → Backward 1 Month |
scroll-calendar-right |
Scroll backward one month. |
C-v Scroll → Forward 3 Months |
scroll-calendar-left-three-months |
Scroll forward three months. |
M-v Scroll → Forward 3 Months |
scroll-calendar-right-three-months |
Scroll backward three months. |
Space |
scroll-other-window |
Scroll another window. |
5.5.1.2 Displaying holidays
Читать дальше