1 @c This is part of the Emacs manual. -*- coding: iso-latin-1 -*-
2 @c Copyright (C) 2004-2012 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
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).
8 @c Moved here from the Emacs Lisp Reference Manual, 2005-03-26.
9 @node Advanced Calendar/Diary Usage
10 @section More advanced features of the Calendar and Diary
12 This section describes some of the more advanced/specialized
13 features of the calendar and diary. It starts with some of the
14 many ways in which you can customize the calendar and diary to suit
18 * Calendar Customizing:: Calendar layout and hooks.
19 * Holiday Customizing:: Defining your own holidays.
20 * Date Display Format:: Changing the format.
21 * Time Display Format:: Changing the format.
22 * Diary Customizing:: Defaults you can set.
23 * Non-Gregorian Diary:: Diary entries based on other calendars.
24 * Diary Display:: A choice of ways to display the diary.
25 * Fancy Diary Display:: Sorting diary entries, using included diary files.
26 * Sexp Diary Entries:: More flexible diary entries.
29 @node Calendar Customizing
30 @subsection Customizing the Calendar
32 @vindex calendar-intermonth-text
33 @cindex calendar layout
34 @cindex calendar week numbers
35 The calendar display unfortunately cannot be changed from three
36 months, but you can customize the whitespace used by setting the
37 variables: @code{calendar-left-margin},
38 @code{calendar-day-header-width}, @code{calendar-day-digit-width},
39 @code{calendar-column-width}, and @code{calendar-intermonth-spacing}.
40 To display text @emph{between} the months, for example week numbers,
41 customize the variables @code{calendar-intermonth-header} and
42 @code{calendar-intermonth-text} as described in their documentation.
44 @vindex calendar-month-header
45 The variable @code{calendar-month-header} controls the text that
46 appears above each month in the calendar. By default, it shows the
49 @vindex calendar-holiday-marker
50 @vindex diary-entry-marker
51 @vindex calendar-today-marker
52 The variable @code{calendar-holiday-marker} specifies how to mark a
53 date that is a holiday. Its value may be a single-character string to
54 insert next to the date, or a face name to use for displaying the date.
55 Likewise, the variable @code{diary-entry-marker} specifies how to mark a
56 date that has diary entries. The function @code{calendar-mark-today}
57 uses @code{calendar-today-marker} to mark today's date. By default,
58 the calendar uses faces named @code{holiday}, @code{diary}, and
59 @code{calendar-today} for these purposes.
61 @vindex calendar-load-hook
62 The variable @code{calendar-load-hook} is a normal hook run when the
63 calendar package is first loaded (before actually starting to display
66 @vindex calendar-initial-window-hook
67 Starting the calendar runs the normal hook
68 @code{calendar-initial-window-hook}. Recomputation of the calendar
69 display does not run this hook. But if you leave the calendar with the
70 @kbd{q} command and reenter it, the hook runs again.@refill
72 @vindex calendar-today-visible-hook
73 @findex calendar-star-date
74 The variable @code{calendar-today-visible-hook} is a normal hook run
75 after the calendar buffer has been prepared with the calendar, when the
76 current date is visible in the window. One use of this hook is to
77 mark today's date; to do that use either of the functions
78 @code{calendar-mark-today} or @code{calendar-star-date}:
80 @findex calendar-mark-today
82 (add-hook 'calendar-today-visible-hook 'calendar-mark-today)
85 @vindex calendar-today-invisible-hook
87 A similar normal hook, @code{calendar-today-invisible-hook} is run if
88 the current date is @emph{not} visible in the window.
90 @vindex calendar-move-hook
91 Each of the calendar cursor motion commands runs the hook
92 @code{calendar-move-hook} after it moves the cursor.
94 @node Holiday Customizing
95 @subsection Customizing the Holidays
97 @vindex calendar-holidays
98 @vindex holiday-oriental-holidays
99 @vindex holiday-solar-holidays
100 There are several variables listing the default holidays that Emacs
101 knows about. These are: @code{holiday-general-holidays},
102 @code{holiday-local-holidays}, @code{holiday-solar-holidays},
103 @code{holiday-bahai-holidays}, @code{holiday-christian-holidays},
104 @code{holiday-hebrew-holidays}, @code{holiday-islamic-holidays},
105 @code{holiday-oriental-holidays}, and @code{holiday-other-holidays}.
106 The names should be self-explanatory; e.g.@: @code{holiday-solar-holidays}
107 lists sun- and moon-related holidays.
109 You can customize these lists of holidays to your own needs, deleting or
110 adding holidays as described below. Set any of them to @code{nil} to
111 not show the associated holidays.
113 @vindex holiday-general-holidays
114 @vindex holiday-local-holidays
115 @vindex holiday-other-holidays
116 The general holidays are, by default, holidays common throughout the
117 United States. In contrast, @code{holiday-local-holidays} and
118 @code{holiday-other-holidays} are both empty by default. These are
119 intended for system-wide settings and your individual use,
122 @vindex holiday-bahai-holidays
123 @vindex holiday-christian-holidays
124 @vindex holiday-hebrew-holidays
125 @vindex holiday-islamic-holidays
126 @vindex calendar-bahai-all-holidays-flag
127 @vindex calendar-christian-all-holidays-flag
128 @vindex calendar-hebrew-all-holidays-flag
129 @vindex calendar-islamic-all-holidays-flag
130 By default, Emacs does not include all the holidays of the religions
131 that it knows, only those commonly found in secular calendars. For a
132 more extensive collection of religious holidays, you can set any (or
133 all) of the variables @code{calendar-bahai-all-holidays-flag},
134 @code{calendar-christian-all-holidays-flag},
135 @code{calendar-hebrew-all-holidays-flag}, or
136 @code{calendar-islamic-all-holidays-flag} to @code{t}.
138 @cindex holiday forms
139 Each of the holiday variables is a list of @dfn{holiday forms}, each
140 form describing a holiday (or sometimes a list of holidays). Here is
141 a table of the possible kinds of holiday form. Day numbers and month
142 numbers count starting from 1, but ``dayname'' numbers count Sunday as
143 0. The argument @var{string} is always the description of the
144 holiday, as a string.
147 @item (holiday-fixed @var{month} @var{day} @var{string})
148 A fixed date on the Gregorian calendar.
150 @item (holiday-float @var{month} @var{dayname} @var{k} @var{string}
152 The @var{k}th @var{dayname} (@var{dayname}=0 for Sunday, and so on)
153 after or before Gregorian date @var{month}, @var{day}. Negative @var{k}
154 means count back from the end of the month. Optional @var{day} defaults
155 to 1 if @var{k} is positive, and the last day of @var{month} otherwise.
157 @item (holiday-chinese @var{month} @var{day} @var{string})
158 A fixed date on the Chinese calendar.
160 @item (holiday-hebrew @var{month} @var{day} @var{string})
161 A fixed date on the Hebrew calendar.
163 @item (holiday-islamic @var{month} @var{day} @var{string})
164 A fixed date on the Islamic calendar.
166 @item (holiday-julian @var{month} @var{day} @var{string})
167 A fixed date on the Julian calendar.
169 @item (holiday-sexp @var{sexp} @var{string})
170 A date calculated by the Lisp expression @var{sexp}. The expression
171 should use the variable @code{year} to compute and return the date of a
172 holiday in the form of a list @code{(@var{month} @var{day} @var{year})},
173 or @code{nil} if the holiday doesn't happen this year.
175 @item (if @var{condition} @var{holiday-form})
176 A holiday that happens only if @var{condition} is true.
178 @item (@var{function} @r{[}@var{args}@r{]})
179 A list of dates calculated by the function @var{function}, called with
180 arguments @var{args}.
183 For example, suppose you want to add Bastille Day, celebrated in
184 France on July 14 (i.e., the fourteenth day of the seventh month). You
185 can do this as follows:
188 (setq holiday-other-holidays '((holiday-fixed 7 14 "Bastille Day")))
191 Many holidays occur on a specific day of the week, at a specific time
192 of month. Here is a holiday form describing Hurricane Supplication Day,
193 celebrated in the Virgin Islands on the fourth Monday in August:
196 (holiday-float 8 1 4 "Hurricane Supplication Day")
200 Here the 8 specifies August, the 1 specifies Monday (Sunday is 0,
201 Tuesday is 2, and so on), and the 4 specifies the fourth occurrence in
202 the month (1 specifies the first occurrence, 2 the second occurrence,
203 @minus{}1 the last occurrence, @minus{}2 the second-to-last occurrence, and
206 You can specify holidays that occur on fixed days of the Bahá'í,
207 Chinese, Hebrew, Islamic, and Julian calendars too. For example,
210 (setq holiday-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")))
217 adds the last day of Hanukkah (since the Hebrew months are numbered with
218 1 starting from Nisan), the Islamic feast celebrating Mohammed's
219 birthday (since the Islamic months are numbered from 1 starting with
220 Muharram), and Thomas Jefferson's birthday, which is 2 April 1743 on the
223 To include a holiday conditionally, use either Emacs Lisp's @code{if}
224 or the @code{holiday-sexp} form. For example, American presidential
225 elections occur on the first Tuesday after the first Monday in November
226 of years divisible by 4:
229 (holiday-sexp '(if (zerop (% year 4))
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")
241 (if (zerop (% displayed-year 4))
243 (calendar-extract-day
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"))
251 Some holidays just don't fit into any of these forms because special
252 calculations are involved in their determination. In such cases you
253 must write a Lisp function to do the calculation. To include eclipses,
254 for example, add @code{(eclipses)} to @code{holiday-other-holidays}
255 and write an Emacs Lisp function @code{eclipses} that returns a
256 (possibly empty) list of the relevant Gregorian dates among the range
257 visible in the calendar window, with descriptive strings, like this:
260 (((6 4 2012) "Lunar Eclipse") ((11 13 2012) "Solar Eclipse") ... )
263 @node Date Display Format
264 @subsection Date Display Format
265 @vindex calendar-date-display-form
267 You can customize the way dates are displayed in the diary, mode
268 lines, and messages by setting @code{calendar-date-display-form}.
269 This variable holds a list of expressions that can involve the variables
270 @code{month}, @code{day}, and @code{year}, which are all numbers in
271 string form, and @code{monthname} and @code{dayname}, which are both
272 alphabetic strings. In the American style, the default value of this
276 ((if dayname (concat dayname ", ")) monthname " " day ", " year)
280 while in the European style this value is the default:
283 ((if dayname (concat dayname ", ")) day " " monthname " " year)
287 The default ISO date representation is:
290 ((format "%s-%.2d-%.2d" year (string-to-number month)
291 (string-to-number day)))
295 Another typical American format is:
298 (month "/" day "/" (substring year -2))
301 @node Time Display Format
302 @subsection Time Display Format
303 @vindex calendar-time-display-form
305 The calendar and diary by default display times of day in the
306 conventional American style with the hours from 1 through 12, minutes,
307 and either @samp{am} or @samp{pm}. If you prefer the European style,
308 also known in the US as military, in which the hours go from 00 to 23,
309 you can alter the variable @code{calendar-time-display-form}. This
310 variable is a list of expressions that can involve the variables
311 @code{12-hours}, @code{24-hours}, and @code{minutes}, which are all
312 numbers in string form, and @code{am-pm} and @code{time-zone}, which are
313 both alphabetic strings. The default value is:
316 (12-hours ":" minutes am-pm
317 (if time-zone " (") time-zone (if time-zone ")"))
321 Here is a value that provides European style times:
324 (24-hours ":" minutes
325 (if time-zone " (") time-zone (if time-zone ")"))
328 Note that few calendar functions return a time of day (at present, only
331 @node Diary Customizing
332 @subsection Customizing the Diary
334 @vindex diary-show-holidays-flag
335 Ordinarily, the diary window indicates any holidays that fall on the
336 date of the diary entries, either in the mode line or the buffer itself.
337 The process of checking for holidays can be slow, depending on the
338 defined holidays. In that case, setting @code{diary-show-holidays-flag}
339 to @code{nil} will speed up the diary display.
341 @vindex diary-number-of-entries
342 The variable @code{diary-number-of-entries} controls the number of
343 days of diary entries to be displayed at one time. It affects the
344 initial display when @code{calendar-view-diary-initially-flag} is
345 @code{t}, as well as the command @kbd{M-x diary}. For example, a value
346 of 1 (the default) displays only the current day's diary entries,
347 whereas a value of 2 will also show the next day's entries. The value
348 can 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
350 current date's and the next day's diary entries appear Monday through
351 Thursday, Friday through Monday's entries appear on Friday, while on
352 Saturday only that day's entries appear.
354 @vindex diary-date-forms
355 You can customize the form of dates in your diary file by setting the
356 variable @code{diary-date-forms}. This variable is a list of patterns
357 for recognizing a date. Each date pattern is a list whose elements may
358 be regular expressions (@pxref{Regular Expressions,,, elisp, the Emacs
359 Lisp Reference Manual}) or the symbols @code{month}, @code{day},
360 @code{year}, @code{monthname}, and @code{dayname}. All these elements
361 serve as patterns that match certain kinds of text in the diary file.
362 In order for the date pattern as a whole to match, all of its elements
363 must match consecutively.
365 A regular expression in a date pattern matches in its usual fashion,
366 using the standard syntax table altered so that @samp{*} is a word
369 The symbols @code{month}, @code{day}, @code{year}, @code{monthname},
370 and @code{dayname} match the month number, day number, year number,
371 month name, and day name of the date being considered. The symbols that
372 match numbers allow leading zeros; those that match names allow
373 capitalization and abbreviation (as specified by
374 @code{calendar-month-abbrev-array} and
375 @code{calendar-day-abbrev-array}). All the symbols can match @samp{*};
376 since @samp{*} in a diary entry means ``any day'', ``any month'', and so
377 on, it should match regardless of the date being considered.
379 The default value of @code{diary-date-forms} in the American style is
380 provided by @code{diary-american-date-forms}:
383 ((month "/" day "[^/0-9]")
384 (month "/" day "/" year "[^0-9]")
385 (monthname " *" day "[^,0-9]")
386 (monthname " *" day ", *" year "[^0-9]")
391 The variables @code{diary-european-date-forms} and
392 @code{diary-iso-date-forms} provide other default styles.
394 The date patterns in the list must be @emph{mutually exclusive} and
395 must not match any portion of the diary entry itself, just the date and
396 one character of whitespace. If, to be mutually exclusive, the pattern
397 must match a portion of the diary entry text---beyond the whitespace
398 that ends the date---then the first element of the date pattern
399 @emph{must} be @code{backup}. This causes the date recognizer to back
400 up to the beginning of the current word of the diary entry, after
401 finishing the match. Even if you use @code{backup}, the date pattern
402 must absolutely not match more than a portion of the first word of the
403 diary entry. For example, the default value of
404 @code{diary-european-date-forms} is:
407 ((day "/" month "[^/0-9]")
408 (day "/" month "/" year "[^0-9]")
409 (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
410 (day " *" monthname " *" year "[^0-9]")
415 Notice the use of @code{backup} in the third pattern, because it needs
416 to match part of a word beyond the date itself to distinguish it from
419 @node Non-Gregorian Diary
420 @subsection Diary Entries Using non-Gregorian Calendars
422 As well as entries based on the standard Gregorian calendar, your
423 diary can have entries based on Bahá'í, Hebrew, or Islamic dates.
424 Recognition of such entries can be time-consuming, however, and since
425 most people don't use them, you must explicitly enable their use. If
426 you want the diary to recognize Hebrew-date diary entries, for example,
429 @vindex diary-nongregorian-listing-hook
430 @vindex diary-nongregorian-marking-hook
431 @findex diary-hebrew-list-entries
432 @findex diary-hebrew-mark-entries
433 @findex diary-islamic-list-entries
434 @findex diary-islamic-mark-entries
435 @findex diary-bahai-list-entries
436 @findex diary-bahai-mark-entries
438 (add-hook 'diary-nongregorian-listing-hook 'diary-hebrew-list-entries)
439 (add-hook 'diary-nongregorian-marking-hook 'diary-hebrew-mark-entries)
443 Similarly, for Islamic and Bahá'í entries, add
444 @code{diary-islamic-list-entries} and @code{diary-islamic-mark-entries}, or
445 @code{diary-bahai-list-entries} and @code{diary-bahai-mark-entries}.
447 @vindex diary-bahai-entry-symbol
448 @vindex diary-hebrew-entry-symbol
449 @vindex diary-islamic-entry-symbol
450 These diary entries have the same formats as Gregorian-date diary
451 entries; except that @code{diary-bahai-entry-symbol} (default @samp{B})
452 must precede a Bahá'í date, @code{diary-hebrew-entry-symbol} (default
453 @samp{H}) a Hebrew date, and @code{diary-islamic-entry-symbol} (default
454 @samp{I}) an Islamic date. Moreover, non-Gregorian month names may not
455 be abbreviated (because the first three letters are often not unique).
456 (Note also that you must use ``Adar I'' if you want Adar of a common
457 Hebrew year.) For example, a diary entry for the Hebrew date Heshvan 25
458 could look like this:
461 HHeshvan 25 Happy Hebrew birthday!
465 and would appear in the diary for any date that corresponds to Heshvan 25
466 on the Hebrew calendar. And here is an Islamic-date diary entry that matches
470 IDhu al-Qada 25 Happy Islamic birthday!
473 As with Gregorian-date diary entries, non-Gregorian entries are
474 nonmarking if preceded by @code{diary-nonmarking-symbol} (default
477 Here is a table of commands used in the calendar to create diary
478 entries that match the selected date and other dates that are similar in
479 the Bahá'í, Hebrew, or Islamic calendars:
483 @code{diary-hebrew-insert-entry}
485 @code{diary-hebrew-insert-monthly-entry}
487 @code{diary-hebrew-insert-yearly-entry}
489 @code{diary-islamic-insert-entry}
491 @code{diary-islamic-insert-monthly-entry}
493 @code{diary-islamic-insert-yearly-entry}
495 @code{diary-bahai-insert-entry}
497 @code{diary-bahai-insert-monthly-entry}
499 @code{diary-bahai-insert-yearly-entry}
502 @findex diary-hebrew-insert-entry
503 @findex diary-hebrew-insert-monthly-entry
504 @findex diary-hebrew-insert-yearly-entry
505 @findex diary-islamic-insert-entry
506 @findex diary-islamic-insert-monthly-entry
507 @findex diary-islamic-insert-yearly-entry
508 @findex diary-bahai-insert-entry
509 @findex diary-bahai-insert-monthly-entry
510 @findex diary-bahai-insert-yearly-entry
511 These commands work much like the corresponding commands for ordinary
512 diary entries: they apply to the date that point is on in the calendar
513 window, and what they do is insert just the date portion of a diary
514 entry at the end of your diary file. You must then insert the rest of
515 the diary entry. The basic commands add an entry for the specific
516 non-Gregorian date, the @samp{monthly} commands for the given
517 non-Gregorian day-within-month in every month, and the @samp{yearly}
518 commands for the given non-Gregorian day and month in every year.
521 @subsection Diary Display
522 @vindex diary-display-function
523 @findex diary-simple-display
524 @findex diary-fancy-display
527 Diary display works by preparing the list of diary entries and then
528 running the function specified by the variable
529 @code{diary-display-function}. The default value
530 @code{diary-fancy-display} displays diary entries and holidays by
531 copying them into a special buffer that exists only for the sake of
532 display. Copying diary entries to a separate buffer provides an
533 opportunity to change the displayed text to make it prettier---for
534 example, to sort the entries by the dates they apply to.
536 @vindex diary-list-include-blanks
537 Ordinarily, the fancy diary buffer does not show days for which there
538 are no diary entries, even if that day is a holiday. If you want such
539 days to be shown in the fancy diary buffer, set the variable
540 @code{diary-list-include-blanks} to @code{t}.@refill
542 The fancy diary buffer enables View mode
544 (@pxref{View Mode,,, emacs, the Emacs Manual}).
550 The alternative display method @code{diary-simple-display} shows the
551 actual diary buffer, and uses invisible text to hide entries that don't
552 apply. Holidays are shown in the mode line. The advantage of this
553 method is that you can edit the buffer and save your changes directly to
554 the diary file. This method is not as flexible as the fancy method,
555 however. For example, it cannot sort entries. Another disadvantage is
556 that invisible text can be confusing. For example, if you copy a region
557 of text in order to paste it elsewhere, invisible text may be included.
558 Similarly, since the diary buffer as you see it is an illusion, simply
559 printing the buffer may not print what you see on your screen.
561 @vindex diary-print-entries-hook
562 @findex diary-print-entries
563 For this reason, there is a special command to print hard copy of the
564 diary buffer @emph{as it appears}; this command is @kbd{M-x
565 diary-print-entries}. It works with either display method, although
566 with the fancy display you can also print the buffer like any other. To
567 print a hard copy of a day-by-day diary for a week, position point on
568 the first day of the week, type @kbd{7 d}, and then do @kbd{M-x
569 diary-print-entries}. As usual, the inclusion of the holidays slows
570 down the display slightly; you can speed things up by setting the
571 variable @code{diary-show-holidays-flag} to @code{nil}.
573 This command prepares a temporary buffer that contains only the diary
574 entries currently visible in the diary buffer. Unlike with the simple
575 display, the other irrelevant entries are really absent, not just
576 hidden. After preparing the buffer, it runs the hook
577 @code{diary-print-entries-hook}. The default value of this hook sends
578 the data directly to the printer with the command @code{lpr-buffer}
580 (@pxref{Printing,,, emacs, the Emacs Manual}).
585 If you want to use a different command to do the
586 printing, just change the value of this hook. Other uses might include,
587 for example, rearranging the lines into order by day and time.
589 You can edit the diary entries as they appear in the simple diary
590 window, but it is important to remember that the buffer displayed
591 contains the @emph{entire} diary file, with portions of it concealed
592 from view. This means, for instance, that the @kbd{C-f}
593 (@code{forward-char}) command can put point at what appears to be the
594 end of the line, but what is in reality the middle of some concealed
597 @emph{Be careful when editing the diary entries in the simple display!}
598 Inserting additional lines or adding/deleting characters in the middle
599 of a visible line cannot cause problems, but editing at the end of a
600 line may not do what you expect. Deleting a line may delete other
601 invisible entries that follow it. Before editing the simple diary
602 buffer, it is best to display the entire file with @kbd{s}
603 (@code{diary-show-all-entries}).
605 @node Fancy Diary Display
606 @subsection Fancy Diary Display
608 The following features only work with the fancy diary display.
610 @cindex sorting diary entries
611 You can use the normal hook @code{diary-list-entries-hook} to sort
612 each day's diary entries by their time of day. Here's how:
614 @findex diary-sort-entries
616 (add-hook 'diary-list-entries-hook 'diary-sort-entries t)
620 For each day, this sorts diary entries that begin with a recognizable
621 time of day according to their times. Diary entries without times come
622 first within each day. Note how the sort command is placed at the end
623 of the hook list, in case earlier members of the list change the order
624 of the diary entries, or add items.
626 @vindex diary-comment-start
627 You can write @samp{comments} in diary entries, by setting the
628 variables @code{diary-comment-start} and @code{diary-comment-end} to
629 strings that delimit comments. The fancy display does not print
630 comments. You might want to put meta-data for the use of other packages
631 (e.g.@: the appointment package,
633 @pxref{Appointments,,,emacs, the Emacs Manual})
636 @pxref{Appointments})
640 @vindex diary-include-string
641 Your main diary file can include other files. This permits a group of
642 people to share a diary file for events that apply to all of them.
643 Lines in the diary file starting with @code{diary-include-string}:
646 #include "@var{filename}"
650 include the diary entries from the file @var{filename} in the fancy
651 diary buffer. The include mechanism is recursive, so that included
652 files can include other files, and so on (you must be careful not to
653 have a cycle of inclusions, of course). Here is how to enable the
656 @vindex diary-list-entries-hook
657 @vindex diary-mark-entries-hook
658 @findex diary-include-other-diary-files
659 @findex diary-mark-included-diary-files
661 (add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
662 (add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)
665 The include mechanism works only with the fancy diary display, because
666 simple diary display shows the entries directly from your diary file.
668 @node Sexp Diary Entries
669 @subsection Sexp Entries and the Fancy Diary Display
670 @cindex sexp diary entries
672 @vindex diary-sexp-entry-symbol
673 Sexp diary entries allow you to do more than just have complicated
674 conditions under which a diary entry applies. Sexp entries should be
675 preceded by @code{diary-sexp-entry-symbol} (default @samp{%%}) in the
676 diary file. With the fancy diary display, sexp entries can generate the
677 text of the entry depending on the date itself.
679 For example, an anniversary diary entry can insert
680 the number of years since the anniversary date into the text of the
681 diary entry. Thus the @samp{%d} in this diary entry:
683 @findex diary-anniversary
685 %%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)
689 gets replaced by the age, so on October 31, 1990 the entry appears in
690 the fancy diary buffer like this:
693 Arthur's birthday (42 years old)
697 If the diary file instead contains this entry:
700 %%(diary-anniversary 10 31 1948) Arthur's %d%s birthday
704 the entry in the fancy diary buffer for October 31, 1990 appears like this:
707 Arthur's 42nd birthday
710 Similarly, cyclic diary entries can interpolate the number of repetitions
715 %%(diary-cyclic 50 1 1 2012) Renew medication (%d%s time)
722 Renew medication (5th time)
726 in the fancy diary display on September 7, 2012.
728 There is an ``early reminder'' diary sexp that includes its entry in the
729 diary not only on the date of occurrence, but also on earlier dates.
730 For example, if you want a reminder a week before your anniversary, you
735 %%(diary-remind '(diary-anniversary 12 22 1968) 7) Ed's anniversary
739 and the fancy diary will show @samp{Ed's anniversary} both on December
740 15 and on December 22.
743 The function @code{diary-date} applies to dates described by a month,
744 day, year combination, each of which can be an integer, a list of
745 integers, or @code{t} (meaning all values). For example,
748 %%(diary-date '(10 11 12) 22 t) Rake leaves
752 causes the fancy diary to show
759 on October 22, November 22, and December 22 of every year.
762 The function @code{diary-float} allows you to describe diary entries
763 that apply to dates like the third Friday of November, or the last
764 Tuesday in April. The parameters are the @var{month}, @var{dayname},
765 and an index @var{n}. The entry appears on the @var{n}th @var{dayname}
766 after the first day of @var{month}, where @var{dayname}=0 means Sunday,
767 1 means Monday, and so on. If @var{n} is negative it counts backward
768 from the end of @var{month}. The value of @var{month} can be a list of
769 months, a single month, or @code{t} to specify all months. You can also
770 use an optional parameter @var{day} to specify the @var{n}th
771 @var{dayname} on or after/before @var{day} of @var{month}; the value of
772 @var{day} defaults to 1 if @var{n} is positive and to the last day of
773 @var{month} if @var{n} is negative. For example,
776 %%(diary-float t 1 -1) Pay rent
780 causes the fancy diary to show
787 on the last Monday of every month.
789 The generality of sexp diary entries lets you specify any diary
790 entry that you can describe algorithmically. A sexp diary entry
791 contains an expression that computes whether the entry applies to any
792 given date. If its value is non-@code{nil}, the entry applies to that
793 date; otherwise, it does not. The expression can use the variable
794 @code{date} to find the date being considered; its value is a list
795 (@var{month} @var{day} @var{year}) that refers to the Gregorian
798 The sexp diary entry applies to a date when the expression's value
799 is non-@code{nil}, but some values have more specific meanings. If
800 the value is a string, that string is a description of the event which
801 occurs on that date. The value can also have the form
802 @code{(@var{mark} . @var{string})}; then @var{mark} specifies how to
803 mark the date in the calendar, and @var{string} is the description of
804 the event. If @var{mark} is a single-character string, that character
805 appears next to the date in the calendar. If @var{mark} is a face
806 name, the date is displayed in that face. If @var{mark} is
807 @code{nil}, that specifies no particular highlighting for the date.
809 Suppose you get paid on the 21st of the month if it is a weekday, and
810 on the Friday before if the 21st is on a weekend. Here is how to write
811 a sexp diary entry that matches those dates:
814 &%%(let ((dayname (calendar-day-of-week date))
816 (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
817 (and (memq day '(19 20)) (= dayname 5)))
818 ) Pay check deposited
821 The following sexp diary entries take advantage of the ability (in the fancy
822 diary display) to concoct diary entries whose text varies based on the date:
824 @findex diary-sunrise-sunset
825 @findex diary-lunar-phases
826 @findex diary-day-of-year
827 @findex diary-iso-date
828 @findex diary-julian-date
829 @findex diary-astro-day-number
830 @findex diary-bahai-date
831 @findex diary-chinese-date
832 @findex diary-coptic-date
833 @findex diary-ethiopic-date
834 @findex diary-hebrew-date
835 @findex diary-islamic-date
836 @findex diary-french-date
837 @findex diary-mayan-date
838 @findex diary-persian-date
840 @item %%(diary-sunrise-sunset)
841 Make a diary entry for today's local times of sunrise and sunset.
842 @item %%(diary-lunar-phases)
843 Make a diary entry for the phases (quarters) of the moon.
844 @item %%(diary-day-of-year)
845 Make a diary entry with today's day number in the current year and the number
846 of days remaining in the current year.
847 @item %%(diary-iso-date)
848 Make a diary entry with today's equivalent ISO commercial date.
849 @item %%(diary-julian-date)
850 Make a diary entry with today's equivalent Julian calendar date.
851 @item %%(diary-astro-day-number)
852 Make a diary entry with today's equivalent astronomical (Julian) day number.
853 @item %%(diary-bahai-date)
854 Make a diary entry with today's equivalent Bahá'í calendar date.
855 @item %%(diary-chinese-date)
856 Make a diary entry with today's equivalent Chinese calendar date.
857 @item %%(diary-coptic-date)
858 Make a diary entry with today's equivalent Coptic calendar date.
859 @item %%(diary-ethiopic-date)
860 Make a diary entry with today's equivalent Ethiopic calendar date.
861 @item %%(diary-french-date)
862 Make a diary entry with today's equivalent date on the French Revolutionary
864 @item %%(diary-hebrew-date)
865 Make a diary entry with today's equivalent Hebrew calendar date.
866 @item %%(diary-islamic-date)
867 Make a diary entry with today's equivalent Islamic calendar date.
868 @item %%(diary-mayan-date)
869 Make a diary entry with today's equivalent Mayan calendar date.
870 @item %%(diary-persian-date)
871 Make a diary entry with today's equivalent Persian calendar date.
875 For example, including the diary entry
878 &%%(diary-hebrew-date)
882 causes every day's diary display to contain the equivalent date on the
883 Hebrew calendar, if you are using the fancy diary display. (With simple
884 diary display, the literal line @samp{&%%(diary-hebrew-date)} appears in
885 the diary for any date.)
887 This function has been used to construct certain standard Hebrew sexp
891 @findex diary-hebrew-rosh-hodesh
892 @cindex parasha, weekly
893 @findex diary-hebrew-parasha
894 @cindex candle lighting times
895 @findex diary-hebrew-sabbath-candles
897 @findex diary-hebrew-omer
899 @findex diary-hebrew-yahrzeit
900 @findex diary-hebrew-birthday
902 @item %%(diary-hebrew-rosh-hodesh)
903 Make a diary entry that tells the occurrence and ritual announcement of each
905 @item %%(diary-hebrew-parasha)
906 Make a Saturday diary entry that tells the weekly synagogue scripture reading.
907 @item %%(diary-hebrew-sabbath-candles)
908 Make a Friday diary entry that tells the @emph{local time} of Sabbath
910 @item %%(diary-hebrew-omer)
911 Make a diary entry that gives the omer count, when appropriate.
912 @item %%(diary-hebrew-yahrzeit @var{month} @var{day} @var{year}) @var{name}
913 Make a diary entry marking the anniversary of a date of death. The date
914 is the @emph{Gregorian} (civil) date of death. The diary entry appears
915 on the proper Hebrew calendar anniversary and on the day before. (The
916 order of the parameters changes according to the calendar date style;
917 for example in the European style to @var{day}, @var{month}, @var{year}.)
918 @item %%(diary-hebrew-birthday @var{month} @var{day} @var{year})
919 Make a diary entry for a birthday on the Hebrew calendar.
922 All the functions documented above take an optional argument
923 @var{mark} which specifies how to mark the date in the calendar display.
924 If one of these functions decides that it applies to a certain date,
925 it returns a value that contains @var{mark}, as described above.