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