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