Fix some emacs-xtra.pdf cross-references to other manuals
[bpt/emacs.git] / doc / emacs / cal-xtra.texi
CommitLineData
6f585e44 1@c This is part of the Emacs manual.
acaf905b 2@c Copyright (C) 2004-2012 Free Software Foundation, Inc.
6f585e44
EZ
3@c See file emacs.texi for copying conditions.
4@c
c5184807
EZ
5@c This file is included either in emacs-xtra.texi (when producing the
6@c printed version) or in the main Emacs manual (for the on-line version).
7
8@c Moved here from the Emacs Lisp Reference Manual, 2005-03-26.
9@node Advanced Calendar/Diary Usage
10@section Customizing the Calendar and Diary
11
12 There are many customizations that you can use to make the calendar and
13diary suit your personal tastes.
14
15@menu
f9b4c05d 16* Calendar Customizing:: Calendar layout and hooks.
c5184807
EZ
17* Holiday Customizing:: Defining your own holidays.
18* Date Display Format:: Changing the format.
19* Time Display Format:: Changing the format.
20* Diary Customizing:: Defaults you can set.
f9b4c05d 21* Non-Gregorian Diary:: Diary entries based on other calendars.
cad04c66
GM
22* Diary Display:: A choice of ways to display the diary.
23* Fancy Diary Display:: Sorting diary entries, using included diary files.
24* Sexp Diary Entries:: More flexible diary entries.
c5184807
EZ
25@end menu
26
27@node Calendar Customizing
28@subsection Customizing the Calendar
a43a8a2e
GM
29
30@vindex calendar-intermonth-text
31@cindex calendar layout
f9b4c05d
GM
32@cindex calendar week numbers
33 The calendar display unfortunately cannot be changed from three
34months, but you can customize the whitespace used by setting the
35variables: @code{calendar-left-margin},
c1e67aad
GM
36@code{calendar-day-header-width}, @code{calendar-day-digit-width},
37@code{calendar-column-width}, and @code{calendar-intermonth-spacing}.
f9b4c05d
GM
38To display text @emph{between} the months, for example week numbers,
39customize the variables @code{calendar-intermonth-header} and
40@code{calendar-intermonth-text} as described in their documentation.
a43a8a2e 41
c5184807
EZ
42@vindex calendar-holiday-marker
43@vindex diary-entry-marker
301b181a 44@vindex calendar-today-marker
c5184807 45 The variable @code{calendar-holiday-marker} specifies how to mark a
f9b4c05d
GM
46date as being a holiday. Its value may be a single-character string to
47insert next to the date, or a face name to use for displaying the date.
48Likewise, the variable @code{diary-entry-marker} specifies how to mark a
301b181a 49date that has diary entries, and @code{calendar-today-marker} is used by
f9b4c05d
GM
50the function @code{calendar-mark-today} to mark today's date. By
51default, the calendar uses faces named @code{holiday}, @code{diary}, and
52@code{calendar-today} for these purposes.
c5184807
EZ
53
54@vindex calendar-load-hook
55 The variable @code{calendar-load-hook} is a normal hook run when the
56calendar package is first loaded (before actually starting to display
57the calendar).
58
36c0514c 59@vindex calendar-initial-window-hook
c5184807 60 Starting the calendar runs the normal hook
36c0514c 61@code{calendar-initial-window-hook}. Recomputation of the calendar
c5184807
EZ
62display does not run this hook. But if you leave the calendar with the
63@kbd{q} command and reenter it, the hook runs again.@refill
64
36c0514c 65@vindex calendar-today-visible-hook
f9b4c05d 66@findex calendar-star-date
36c0514c 67 The variable @code{calendar-today-visible-hook} is a normal hook run
c5184807
EZ
68after the calendar buffer has been prepared with the calendar when the
69current date is visible in the window. One use of this hook is to
f9b4c05d
GM
70mark today's date; to do that use either of the functions
71@code{calendar-mark-today} or @code{calendar-star-date}:
c5184807
EZ
72
73@findex calendar-mark-today
f9b4c05d 74@smallexample
36c0514c 75(add-hook 'calendar-today-visible-hook 'calendar-mark-today)
f9b4c05d 76@end smallexample
c5184807 77
36c0514c 78@vindex calendar-today-invisible-hook
c5184807 79@noindent
36c0514c 80 A similar normal hook, @code{calendar-today-invisible-hook} is run if
c5184807
EZ
81the current date is @emph{not} visible in the window.
82
83@vindex calendar-move-hook
84 Each of the calendar cursor motion commands runs the hook
85@code{calendar-move-hook} after it moves the cursor.
86
87@node Holiday Customizing
88@subsection Customizing the Holidays
89
90@vindex calendar-holidays
f9b4c05d
GM
91@vindex holiday-oriental-holidays
92@vindex holiday-solar-holidays
c5184807 93 Emacs knows about holidays defined by entries on one of several lists.
c1e67aad
GM
94The lists of holidays that Emacs uses are for
95general holidays (@code{holiday-general-holidays}),
96local holidays (@code{holiday-local-holidays}),
97sun- and moon-related holidays (@code{holiday-solar-holidays}),
98Baha'i holidays (@code{holiday-bahai-holidays}),
99Christian holidays (@code{holiday-christian-holidays}),
100Hebrew (Jewish) holidays (@code{holiday-hebrew-holidays}),
101Islamic (Muslim) holidays (@code{holiday-islamic-holidays}),
102Oriental holidays (@code{holiday-oriental-holidays}),
103and other holidays (@code{holiday-other-holidays}).
36c0514c 104
f9b4c05d
GM
105You can customize these lists of holidays to your own needs, deleting or
106adding holidays as described below. Set any of them to @code{nil} to
107eliminate the associated holidays.
108
36c0514c 109@vindex holiday-general-holidays
c5184807 110 The general holidays are, by default, holidays common throughout the
f9b4c05d 111United States.
c5184807 112
36c0514c 113@vindex holiday-local-holidays
f9b4c05d 114 There are no default local holidays, but your site may supply some.
c5184807 115
f9b4c05d
GM
116@vindex holiday-bahai-holidays
117@vindex holiday-christian-holidays
118@vindex holiday-hebrew-holidays
119@vindex holiday-islamic-holidays
36c0514c
GM
120@vindex calendar-bahai-all-holidays-flag
121@vindex calendar-christian-all-holidays-flag
122@vindex calendar-hebrew-all-holidays-flag
123@vindex calendar-islamic-all-holidays-flag
c5184807
EZ
124 By default, Emacs does not include all the holidays of the religions
125that it knows, only those commonly found in secular calendars. For a
126more extensive collection of religious holidays, you can set any (or
36c0514c
GM
127all) of the variables @code{calendar-bahai-all-holidays-flag},
128@code{calendar-christian-all-holidays-flag},
129@code{calendar-hebrew-all-holidays-flag}, or
f9b4c05d 130@code{calendar-islamic-all-holidays-flag} to @code{t}.
c5184807 131
36c0514c
GM
132@vindex holiday-other-holidays
133 You can set the variable @code{holiday-other-holidays} to any list of
c5184807
EZ
134holidays. This list, normally empty, is intended for individual use.
135
136@cindex holiday forms
f9b4c05d
GM
137 Each of the holiday variables is a list of @dfn{holiday forms}, each
138form describing a holiday (or sometimes a list of holidays).
c5184807
EZ
139
140 Here is a table of the possible kinds of holiday form. Day numbers
141and month numbers count starting from 1, but ``dayname'' numbers
142count Sunday as 0. The element @var{string} is always the
f9b4c05d 143description of the holiday, as a string.
c5184807
EZ
144
145@table @code
146@item (holiday-fixed @var{month} @var{day} @var{string})
147A fixed date on the Gregorian calendar.
148
f9b4c05d
GM
149@item (holiday-float @var{month} @var{dayname} @var{k} @var{string}
150 &optional @var{day})
151The @var{k}th @var{dayname} (@var{dayname}=0 for Sunday, and so on)
152after or before Gregorian date @var{month}, @var{day}. Negative @var{k}
153means count back from the end of the month. Optional @var{day} defaults
154to 1 if @var{k} is positive, and the last day of @var{month} otherwise.
c5184807 155
a43a8a2e
GM
156@item (holiday-chinese @var{month} @var{day} @var{string})
157A fixed date on the Chinese calendar.
158
c5184807
EZ
159@item (holiday-hebrew @var{month} @var{day} @var{string})
160A fixed date on the Hebrew calendar.
161
162@item (holiday-islamic @var{month} @var{day} @var{string})
163A fixed date on the Islamic calendar.
164
165@item (holiday-julian @var{month} @var{day} @var{string})
166A fixed date on the Julian calendar.
167
168@item (holiday-sexp @var{sexp} @var{string})
169A date calculated by the Lisp expression @var{sexp}. The expression
170should use the variable @code{year} to compute and return the date of a
f9b4c05d
GM
171holiday in the form of a list @code{(@var{month} @var{day} @var{year})},
172or @code{nil} if the holiday doesn't happen this year.
c5184807
EZ
173
174@item (if @var{condition} @var{holiday-form})
175A holiday that happens only if @var{condition} is true.
176
177@item (@var{function} @r{[}@var{args}@r{]})
178A list of dates calculated by the function @var{function}, called with
179arguments @var{args}.
180@end table
181
182 For example, suppose you want to add Bastille Day, celebrated in
f9b4c05d
GM
183France on July 14 (i.e., the fourteenth day of the seventh month). You
184can do this as follows:
c5184807
EZ
185
186@smallexample
98ad1bae 187(setq holiday-other-holidays '((holiday-fixed 7 14 "Bastille Day")))
c5184807
EZ
188@end smallexample
189
c5184807
EZ
190 Many holidays occur on a specific day of the week, at a specific time
191of month. Here is a holiday form describing Hurricane Supplication Day,
192celebrated in the Virgin Islands on the fourth Monday in August:
193
194@smallexample
195(holiday-float 8 1 4 "Hurricane Supplication Day")
196@end smallexample
197
198@noindent
199Here the 8 specifies August, the 1 specifies Monday (Sunday is 0,
200Tuesday is 2, and so on), and the 4 specifies the fourth occurrence in
201the month (1 specifies the first occurrence, 2 the second occurrence,
202@minus{}1 the last occurrence, @minus{}2 the second-to-last occurrence, and
203so on).
204
36c0514c 205 You can specify holidays that occur on fixed days of the Baha'i,
a43a8a2e 206Chinese, Hebrew, Islamic, and Julian calendars too. For example,
c5184807
EZ
207
208@smallexample
98ad1bae 209(setq holiday-other-holidays
c5184807
EZ
210 '((holiday-hebrew 10 2 "Last day of Hanukkah")
211 (holiday-islamic 3 12 "Mohammed's Birthday")
212 (holiday-julian 4 2 "Jefferson's Birthday")))
213@end smallexample
214
215@noindent
216adds the last day of Hanukkah (since the Hebrew months are numbered with
2171 starting from Nisan), the Islamic feast celebrating Mohammed's
218birthday (since the Islamic months are numbered from 1 starting with
219Muharram), and Thomas Jefferson's birthday, which is 2 April 1743 on the
220Julian calendar.
221
f9b4c05d
GM
222 To include a holiday conditionally, use either Emacs Lisp's @code{if}
223or the @code{holiday-sexp} form. For example, American presidential
224elections occur on the first Tuesday after the first Monday in November
225of years divisible by 4:
c5184807
EZ
226
227@smallexample
f9b4c05d 228(holiday-sexp '(if (zerop (% year 4))
c5184807
EZ
229 (calendar-gregorian-from-absolute
230 (1+ (calendar-dayname-on-or-before
231 1 (+ 6 (calendar-absolute-from-gregorian
232 (list 11 1 year)))))))
233 "US Presidential Election")
234@end smallexample
235
236@noindent
237or
238
239@smallexample
f9b4c05d
GM
240(if (zerop (% displayed-year 4))
241 (holiday-fixed 11
36c0514c 242 (calendar-extract-day
c5184807
EZ
243 (calendar-gregorian-from-absolute
244 (1+ (calendar-dayname-on-or-before
245 1 (+ 6 (calendar-absolute-from-gregorian
246 (list 11 1 displayed-year)))))))
247 "US Presidential Election"))
248@end smallexample
249
250 Some holidays just don't fit into any of these forms because special
251calculations are involved in their determination. In such cases you
252must write a Lisp function to do the calculation. To include eclipses,
36c0514c 253for example, add @code{(eclipses)} to @code{holiday-other-holidays}
c5184807
EZ
254and write an Emacs Lisp function @code{eclipses} that returns a
255(possibly empty) list of the relevant Gregorian dates among the range
256visible in the calendar window, with descriptive strings, like this:
257
258@smallexample
259(((6 27 1991) "Lunar Eclipse") ((7 11 1991) "Solar Eclipse") ... )
260@end smallexample
261
262@node Date Display Format
263@subsection Date Display Format
264@vindex calendar-date-display-form
265
266 You can customize the manner of displaying dates in the diary, in mode
267lines, and in messages by setting @code{calendar-date-display-form}.
268This variable holds a list of expressions that can involve the variables
269@code{month}, @code{day}, and @code{year}, which are all numbers in
270string form, and @code{monthname} and @code{dayname}, which are both
271alphabetic strings. In the American style, the default value of this
272list is as follows:
273
274@smallexample
275((if dayname (concat dayname ", ")) monthname " " day ", " year)
276@end smallexample
277
278@noindent
279while in the European style this value is the default:
280
281@smallexample
282((if dayname (concat dayname ", ")) day " " monthname " " year)
283@end smallexample
284
285@noindent
f9b4c05d 286The default ISO date representation is:
c5184807
EZ
287
288@smallexample
f9b4c05d
GM
289((format "%s-%.2d-%.2d" year (string-to-number month)
290 (string-to-number day)))
c5184807
EZ
291@end smallexample
292
293@noindent
294This specifies a typical American format:
295
296@smallexample
297(month "/" day "/" (substring year -2))
298@end smallexample
299
300@node Time Display Format
301@subsection Time Display Format
302@vindex calendar-time-display-form
303
304 The calendar and diary by default display times of day in the
305conventional American style with the hours from 1 through 12, minutes,
306and either @samp{am} or @samp{pm}. If you prefer the European style,
307also known in the US as military, in which the hours go from 00 to 23,
308you can alter the variable @code{calendar-time-display-form}. This
309variable is a list of expressions that can involve the variables
310@code{12-hours}, @code{24-hours}, and @code{minutes}, which are all
311numbers in string form, and @code{am-pm} and @code{time-zone}, which are
f9b4c05d 312both alphabetic strings. The default value is:
c5184807
EZ
313
314@smallexample
315(12-hours ":" minutes am-pm
316 (if time-zone " (") time-zone (if time-zone ")"))
317@end smallexample
318
319@noindent
320Here is a value that provides European style times:
321
322@smallexample
323(24-hours ":" minutes
324 (if time-zone " (") time-zone (if time-zone ")"))
325@end smallexample
326
f9b4c05d
GM
327Note that few calendar functions return a time of day (at present, only
328solar functions).
329
c5184807
EZ
330@node Diary Customizing
331@subsection Customizing the Diary
332
36c0514c 333@vindex diary-show-holidays-flag
cad04c66
GM
334 Ordinarily, the diary window indicates any holidays that fall on the
335date of the diary entries, either in the mode line or the buffer itself.
336The process of checking for holidays can be slow, depending on the
337defined holidays. In that case, setting @code{diary-show-holidays-flag}
338to @code{nil} will speed up the diary display.
c5184807 339
36c0514c
GM
340@vindex diary-number-of-entries
341 The variable @code{diary-number-of-entries} controls the number of
c5184807 342days of diary entries to be displayed at one time. It affects the
36c0514c 343initial display when @code{calendar-view-diary-initially-flag} is
f9b4c05d
GM
344@code{t}, as well as the command @kbd{M-x diary}. For example, a value
345of 1 (the default) displays only the current day's diary entries,
346whereas a value of 2 will also show the next day's entries. The value
347can also be a vector of seven integers: for example, if the value is
348@code{[0 2 2 2 2 4 1]} then no diary entries appear on Sunday, the
349current date's and the next day's diary entries appear Monday through
350Thursday, Friday through Monday's entries appear on Friday, while on
351Saturday only that day's entries appear.
36c0514c 352
c5184807 353@vindex diary-date-forms
f9b4c05d 354 You can customize the form of dates in your diary file by setting the
c5184807
EZ
355variable @code{diary-date-forms}. This variable is a list of patterns
356for recognizing a date. Each date pattern is a list whose elements may
357be regular expressions (@pxref{Regular Expressions,,, elisp, the Emacs
358Lisp Reference Manual}) or the symbols @code{month}, @code{day},
359@code{year}, @code{monthname}, and @code{dayname}. All these elements
360serve as patterns that match certain kinds of text in the diary file.
361In order for the date pattern, as a whole, to match, all of its elements
362must match consecutively.
363
364 A regular expression in a date pattern matches in its usual fashion,
365using the standard syntax table altered so that @samp{*} is a word
366constituent.
367
368 The symbols @code{month}, @code{day}, @code{year}, @code{monthname},
369and @code{dayname} match the month number, day number, year number,
370month name, and day name of the date being considered. The symbols that
371match numbers allow leading zeros; those that match names allow
f9b4c05d
GM
372capitalization and abbreviation (as specified by
373@code{calendar-month-abbrev-array} and
374@code{calendar-day-abbrev-array}). All the symbols can match @samp{*};
375since @samp{*} in a diary entry means ``any day'', ``any month'', and so
376on, it should match regardless of the date being considered.
c5184807
EZ
377
378 The default value of @code{diary-date-forms} in the American style is
f9b4c05d 379provided by @code{diary-american-date-forms}:
c5184807
EZ
380
381@example
382((month "/" day "[^/0-9]")
383 (month "/" day "/" year "[^0-9]")
384 (monthname " *" day "[^,0-9]")
385 (monthname " *" day ", *" year "[^0-9]")
386 (dayname "\\W"))
387@end example
388
f9b4c05d
GM
389@noindent
390Other default styles are provided by @code{diary-european-date-forms}
391and @code{diary-iso-date-forms}.
392
c5184807
EZ
393 The date patterns in the list must be @emph{mutually exclusive} and
394must not match any portion of the diary entry itself, just the date and
395one character of whitespace. If, to be mutually exclusive, the pattern
396must match a portion of the diary entry text---beyond the whitespace
397that ends the date---then the first element of the date pattern
398@emph{must} be @code{backup}. This causes the date recognizer to back
399up to the beginning of the current word of the diary entry, after
400finishing the match. Even if you use @code{backup}, the date pattern
401must absolutely not match more than a portion of the first word of the
f9b4c05d
GM
402diary entry. For example, the default value of
403@code{diary-european-date-forms} is:
c5184807
EZ
404
405@example
406((day "/" month "[^/0-9]")
407 (day "/" month "/" year "[^0-9]")
f9b4c05d 408 (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
c5184807
EZ
409 (day " *" monthname " *" year "[^0-9]")
410 (dayname "\\W"))
411@end example
412
413@noindent
414Notice the use of @code{backup} in the third pattern, because it needs
415to match part of a word beyond the date itself to distinguish it from
416the fourth pattern.
417
f9b4c05d 418@node Non-Gregorian Diary
c216ec2b 419@subsection Diary Entries Using non-Gregorian Calendars
c5184807 420
f9b4c05d
GM
421 As well as entries based on the standard Gregorian calendar, your
422diary can have entries based on Baha'i, Hebrew, or Islamic dates.
423Recognition of such entries can be time-consuming, however, and since
424most people don't use them, you must explicitly enable their use. If
425you want the diary to recognize Hebrew-date diary entries, for example,
426you must do this:
36c0514c
GM
427
428@vindex diary-nongregorian-listing-hook
429@vindex diary-nongregorian-marking-hook
430@findex diary-hebrew-list-entries
431@findex diary-hebrew-mark-entries
f9b4c05d
GM
432@findex diary-islamic-list-entries
433@findex diary-islamic-mark-entries
434@findex diary-bahai-list-entries
435@findex diary-bahai-mark-entries
c5184807 436@smallexample
36c0514c
GM
437(add-hook 'diary-nongregorian-listing-hook 'diary-hebrew-list-entries)
438(add-hook 'diary-nongregorian-marking-hook 'diary-hebrew-mark-entries)
c5184807
EZ
439@end smallexample
440
441@noindent
f9b4c05d
GM
442Similarly, for Islamic and Baha'i entries, add
443@code{diary-islamic-list-entries} and @code{diary-islamic-mark-entries}, or
444@code{diary-bahai-list-entries} and @code{diary-bahai-mark-entries}.
445
446@vindex diary-bahai-entry-symbol
447@vindex diary-hebrew-entry-symbol
448@vindex diary-islamic-entry-symbol
449 These diary entries have the same formats as Gregorian-date diary
450entries; except that @code{diary-bahai-entry-symbol} (default @samp{B})
451must precede a Baha'i date, @code{diary-hebrew-entry-symbol} (default
452@samp{H}) a Hebrew date, and @code{diary-islamic-entry-symbol} (default
453@samp{I}) an Islamic date. Moreover, non-Gregorian month names may not
454be abbreviated (because the first three letters are often not unique).
fb89fad9
GM
455(Note also that you must use ``Adar I'' if you want Adar of a common
456Hebrew year.) For example, a diary entry for the Hebrew date Heshvan 25
457could look like this:
c5184807
EZ
458
459@smallexample
460HHeshvan 25 Happy Hebrew birthday!
461@end smallexample
462
463@noindent
464and would appear in the diary for any date that corresponds to Heshvan 25
465on the Hebrew calendar. And here is an Islamic-date diary entry that matches
466Dhu al-Qada 25:
467
468@smallexample
469IDhu al-Qada 25 Happy Islamic birthday!
470@end smallexample
471
f9b4c05d
GM
472 As with Gregorian-date diary entries, non-Gregorian entries are
473nonmarking if preceded by @code{diary-nonmarking-symbol} (default
474@samp{&}).
c5184807 475
f9b4c05d
GM
476 Here is a table of commands used in the calendar to create diary
477entries that match the selected date and other dates that are similar in
478the Baha'i, Hebrew, or Islamic calendars:
c5184807
EZ
479
480@table @kbd
481@item i h d
f9b4c05d 482@code{diary-hebrew-insert-entry}
c5184807 483@item i h m
f9b4c05d 484@code{diary-hebrew-insert-monthly-entry}
c5184807 485@item i h y
f9b4c05d 486@code{diary-hebrew-insert-yearly-entry}
c5184807 487@item i i d
f9b4c05d 488@code{diary-islamic-insert-entry}
c5184807 489@item i i m
f9b4c05d 490@code{diary-islamic-insert-monthly-entry}
c5184807 491@item i i y
f9b4c05d
GM
492@code{diary-islamic-insert-yearly-entry}
493@item i B d
494@code{diary-bahai-insert-entry}
495@item i B m
496@code{diary-bahai-insert-monthly-entry}
497@item i B y
498@code{diary-bahai-insert-yearly-entry}
c5184807
EZ
499@end table
500
36c0514c
GM
501@findex diary-hebrew-insert-entry
502@findex diary-hebrew-insert-monthly-entry
503@findex diary-hebrew-insert-yearly-entry
504@findex diary-islamic-insert-entry
505@findex diary-islamic-insert-monthly-entry
506@findex diary-islamic-insert-yearly-entry
f9b4c05d
GM
507@findex diary-bahai-insert-entry
508@findex diary-bahai-insert-monthly-entry
509@findex diary-bahai-insert-yearly-entry
c5184807
EZ
510 These commands work much like the corresponding commands for ordinary
511diary entries: they apply to the date that point is on in the calendar
f9b4c05d
GM
512window, and what they do is insert just the date portion of a diary
513entry at the end of your diary file. You must then insert the rest of
514the diary entry. The basic commands add an entry for the specific
515non-Gregorian date, the @samp{monthly} commands for the given
516non-Gregorian day-within-month in every month, and the @samp{yearly}
517commands for the given non-Gregorian day and month in every year.
c5184807 518
cad04c66
GM
519@node Diary Display
520@subsection Diary Display
d21d2618 521@vindex diary-display-function
36c0514c 522@findex diary-simple-display
daf7e339
GM
523@findex diary-fancy-display
524@cindex diary buffer
c5184807 525
cad04c66
GM
526 Diary display works by preparing the list of diary entries and then
527running the function specified by the variable
528@code{diary-display-function}. The default value
daf7e339
GM
529@code{diary-fancy-display} displays diary entries and holidays by
530copying them into a special buffer that exists only for the sake of
cad04c66
GM
531display. Copying diary entries to a separate buffer provides an
532opportunity to change the displayed text to make it prettier---for
533example, to sort the entries by the dates they apply to.
c5184807
EZ
534
535@vindex diary-list-include-blanks
cad04c66
GM
536 Ordinarily, the fancy diary buffer does not show days for which there
537are no diary entries, even if that day is a holiday. If you want such
538days to be shown in the fancy diary buffer, set the variable
c5184807
EZ
539@code{diary-list-include-blanks} to @code{t}.@refill
540
5f9756ec
GM
541 The fancy diary buffer enables View mode
542@iftex
543(@pxref{View Mode,,, emacs, the Emacs Manual}).
544@end iftex
545@ifnottex
546(@pxref{View Mode}).
547@end ifnottex
e11adbd8
GM
548
549 The alternative display method @code{diary-simple-display} shows the
550actual diary buffer, and uses invisible text to hide entries that don't
551apply. Holidays are shown in the mode line. The advantage of this
552method is that you can edit the buffer and save your changes directly to
553the diary file. This method is not as flexible as the fancy method,
554however. For example, it cannot sort entries. Another disadvantage is
555that invisible text can be confusing. For example, if you copy a region
556of text in order to paste it elsewhere, invisible text may be included.
557Similarly, since the diary buffer as you see it is an illusion, simply
558printing the buffer may not print what you see on your screen.
cad04c66
GM
559
560@vindex diary-print-entries-hook
561@findex diary-print-entries
562 For this reason, there is a special command to print hard copy of the
563diary buffer @emph{as it appears}; this command is @kbd{M-x
564diary-print-entries}. It works with either display method, although
565with the fancy display you can also print the buffer like any other. To
566print a hard copy of a day-by-day diary for a week, position point on
567the first day of the week, type @kbd{7 d}, and then do @kbd{M-x
568diary-print-entries}. As usual, the inclusion of the holidays slows
569down the display slightly; you can speed things up by setting the
570variable @code{diary-show-holidays-flag} to @code{nil}.
571
572 This command prepares a temporary buffer that contains only the diary
573entries currently visible in the diary buffer. Unlike with the simple
574display, the other irrelevant entries are really absent, not just
575hidden. After preparing the buffer, it runs the hook
576@code{diary-print-entries-hook}. The default value of this hook sends
577the data directly to the printer with the command @code{lpr-buffer}
5f9756ec
GM
578@iftex
579(@pxref{Printing,,, emacs, the Emacs Manual}).
580@end iftex
581@ifnottex
582(@pxref{Printing}).
583@end ifnottex
584If you want to use a different command to do the
cad04c66
GM
585printing, just change the value of this hook. Other uses might include,
586for example, rearranging the lines into order by day and time.
587
588 You can edit the diary entries as they appear in the simple diary
589window, but it is important to remember that the buffer displayed
590contains the @emph{entire} diary file, with portions of it concealed
591from view. This means, for instance, that the @kbd{C-f}
592(@code{forward-char}) command can put point at what appears to be the
593end of the line, but what is in reality the middle of some concealed
594line.
595
596 @emph{Be careful when editing the diary entries in the simple display!}
597Inserting additional lines or adding/deleting characters in the middle
598of a visible line cannot cause problems, but editing at the end of a
599line may not do what you expect. Deleting a line may delete other
600invisible entries that follow it. Before editing the simple diary
601buffer, it is best to display the entire file with @kbd{s}
602(@code{diary-show-all-entries}).
603
604@node Fancy Diary Display
605@subsection Fancy Diary Display
606
607The following features only work with the fancy diary display.
608
c5184807 609@cindex sorting diary entries
cad04c66
GM
610 You can use the normal hook @code{diary-list-entries-hook} to sort
611each day's diary entries by their time of day. Here's how:
c5184807 612
36c0514c 613@findex diary-sort-entries
c5184807 614@example
36c0514c 615(add-hook 'diary-list-entries-hook 'diary-sort-entries t)
c5184807
EZ
616@end example
617
618@noindent
619For each day, this sorts diary entries that begin with a recognizable
620time of day according to their times. Diary entries without times come
67ae9766
GM
621first within each day. Note how the sort command is placed at the end
622of the hook list, in case earlier members of the list change the order
623of the diary entries, or add items.
c5184807 624
548d0a63
GM
625@vindex diary-comment-start
626 You can write @samp{comments} in diary entries, by setting the
627variables @code{diary-comment-start} and @code{diary-comment-end} to
628strings that delimit comments. The fancy display does not print
629comments. You might want to put meta-data for the use of other packages
630(e.g. the appointment package,
631@iftex
632@pxref{Appointments,,,emacs, the Emacs Manual})
633@end iftex
634@ifnottex
635@pxref{Appointments})
636@end ifnottex
637inside comments.
638
f9b4c05d 639@vindex diary-include-string
cad04c66
GM
640 Your main diary file can include other files. This permits a group of
641people to share a diary file for events that apply to all of them.
642Lines in the diary file starting with @code{diary-include-string}:
c5184807
EZ
643
644@smallexample
645#include "@var{filename}"
646@end smallexample
647
648@noindent
f9b4c05d
GM
649include the diary entries from the file @var{filename} in the fancy
650diary buffer. The include mechanism is recursive, so that included
651files can include other files, and so on (you must be careful not to
652have a cycle of inclusions, of course). Here is how to enable the
653include facility:
c5184807 654
36c0514c
GM
655@vindex diary-list-entries-hook
656@vindex diary-mark-entries-hook
657@findex diary-include-other-diary-files
658@findex diary-mark-included-diary-files
c5184807 659@smallexample
36c0514c
GM
660(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
661(add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)
c5184807
EZ
662@end smallexample
663
664The include mechanism works only with the fancy diary display, because
cad04c66 665simple diary display shows the entries directly from your diary file.
c5184807
EZ
666
667@node Sexp Diary Entries
668@subsection Sexp Entries and the Fancy Diary Display
669@cindex sexp diary entries
670
f9b4c05d 671@vindex diary-sexp-entry-symbol
c5184807 672 Sexp diary entries allow you to do more than just have complicated
f9b4c05d
GM
673conditions under which a diary entry applies. Sexp entries should be
674preceded by @code{diary-sexp-entry-symbol} (default @samp{%%}) in the
cad04c66
GM
675diary file. With the fancy diary display, sexp entries can generate the
676text of the entry depending on the date itself.
f9b4c05d
GM
677
678For example, an anniversary diary entry can insert
c5184807 679the number of years since the anniversary date into the text of the
5de4980c 680diary entry. Thus the @samp{%d} in this diary entry:
c5184807
EZ
681
682@findex diary-anniversary
683@smallexample
684%%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)
685@end smallexample
686
687@noindent
688gets replaced by the age, so on October 31, 1990 the entry appears in
689the fancy diary buffer like this:
690
691@smallexample
692Arthur's birthday (42 years old)
693@end smallexample
694
695@noindent
696If the diary file instead contains this entry:
697
698@smallexample
699%%(diary-anniversary 10 31 1948) Arthur's %d%s birthday
700@end smallexample
701
702@noindent
703the entry in the fancy diary buffer for October 31, 1990 appears like this:
704
705@smallexample
706Arthur's 42nd birthday
707@end smallexample
708
709 Similarly, cyclic diary entries can interpolate the number of repetitions
710that have occurred:
711
712@findex diary-cyclic
713@smallexample
714%%(diary-cyclic 50 1 1 1990) Renew medication (%d%s time)
715@end smallexample
716
717@noindent
718looks like this:
719
720@smallexample
721Renew medication (5th time)
722@end smallexample
723
724@noindent
725in the fancy diary display on September 8, 1990.
726
727 There is an early reminder diary sexp that includes its entry in the
728diary not only on the date of occurrence, but also on earlier dates.
729For example, if you want a reminder a week before your anniversary, you
730can use
731
732@findex diary-remind
733@smallexample
734%%(diary-remind '(diary-anniversary 12 22 1968) 7) Ed's anniversary
735@end smallexample
736
737@noindent
f9b4c05d
GM
738and the fancy diary will show @samp{Ed's anniversary} both on December
73915 and on December 22.
c5184807
EZ
740
741@findex diary-date
742 The function @code{diary-date} applies to dates described by a month,
743day, year combination, each of which can be an integer, a list of
f9b4c05d 744integers, or @code{t} (meaning all values). For example,
c5184807
EZ
745
746@smallexample
747%%(diary-date '(10 11 12) 22 t) Rake leaves
748@end smallexample
749
750@noindent
751causes the fancy diary to show
752
753@smallexample
754Rake leaves
755@end smallexample
756
757@noindent
758on October 22, November 22, and December 22 of every year.
759
760@findex diary-float
761 The function @code{diary-float} allows you to describe diary entries
762that apply to dates like the third Friday of November, or the last
763Tuesday in April. The parameters are the @var{month}, @var{dayname},
f9b4c05d 764and an index @var{n}. The entry appears on the @var{n}th @var{dayname}
ff2c14fc
GM
765after the first day of @var{month}, where @var{dayname}=0 means Sunday,
7661 means Monday, and so on. If @var{n} is negative it counts backward
767from the end of @var{month}. The value of @var{month} can be a list of
768months, a single month, or @code{t} to specify all months. You can also
769use an optional parameter @var{day} to specify the @var{n}th
770@var{dayname} on or after/before @var{day} of @var{month}; the value of
771@var{day} defaults to 1 if @var{n} is positive and to the last day of
772@var{month} if @var{n} is negative. For example,
c5184807
EZ
773
774@smallexample
775%%(diary-float t 1 -1) Pay rent
776@end smallexample
777
778@noindent
779causes the fancy diary to show
780
781@smallexample
782Pay rent
783@end smallexample
784
785@noindent
786on the last Monday of every month.
787
788 The generality of sexp diary entries lets you specify any diary
789entry that you can describe algorithmically. A sexp diary entry
790contains an expression that computes whether the entry applies to any
791given date. If its value is non-@code{nil}, the entry applies to that
792date; otherwise, it does not. The expression can use the variable
793@code{date} to find the date being considered; its value is a list
794(@var{month} @var{day} @var{year}) that refers to the Gregorian
795calendar.
796
797 The sexp diary entry applies to a date when the expression's value
798is non-@code{nil}, but some values have more specific meanings. If
799the value is a string, that string is a description of the event which
800occurs on that date. The value can also have the form
801@code{(@var{mark} . @var{string})}; then @var{mark} specifies how to
802mark the date in the calendar, and @var{string} is the description of
803the event. If @var{mark} is a single-character string, that character
804appears next to the date in the calendar. If @var{mark} is a face
805name, the date is displayed in that face. If @var{mark} is
806@code{nil}, that specifies no particular highlighting for the date.
807
808 Suppose you get paid on the 21st of the month if it is a weekday, and
809on the Friday before if the 21st is on a weekend. Here is how to write
810a sexp diary entry that matches those dates:
811
812@smallexample
813&%%(let ((dayname (calendar-day-of-week date))
f9b4c05d 814 (day (cadr date)))
c5184807
EZ
815 (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
816 (and (memq day '(19 20)) (= dayname 5)))
817 ) Pay check deposited
818@end smallexample
819
820 The following sexp diary entries take advantage of the ability (in the fancy
821diary display) to concoct diary entries whose text varies based on the date:
822
823@findex diary-sunrise-sunset
8ce2c66f 824@findex diary-lunar-phases
c5184807
EZ
825@findex diary-day-of-year
826@findex diary-iso-date
827@findex diary-julian-date
828@findex diary-astro-day-number
36c0514c 829@findex diary-bahai-date
f9b4c05d
GM
830@findex diary-chinese-date
831@findex diary-coptic-date
832@findex diary-ethiopic-date
c5184807
EZ
833@findex diary-hebrew-date
834@findex diary-islamic-date
835@findex diary-french-date
836@findex diary-mayan-date
f9b4c05d 837@findex diary-persian-date
c5184807
EZ
838@table @code
839@item %%(diary-sunrise-sunset)
f9b4c05d 840Make a diary entry for today's local times of sunrise and sunset.
8ce2c66f 841@item %%(diary-lunar-phases)
c5184807
EZ
842Make a diary entry for the phases (quarters) of the moon.
843@item %%(diary-day-of-year)
844Make a diary entry with today's day number in the current year and the number
845of days remaining in the current year.
846@item %%(diary-iso-date)
847Make a diary entry with today's equivalent ISO commercial date.
848@item %%(diary-julian-date)
f9b4c05d 849Make a diary entry with today's equivalent Julian calendar date.
c5184807
EZ
850@item %%(diary-astro-day-number)
851Make a diary entry with today's equivalent astronomical (Julian) day number.
36c0514c 852@item %%(diary-bahai-date)
f9b4c05d
GM
853Make a diary entry with today's equivalent Baha'i calendar date.
854@item %%(diary-chinese-date)
855Make a diary entry with today's equivalent Chinese calendar date.
856@item %%(diary-coptic-date)
857Make a diary entry with today's equivalent Coptic calendar date.
858@item %%(diary-ethiopic-date)
859Make a diary entry with today's equivalent Ethiopic calendar date.
c5184807
EZ
860@item %%(diary-french-date)
861Make a diary entry with today's equivalent date on the French Revolutionary
862calendar.
f9b4c05d
GM
863@item %%(diary-hebrew-date)
864Make a diary entry with today's equivalent Hebrew calendar date.
865@item %%(diary-islamic-date)
866Make a diary entry with today's equivalent Islamic calendar date.
c5184807 867@item %%(diary-mayan-date)
f9b4c05d
GM
868Make a diary entry with today's equivalent Mayan calendar date.
869@item %%(diary-persian-date)
870Make a diary entry with today's equivalent Persian calendar date.
c5184807
EZ
871@end table
872
873@noindent
f9b4c05d 874For example, including the diary entry
c5184807 875
f9b4c05d 876@smallexample
c5184807 877&%%(diary-hebrew-date)
f9b4c05d 878@end smallexample
c5184807
EZ
879
880@noindent
881causes every day's diary display to contain the equivalent date on the
882Hebrew calendar, if you are using the fancy diary display. (With simple
f9b4c05d
GM
883diary display, the literal line @samp{&%%(diary-hebrew-date)} appears in
884the diary for any date.)
c5184807 885
f9b4c05d
GM
886 This function has been used to construct certain standard Hebrew sexp
887diary entries:
c5184807
EZ
888
889@cindex rosh hodesh
36c0514c 890@findex diary-hebrew-rosh-hodesh
c5184807 891@cindex parasha, weekly
36c0514c 892@findex diary-hebrew-parasha
c5184807 893@cindex candle lighting times
36c0514c 894@findex diary-hebrew-sabbath-candles
c5184807 895@cindex omer count
36c0514c 896@findex diary-hebrew-omer
c5184807 897@cindex yahrzeits
36c0514c 898@findex diary-hebrew-yahrzeit
d306b4da 899@findex diary-hebrew-birthday
c5184807 900@table @code
36c0514c 901@item %%(diary-hebrew-rosh-hodesh)
c5184807
EZ
902Make a diary entry that tells the occurrence and ritual announcement of each
903new Hebrew month.
36c0514c 904@item %%(diary-hebrew-parasha)
c5184807 905Make a Saturday diary entry that tells the weekly synagogue scripture reading.
36c0514c 906@item %%(diary-hebrew-sabbath-candles)
c5184807
EZ
907Make a Friday diary entry that tells the @emph{local time} of Sabbath
908candle lighting.
36c0514c 909@item %%(diary-hebrew-omer)
c5184807 910Make a diary entry that gives the omer count, when appropriate.
36c0514c 911@item %%(diary-hebrew-yahrzeit @var{month} @var{day} @var{year}) @var{name}
c5184807
EZ
912Make a diary entry marking the anniversary of a date of death. The date
913is the @emph{Gregorian} (civil) date of death. The diary entry appears
f9b4c05d
GM
914on the proper Hebrew calendar anniversary and on the day before. (The
915order of the parameters changes according to the calendar date style;
916for example in the European style to @var{day}, @var{month}, @var{year}.)
d306b4da
GM
917@item %%(diary-hebrew-birthday @var{month} @var{day} @var{year})
918Make a diary entry for a birthday on the Hebrew calendar.
c5184807
EZ
919@end table
920
921 All the functions documented above take an optional argument
922@var{mark} which specifies how to mark the date in the calendar display.
923If one of these functions decides that it applies to a certain date,
f9b4c05d 924it returns a value that contains @var{mark}, as described above.