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