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.
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)
When you're in the calendar, Emacs sensibly moves by day rather than by character. C-f moves you to the next day; C-b moves you to the previous day. C-n moves you to the same day of the next week; C-p moves 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-v scrolls forward by three months; M-v scrolls 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-a and C-e move to the beginning and end of the week, M-a moves to the beginning of the month, and M-< moves to the beginning of the year. Table 5-4 summarizes 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. |
Let's move to a topic everyone is interested in: holidays. To display the holidays for the part of the calendar you are looking at, type a (for list-calendar-holidays) or select 3 Months from the Holidays menu.
As you can see, Emacs knows about a fairly wide variety of holidays or, as it calls them, "notable dates." If you are somewhere else on the calendar but want to see holidays surrounding the current month, type M-x holidays. Emacs lists them. To see whether today is a holiday, type h or select One Day from the Holidays menu.
Typing x marks holidays in a special way, typically highlighting them in pink. If the display doesn't support this, Emacs puts an asterisk to the right of the date. Typing u removes the marks.
We have taught you only the bare bones of the calendar commands. Emacs offers to tell you sunrise and sunset and phases of the moon. You can choose other calendars, like the Islamic calendar, the Hebrew calendar, the Mayan calendar, or even the French Revolutionary calendar. But we will leave these for you to explore.
More calendar commands are used in the context of the diary, discussed next.
The diary, closely related to the calendar, allows you to make notes about certain dates. You can enter a full daily schedule or just mark major events. The level of detail is entirely up to you.
To use the diary, you must have a diary file that contains notations about important events or things to do. It can remind you to back up your system every Thursday, that you get paid every two weeks, that you're on vacation during the first two weeks in July, or that your mother's birthday is August 6.
The file must be called diary and must exist in your home directory. In this file, you insert lines—or have Emacs write lines for you—that note dates you want to remember. The diary file need not be all in one format and need not be sorted in any particular order. Date formats can be mixed: December 19, 2004 could be 12/19/04, Dec 19 04, or dec 19 2004. Here are a few lines from a diary file to illustrate what we mean.
11/14 My birthday July 17 2004 Company picnic March 18 2004 Annual report due January 8 2004 Hair appointment &Saturday Tea with Queen Elizabeth Friday Payday
If you don't specify a year, Emacs assumes you want to mark that date every year, as in birthdays. If you don't specify a date but only the day of the week (as in tea with the queen on Saturday), Emacs displays the diary entry every Saturday. Putting an ampersand (&) before an entry tells Emacs not to mark it on the calendar (you don't want every Saturday marked, and you may not want everyone to know that you hang around with the royal family).
Date formats can be mixed, but the choice to use European date format (DD/MM/YYYY or 9 October 2004) versus the default American format (MM/DD/YYYY or October 9, 2004) must be made before you create the diary file. To specify European date format, add this line to your .emacs file:
(setq european-calendar-style 't)
You can write your own
entries or have Emacs help you put
them in. To have Emacs help you, go to the calendar by typing
M-x calendar. Then press g d to specify the date you want to move to.
Press i d (for insert-diary-entry). Emacs moves you to the
diary window with the date written out. You can then make a diary
entry next to the date. If your entry spans more than one line, begin
the second and subsequent lines with a single space, so that Emacs
understands it's a continuation. After you make the
notation about the date, Emacs leaves you in the
diary
buffer so you can make more entries. Type
C-x b to move to another buffer.
The insert-diary-entry command
assumes you want to make a single, one-time entry. To create a
recurring entry, you need a few more commands. To insert a weekly
entry, type i w. Emacs moves you to
the diary
buffer with the day of the week written
out. Type the weekly activity (such as a staff meeting), and save the
diary file. To insert an annual entry, type
i y. Emacs moves you to the
diary
buffer with the day and month written out;
type the annual event. There is a more specific command for
anniversaries. Type i a to add an
anniversary; this entry includes the year (though we have not seen a
function that uses this information for any particular purpose, such
as counting which anniversary this is).
You can also put
in cyclic diary
entries, entries that occur at regular intervals, like reminders to
change the oil in your car every three months. To do so, move to the
date you changed your oil last and type i
c. Emacs says, Repeat every how many
days
: and you type the number of days between oil changes.
Emacs writes a Lisp function to handle this and puts it in the
diary
buffer. You can then make a notation next to
the Lisp function, such as a note that tells you to change the oil.
The entry that Emacs inserts looks like this (we put the part about
changing the oil in ourselves):
%%(diary-cyclic 90 12 23 2004) Change the oil
The entry says that every 90 days, counting from the day we inserted the entry, December 23, 2004, we should change the oil in our car.
You can mark a block of dates, as in the
case of a week-long conference or a vacation. Put the cursor on the
first date and press C-Space to set
the mark.[7] Move
(using calendar movement commands like C-f, C-n, and
so on) to the second date and press i
b. Emacs moves you to the diary
buffer
and inserts an incantation that marks the week on your calendar. Make
a notation following the Lisp function Emacs inserts. The entry will
look something like this:
%%(diary-block 3 15 2004 3 20 2004) Trip to Alabama
This entry indicates that from March 15 to March 20, we'll go on a trip to Alabama.
What if you want to note that you have to file your expense report on the fifteenth of every month? Emacs accepts the asterisk wildcard (*) for the month, as you will see when you type i m (for insert-monthly-diary-entry). Emacs inserts an asterisk in place of the month, followed by the day, as in * 15 for something scheduled for the fifteenth of each month. As always, you make a note following the entry.
Now that you see how Emacs constructs diary entries, you can try writing some of your own based on what Emacs has done. After all, the diary file is like any other Emacs file; you can make changes, add lines, and delete lines at will. The only requirement is that you save the file when you're through. Now let's see how to display diary entries on the appropriate dates.
If you want to review the diary entries for a given date, press d from the calendar. In order to see the whole diary file, press s from the calendar. If you want today's diary entries to display automatically when you start Emacs, add this line to your .emacs file:
(diary)
That way, when you start up Emacs on a day for which there is a diary entry, the diary entry displays automatically. For example, let's say you marked your best friend's birthday some time ago, and today is the day. When you start Emacs, the screen would look like this:
If there are no diary entries for a given day, the diary is not displayed. If you start Emacs with two files so that you are editing in two windows, the diary is also not displayed.
If you have already put in a (calendar) entry in your .emacs file to have the calendar displayed automatically, the calendar supersedes the diary, and you'll have to remove the calendar if you prefer to see the diary instead.
To mark dates with diary entries in red, press m from the calendar. To remove the marks, press u. (This command removes highlighting for diary entries as well as for holidays.)
Table 5-5 summarizes the calendar and diary commands.
Table 5-5. Holiday and diary commands
Keystrokes |
Command name |
Action |
---|---|---|
p d |
calendar-print-day-of-year |
Display the day of the year this is (for example, Day 364 of 365). |
p o |
calendar-print-other-dates |
Display information about this date for all calendars. |
Space |
scroll-other-window |
Scroll the other window. |
q |
exit-calendar |
Quit calendar. |
a Holidays → For Window |
list-calendar-holidays |
Display holidays for calendar period shown. |
h Holidays → For Cursor Date |
calendar-cursor-holidays |
In the minibuffer, display holiday information for the day the cursor is on. |
x Holidays → Mark |
mark-calendar-holidays |
Display holidays in a different typeface, color, or with an asterisk beside them. |
u Holidays → Unmark Calendar |
calendar-unmark |
Remove marks for holidays and diary entries (opposite of x command). |
i w Diary → Insert Weekly |
insert-weekly-diary-entry |
Add a weekly entry based on the day of the week. |
i y Diary → Insert Yearly |
insert-yearly-diary-entry |
Add an annual entry. |
i d Diary → Insert Daily |
insert-diary-entry |
Add an entry for a particular day. |
i m Diary → Insert Monthly |
insert-monthly-diary-entry |
Add an entry for the day of the month. |
i c Diary → Insert Cyclic |
insert-cyclic-diary-entry |
Add an entry to recur every n days. |
i a Diary → Insert Anniversary |
insert-anniversary-diary-entry |
Add an annual entry (the year is included for reference). |
i b Diary → Insert Block |
insert-block-diary-entry |
Add a block entry. |
m |
mark-diary-entries |
Display diary entries in a different typeface, color, or with a plus sign beside them. |
d |
view-diary-entries |
Display diary entries for the current date. |
s Diary → Show All |
show-all-diary-entries |
Display diary file. |
M-= |
calendar-count-days-region |
Count the number of days in a region. |
M Moon → Lunar Phases |
calendar-phases-of-moon |
Display phases of the moon for a three-month period. |
S |
calendar-sunrise-sunset |
Given longitude and latitude, display sunrise and sunset times for the current date. |
C-Space or C-@ |
calendar-set-mark |
Mark regions by time rather than horizontally. |
In shell mode on Mac OS X, Emacs says, "Warning: no access to tty (Bad file descriptor). Thus no job control in this shell." This happens with the graphical version of Emacs, not with the version run from the Mac OS X Terminal application. If you change to a different shell using the instructions under "Which shell?" earlier in this chapter, the error goes away.
Some commands don't work on Mac OS X. The graphical version of Mac OS X fails to find some operating system commands, especially when invoking them through M-! (for shell-command). Change to a different shell; see "Which shell?" earlier in this chapter for details. Another problem is that some Unix commands are not available by default on Mac OS X. Try them in the Mac Terminal application to see if they work at all before trying them in shell mode. To increase Mac OS X's Unix functionality, use Fink (http://fink.sourceforge.net) to download a wide variety of Unix commands and software for Mac OS X.
Some commands don't work on Windows. This chapter describes many commands that have no Windows equivalent. The Windows port of Emacs works well for most Dired functions, the calendar, and the diary. To get Unix command functionality under Windows, install Cygwin (http://cygwin.com).
Printing does not work from Windows on USB printers. Many USB printers do not support printing from the command line. This problem is not specific to Emacs.
[7] If you normally use another binding for the set-mark command or if you typically spell out that command, you'll run into a problem marking regions in the calendar. In the calendar, C-Space and C-@ run calendar-set-mark rather than set-mark, so that regions are marked by time rather than just across the screen. To mark regions correctly in the calendar (linearly by time rather than simply across the screen), you must type C-Space, C-@, or M-x calendar-set-mark to set the mark.