1 @c This is part of the Emacs manual. -*- coding: utf-8 -*-
2 @c Copyright (C) 2004-2018 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions.
5 @c This file is included either in emacs-xtra.texi (when producing the
6 @c printed version) or in the main Emacs manual (for the on-line version).
8 @c Moved here from the Emacs Lisp Reference Manual, 2005-03-26.
9 @node Advanced Calendar/Diary Usage
10 @section More advanced features of the Calendar and Diary
12 This section describes some of the more advanced/specialized
13 features of the calendar and diary. It starts with some of the
14 many ways in which you can customize the calendar and diary to suit
18 * Calendar Customizing:: Calendar layout and hooks.
19 * Holiday Customizing:: Defining your own holidays.
20 * 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.
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 @vindex calendar-day-header-array
47 The variable @code{calendar-month-header} controls the text that
48 appears above each month in the calendar. By default, it shows the
49 month and year. The variable @code{calendar-day-header-array}
50 controls the text that appears above each day's column in every month.
51 By default, it shows the first two letters of each day's name.
53 @vindex calendar-holiday-marker
54 @vindex diary-entry-marker
55 @vindex calendar-today-marker
56 The variable @code{calendar-holiday-marker} specifies how to mark a
57 date that is a holiday. Its value may be a single-character string to
58 insert next to the date, or a face name to use for displaying the date.
59 Likewise, the variable @code{diary-entry-marker} specifies how to mark a
60 date that has diary entries. The function @code{calendar-mark-today}
61 uses @code{calendar-today-marker} to mark today's date. By default,
62 the calendar uses faces named @code{holiday}, @code{diary}, and
63 @code{calendar-today} for these purposes.
65 @vindex calendar-initial-window-hook
66 Starting the calendar runs the normal hook
67 @code{calendar-initial-window-hook}. Recomputation of the calendar
68 display does not run this hook. But if you leave the calendar with the
69 @kbd{q} command and reenter it, the hook runs again.
71 @vindex calendar-today-visible-hook
72 @findex calendar-star-date
73 The variable @code{calendar-today-visible-hook} is a normal hook run
74 after the calendar buffer has been prepared with the calendar, when the
75 current date is visible in the window. One use of this hook is to
76 mark today's date; to do that use either of the functions
77 @code{calendar-mark-today} or @code{calendar-star-date}:
79 @findex calendar-mark-today
81 (add-hook 'calendar-today-visible-hook 'calendar-mark-today)
84 @vindex calendar-today-invisible-hook
86 A similar normal hook, @code{calendar-today-invisible-hook} is run if
87 the current date is @emph{not} visible in the window.
89 @vindex calendar-move-hook
90 Each of the calendar cursor motion commands runs the hook
91 @code{calendar-move-hook} after it moves the cursor.
93 @node Holiday Customizing
94 @subsection Customizing the Holidays
96 @vindex calendar-holidays
97 @vindex holiday-oriental-holidays
98 @vindex holiday-solar-holidays
99 There are several variables listing the default holidays that Emacs
100 knows about. These are: @code{holiday-general-holidays},
101 @code{holiday-local-holidays}, @code{holiday-solar-holidays},
102 @code{holiday-bahai-holidays}, @code{holiday-christian-holidays},
103 @code{holiday-hebrew-holidays}, @code{holiday-islamic-holidays},
104 @code{holiday-oriental-holidays}, and @code{holiday-other-holidays}.
105 The names should be self-explanatory; e.g., @code{holiday-solar-holidays}
106 lists sun- and moon-related holidays.
108 You can customize these lists of holidays to your own needs, deleting or
109 adding holidays as described below. Set any of them to @code{nil} to
110 not show the associated holidays.
112 @vindex holiday-general-holidays
113 @vindex holiday-local-holidays
114 @vindex holiday-other-holidays
115 The general holidays are, by default, holidays common throughout the
116 United States. In contrast, @code{holiday-local-holidays} and
117 @code{holiday-other-holidays} are both empty by default. These are
118 intended for system-wide settings and your individual use,
121 @vindex holiday-bahai-holidays
122 @vindex holiday-christian-holidays
123 @vindex holiday-hebrew-holidays
124 @vindex holiday-islamic-holidays
125 @vindex calendar-bahai-all-holidays-flag
126 @vindex calendar-christian-all-holidays-flag
127 @vindex calendar-hebrew-all-holidays-flag
128 @vindex calendar-islamic-all-holidays-flag
129 By default, Emacs does not include all the holidays of the religions
130 that it knows, only those commonly found in secular calendars. For a
131 more extensive collection of religious holidays, you can set any (or
132 all) of the variables @code{calendar-bahai-all-holidays-flag},
133 @code{calendar-christian-all-holidays-flag},
134 @code{calendar-hebrew-all-holidays-flag}, or
135 @code{calendar-islamic-all-holidays-flag} to @code{t}.
137 @cindex holiday forms
138 Each of the holiday variables is a list of @dfn{holiday forms}, each
139 form describing a holiday (or sometimes a list of holidays). Here is
140 a table of the possible kinds of holiday form. Day numbers and month
141 numbers count starting from 1, but @dfn{dayname} numbers count Sunday as
142 0. The argument @var{string} is always the description of the
143 holiday, as a string.
146 @item (holiday-fixed @var{month} @var{day} @var{string})
147 A fixed date on the Gregorian calendar.
149 @item (holiday-float @var{month} @var{dayname} @var{k} @var{string}
151 The @var{k}th @var{dayname} (@var{dayname}=0 for Sunday, and so on)
152 after or before Gregorian date @var{month}, @var{day}. Negative @var{k}
153 means count back from the end of the month. Optional @var{day} defaults
154 to 1 if @var{k} is positive, and the last day of @var{month} otherwise.
156 @item (holiday-chinese @var{month} @var{day} @var{string})
157 A fixed date on the Chinese calendar.
159 @item (holiday-hebrew @var{month} @var{day} @var{string})
160 A fixed date on the Hebrew calendar.
162 @item (holiday-islamic @var{month} @var{day} @var{string})
163 A fixed date on the Islamic calendar.
165 @item (holiday-julian @var{month} @var{day} @var{string})
166 A fixed date on the Julian calendar.
168 @item (holiday-sexp @var{sexp} @var{string})
169 A date calculated by the Lisp expression @var{sexp}. The expression
170 should use the variable @code{year} to compute and return the date of a
171 holiday in the form of a list @code{(@var{month} @var{day} @var{year})},
172 or @code{nil} if the holiday doesn't happen this year.
174 @item (if @var{condition} @var{holiday-form})
175 A holiday that happens only if @var{condition} is true.
177 @item (@var{function} @r{[}@var{args}@r{]})
178 A list of dates calculated by the function @var{function}, called with
179 arguments @var{args}.
182 For example, suppose you want to add Bastille Day, celebrated in
183 France on July 14 (i.e., the fourteenth day of the seventh month). You
184 can do this as follows:
187 (setq holiday-other-holidays '((holiday-fixed 7 14 "Bastille Day")))
190 Many holidays occur on a specific day of the week, at a specific time
191 of month. Here is a holiday form describing Hurricane Supplication Day,
192 celebrated in the Virgin Islands on the fourth Monday in July:
195 (holiday-float 7 1 4 "Hurricane Supplication Day")
199 Here the 7 specifies July, the 1 specifies Monday (Sunday is 0,
200 Tuesday is 2, and so on), and the 4 specifies the fourth occurrence in
201 the month (1 specifies the first occurrence, 2 the second occurrence,
202 @minus{}1 the last occurrence, @minus{}2 the second-to-last occurrence, and
205 You can specify holidays that occur on fixed days of the Bahá'í,
206 Chinese, Hebrew, Islamic, and Julian calendars too. For example,
209 (setq holiday-other-holidays
210 '((holiday-hebrew 10 2 "Last day of Hanukkah")
211 (holiday-islamic 3 12 "Mohammed's Birthday")
212 (holiday-julian 4 2 "Jefferson's Birthday")))
216 adds the last day of Hanukkah (since the Hebrew months are numbered with
217 1 starting from Nisan), the Islamic feast celebrating Mohammed's
218 birthday (since the Islamic months are numbered from 1 starting with
219 Muharram), and Thomas Jefferson's birthday, which is 2 April 1743 on the
222 To include a holiday conditionally, use either Emacs Lisp's @code{if}
223 or the @code{holiday-sexp} form. For example, American presidential
224 elections occur on the first Tuesday after the first Monday in November
225 of years divisible by 4:
228 (holiday-sexp '(if (zerop (% year 4))
229 (calendar-gregorian-from-absolute
230 (1+ (calendar-dayname-on-or-before
231 1 (+ 6 (calendar-absolute-from-gregorian
232 (list 11 1 year)))))))
233 "US Presidential Election")
240 (if (zerop (% displayed-year 4))
242 (calendar-extract-day
243 (calendar-gregorian-from-absolute
244 (1+ (calendar-dayname-on-or-before
245 1 (+ 6 (calendar-absolute-from-gregorian
246 (list 11 1 displayed-year)))))))
247 "US Presidential Election"))
250 Some holidays just don't fit into any of these forms because special
251 calculations are involved in their determination. In such cases you
252 must write a Lisp function to do the calculation. To include eclipses,
253 for example, add @code{(eclipses)} to @code{holiday-other-holidays}
254 and write an Emacs Lisp function @code{eclipses} that returns a
255 (possibly empty) list of the relevant Gregorian dates among the range
256 visible in the calendar window, with descriptive strings, like this:
259 (((6 4 2012) "Lunar Eclipse") ((11 13 2012) "Solar Eclipse") ... )
263 @subsection Converting from the Mayan Calendar
264 @cindex Mayan calendar
266 Here are the commands to select dates based on the Mayan calendar:
270 Move to a date specified by the long count calendar
271 (@code{calendar-mayan-goto-long-count-date}).
273 Move to the next occurrence of a place in the
274 tzolkin calendar (@code{calendar-mayan-next-tzolkin-date}).
276 Move to the previous occurrence of a place in the
277 tzolkin calendar (@code{calendar-mayan-previous-tzolkin-date}).
279 Move to the next occurrence of a place in the
280 haab calendar (@code{calendar-mayan-next-haab-date}).
282 Move to the previous occurrence of a place in the
283 haab calendar (@code{calendar-mayan-previous-haab-date}).
285 Move to the next occurrence of a place in the
286 calendar round (@code{calendar-mayan-next-calendar-round-date}).
288 Move to the previous occurrence of a place in the
289 calendar round (@code{calendar-mayan-previous-calendar-round-date}).
292 @cindex Mayan long count
293 To understand these commands, you need to understand the Mayan calendars.
294 The @dfn{long count} is a counting of days with these units:
297 1 kin = 1 day@ @ @ 1 uinal = 20 kin@ @ @ 1 tun = 18 uinal
298 1 katun = 20 tun@ @ @ 1 baktun = 20 katun
301 @kindex g m @r{(Calendar mode)}
302 @findex calendar-mayan-goto-long-count-date
304 Thus, the long count date 12.16.11.16.6 means 12 baktun, 16 katun, 11
305 tun, 16 uinal, and 6 kin. The Emacs calendar can handle Mayan long
306 count dates as early as 7.17.18.13.3, but no earlier. When you use the
307 @kbd{g m l} command, type the Mayan long count date with the baktun,
308 katun, tun, uinal, and kin separated by periods.
310 @findex calendar-mayan-previous-tzolkin-date
311 @findex calendar-mayan-next-tzolkin-date
312 @cindex Mayan tzolkin calendar
313 The Mayan tzolkin calendar is a cycle of 260 days formed by a pair of
314 independent cycles of 13 and 20 days. Since this cycle repeats
315 endlessly, Emacs provides commands to move backward and forward to the
316 previous or next point in the cycle. Type @kbd{g m p t} to go to the
317 previous tzolkin date; Emacs asks you for a tzolkin date and moves point
318 to the previous occurrence of that date. Similarly, type @kbd{g m n t}
319 to go to the next occurrence of a tzolkin date.
321 @findex calendar-mayan-previous-haab-date
322 @findex calendar-mayan-next-haab-date
323 @cindex Mayan haab calendar
324 The Mayan haab calendar is a cycle of 365 days arranged as 18 months
325 of 20 days each, followed by a 5-day monthless period. Like the tzolkin
326 cycle, this cycle repeats endlessly, and there are commands to move
327 backward and forward to the previous or next point in the cycle. Type
328 @kbd{g m p h} to go to the previous haab date; Emacs asks you for a haab
329 date and moves point to the previous occurrence of that date.
330 Similarly, type @kbd{g m n h} to go to the next occurrence of a haab
333 @c This is omitted because it is too long for smallbook format.
334 @c @findex calendar-mayan-previous-calendar-round-date
335 @findex calendar-mayan-next-calendar-round-date
336 @cindex Mayan calendar round
337 The Maya also used the combination of the tzolkin date and the haab
338 date. This combination is a cycle of about 52 years called a
339 @emph{calendar round}. If you type @kbd{g m p c}, Emacs asks you for
340 both a haab and a tzolkin date and then moves point to the previous
341 occurrence of that combination. Use @kbd{g m n c} to move point to the
342 next occurrence of a combination. These commands signal an error if the
343 haab/tzolkin date combination you have typed is impossible.
345 Emacs uses strict completion
347 (@pxref{Completion Exit,,, emacs, the Emacs Manual})
350 (@pxref{Completion Exit})
352 whenever it asks you to type a Mayan name, so you don't have to worry
355 @node Date Display Format
356 @subsection Date Display Format
357 @vindex calendar-date-display-form
359 You can customize the way dates are displayed in the diary, mode
360 lines, and messages by setting @code{calendar-date-display-form}.
361 This variable holds a list of expressions that can involve the variables
362 @code{month}, @code{day}, and @code{year}, which are all numbers in
363 string form, and @code{monthname} and @code{dayname}, which are both
364 alphabetic strings. In the American style, the default value of this
368 ((if dayname (concat dayname ", ")) monthname " " day ", " year)
372 while in the European style this value is the default:
375 ((if dayname (concat dayname ", ")) day " " monthname " " year)
379 The default ISO date representation is:
382 ((format "%s-%.2d-%.2d" year (string-to-number month)
383 (string-to-number day)))
387 Another typical American format is:
390 (month "/" day "/" (substring year -2))
393 @node Time Display Format
394 @subsection Time Display Format
395 @vindex calendar-time-display-form
397 The calendar and diary by default display times of day in the
398 conventional American style with the hours from 1 through 12, minutes,
399 and either @samp{am} or @samp{pm}. If you prefer the European style,
400 also known in the US as military, in which the hours go from 00 to 23,
401 you can alter the variable @code{calendar-time-display-form}. This
402 variable is a list of expressions that can involve the variables
403 @code{12-hours}, @code{24-hours}, and @code{minutes}, which are all
404 numbers in string form, and @code{am-pm} and @code{time-zone}, which are
405 both alphabetic strings. The default value is:
408 (12-hours ":" minutes am-pm
409 (if time-zone " (") time-zone (if time-zone ")"))
413 Here is a value that provides European style times:
416 (24-hours ":" minutes
417 (if time-zone " (") time-zone (if time-zone ")"))
420 Note that few calendar functions return a time of day (at present, only
423 @node Diary Customizing
424 @subsection Customizing the Diary
426 @vindex diary-show-holidays-flag
427 Ordinarily, the diary window indicates any holidays that fall on the
428 date of the diary entries, either in the mode line or the buffer itself.
429 The process of checking for holidays can be slow, depending on the
430 defined holidays. In that case, setting @code{diary-show-holidays-flag}
431 to @code{nil} will speed up the diary display.
433 @vindex diary-number-of-entries
434 The variable @code{diary-number-of-entries} controls the number of
435 days of diary entries to be displayed at one time. It affects the
436 initial display when @code{calendar-view-diary-initially-flag} is
437 @code{t}, as well as the command @kbd{M-x diary}. For example, a value
438 of 1 (the default) displays only the current day's diary entries,
439 whereas a value of 2 will also show the next day's entries. The value
440 can also be a vector of seven integers: for example, if the value is
441 @code{[0 2 2 2 2 4 1]} then no diary entries appear on Sunday, the
442 current date's and the next day's diary entries appear Monday through
443 Thursday, Friday through Monday's entries appear on Friday, while on
444 Saturday only that day's entries appear.
446 @vindex diary-date-forms
447 You can customize the form of dates in your diary file by setting the
448 variable @code{diary-date-forms}. This variable is a list of patterns
449 for recognizing a date. Each date pattern is a list whose elements may
450 be regular expressions (@pxref{Regular Expressions,,, elisp, the Emacs
451 Lisp Reference Manual}) or the symbols @code{month}, @code{day},
452 @code{year}, @code{monthname}, and @code{dayname}. All these elements
453 serve as patterns that match certain kinds of text in the diary file.
454 In order for the date pattern as a whole to match, all of its elements
455 must match consecutively.
457 A regular expression in a date pattern matches in its usual fashion,
458 using the standard syntax table altered so that @samp{*} is a word
461 The symbols @code{month}, @code{day}, @code{year}, @code{monthname},
462 and @code{dayname} match the month number, day number, year number,
463 month name, and day name of the date being considered. The symbols that
464 match numbers allow leading zeros; those that match names allow
465 capitalization and abbreviation (as specified by
466 @code{calendar-month-abbrev-array} and
467 @code{calendar-day-abbrev-array}). All the symbols can match @samp{*};
468 since @samp{*} in a diary entry means ``any day'', ``any month'', and so
469 on, it should match regardless of the date being considered.
471 The default value of @code{diary-date-forms} in the American style is
472 provided by @code{diary-american-date-forms}:
475 ((month "/" day "[^/0-9]")
476 (month "/" day "/" year "[^0-9]")
477 (monthname " *" day "[^,0-9]")
478 (monthname " *" day ", *" year "[^0-9]")
483 The variables @code{diary-european-date-forms} and
484 @code{diary-iso-date-forms} provide other default styles.
486 The date patterns in the list must be @emph{mutually exclusive} and
487 must not match any portion of the diary entry itself, just the date and
488 one character of whitespace. If, to be mutually exclusive, the pattern
489 must match a portion of the diary entry text---beyond the whitespace
490 that ends the date---then the first element of the date pattern
491 @emph{must} be @code{backup}. This causes the date recognizer to back
492 up to the beginning of the current word of the diary entry, after
493 finishing the match. Even if you use @code{backup}, the date pattern
494 must absolutely not match more than a portion of the first word of the
495 diary entry. For example, the default value of
496 @code{diary-european-date-forms} is:
498 @c backup line is a fraction too wide in PDF, but it looks ok.
500 ((day "/" month "[^/0-9]")
501 (day "/" month "/" year "[^0-9]")
502 (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
503 (day " *" monthname " *" year "[^0-9]")
508 Notice the use of @code{backup} in the third pattern, because it needs
509 to match part of a word beyond the date itself to distinguish it from
512 @node Non-Gregorian Diary
513 @subsection Diary Entries Using non-Gregorian Calendars
515 As well as entries based on the standard Gregorian calendar, your
516 diary can have entries based on Bahá'í, Chinese, Hebrew, or Islamic dates.
517 Recognition of such entries can be time-consuming, however, and since
518 most people don't use them, you must explicitly enable their use. If
519 you want the diary to recognize Hebrew-date diary entries, for example,
522 @vindex diary-nongregorian-listing-hook
523 @vindex diary-nongregorian-marking-hook
524 @findex diary-hebrew-list-entries
525 @findex diary-hebrew-mark-entries
526 @findex diary-islamic-list-entries
527 @findex diary-islamic-mark-entries
528 @findex diary-bahai-list-entries
529 @findex diary-bahai-mark-entries
530 @findex diary-chinese-list-entries
531 @findex diary-chinese-mark-entries
533 (add-hook 'diary-nongregorian-listing-hook 'diary-hebrew-list-entries)
534 (add-hook 'diary-nongregorian-marking-hook 'diary-hebrew-mark-entries)
538 Similarly, for Islamic, Bahá'í and Chinese entries, add
539 @code{diary-islamic-list-entries} and @code{diary-islamic-mark-entries},
540 @code{diary-bahai-list-entries} and @code{diary-bahai-mark-entries},
541 or @code{diary-chinese-list-entries} and @code{diary-chinese-mark-entries}.
543 @vindex diary-bahai-entry-symbol
544 @vindex diary-chinese-entry-symbol
545 @vindex diary-hebrew-entry-symbol
546 @vindex diary-islamic-entry-symbol
547 These diary entries have the same formats as Gregorian-date diary
548 entries; except that @code{diary-bahai-entry-symbol} (default @samp{B})
549 must precede a Bahá'í date, @code{diary-chinese-entry-symbol} (default
550 @samp{C}) a Chinese date, @code{diary-hebrew-entry-symbol} (default
551 @samp{H}) a Hebrew date, and @code{diary-islamic-entry-symbol} (default
552 @samp{I}) an Islamic date. Moreover, non-Gregorian month names may not
553 be abbreviated (because the first three letters are often not unique).
554 (Note also that you must use ``Adar I'' if you want Adar of a common
555 Hebrew year.) For example, a diary entry for the Hebrew date Heshvan 25
556 could look like this:
559 HHeshvan 25 Happy Hebrew birthday!
563 and would appear in the diary for any date that corresponds to Heshvan 25
564 on the Hebrew calendar. And here is an Islamic-date diary entry that matches
568 IDhu al-Qada 25 Happy Islamic birthday!
571 As with Gregorian-date diary entries, non-Gregorian entries are
572 nonmarking if preceded by @code{diary-nonmarking-symbol} (default
575 Here is a table of commands used in the calendar to create diary
576 entries that match the selected date and other dates that are similar in
577 the Bahá'í, Chinese, Hebrew, or Islamic calendars:
581 @code{diary-hebrew-insert-entry}
583 @code{diary-hebrew-insert-monthly-entry}
585 @code{diary-hebrew-insert-yearly-entry}
587 @code{diary-islamic-insert-entry}
589 @code{diary-islamic-insert-monthly-entry}
591 @code{diary-islamic-insert-yearly-entry}
593 @code{diary-bahai-insert-entry}
595 @code{diary-bahai-insert-monthly-entry}
597 @code{diary-bahai-insert-yearly-entry}
599 @code{diary-chinese-insert-entry}
601 @code{diary-chinese-insert-monthly-entry}
603 @code{diary-chinese-insert-yearly-entry}
605 @code{diary-chinese-insert-anniversary-entry}
608 @findex diary-hebrew-insert-entry
609 @findex diary-hebrew-insert-monthly-entry
610 @findex diary-hebrew-insert-yearly-entry
611 @findex diary-islamic-insert-entry
612 @findex diary-islamic-insert-monthly-entry
613 @findex diary-islamic-insert-yearly-entry
614 @findex diary-bahai-insert-entry
615 @findex diary-bahai-insert-monthly-entry
616 @findex diary-bahai-insert-yearly-entry
617 @findex diary-chinese-insert-entry
618 @findex diary-chinese-insert-monthly-entry
619 @findex diary-chinese-insert-yearly-entry
620 @findex diary-chinese-insert-anniversary-entry
622 These commands work much like the corresponding commands for ordinary
623 diary entries: they apply to the date that point is on in the calendar
624 window, and what they do is insert just the date portion of a diary
625 entry at the end of your diary file. You must then insert the rest of
626 the diary entry. The basic commands add an entry for the specific
627 non-Gregorian date, the @samp{monthly} commands for the given
628 non-Gregorian day-within-month in every month, and the @samp{yearly}
629 commands for the given non-Gregorian day and month in every year.
632 @subsection Diary Display
633 @vindex diary-display-function
634 @findex diary-simple-display
635 @findex diary-fancy-display
638 Diary display works by preparing the list of diary entries and then
639 running the function specified by the variable
640 @code{diary-display-function}. The default value
641 @code{diary-fancy-display} displays diary entries and holidays by
642 copying them into a special buffer that exists only for the sake of
643 display. Copying diary entries to a separate buffer provides an
644 opportunity to change the displayed text to make it prettier---for
645 example, to sort the entries by the dates they apply to.
647 @vindex diary-list-include-blanks
648 Ordinarily, the fancy diary buffer does not show days for which there
649 are no diary entries, even if that day is a holiday. If you want such
650 days to be shown in the fancy diary buffer, set the variable
651 @code{diary-list-include-blanks} to @code{t}.
653 The fancy diary buffer enables View mode
655 (@pxref{View Mode,,, emacs, the Emacs Manual}).
661 The alternative display method @code{diary-simple-display} shows the
662 actual diary buffer, and uses invisible text to hide entries that don't
663 apply. Holidays are shown in the mode line. The advantage of this
664 method is that you can edit the buffer and save your changes directly to
665 the diary file. This method is not as flexible as the fancy method,
666 however. For example, it cannot sort entries. Another disadvantage is
667 that invisible text can be confusing. For example, if you copy a region
668 of text in order to paste it elsewhere, invisible text may be included.
669 Similarly, since the diary buffer as you see it is an illusion, simply
670 printing the buffer may not print what you see on your screen.
672 @vindex diary-print-entries-hook
673 @findex diary-print-entries
674 For this reason, there is a special command to print hard copy of the
675 diary buffer @emph{as it appears}; this command is @kbd{M-x
676 diary-print-entries}. It works with either display method, although
677 with the fancy display you can also print the buffer like any other. To
678 print a hard copy of a day-by-day diary for a week, position point on
679 the first day of the week, type @kbd{7 d}, and then do @kbd{M-x
680 diary-print-entries}. As usual, the inclusion of the holidays slows
681 down the display slightly; you can speed things up by setting the
682 variable @code{diary-show-holidays-flag} to @code{nil}.
684 This command prepares a temporary buffer that contains only the diary
685 entries currently visible in the diary buffer. Unlike with the simple
686 display, the other irrelevant entries are really absent, not just
687 hidden. After preparing the buffer, it runs the hook
688 @code{diary-print-entries-hook}. The default value of this hook sends
689 the data directly to the printer with the command @code{lpr-buffer}
691 (@pxref{Printing,,, emacs, the Emacs Manual}).
696 If you want to use a different command to do the
697 printing, just change the value of this hook. Other uses might include,
698 for example, rearranging the lines into order by day and time.
700 You can edit the diary entries as they appear in the simple diary
701 window, but it is important to remember that the buffer displayed
702 contains the @emph{entire} diary file, with portions of it concealed
703 from view. This means, for instance, that the @kbd{C-f}
704 (@code{forward-char}) command can put point at what appears to be the
705 end of the line, but what is in reality the middle of some concealed
708 @emph{Be careful when editing the diary entries in the simple display!}
709 Inserting additional lines or adding/deleting characters in the middle
710 of a visible line cannot cause problems, but editing at the end of a
711 line may not do what you expect. Deleting a line may delete other
712 invisible entries that follow it. Before editing the simple diary
713 buffer, it is best to display the entire file with @kbd{s}
714 (@code{diary-show-all-entries}).
716 @node Fancy Diary Display
717 @subsection Fancy Diary Display
719 The following features only work with the fancy diary display.
721 @cindex sorting diary entries
722 You can use the normal hook @code{diary-list-entries-hook} to sort
723 each day's diary entries by their time of day. Here's how:
725 @findex diary-sort-entries
727 (add-hook 'diary-list-entries-hook 'diary-sort-entries t)
731 For each day, this sorts diary entries that begin with a recognizable
732 time of day according to their times. Diary entries without times come
733 first within each day. Note how the sort command is placed at the end
734 of the hook list, in case earlier members of the list change the order
735 of the diary entries, or add items.
737 @vindex diary-comment-start
738 You can write @samp{comments} in diary entries, by setting the
739 variables @code{diary-comment-start} and @code{diary-comment-end} to
740 strings that delimit comments. The fancy display does not print
741 comments. You might want to put meta-data for the use of other packages
742 (e.g., the appointment package,
744 @pxref{Appointments,,,emacs, the Emacs Manual})
747 @pxref{Appointments})
751 @vindex diary-include-string
752 Your main diary file can include other files. This permits a group of
753 people to share a diary file for events that apply to all of them.
754 Lines in the diary file starting with @code{diary-include-string}:
757 #include "@var{filename}"
761 include the diary entries from the file @var{filename} in the fancy
762 diary buffer. The include mechanism is recursive, so that included
763 files can include other files, and so on (you must be careful not to
764 have a cycle of inclusions, of course). Here is how to enable the
767 @vindex diary-list-entries-hook
768 @vindex diary-mark-entries-hook
769 @findex diary-include-other-diary-files
770 @findex diary-mark-included-diary-files
772 (add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
773 (add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)
776 The include mechanism works only with the fancy diary display, because
777 simple diary display shows the entries directly from your diary file.
779 @node Sexp Diary Entries
780 @subsection Sexp Entries and the Fancy Diary Display
781 @cindex sexp diary entries
783 @vindex diary-sexp-entry-symbol
784 Sexp diary entries allow you to do more than just have complicated
785 conditions under which a diary entry applies. Sexp entries should be
786 preceded by @code{diary-sexp-entry-symbol} (default @samp{%%}) in the
787 diary file. With the fancy diary display, sexp entries can generate the
788 text of the entry depending on the date itself.
790 For example, an anniversary diary entry can insert
791 the number of years since the anniversary date into the text of the
792 diary entry. Thus the @samp{%d} in this diary entry:
794 @findex diary-anniversary@r{, and sexp diary entries}
796 %%(diary-anniversary 10 31 1948) Arthur's birthday (%d years old)
800 gets replaced by the age, so on October 31, 1990 the entry appears in
801 the fancy diary buffer like this:
804 Arthur's birthday (42 years old)
808 If the diary file instead contains this entry:
811 %%(diary-anniversary 10 31 1948) Arthur's %d%s birthday
815 the entry in the fancy diary buffer for October 31, 1990 appears like this:
818 Arthur's 42nd birthday
821 Similarly, cyclic diary entries can interpolate the number of repetitions
824 @findex diary-cyclic@r{, and sexp diary entries}
826 %%(diary-cyclic 50 1 1 2012) Renew medication (%d%s time)
833 Renew medication (5th time)
837 in the fancy diary display on September 7, 2012.
839 There is an early-reminder diary sexp that includes its entry in the
840 diary not only on the date of occurrence, but also on earlier dates.
841 For example, if you want a reminder a week before your anniversary, you
846 %%(diary-remind '(diary-anniversary 12 22 1968) 7) Ed's anniversary
850 and the fancy diary will show @samp{Ed's anniversary} both on December
851 15 and on December 22.
854 The function @code{diary-date} applies to dates described by a month,
855 day, year combination, each of which can be an integer, a list of
856 integers, or @code{t} (meaning all values). For example,
859 %%(diary-date '(10 11 12) 22 t) Rake leaves
863 causes the fancy diary to show
870 on October 22, November 22, and December 22 of every year.
872 @findex diary-float@r{, and sexp diary entries}
873 The function @code{diary-float} allows you to describe diary entries
874 that apply to dates like the third Friday of November, or the last
875 Tuesday in April. The parameters are the @var{month}, @var{dayname},
876 and an index @var{n}. The entry appears on the @var{n}th @var{dayname}
877 after the first day of @var{month}, where @var{dayname}=0 means Sunday,
878 1 means Monday, and so on. If @var{n} is negative it counts backward
879 from the end of @var{month}. The value of @var{month} can be a list of
880 months, a single month, or @code{t} to specify all months. You can also
881 use an optional parameter @var{day} to specify the @var{n}th
882 @var{dayname} on or after/before @var{day} of @var{month}; the value of
883 @var{day} defaults to 1 if @var{n} is positive and to the last day of
884 @var{month} if @var{n} is negative. For example,
887 %%(diary-float t 1 -1) Pay rent
891 causes the fancy diary to show
898 on the last Monday of every month.
900 The generality of sexp diary entries lets you specify any diary
901 entry that you can describe algorithmically. A sexp diary entry
902 contains an expression that computes whether the entry applies to any
903 given date. If its value is non-@code{nil}, the entry applies to that
904 date; otherwise, it does not. The expression can use the variable
905 @code{date} to find the date being considered; its value is a list
906 (@var{month} @var{day} @var{year}) that refers to the Gregorian
909 The sexp diary entry applies to a date when the expression's value
910 is non-@code{nil}, but some values have more specific meanings. If
911 the value is a string, that string is a description of the event which
912 occurs on that date. The value can also have the form
913 @code{(@var{mark} . @var{string})}; then @var{mark} specifies how to
914 mark the date in the calendar, and @var{string} is the description of
915 the event. If @var{mark} is a single-character string, that character
916 appears next to the date in the calendar. If @var{mark} is a face
917 name, the date is displayed in that face. If @var{mark} is
918 @code{nil}, that specifies no particular highlighting for the date.
920 Suppose you get paid on the 21st of the month if it is a weekday, and
921 on the Friday before if the 21st is on a weekend. Here is how to write
922 a sexp diary entry that matches those dates:
925 &%%(let ((dayname (calendar-day-of-week date))
927 (or (and (= day 21) (memq dayname '(1 2 3 4 5)))
928 (and (memq day '(19 20)) (= dayname 5)))
929 ) Pay check deposited
932 The following sexp diary entries take advantage of the ability (in the fancy
933 diary display) to concoct diary entries whose text varies based on the date:
935 @findex diary-sunrise-sunset
936 @findex diary-lunar-phases
937 @findex diary-day-of-year
938 @findex diary-iso-date
939 @findex diary-julian-date
940 @findex diary-astro-day-number
941 @findex diary-bahai-date
942 @findex diary-chinese-date
943 @findex diary-coptic-date
944 @findex diary-ethiopic-date
945 @findex diary-hebrew-date
946 @findex diary-islamic-date
947 @findex diary-french-date
948 @findex diary-mayan-date
949 @findex diary-persian-date
951 @item %%(diary-sunrise-sunset)
952 Make a diary entry for today's local times of sunrise and sunset.
953 @item %%(diary-lunar-phases)
954 Make a diary entry for the phases (quarters) of the moon.
955 @item %%(diary-day-of-year)
956 Make a diary entry with today's day number in the current year and the number
957 of days remaining in the current year.
958 @item %%(diary-iso-date)
959 Make a diary entry with today's equivalent ISO commercial date.
960 @item %%(diary-julian-date)
961 Make a diary entry with today's equivalent Julian calendar date.
962 @item %%(diary-astro-day-number)
963 Make a diary entry with today's equivalent astronomical (Julian) day number.
964 @item %%(diary-bahai-date)
965 Make a diary entry with today's equivalent Bahá'í calendar date.
966 @item %%(diary-chinese-date)
967 Make a diary entry with today's equivalent Chinese calendar date.
968 @item %%(diary-coptic-date)
969 Make a diary entry with today's equivalent Coptic calendar date.
970 @item %%(diary-ethiopic-date)
971 Make a diary entry with today's equivalent Ethiopic calendar date.
972 @item %%(diary-french-date)
973 Make a diary entry with today's equivalent date on the French Revolutionary
975 @item %%(diary-hebrew-date)
976 Make a diary entry with today's equivalent Hebrew calendar date.
977 @item %%(diary-islamic-date)
978 Make a diary entry with today's equivalent Islamic calendar date.
979 @item %%(diary-mayan-date)
980 Make a diary entry with today's equivalent Mayan calendar date.
981 @item %%(diary-persian-date)
982 Make a diary entry with today's equivalent Persian calendar date.
986 For example, including the diary entry
989 &%%(diary-hebrew-date)
993 causes every day's diary display to contain the equivalent date on the
994 Hebrew calendar, if you are using the fancy diary display. (With simple
995 diary display, the literal line @samp{&%%(diary-hebrew-date)} appears in
996 the diary for any date.)
998 This function has been used to construct certain standard Hebrew sexp
1002 @findex diary-hebrew-rosh-hodesh
1003 @cindex parasha, weekly
1004 @findex diary-hebrew-parasha
1005 @cindex candle lighting times
1006 @findex diary-hebrew-sabbath-candles
1008 @findex diary-hebrew-omer
1009 @cindex yahrzeits, and sexp diary entries
1010 @findex diary-hebrew-yahrzeit
1011 @findex diary-hebrew-birthday
1013 @item %%(diary-hebrew-rosh-hodesh)
1014 Make a diary entry that tells the occurrence and ritual announcement of each
1016 @item %%(diary-hebrew-parasha)
1017 Make a Saturday diary entry that tells the weekly synagogue scripture reading.
1018 @item %%(diary-hebrew-sabbath-candles)
1019 Make a Friday diary entry that tells the @emph{local time} of Sabbath
1021 @item %%(diary-hebrew-omer)
1022 Make a diary entry that gives the omer count, when appropriate.
1023 @item %%(diary-hebrew-yahrzeit @var{month} @var{day} @var{year}) @var{name}
1024 Make a diary entry marking the anniversary of a date of death. The date
1025 is the @emph{Gregorian} (civil) date of death. The diary entry appears
1026 on the proper Hebrew calendar anniversary and on the day before. (The
1027 order of the parameters changes according to the calendar date style;
1028 for example in the European style to @var{day}, @var{month}, @var{year}.)
1029 @item %%(diary-hebrew-birthday @var{month} @var{day} @var{year})
1030 Make a diary entry for a birthday on the Hebrew calendar.
1033 All the functions documented above take an optional argument
1034 @var{mark} which specifies how to mark the date in the calendar display.
1035 If one of these functions decides that it applies to a certain date,
1036 it returns a value that contains @var{mark}, as described above.