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