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