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