*** empty log message ***
[bpt/emacs.git] / lisp / calendar / calendar.el
1 ;;; calendar.el --- Calendar functions.
2
3 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
4 ;; Last-Modified: 30 Jun 1992
5 ;; Keyword: calendar
6
7 (defconst calendar-version "Version 4.02, released June 14, 1992")
8
9 ;;; Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY. No author or distributor
15 ;; accepts responsibility to anyone for the consequences of using it
16 ;; or for whether it serves any particular purpose or works at all,
17 ;; unless he says so in writing. Refer to the GNU Emacs General Public
18 ;; License for full details.
19
20 ;; Everyone is granted permission to copy, modify and redistribute
21 ;; GNU Emacs, but only under the conditions described in the
22 ;; GNU Emacs General Public License. A copy of this license is
23 ;; supposed to have been given to you along with GNU Emacs so you
24 ;; can know your rights and responsibilities. It should be in a
25 ;; file named COPYING. Among other things, the copyright notice
26 ;; and this notice must be preserved on all copies.
27
28 ;;; Commentary:
29
30 ;; This collection of functions implements a calendar window. It generates
31 ;; generates a calendar for the current month, together with the previous and
32 ;; coming months, or for any other three-month period. The calendar can be
33 ;; scrolled forward and backward in the window to show months in the past or
34 ;; future; the cursor can move forward and backward by days, weeks, or months,
35 ;; making it possible, for instance, to jump to the date a specified number of
36 ;; days, weeks, or months from the date under the cursor. The user can
37 ;; display a list of holidays and other notable days for the period shown; the
38 ;; notable days can be marked on the calendar, if desired. The user can also
39 ;; specify that dates having corresponding diary entries (in a file that the
40 ;; user specifies) be marked; the diary entries for any date can be viewed in
41 ;; a separate window. The diary and the notable days can be viewed
42 ;; independently of the calendar. Dates can be translated from the (usual)
43 ;; Gregorian calendar to the day of the year/days remaining in year, to the
44 ;; ISO commercial calendar, to the Julian (old style) calendar, to the Hebrew
45 ;; calendar, to the Islamic calendar, and to the French Revolutionary calendar.
46
47 ;; The diary related functions are in diary.el; the holiday related functions
48 ;; are in holiday.el
49
50 ;; Comments, corrections, and improvements should be sent to
51 ;; Edward M. Reingold Department of Computer Science
52 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
53 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
54 ;; Urbana, Illinois 61801
55
56 ;; GNU Emacs users too numerous to list pointed out a variety of problems
57 ;; with earlier forms of the `infinite' sliding calendar and suggested some
58 ;; of the features included in this package. Especially significant in this
59 ;; regard was the suggestion of mark-diary-entries and view-diary-entries,
60 ;; together ideas for their implementation, by
61 ;; Michael S. Littman Cognitive Science Research Group
62 ;; (201) 829-5155 Bell Communications Research
63 ;; mlittman@wind.bellcore.com 445 South St. Box 1961 (2L-331)
64 ;; Morristown, NJ 07960
65
66 ;; The algorithms for the Hebrew calendar are those of the Rambam (Rabbi Moses
67 ;; Maimonides), from his Mishneh Torah, as implemented by
68 ;; Nachum Dershowitz Department of Computer Science
69 ;; (217) 333-4219 University of Illinois at Urbana-Champaign
70 ;; nachum@cs.uiuc.edu 1304 West Springfield Avenue
71 ;; Urbana, Illinois 61801
72
73 ;; Technical details of all the calendrical calculations can be found in
74 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
75 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
76 ;; pages 899-928.
77
78 ;;; Code:
79
80 (defvar view-diary-entries-initially nil
81 "*If T, the diary entries for the current date will be displayed on entry.
82 The diary is displayed in another window when the calendar is first displayed,
83 if the current date is visible. The number of days of diary entries displayed
84 is governed by the variable `number-of-diary-entries'.")
85
86 (defvar number-of-diary-entries 1
87 "*Specifies how many days of diary entries are to be displayed initially.
88 This variable affects the diary display when the command M-x diary is used,
89 or if the value of the variable `view-diary-entries-initially' is t. For
90 example, if the default value 1 is used, then only the current day's diary
91 entries will be displayed. If the value 2 is used, then both the current
92 day's and the next day's entries will be displayed. The value can also be
93 a vector such as [0 2 2 2 2 4 1]; this value will cause no diary entries to
94 be displayed on Sunday, the current date's and the next day's diary entries
95 to be displayed Monday through Thursday, Friday through Monday's entries to
96 be displayed on Friday, and only Saturday's entries to be displayed on
97 Saturday. This variable does not affect the diary display with the `d'
98 command from the calendar; in that case, the prefix argument controls the
99 number of days of diary entries displayed.")
100
101 (defvar mark-diary-entries-in-calendar nil
102 "*If t, dates with diary entries will be marked in the calendar window.
103 The marking symbol is specified by the variable `diary-entry-marker'.")
104
105 (defvar diary-entry-marker "+"
106 "*The symbol used to mark dates that have diary entries.")
107
108 (defvar view-calendar-holidays-initially nil
109 "*If t, the holidays for the current three month period will be displayed
110 on entry. The holidays are displayed in another window when the calendar is
111 first displayed.")
112
113 ;;;###autoload
114 (defvar mark-holidays-in-calendar nil
115 "*If t, dates of holidays will be marked in the calendar window.
116 The marking symbol is specified by the variable `calendar-holiday-marker'.")
117
118 (defvar calendar-holiday-marker "*"
119 "*The symbol used to mark notable dates in the calendar.")
120
121 ;;;###autoload
122 (defvar all-hebrew-calendar-holidays nil
123 "*If nil, the holidays from the Hebrew calendar that are shown will
124 include only those days of such major interest as to appear on secular
125 calendars. If t, the holidays shown in the calendar will include all
126 special days that would be shown on a complete Hebrew calendar.")
127
128 ;;;###autoload
129 (defvar all-christian-calendar-holidays nil
130 "*If nil, the holidays from the Christian calendar that are shown will
131 include only those days of such major interest as to appear on secular
132 calendars. If t, the holidays shown in the calendar will include all
133 special days that would be shown on a complete Christian calendar.")
134
135 ;;;###autoload
136 (defvar all-islamic-calendar-holidays nil
137 "*If nil, the holidays from the Islamic calendar that are shown will
138 include only those days of such major interest as to appear on secular
139 calendars. If t, the holidays shown in the calendar will include all
140 special days that would be shown on a complete Islamic calendar.")
141
142 (defvar initial-calendar-window-hook nil
143 "*List of functions to be called when the calendar window is first opened.
144 The functions invoked are called after the calendar window is opened, but
145 once opened is never called again. Leaving the calendar with the `q' command
146 and reentering it will cause these functions to be called again.")
147
148 (defvar today-visible-calendar-hook nil
149 "*List of functions called whenever the current date is visible.
150 This can be used, for example, to replace today's date with asterisks; a
151 function `calendar-star-date' is included for this purpose:
152 (setq today-visible-calendar-hook 'calendar-star-date)
153 It could also be used to mark the current date with `='; a function is also
154 provided for this:
155 (setq today-visible-calendar-hook 'calendar-mark-today)
156
157 The corresponding variable `today-invisible-calendar-hook' is the list of
158 functions called when the calendar function was called when the current
159 date is not visible in the window.
160
161 Other than the use of the provided functions, the changing of any
162 characters in the calendar buffer by the hooks may cause the failure of the
163 functions that move by days and weeks.")
164
165 (defvar today-invisible-calendar-hook nil
166 "*List of functions called whenever the current date is not visible.
167
168 The corresponding variable `today-visible-calendar-hook' is the list of
169 functions called when the calendar function was called when the current
170 date is visible in the window.
171
172 Other than the use of the provided functions, the changing of any
173 characters in the calendar buffer by the hooks may cause the failure of the
174 functions that move by days and weeks.")
175
176 (defvar diary-file "~/diary"
177 "*Name of the file in which one's personal diary of dates is kept.
178
179 The file's entries are lines in any of the forms
180
181 MONTH/DAY
182 MONTH/DAY/YEAR
183 MONTHNAME DAY
184 MONTHNAME DAY, YEAR
185 DAYNAME
186
187 at the beginning of the line; the remainder of the line is the diary entry
188 string for that date. MONTH and DAY are one or two digit numbers, YEAR is
189 a number and may be written in full or abbreviated to the final two digits.
190 If the date does not contain a year, it is generic and applies to any year.
191 DAYNAME entries apply to any date on which is on that day of the week.
192 MONTHNAME and DAYNAME can be spelled in full, abbreviated to three
193 characters (with or without a period), capitalized or not. Any of DAY,
194 MONTH, or MONTHNAME, YEAR can be `*' which matches any day, month, or year,
195 respectively.
196
197 The European style (in which the day precedes the month) can be used
198 instead, if you execute `european-calendar' when in the calendar, or set
199 `european-calendar-style' to t in your .emacs file. The European forms are
200
201 DAY/MONTH
202 DAY/MONTH/YEAR
203 DAY MONTHNAME
204 DAY MONTHNAME YEAR
205 DAYNAME
206
207 To revert to the default American style from the European style, execute
208 `american-calendar' in the calendar.
209
210 A diary entry can be preceded by a diary-nonmarking-symbol (ordinarily `&')
211 to make that entry nonmarking--that is, it will not be marked on dates in
212 the calendar window but will appear in a diary window.
213
214 Multiline diary entries are made by indenting lines after the first with
215 either a TAB or one or more spaces.
216
217 Lines not in one the above formats are ignored. Here are some sample diary
218 entries (in the default American style):
219
220 12/22/1988 Twentieth wedding anniversary!!
221 &1/1. Happy New Year!
222 10/22 Ruth's birthday.
223 21: Payday
224 Tuesday--weekly meeting with grad students at 10am
225 Supowit, Shen, Bitner, and Kapoor to attend.
226 1/13/89 Friday the thirteenth!!
227 &thu 4pm squash game with Lloyd.
228 mar 16 Dad's birthday
229 April 15, 1989 Income tax due.
230 &* 15 time cards due.
231
232 If the first line of a diary entry consists only of the date or day name with
233 no trailing blanks or punctuation, then that line will not be displayed in the
234 diary window; only the continuation lines will be shown. For example, the
235 single diary entry
236
237 02/11/1989
238 Bill Blattner visits Princeton today
239 2pm Cognitive Studies Committee meeting
240 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
241 4:00pm Jamie Tappenden
242 7:30pm Dinner at George and Ed's for Alan Ryan
243 7:30-10:00pm dance at Stewart Country Day School
244
245 will appear in the diary window without the date line at the beginning. This
246 facility allows the diary window to look neater, but can cause confusion if
247 used with more than one day's entries displayed.
248
249 Diary entries can be based on Lisp sexps. For example, the diary entry
250
251 %%(diary-block 11 1 1990 11 10 1990) Vacation
252
253 causes the diary entry \"Vacation\" to appear from November 1 through November
254 10, 1990. Other functions available are `diary-float', `diary-anniversary',
255 `diary-cyclic', `day-of-year', `iso-date', `commercial-date', `french-date',
256 `hebrew-date', `islamic-date', `parasha', `omer', and `rosh-hodesh'. See the
257 documentation for the function `list-sexp-diary-entries' for more details.
258
259 Diary entries based on the Hebrew and/or the Islamic calendar are also
260 possible, but because these are somewhat slow, they are ignored
261 unless you set the `nongregorian-diary-listing-hook' and the
262 `nongregorian-diary-marking-hook' appropriately. See the documentation
263 for these functions for details.
264
265 Diary files can contain directives to include the contents of other files; for
266 details, see the documentation for the variable `list-diary-entries-hook'.")
267
268 (defvar diary-nonmarking-symbol "&"
269 "*The symbol used to indicate that a diary entry is not to be marked in the
270 calendar window.")
271
272 (defvar hebrew-diary-entry-symbol "H"
273 "*The symbol used to indicate that a diary entry is according to the
274 Hebrew calendar.")
275
276 (defvar islamic-diary-entry-symbol "I"
277 "*The symbol used to indicate that a diary entry is according to the
278 Islamic calendar.")
279
280 (defvar diary-include-string "#include"
281 "*The string used to indicate the inclusion of another file of diary entries
282 in diary-file. See the documentation for the function
283 `include-other-diary-files'.")
284
285 (defvar sexp-diary-entry-symbol "%%"
286 "*The string used to indicate a sexp diary entry in diary-file.
287 See the documentation for the function `list-sexp-diary-entries'.")
288
289 (defvar abbreviated-calendar-year t
290 "*Interpret a two-digit year DD in a diary entry as being either 19DD or
291 20DD, as appropriate, for the Gregorian calendar; similarly for the Hebrew and
292 Islamic calendars. If this variable is nil, years must be written in full.")
293
294 (defvar european-calendar-style nil
295 "*Use the European style of dates in the diary and in any displays. If this
296 variable is t, a date 1/2/1990 would be interpreted as February 1, 1990.
297 The accepted European date styles are
298
299 DAY/MONTH
300 DAY/MONTH/YEAR
301 DAY MONTHNAME
302 DAY MONTHNAME YEAR
303 DAYNAME
304
305 Names can be capitalized or not, written in full, or abbreviated to three
306 characters with or without a period.")
307
308 (defvar american-date-diary-pattern
309 '((month "/" day "[^/0-9]")
310 (month "/" day "/" year "[^0-9]")
311 (monthname " *" day "[^,0-9]")
312 (monthname " *" day ", *" year "[^0-9]")
313 (dayname "\\W"))
314 "*List of pseudo-patterns describing the American patterns of date used.
315 See the documentation of diary-date-forms for an explanantion.")
316
317 (defvar european-date-diary-pattern
318 '((day "/" month "[^/0-9]")
319 (day "/" month "/" year "[^0-9]")
320 (backup day " *" monthname "\\W+\\<[^*0-9]")
321 (day " *" monthname " *" year "[^0-9]")
322 (dayname "\\W"))
323 "*List of pseudo-patterns describing the European patterns of date used.
324 See the documentation of diary-date-forms for an explanantion.")
325
326 (defvar diary-date-forms
327 (if european-calendar-style
328 european-date-diary-pattern
329 american-date-diary-pattern)
330 "*List of pseudo-patterns describing the forms of date used in the diary.
331 The patterns on the list must be MUTUALLY EXCLUSIVE and must should not match
332 any portion of the diary entry itself, just the date component.
333
334 A pseudo-pattern is a list of regular expressions and the keywords `month',
335 `day', `year', `monthname', and `dayname'. The keyword `monthname' will
336 match the name of the month, capitalized or not, or its three-letter
337 abbreviation, followed by a period or not; it will also match `*'.
338 Similarly, `dayname' will match the name of the day, capitalized or not, or
339 its three-letter abbreviation, followed by a period or not. The keywords
340 `month', `day', and `year' will match those numerical values, preceded by
341 arbitrarily many zeros; they will also match `*'.
342
343 The matching of the diary entries with the date forms is done with the
344 standard syntax table from Fundamental mode, but with the `*' changed so
345 that it is a word constituent.
346
347 If, to be mutually exclusive, a pseudo-pattern must match a portion of the
348 diary entry itself, the first element of the pattern MUST be `backup'. This
349 directive causes the the date recognizer to back up to the beginning of the
350 current word of the diary entry, so in no case can the pattern match more
351 than a portion of the first word of the diary entry.")
352
353 (defvar european-calendar-display-form
354 '(dayname ", " day " " monthname " " year)
355 "*The pseudo-pattern that governs the way a Gregorian date is formatted
356 in the European style. See the documentation of calendar-date-display-forms
357 for an explanantion.")
358
359 (defvar american-calendar-display-form
360 '(dayname ", " monthname " " day ", " year)
361 "*The pseudo-pattern that governs the way a Gregorian date is formatted
362 in the American style. See the documentation of calendar-date-display-forms
363 for an explanantion.")
364
365 (defvar calendar-date-display-form
366 (if european-calendar-style
367 european-calendar-display-form
368 american-calendar-display-form)
369 "*The pseudo-pattern that governs the way a Gregorian date is formatted
370 as a string by the function `calendar-date-string'. A pseudo-pattern is a
371 list of expressions that can involve the keywords `month', `day', and
372 `year', all numbers in string form, and `monthname' and `dayname', both
373 alphabetic strings. For example, the ISO standard would use the pseudo-
374 pattern
375
376 '(year \"-\" month \"-\" day)
377
378 while a typical American form would be
379
380 '(month \"/\" day \"/\" (substring year -2))
381
382 and
383
384 '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
385
386 would give the usual American style in fixed-length fields.
387
388 See the documentation of the function `calendar-date-string'.")
389
390 (defun european-calendar ()
391 "Set the interpretation and display of dates to the European style."
392 (interactive)
393 (setq european-calendar-style t)
394 (setq calendar-date-display-form european-calendar-display-form)
395 (setq diary-date-forms european-date-diary-pattern)
396 (update-calendar-mode-line))
397
398 (defun american-calendar ()
399 "Set the interpretation and display of dates to the American style."
400 (interactive)
401 (setq european-calendar-style nil)
402 (setq calendar-date-display-form american-calendar-display-form)
403 (setq diary-date-forms american-date-diary-pattern)
404 (update-calendar-mode-line))
405
406 (defvar print-diary-entries-hook
407 '(add-diary-heading lpr-buffer (lambda nil (kill-buffer temp-buffer)))
408 "*List of functions to be called after a temporary buffer is prepared
409 with the diary entries currently visible in the diary buffer. The default
410 value adds a heading (formed from the information in the mode line of the
411 diary buffer), does the printing, and kills the buffer. Other uses might
412 include, for example, rearranging the lines into order by day and time,
413 saving the buffer instead of deleting it, or changing the function used to
414 do the printing.")
415
416 ;;;###autoload
417 (defvar list-diary-entries-hook nil
418 "*List of functions to be called after the diary file is culled for
419 relevant entries. It is to be used for diary entries that are not found in
420 the diary file.
421
422 A function `include-other-diary-files' is provided for use as the value of
423 this hook. This function enables you to use shared diary files together
424 with your own. The files included are specified in the diary-file by lines
425 of the form
426
427 #include \"filename\"
428
429 This is recursive; that is, #include directives in files thus included are
430 obeyed. You can change the \"#include\" to some other string by changing
431 the variable `diary-include-string'. When you use `include-other-diary-files'
432 as part of the list-diary-entries-hook, you will probably also want to use the
433 function `mark-included-diary-files' as part of the mark-diary-entries-hook.
434
435 For example, you could use
436
437 (setq list-diary-entries-hook
438 '(include-other-diary-files
439 (lambda nil
440 (setq diary-entries-list
441 (sort diary-entries-list 'diary-entry-compare)))))
442 (setq diary-display-hook 'fancy-diary-display)
443
444 in your .emacs file to cause the fancy diary buffer to be displayed with
445 diary entries from various included files, each day's entries sorted into
446 lexicographic order.")
447
448 ;;;###autoload
449 (defvar diary-display-hook 'simple-diary-display
450 "*List of functions that handle the display of the diary.
451
452 Ordinarily, this just displays the diary buffer (with holidays indicated in
453 the mode line), if there are any relevant entries. At the time these
454 functions are called, the variable `diary-entries-list' is a list, in order
455 by date, of all relevant diary entries in the form of ((MONTH DAY YEAR)
456 STRING), where string is the diary entry for the given date. This can be
457 used, for example, to handle appointment notification, prepare a different
458 buffer for display (perhaps combined with holidays), or produce hard copy
459 output.
460
461 A function `fancy-diary-display' is provided as an alternative
462 choice for this hook; this function prepares a special noneditable diary
463 buffer with the relevant diary entries that has neat day-by-day arrangement
464 with headings. The fancy diary buffer will show the holidays unless the
465 variable `holidays-in-diary-buffer' is set to nil. Ordinarily, the fancy
466 diary buffer will not show days for which there are no diary entries, even
467 if that day is a holiday; if you want such days to be shown in the fancy
468 diary buffer, set the variable `diary-list-include-blanks' to t.")
469
470 ;;;###autoload
471 (defvar nongregorian-diary-listing-hook nil
472 "*List of functions to be called for the diary file and included files as
473 they are processed for listing diary entries. You can use any or all of
474 `list-hebrew-diary-entries', `yahrzeit-diary-entry', and
475 `list-islamic-diary-entries'. The documentation for these functions
476 describes the style of such diary entries.")
477
478 (defvar mark-diary-entries-hook nil
479 "*List of functions called after marking diary entries in the calendar.
480
481 A function `mark-included-diary-files' is also provided for use as the
482 mark-diary-entries-hook; it enables you to use shared diary files together
483 with your own. The files included are specified in the diary-file by lines
484 of the form
485 #include \"filename\"
486 This is recursive; that is, #include directives in files thus included are
487 obeyed. You can change the \"#include\" to some other string by changing the
488 variable `diary-include-string'. When you use `mark-included-diary-files' as
489 part of the mark-diary-entries-hook, you will probably also want to use the
490 function `include-other-diary-files' as part of the list-diary-entries-hook.")
491
492 ;;;###autoload
493 (defvar nongregorian-diary-marking-hook nil
494 "*List of functions to be called as the diary file and included files are
495 processed for marking diary entries. You can use either or both of
496 mark-hebrew-diary-entries and mark-islamic-diary-entries. The documentation
497 for these functions describes the style of such diary entries.")
498
499 ;;;###autoload
500 (defvar diary-list-include-blanks nil
501 "*If nil, do not include days with no diary entry in the list of diary
502 entries. Such days will then not be shown in the the fancy diary buffer,
503 even if they are holidays.")
504
505 (defvar holidays-in-diary-buffer t
506 "*If t, the holidays will be indicated in the mode line of the diary buffer
507 (or in the fancy diary buffer next to the date). This slows down the diary
508 functions somewhat; setting it to nil will make the diary display faster.")
509
510 (defvar calendar-holidays
511 '(
512 ;; General Holidays (American)
513 (fixed 1 1 "New Year's Day")
514 (float 1 1 3 "Martin Luther King Day")
515 (fixed 2 2 "Ground Hog Day")
516 (fixed 2 14 "Valentine's Day")
517 (float 2 1 3 "President's Day")
518 (fixed 3 17 "St. Patrick's Day")
519 (fixed 4 1 "April Fool's Day")
520 (float 4 0 1 "Daylight Savings Time Begins")
521 (float 5 0 2 "Mother's Day")
522 (float 5 1 -1 "Memorial Day")
523 (fixed 6 14 "Flag Day")
524 (float 6 0 3 "Father's Day")
525 (fixed 7 4 "Independence Day")
526 (float 9 1 1 "Labor Day")
527 (float 10 1 2 "Columbus Day")
528 (float 10 0 -1 "Daylight Savings Time Ends")
529 (fixed 10 31 "Halloween")
530 (fixed 11 11 "Veteran's Day")
531 (float 11 4 4 "Thanksgiving")
532
533 ;; Christian Holidays
534 (if all-christian-calendar-holidays
535 (fixed 1 6 "Epiphany"))
536 (easter-etc)
537 (if all-christian-calendar-holidays
538 (fixed 8 15 "Assumption"))
539 (if all-christian-calendar-holidays
540 (advent))
541 (fixed 12 25 "Christmas")
542 (if all-christian-calendar-holidays
543 (julian 12 25 "Eastern Orthodox Christmas"))
544
545 ;; Jewish Holidays
546 (rosh-hashanah-etc)
547 (if all-hebrew-calendar-holidays
548 (julian 11
549 (let* ((m displayed-month)
550 (y displayed-year)
551 (year))
552 (increment-calendar-month m y -1)
553 (let ((year (extract-calendar-year
554 (calendar-julian-from-absolute
555 (calendar-absolute-from-gregorian
556 (list m 1 y))))))
557 (if (zerop (% (1+ year) 4))
558 22
559 21))) "\"Tal Umatar\" (evening)"))
560 (if all-hebrew-calendar-holidays
561 (hanukkah)
562 (hebrew 9 25 "Hanukkah"))
563 (if all-hebrew-calendar-holidays
564 (hebrew 10
565 (let ((h-year (extract-calendar-year
566 (calendar-hebrew-from-absolute
567 (calendar-absolute-from-gregorian
568 (list displayed-month 28 displayed-year))))))
569 (if (= (% (calendar-absolute-from-hebrew (list 10 10 h-year))
570 7)
571 6)
572 11 10))
573 "Tzom Teveth"))
574 (if all-hebrew-calendar-holidays
575 (hebrew 11 15 "Tu B'Shevat"))
576 (if all-hebrew-calendar-holidays
577 (hebrew
578 11
579 (let ((m displayed-month)
580 (y displayed-year))
581 (increment-calendar-month m y 1)
582 (let* ((h-year (extract-calendar-year
583 (calendar-hebrew-from-absolute
584 (calendar-absolute-from-gregorian
585 (list m
586 (calendar-last-day-of-month m y)
587 y)))))
588 (s-s
589 (calendar-hebrew-from-absolute
590 (if (=
591 (% (calendar-absolute-from-hebrew
592 (list 7 1 h-year))
593 7)
594 6)
595 (calendar-dayname-on-or-before
596 6 (calendar-absolute-from-hebrew
597 (list 11 17 h-year)))
598 (calendar-dayname-on-or-before
599 6 (calendar-absolute-from-hebrew
600 (list 11 16 h-year))))))
601 (day (extract-calendar-day s-s)))
602 day))
603 "Shabbat Shirah"))
604 (passover-etc)
605 (if (and all-hebrew-calendar-holidays
606 (let* ((m displayed-month)
607 (y displayed-year)
608 (year))
609 (increment-calendar-month m y -1)
610 (let ((year (extract-calendar-year
611 (calendar-julian-from-absolute
612 (calendar-absolute-from-gregorian
613 (list m 1 y))))))
614 (= 21 (% year 28)))))
615 (julian 3 26 "Kiddush HaHamah"))
616 (if all-hebrew-calendar-holidays
617 (tisha-b-av-etc))
618
619 ;; Islamic Holidays
620 (islamic 1 1 (format "Islamic New Year %d"
621 (let ((m displayed-month)
622 (y displayed-year))
623 (increment-calendar-month m y 1)
624 (extract-calendar-year
625 (calendar-islamic-from-absolute
626 (calendar-absolute-from-gregorian
627 (list m (calendar-last-day-of-month m y) y)))))))
628 (if all-islamic-calendar-holidays
629 (islamic 1 10 "Ashura"))
630 (if all-islamic-calendar-holidays
631 (islamic 3 12 "Mulad-al-Nabi"))
632 (if all-islamic-calendar-holidays
633 (islamic 7 26 "Shab-e-Mi'raj"))
634 (if all-islamic-calendar-holidays
635 (islamic 8 15 "Shab-e-Bara't"))
636 (islamic 9 1 "Ramadan Begins")
637 (if all-islamic-calendar-holidays
638 (islamic 9 27 "Shab-e Qadr"))
639 (if all-islamic-calendar-holidays
640 (islamic 10 1 "Id-al-Fitr"))
641 (if all-islamic-calendar-holidays
642 (islamic 12 10 "Id-al-Adha")))
643 "List of notable days for the command M-x holidays.
644 Additional holidays are easy to add to the list. The possible holiday-forms
645 are as follows:
646
647 (fixed MONTH DAY STRING) a fixed date on the Gregorian calendar
648 (float MONTH DAYNAME K STRING) the Kth DAYNAME in MONTH on the Gregorian
649 calendar (0 for Sunday, etc.); K<0 means
650 count back from the end of the month
651 (hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
652 (islamic MONTH DAY STRING) a fixed date on the Islamic calendar
653 (julian MONTH DAY STRING) a fixed date on the Julian calendar
654 (if BOOLEAN HOLIDAY-FORM &optional HOLIDAY-FORM) gives a choice between
655 two holidays based on the value of BOOLEAN
656 (FUNCTION &optional ARGS) dates requiring special computation; ARGS,
657 if any, are passed in a list to the function
658 `calendar-holiday-function-FUNCTION'
659
660 For example, to add Bastille Day, celebrated in France on July 14, add
661
662 (fixed 7 14 \"Bastille Day\")
663
664 to the list. To add Hurricane Supplication Day, celebrated in the Virgin
665 Islands on the fourth Monday in August, add
666
667 (float 8 1 4 \"Hurricane Supplication Day\")
668
669 to the list (the last Monday would be specified with `-1' instead of `4').
670 To add the last day of Hanukah to the list, use
671
672 (hebrew 10 2 \"Last day of Hanukah\")
673
674 since the Hebrew months are numbered with 1 starting from Nisan, while to
675 add the Islamic feast celebrating Mohammed's birthday use
676
677 (islamic 3 12 \"Mohammed's Birthday\")
678
679 since the Islamic months are numbered from 1 starting with Muharram. To
680 add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
681
682 (julian 4 2 \"Jefferson's Birthday\")
683
684 To include a holiday conditionally, use the if form. For example, to
685 include American presidential elections, which occur on the first Tuesday
686 after the first Monday in November of years divisble by 4, add
687
688 (if (zerop (% displayed-year 4))
689 (fixed 11
690 (extract-calendar-day
691 (calendar-gregorian-from-absolute
692 (1+ (calendar-dayname-on-or-before
693 1 (+ 6 (calendar-absolute-from-gregorian
694 (list 11 1 displayed-year)))))))
695 \"US Presidential Election\"))
696
697 to the list. To include the phases of the moon, add
698
699 (lunar-phases)
700
701 to the holiday list, where `calendar-holiday-function-lunar-phases' is an
702 Emacs-Lisp function that you've written to return a (possibly empty) list of
703 the relevant VISIBLE dates with descriptive strings such as
704
705 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )
706
707 The fixed, float, hebrew, islamic, julian and if forms are implemented by
708 the inclusion of the functions `calendar-holiday-function-fixed',
709 `calendar-holiday-function-float', `calendar-holiday-function-hebrew',
710 `calendar-holiday-function-islamic', `calendar-holiday-function-julian',
711 and `calendar-holiday-function-if', respectively.")
712
713 (defconst calendar-buffer "*Calendar*"
714 "Name of the buffer used for the calendar.")
715
716 (defconst holiday-buffer "*Holidays*"
717 "Name of the buffer used for the displaying the holidays.")
718
719 (defconst fancy-diary-buffer "*Fancy Diary Entries*"
720 "Name of the buffer used for the optional fancy display of the diary.")
721
722 (defmacro increment-calendar-month (mon yr n)
723 "Move the variables MON and YR to the month and year N months forward
724 if N is positive or backward if N is negative."
725 (` (let (( macro-y (+ (* (, yr) 12) (, mon) -1 (, n) )))
726 (setq (, mon) (1+ (% macro-y 12) ))
727 (setq (, yr) (/ macro-y 12)))))
728
729 (defmacro calendar-for-loop (var from init to final do &rest body)
730 "Execute a for loop."
731 (` (let (( (, var) (1- (, init)) ))
732 (while (>= (, final) (setq (, var) (1+ (, var))))
733 (,@ body)))))
734
735 (defmacro calendar-sum (index initial condition expression)
736 "For INDEX = INITIAL and successive integers, as long as CONDITION holds,
737 sum EXPRESSION."
738 (` (let (( (, index) (, initial))
739 (sum 0))
740 (while (, condition)
741 (setq sum (+ sum (, expression) ))
742 (setq (, index) (1+ (, index))))
743 sum)))
744
745 ;; The following macros are for speed; the code would be clearer if they
746 ;; were functions, but they can be called thousands of times when
747 ;; looking up holidays or processing the diary. Here, for example, are the
748 ;; numbers of calls to calendar/diary/holiday functions in preparing the
749 ;; fancy diary display, for a moderately complex diary file, with functions
750 ;; used instead of macros. There were a total of 10000 such calls:
751 ;;
752 ;; 1934 extract-calendar-month
753 ;; 1852 extract-calendar-year
754 ;; 1819 extract-calendar-day
755 ;; 845 calendar-leap-year-p
756 ;; 837 calendar-day-number
757 ;; 775 calendar-absolute-from-gregorian
758 ;; 346 calendar-last-day-of-month
759 ;; 286 hebrew-calendar-last-day-of-month
760 ;; 188 hebrew-calendar-leap-year-p
761 ;; 180 hebrew-calendar-elapsed-days
762 ;; 163 hebrew-calendar-last-month-of-year
763 ;; 66 calendar-date-compare
764 ;; 65 hebrew-calendar-days-in-year
765 ;; 60 calendar-absolute-from-julian
766 ;; 50 calendar-absolute-from-hebrew
767 ;; 43 calendar-date-equal
768 ;; 38 calendar-gregorian-from-absolute
769 ;; .
770 ;; .
771 ;; .
772 ;;
773 ;; The use of these seven macros eliminates the overhead of 92% of the function
774 ;; calls; it's faster this way.
775
776 (defmacro extract-calendar-month (date)
777 "Extract the month part of DATE which has the form (month day year)."
778 (` (car (, date))))
779
780 (defmacro extract-calendar-day (date)
781 "Extract the day part of DATE which has the form (month day year)."
782 (` (car (cdr (, date)))))
783
784 (defmacro extract-calendar-year (date)
785 "Extract the year part of DATE which has the form (month day year)."
786 (` (car (cdr (cdr (, date))))))
787
788 (defmacro calendar-leap-year-p (year)
789 "Returns t if YEAR is a Gregorian leap year."
790 (` (or
791 (and (= (% (, year) 4) 0)
792 (/= (% (, year) 100) 0))
793 (= (% (, year) 400) 0))))
794
795 (defmacro calendar-last-day-of-month (month year)
796 "The last day in MONTH during YEAR."
797 (` (if (and
798 (, (macroexpand (` (calendar-leap-year-p (, year)))))
799 (= (, month) 2))
800 29
801 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- (, month))))))
802
803 (defmacro calendar-day-number (date)
804 "Return the day number within the year of the date DATE.
805 For example, (calendar-day-number '(1 1 1987)) returns the value 1,
806 while (calendar-day-number '(12 31 1980)) returns 366."
807 ;;
808 ;; An explanation of the calculation can be found in PascAlgorithms by
809 ;; Edward and Ruth Reingold, Scott-Foresman/Little, Brown, 1988.
810 ;;
811 (` (let* ((month (, (macroexpand (` (extract-calendar-month (, date))))))
812 (day (, (macroexpand (` (extract-calendar-day (, date))))))
813 (year (, (macroexpand (` (extract-calendar-year (, date))))))
814 (day-of-year (+ day (* 31 (1- month)))))
815 (if (> month 2)
816 (progn
817 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
818 (if (, (macroexpand (` (calendar-leap-year-p year))))
819 (setq day-of-year (1+ day-of-year)))))
820 day-of-year)))
821
822 (defmacro calendar-absolute-from-gregorian (date)
823 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
824 The Gregorian date Sunday, December 31, 1 BC is imaginary."
825 (` (let ((month (, (macroexpand (` (extract-calendar-month (, date))))))
826 (day (, (macroexpand (` (extract-calendar-day (, date))))))
827 (year (, (macroexpand (` (extract-calendar-year (, date)))))))
828 (+ (, (macroexpand (` (calendar-day-number (, date)))));; Days this year
829 (* 365 (1- year));; + Days in prior years
830 (/ (1- year) 4);; + Julian leap years
831 (- (/ (1- year) 100));; - century years
832 (/ (1- year) 400)))));; + Gregorian leap years
833
834 ;;;###autoload
835 (defun calendar (&optional arg)
836 "Display a three-month calendar in another window.
837 The three months appear side by side, with the current month in the middle
838 surrounded by the previous and next months. The cursor is put on today's date.
839
840 This function is suitable for execution in a .emacs file; appropriate setting
841 of the variable `view-diary-entries-initially' will cause the diary entries for
842 the current date to be displayed in another window. The value of the variable
843 `number-of-diary-entries' controls the number of days of diary entries
844 displayed upon initial display of the calendar.
845
846 An optional prefix argument ARG causes the calendar displayed to be ARG
847 months in the future if ARG is positive or in the past if ARG is negative;
848 in this case the cursor goes on the first day of the month.
849
850 Once in the calendar window, future or past months can be moved into view.
851 Arbitrary months can be displayed, or the calendar can be scrolled forward
852 or backward.
853
854 The cursor can be moved forward or backward by one day, one week, one month,
855 or one year. All of these commands take prefix arguments which, when negative,
856 cause movement in the opposite direction. For convenience, the digit keys
857 and the minus sign are automatically prefixes. The window is replotted as
858 necessary to display the desired date.
859
860 Diary entries can be marked on the calendar or displayed in another window.
861
862 Use M-x describe-mode for details of the key bindings in the calendar window.
863
864 The Gregorian calendar is assumed.
865
866 After preparing the calendar window initially, the hooks given by the variable
867 `initial-calendar-window-hook' are run.
868
869 The hooks given by the variable `today-visible-calendar-hook' are run
870 everytime the calendar window gets scrolled, if the current date is visible
871 in the window. If it is not visible, the hooks given by the variable
872 `today-invisible-calendar-hook' are run. Thus, for example, setting
873 `today-visible-calendar-hook' to 'calendar-star-date will cause today's date
874 to be replaced by asterisks to highlight it whenever it is in the window."
875 (interactive "P")
876 (setq arg (if arg (prefix-numeric-value arg) 0))
877 (set-buffer (get-buffer-create calendar-buffer))
878 (calendar-mode)
879 (setq calendar-window-configuration (current-window-configuration))
880 (let ((pop-up-windows t)
881 (split-height-threshold 1000))
882 (pop-to-buffer calendar-buffer)
883 (regenerate-calendar-window arg)
884 (let ((date (list current-month current-day current-year)))
885 (if (and view-diary-entries-initially (calendar-date-is-visible-p date))
886 (view-diary-entries
887 (if (vectorp number-of-diary-entries)
888 (aref number-of-diary-entries (calendar-day-of-week date))
889 number-of-diary-entries))))
890 (let* ((diary-buffer (get-file-buffer diary-file))
891 (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
892 (split-height-threshold (if diary-window 2 1000)))
893 (if view-calendar-holidays-initially
894 (list-calendar-holidays))))
895 (run-hooks 'initial-calendar-window-hook))
896
897 (autoload 'view-diary-entries "diary"
898 "Prepare and display a buffer with diary entries.
899 Searches the file diary-file for entries that match ARG days starting with
900 the date indicated by the cursor position in the displayed three-month
901 calendar."
902 t)
903
904 (autoload 'show-all-diary-entries "diary"
905 "Show all of the diary entries in the diary-file.
906 This function gets rid of the selective display of the diary-file so that
907 all entries, not just some, are visible. If there is no diary buffer, one
908 is created."
909 t)
910
911 (autoload 'mark-diary-entries "diary"
912 "Mark days in the calendar window that have diary entries.
913 Each entry in diary-file visible in the calendar window is marked."
914 t)
915
916 (autoload 'insert-diary-entry "diary"
917 "Insert a diary entry for the date indicated by point."
918 t)
919
920 (autoload 'insert-weekly-diary-entry "diary"
921 "Insert a weekly diary entry for the day of the week indicated by point."
922 t)
923
924 (autoload 'insert-monthly-diary-entry "diary"
925 "Insert a monthly diary entry for the day of the month indicated by point."
926 t)
927
928 (autoload 'insert-yearly-diary-entry "diary"
929 "Insert an annual diary entry for the day of the year indicated by point."
930 t)
931
932 (autoload 'insert-anniversary-diary-entry "diary"
933 "Insert an anniversary diary entry for the date indicated by point."
934 t)
935
936 (autoload 'insert-block-diary-entry "diary"
937 "Insert a block diary entry for the dates indicated by point and mark."
938 t)
939
940 (autoload 'insert-cyclic-diary-entry "diary"
941 "Insert a cyclic diary entry starting at the date indicated by point."
942 t)
943
944 (autoload 'insert-hebrew-diary-entry "diary"
945 "Insert a diary entry for the Hebrew date corresponding to the date
946 indicated by point."
947 t)
948
949 (autoload 'insert-monthly-hebrew-diary-entry "diary"
950 "Insert a monthly diary entry for the day of the Hebrew month corresponding
951 to the date indicated by point."
952 t)
953
954 (autoload 'insert-yearly-hebrew-diary-entry "diary"
955 "Insert an annual diary entry for the day of the Hebrew year corresponding
956 to the date indicated by point."
957 t)
958
959 (autoload 'insert-islamic-diary-entry "diary"
960 "Insert a diary entry for the Islamic date corresponding to the date
961 indicated by point."
962 t)
963
964 (autoload 'insert-monthly-islamic-diary-entry "diary"
965 "Insert a monthly diary entry for the day of the Islamic month corresponding
966 to the date indicated by point."
967 t)
968
969 (autoload 'insert-yearly-islamic-diary-entry "diary"
970 "Insert an annual diary entry for the day of the Islamic year corresponding
971 to the date indicated by point."
972 t)
973
974 (autoload 'list-calendar-holidays "holidays"
975 "Create a buffer containing the holidays for the current calendar window.
976 The holidays are those in the list `calendar-notable-days'. Returns t if any
977 holidays are found, nil if not."
978 t)
979
980 (autoload 'mark-calendar-holidays "holidays"
981 "Mark notable days in the calendar window."
982 t)
983
984 (autoload 'calendar-cursor-holidays "holidays"
985 "Find holidays for the date specified by the cursor in the calendar window."
986 t)
987
988 (defun regenerate-calendar-window (&optional arg)
989 "Generate the calendar window, offset from the current date by ARG months."
990 (if (not arg) (setq arg 0))
991 (let* ((buffer-read-only nil)
992 (today-visible (and (<= arg 1) (>= arg -1)))
993 (today (calendar-current-date))
994 (month (extract-calendar-month today))
995 (day (extract-calendar-day today))
996 (year (extract-calendar-year today))
997 (day-in-week (calendar-day-of-week today)))
998 (update-calendar-mode-line)
999 (setq current-month month)
1000 (setq current-day day)
1001 (setq current-year year)
1002 (increment-calendar-month month year arg)
1003 (generate-calendar month year)
1004 (calendar-cursor-to-visible-date
1005 (if today-visible today (list displayed-month 1 displayed-year)))
1006 (set-buffer-modified-p nil)
1007 (or (one-window-p t)
1008 (/= (frame-width) (window-width))
1009 (shrink-window (- (window-height) 9)))
1010 (sit-for 0)
1011 (and mark-holidays-in-calendar
1012 (mark-calendar-holidays)
1013 (sit-for 0))
1014 (unwind-protect
1015 (if mark-diary-entries-in-calendar (mark-diary-entries))
1016 (if today-visible
1017 (run-hooks 'today-visible-calendar-hook)
1018 (run-hooks 'today-invisible-calendar-hook)))))
1019
1020 (defun generate-calendar (month year)
1021 "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
1022 (if (< (+ month (* 12 (1- year))) 2)
1023 (error "Months before February, 1 AD are not available."))
1024 (setq displayed-month month)
1025 (setq displayed-year year)
1026 (erase-buffer)
1027 (increment-calendar-month month year -1)
1028 (calendar-for-loop i from 0 to 2 do
1029 (generate-calendar-month month year (+ 5 (* 25 i)))
1030 (increment-calendar-month month year 1)))
1031
1032 (defun generate-calendar-month (month year indent)
1033 "Produce a calendar for MONTH, YEAR on the Gregorian calendar.
1034 The calendar is inserted in the buffer starting at the line on which point
1035 is currently located, but indented INDENT spaces. The indentation is done
1036 from the first character on the line and does not disturb the first INDENT
1037 characters on the line."
1038 (let* ((first-day-of-month (calendar-day-of-week (list month 1 year)))
1039 (first-saturday (- 7 first-day-of-month))
1040 (last (calendar-last-day-of-month month year))
1041 (heading (format "%s %d" (calendar-month-name month) year)))
1042 (goto-char (point-min))
1043 (calendar-insert-indented
1044 heading (+ indent (/ (- 20 (length heading)) 2)) t)
1045 (calendar-insert-indented " S M Tu W Th F S" indent t)
1046 (calendar-insert-indented "" indent);; Move to appropriate spot on line
1047 ;; Add blank days before the first of the month
1048 (calendar-for-loop i from 1 to first-day-of-month do
1049 (insert " "))
1050 ;; Put in the days of the month
1051 (calendar-for-loop i from 1 to last do
1052 (insert (format "%2d " i))
1053 (and (= (% i 7) (% first-saturday 7))
1054 (/= i last)
1055 (calendar-insert-indented "" 0 t) ;; Force onto following line
1056 (calendar-insert-indented "" indent)))));; Go to proper spot
1057
1058 (defun calendar-insert-indented (string indent &optional newline)
1059 "Insert STRING at column INDENT.
1060 If the optional parameter NEWLINE is t, leave point at start of next line,
1061 inserting a newline if there was no next line; otherwise, leave point after
1062 the inserted text. Value is always t."
1063 ;; Try to move to that column.
1064 (move-to-column indent)
1065 ;; If line is too short, indent out to that column.
1066 (if (< (current-column) indent)
1067 (indent-to indent))
1068 (insert string)
1069 ;; Advance to next line, if requested.
1070 (if newline
1071 (progn
1072 (end-of-line)
1073 (if (eobp)
1074 (newline)
1075 (forward-line 1))))
1076 t)
1077
1078 (defun redraw-calendar ()
1079 "Redraw the calendar display."
1080 (interactive)
1081 (let ((cursor-date (calendar-cursor-to-date)))
1082 (regenerate-calendar-window
1083 (calendar-interval current-month current-year
1084 displayed-month displayed-year))
1085 (calendar-cursor-to-visible-date cursor-date)))
1086
1087 (defvar calendar-mode-map nil)
1088 (if calendar-mode-map
1089 nil
1090 (setq calendar-mode-map (make-sparse-keymap))
1091 (calendar-for-loop i from 0 to 9 do
1092 (define-key calendar-mode-map (int-to-string i) 'digit-argument))
1093 (let ((l (list 'narrow-to-region 'mark-word 'mark-sexp 'mark-paragraph
1094 'mark-defun 'mark-whole-buffer 'mark-page 'kill-region
1095 'copy-region-as-kill 'downcase-region 'upcase-region
1096 'capitalize-region 'write-region)))
1097 (while (car l)
1098 (let ((k (where-is-internal (car l))))
1099 (while (car k)
1100 (define-key calendar-mode-map (car k) 'calendar-not-implemented)
1101 (setq k (cdr k)))
1102 (setq l (cdr l)))))
1103 (define-key calendar-mode-map "-" 'negative-argument)
1104 (define-key calendar-mode-map "\C-x>" 'scroll-calendar-right)
1105 (define-key calendar-mode-map "\ev" 'scroll-calendar-right-three-months)
1106 (define-key calendar-mode-map "\C-x<" 'scroll-calendar-left)
1107 (define-key calendar-mode-map "\C-v" 'scroll-calendar-left-three-months)
1108 (define-key calendar-mode-map "\C-b" 'calendar-backward-day)
1109 (define-key calendar-mode-map "\C-p" 'calendar-backward-week)
1110 (define-key calendar-mode-map "\e[" 'calendar-backward-month)
1111 (define-key calendar-mode-map "\C-x[" 'calendar-backward-year)
1112 (define-key calendar-mode-map "\C-f" 'calendar-forward-day)
1113 (define-key calendar-mode-map "\C-n" 'calendar-forward-week)
1114 (define-key calendar-mode-map "\e]" 'calendar-forward-month)
1115 (define-key calendar-mode-map "\C-x]" 'calendar-forward-year)
1116 (define-key calendar-mode-map "\C-a" 'calendar-beginning-of-week)
1117 (define-key calendar-mode-map "\C-e" 'calendar-end-of-week)
1118 (define-key calendar-mode-map "\ea" 'calendar-beginning-of-month)
1119 (define-key calendar-mode-map "\ee" 'calendar-end-of-month)
1120 (define-key calendar-mode-map "\e<" 'calendar-beginning-of-year)
1121 (define-key calendar-mode-map "\e>" 'calendar-end-of-year)
1122 (define-key calendar-mode-map "\C-@" 'calendar-set-mark)
1123 (define-key calendar-mode-map "\C-x\C-x" 'calendar-exchange-point-and-mark)
1124 (define-key calendar-mode-map "\e=" 'calendar-count-days-region)
1125 (define-key calendar-mode-map "gd" 'calendar-goto-date)
1126 (define-key calendar-mode-map "gJ" 'calendar-goto-julian-date)
1127 (define-key calendar-mode-map "gH" 'calendar-goto-hebrew-date)
1128 (define-key calendar-mode-map "gI" 'calendar-goto-islamic-date)
1129 (define-key calendar-mode-map "gC" 'calendar-goto-iso-date)
1130 (define-key calendar-mode-map " " 'scroll-other-window)
1131 (define-key calendar-mode-map "\C-c\C-l" 'redraw-calendar)
1132 (define-key calendar-mode-map "c" 'calendar-current-month)
1133 (define-key calendar-mode-map "o" 'calendar-other-month)
1134 (define-key calendar-mode-map "q" 'exit-calendar)
1135 (define-key calendar-mode-map "a" 'list-calendar-holidays)
1136 (define-key calendar-mode-map "h" 'calendar-cursor-holidays)
1137 (define-key calendar-mode-map "x" 'mark-calendar-holidays)
1138 (define-key calendar-mode-map "u" 'calendar-unmark)
1139 (define-key calendar-mode-map "m" 'mark-diary-entries)
1140 (define-key calendar-mode-map "d" 'view-diary-entries)
1141 (define-key calendar-mode-map "s" 'show-all-diary-entries)
1142 (define-key calendar-mode-map "D" 'cursor-to-calendar-day-of-year)
1143 (define-key calendar-mode-map "C" 'cursor-to-iso-calendar-date)
1144 (define-key calendar-mode-map "J" 'cursor-to-julian-calendar-date)
1145 (define-key calendar-mode-map "H" 'cursor-to-hebrew-calendar-date)
1146 (define-key calendar-mode-map "I" 'cursor-to-islamic-calendar-date)
1147 (define-key calendar-mode-map "F" 'cursor-to-french-calendar-date)
1148 (define-key calendar-mode-map "\C-cd" 'insert-diary-entry)
1149 (define-key calendar-mode-map "\C-cw" 'insert-weekly-diary-entry)
1150 (define-key calendar-mode-map "\C-cm" 'insert-monthly-diary-entry)
1151 (define-key calendar-mode-map "\C-cy" 'insert-yearly-diary-entry)
1152 (define-key calendar-mode-map "\C-ca" 'insert-anniversary-diary-entry)
1153 (define-key calendar-mode-map "\C-cb" 'insert-block-diary-entry)
1154 (define-key calendar-mode-map "\C-cc" 'insert-cyclic-diary-entry)
1155 (define-key calendar-mode-map "\C-cHd" 'insert-hebrew-diary-entry)
1156 (define-key calendar-mode-map "\C-cHm" 'insert-monthly-hebrew-diary-entry)
1157 (define-key calendar-mode-map "\C-cHy" 'insert-yearly-hebrew-diary-entry)
1158 (define-key calendar-mode-map "\C-cId" 'insert-islamic-diary-entry)
1159 (define-key calendar-mode-map "\C-cIm" 'insert-monthly-islamic-diary-entry)
1160 (define-key calendar-mode-map "\C-cIy" 'insert-yearly-islamic-diary-entry)
1161 (define-key calendar-mode-map "?" 'describe-calendar-mode))
1162
1163 (defun describe-calendar-mode ()
1164 "Create a help buffer with a brief description of the calendar-mode."
1165 (interactive)
1166 (with-output-to-temp-buffer "*Help*"
1167 (princ
1168 (format
1169 "Calendar Mode:\nFor a complete description, type %s\n%s\n"
1170 (substitute-command-keys
1171 "\\<calendar-mode-map>\\[describe-mode] from within the calendar")
1172 (substitute-command-keys "\\{calendar-mode-map}")))
1173 (print-help-return-message)))
1174
1175 ;; Calendar mode is suitable only for specially formatted data.
1176 (put 'calendar-mode 'mode-class 'special)
1177
1178 (defvar calendar-mode-line-format
1179 (substitute-command-keys
1180 "\\<calendar-mode-map>\\[scroll-calendar-left] Calendar \\[describe-calendar-mode] help/\\[calendar-other-month] other/\\[calendar-current-month] current %17s \\[scroll-calendar-right]")
1181 "The mode line of the calendar buffer.")
1182
1183 (defun calendar-mode ()
1184 "A major mode for the sliding calendar window and diary.
1185
1186 The commands for cursor movement are:\\<calendar-mode-map>
1187
1188 \\[calendar-forward-day] one day forward \\[calendar-backward-day] one day backward
1189 \\[calendar-forward-week] one week forward \\[calendar-backward-week] one week backward
1190 \\[calendar-forward-month] one month forward \\[calendar-backward-month] one month backward
1191 \\[calendar-forward-year] one year forward \\[calendar-backward-year] one year backward
1192 \\[calendar-beginning-of-week] beginning of week \\[calendar-end-of-week] end of week
1193 \\[calendar-beginning-of-month] beginning of month \\[calendar-end-of-month] end of month
1194 \\[calendar-beginning-of-year] beginning of year \\[calendar-end-of-year] end of year
1195 \\[calendar-goto-date] go to date \\[calendar-goto-julian-date] go to Julian date
1196 \\[calendar-goto-hebrew-date] go to Hebrew date \\[calendar-goto-islamic-date] go to Islamic date
1197 \\[calendar-goto-iso-date] go to ISO date
1198
1199 You can mark a date in the calendar and switch the point and mark:
1200 \\[calendar-set-mark] mark date \\[calendar-exchange-point-and-mark] exchange point and mark
1201 You can determine the number of days (inclusive) between the point and mark by
1202 \\[calendar-count-days-region] count days in the region
1203
1204 The commands for calendar movement are:
1205
1206 \\[scroll-calendar-right] scroll one month right \\[scroll-calendar-left] scroll one month left
1207 \\[scroll-calendar-right-three-months] scroll 3 months right \\[scroll-calendar-left-three-months] scroll 3 months left
1208 \\[calendar-current-month] display current month \\[calendar-other-month] display another month
1209
1210 Whenever it makes sense, the above commands take prefix arguments that
1211 multiply their affect. For convenience, the digit keys and the minus sign
1212 are bound to digit-argument, so they need not be prefixed with ESC.
1213
1214 If the calendar window somehow becomes corrupted, it can be regenerated with
1215
1216 \\[redraw-calendar] redraw the calendar
1217
1218 The following commands deal with holidays and other notable days:
1219
1220 \\[calendar-cursor-holidays] give holidays for the date specified by the cursor
1221 \\[mark-calendar-holidays] mark notable days
1222 \\[calendar-unmark] unmark dates
1223 \\[list-calendar-holidays] display notable days
1224
1225 The command M-x holidays causes the notable dates for the current month, and
1226 the preceding and succeeding months, to be displayed, independently of the
1227 calendar.
1228
1229 The following commands control the diary:
1230
1231 \\[mark-diary-entries] mark diary entries \\[calendar-unmark] unmark dates
1232 \\[view-diary-entries] display diary entries \\[show-all-diary-entries] show all diary entries
1233 \\[print-diary-entries] print diary entries
1234
1235 Displaying the diary entries causes the diary entries from the diary-file
1236 (for the date indicated by the cursor in the calendar window) to be
1237 displayed in another window. This function takes an integer argument that
1238 specifies the number of days of calendar entries to be displayed, starting
1239 with the date indicated by the cursor.
1240
1241 The command \\[print-diary-entries] prints the diary buffer (as it appears)
1242 on the line printer.
1243
1244 The command M-x diary causes the diary entries for the current date to be
1245 displayed, independently of the calendar. The number of days of entries is
1246 governed by number-of-diary-entries.
1247
1248 The format of the entries in the diary file is described in the
1249 documentation string for the variable diary-file.
1250
1251 When diary entries are in view in the window, they can be edited. It is
1252 important to keep in mind that the buffer displayed contains the entire
1253 diary file, but with portions of it concealed from view. This means, for
1254 instance, that the forward-char command can put the cursor at what appears
1255 to be the end of the line, but what is in reality the middle of some
1256 concealed line. BE CAREFUL WHEN EDITING THE DIARY ENTRIES! (Inserting
1257 additional lines or adding/deleting characters in the middle of a visible
1258 line will not cause problems; watch out for end-of-line, however--it may
1259 put you at the end of a concealed line far from where the cursor appears to
1260 be!) BEFORE EDITING THE DIARY IT IS BEST TO DISPLAY THE ENTIRE FILE WITH
1261 show-all-diary-entries. BE SURE TO WRITE THE FILE BEFORE EXITING FROM THE
1262 CALENDAR.
1263
1264 The following commands assist in making diary entries:
1265
1266 \\[insert-diary-entry] insert a diary entry for the selected date
1267 \\[insert-weekly-diary-entry] insert a diary entry for the selected day of the week
1268 \\[insert-monthly-diary-entry] insert a diary entry for the selected day of the month
1269 \\[insert-yearly-diary-entry] insert a diary entry for the selected day of the year
1270 \\[insert-block-diary-entry] insert a diary entry for the block days between point and mark
1271 \\[insert-anniversary-diary-entry] insert an anniversary diary entry for the selected date
1272 \\[insert-cyclic-diary-entry] insert a cyclic diary entry
1273
1274 There are corresponding commands to assist in making Hebrew- or Islamic-date
1275 diary entries:
1276
1277 \\[insert-hebrew-diary-entry] insert a diary entry for the Hebrew date corresponding
1278 to the selected date
1279 \\[insert-monthly-hebrew-diary-entry] insert a diary entry for the day of the Hebrew month
1280 corresponding to the selected day
1281 \\[insert-yearly-hebrew-diary-entry] insert a diary entry for the day of the Hebrew year
1282 corresponding to the selected day
1283 \\[insert-islamic-diary-entry] insert a diary entry for the Islamic date corresponding
1284 to the selected date
1285 \\[insert-monthly-islamic-diary-entry] insert a diary entry for the day of the Islamic month
1286 corresponding to the selected day
1287 \\[insert-yearly-islamic-diary-entry] insert a diary entry for the day of the Islamic year
1288 corresponding to the selected day
1289
1290 All of the diary entry commands make nonmarking entries when given a prefix
1291 argument; with no prefix argument, the diary entries are marking.
1292
1293 The day number in the year and the number of days remaining in the year can be
1294 determined by
1295
1296 \\[cursor-to-calendar-day-of-year] show day number and the number of days remaining in the year
1297
1298 Equivalent dates on the ISO commercial, Julian, Hebrew, Islamic and French
1299 Revolutionary calendars can be determined by
1300
1301 \\[cursor-to-iso-calendar-date] show equivalent date on the ISO commercial calendar
1302 \\[cursor-to-julian-calendar-date] show equivalent date on the Julian calendar
1303 \\[cursor-to-hebrew-calendar-date] show equivalent date on the Hebrew calendar
1304 \\[cursor-to-islamic-calendar-date] show equivalent date on the Islamic calendar
1305 \\[cursor-to-french-calendar-date] show equivalent date on the French Revolutionary calendar
1306
1307 To exit from the calendar use
1308
1309 \\[exit-calendar] exit from calendar
1310
1311 The variable `view-diary-entries-initially', whose default is nil, can be
1312 set to to t cause diary entries for the current date will be displayed in
1313 another window when the calendar is first displayed, if the current date is
1314 visible. The variable `number-of-diary-entries' controls number of days of
1315 diary entries that will be displayed initially or with the command M-x
1316 diary. For example, if the default value 1 is used, then only the current
1317 day's diary entries will be displayed. If the value 2 is used, both the
1318 current day's and the next day's entries will be displayed. The value can
1319 also be a vector: If the value is [0 2 2 2 2 4 1] then no diary entries
1320 will be displayed on Sunday, the current date's and the next day's diary
1321 entries will be displayed Monday through Thursday, Friday through Monday's
1322 entries will be displayed on Friday, while on Saturday only that day's
1323 entries will be displayed.
1324
1325 The variable `view-calendar-holidays-initially' can be set to t to cause
1326 the holidays for the current three month period will be displayed on entry
1327 to the calendar. The holidays are displayed in another window.
1328
1329 The variable `mark-diary-entries-in-calendar' can be set to t to cause any
1330 dates visible with calendar entries to be marked with the symbol specified
1331 by the variable `diary-entry-marker', normally a plus sign.
1332
1333 The variable `initial-calendar-window-hook', whose default value is nil,
1334 is list of functions to be called when the calendar window is first opened.
1335 The functions invoked are called after the calendar window is opened, but
1336 once opened is never called again. Leaving the calendar with the `q' command
1337 and reentering it will cause these functions to be called again.
1338
1339 The variable `today-visible-calendar-hook', whose default value is nil,
1340 is the list of functions called after the calendar buffer has been prepared
1341 with the calendar when the current date is visible in the window.
1342 This can be used, for example, to replace today's date with asterisks; a
1343 function calendar-star-date is included for this purpose:
1344 (setq today-visible-calendar-hook 'calendar-star-date)
1345 It could also be used to mark the current date with `*'; a function is also
1346 provided for this:
1347 (setq today-visible-calendar-hook 'calendar-mark-today)
1348
1349 The variable `today-invisible-calendar-hook', whose default value is nil,
1350 is the list of functions called after the calendar buffer has been prepared
1351 with the calendar when the current date is not visible in the window.
1352
1353 The variable `diary-display-hook' is the list of functions called
1354 after the diary buffer is prepared. The default value simply displays the
1355 diary file using selective-display to conceal irrelevant diary entries. An
1356 alternative function `fancy-diary-display' is provided that, when
1357 used as the `diary-display-hook', causes a noneditable buffer to be
1358 prepared with a neatly organized day-by-day listing of relevant diary
1359 entries, together with any known holidays. The inclusion of the holidays
1360 slows this fancy display of the diary; to speed it up, set the variable
1361 `holidays-in-diary-buffer' to nil.
1362
1363 The variable `print-diary-entries-hook' is the list of functions called
1364 after a temporary buffer is prepared with the diary entries currently
1365 visible in the diary buffer. The default value of this hook adds a heading
1366 (composed from the diary buffer's mode line), does the printing with the
1367 command lpr-buffer, and kills the temporary buffer. Other uses might
1368 include, for example, rearranging the lines into order by day and time.
1369
1370 The Gregorian calendar is assumed."
1371
1372 (kill-all-local-variables)
1373 (setq major-mode 'calendar-mode)
1374 (setq mode-name "Calendar")
1375 (use-local-map calendar-mode-map)
1376 (setq buffer-read-only t)
1377 (setq indent-tabs-mode nil)
1378 (make-local-variable 'calendar-window-configuration);; Windows on entry.
1379 (make-local-variable 'calendar-mark-ring)
1380 (make-local-variable 'current-month) ;; Current month.
1381 (make-local-variable 'current-day) ;; Current day.
1382 (make-local-variable 'current-year) ;; Current year.
1383 (make-local-variable 'displayed-month);; Month in middle of window.
1384 (make-local-variable 'displayed-year));; Year in middle of window.
1385
1386 (defun update-calendar-mode-line ()
1387 "Update the calendar mode line with the current date and date style."
1388 (if (bufferp (get-buffer calendar-buffer))
1389 (save-excursion
1390 (set-buffer calendar-buffer)
1391 (setq mode-line-format
1392 (format calendar-mode-line-format
1393 (calendar-date-string (calendar-current-date) t))))))
1394
1395 (defun exit-calendar ()
1396 "Get out of the calendar window and destroy it and related buffers."
1397 (interactive)
1398 (let ((diary-buffer (get-file-buffer diary-file))
1399 (d-buffer (get-buffer fancy-diary-buffer))
1400 (h-buffer (get-buffer holiday-buffer)))
1401 (if (not diary-buffer)
1402 (progn
1403 (set-window-configuration calendar-window-configuration)
1404 (kill-buffer calendar-buffer)
1405 (if d-buffer (kill-buffer d-buffer))
1406 (if h-buffer (kill-buffer h-buffer)))
1407 (if (or (not (buffer-modified-p diary-buffer))
1408 (yes-or-no-p "Diary modified; do you really want to exit the calendar? "))
1409 (progn
1410 (set-window-configuration calendar-window-configuration)
1411 (kill-buffer calendar-buffer)
1412 (if d-buffer (kill-buffer d-buffer))
1413 (if h-buffer (kill-buffer h-buffer))
1414 (set-buffer diary-buffer)
1415 (set-buffer-modified-p nil)
1416 (kill-buffer diary-buffer))))))
1417
1418 (defun calendar-current-month ()
1419 "Reposition the calendar window so the current date is visible."
1420 (interactive)
1421 (let ((today (calendar-current-date)));; The date might have changed.
1422 (if (not (calendar-date-is-visible-p today))
1423 (regenerate-calendar-window)
1424 (update-calendar-mode-line)
1425 (calendar-cursor-to-visible-date today))))
1426
1427 (defun calendar-forward-month (arg)
1428 "Move the cursor forward ARG months.
1429 Movement is backward if ARG is negative."
1430 (interactive "p")
1431 (calendar-cursor-to-nearest-date)
1432 (let* ((cursor-date (or (calendar-cursor-to-date)
1433 (error "Cursor is not on a date!")))
1434 (month (extract-calendar-month cursor-date))
1435 (day (extract-calendar-day cursor-date))
1436 (year (extract-calendar-year cursor-date)))
1437 (increment-calendar-month month year arg)
1438 (let ((last (calendar-last-day-of-month month year)))
1439 (if (< last day)
1440 (setq day last)))
1441 ;; Put the new month on the screen, if needed, and go to the new date.
1442 (let ((new-cursor-date (list month day year)))
1443 (if (not (calendar-date-is-visible-p new-cursor-date))
1444 (calendar-other-month month year))
1445 (calendar-cursor-to-visible-date new-cursor-date))))
1446
1447 (defun calendar-forward-year (arg)
1448 "Move the cursor forward by ARG years.
1449 Movement is backward if ARG is negative."
1450 (interactive "p")
1451 (calendar-forward-month (* 12 arg)))
1452
1453 (defun calendar-backward-month (arg)
1454 "Move the cursor backward by ARG months.
1455 Movement is forward if ARG is negative."
1456 (interactive "p")
1457 (calendar-forward-month (- arg)))
1458
1459 (defun calendar-backward-year (arg)
1460 "Move the cursor backward ARG years.
1461 Movement is forward is ARG is negative."
1462 (interactive "p")
1463 (calendar-forward-month (* -12 arg)))
1464
1465 (defun scroll-calendar-left (arg)
1466 "Scroll the displayed calendar left by ARG months.
1467 If ARG is negative the calendar is scrolled right. Maintains the relative
1468 position of the cursor with respect to the calendar as well as possible."
1469 (interactive "p")
1470 (calendar-cursor-to-nearest-date)
1471 (let ((old-date (calendar-cursor-to-date))
1472 (today (calendar-current-date)))
1473 (if (/= arg 0)
1474 (progn
1475 (regenerate-calendar-window
1476 (+ arg (calendar-interval current-month current-year
1477 displayed-month displayed-year)))
1478 (calendar-cursor-to-visible-date
1479 (cond
1480 ((calendar-date-is-visible-p old-date) old-date)
1481 ((calendar-date-is-visible-p today) today)
1482 (t (list displayed-month 1 displayed-year))))))))
1483
1484 (defun scroll-calendar-right (arg)
1485 "Scroll the displayed calendar window right by ARG months.
1486 If ARG is negative the calendar is scrolled left. Maintains the relative
1487 position of the cursor with respect to the calendar as well as possible."
1488 (interactive "p")
1489 (scroll-calendar-left (- arg)))
1490
1491 (defun scroll-calendar-left-three-months (arg)
1492 "Scroll the displayed calendar window left by 3*ARG months.
1493 If ARG is negative the calendar is scrolled right. Maintains the relative
1494 position of the cursor with respect to the calendar as well as possible."
1495 (interactive "p")
1496 (scroll-calendar-left (* 3 arg)))
1497
1498 (defun scroll-calendar-right-three-months (arg)
1499 "Scroll the displayed calendar window right by 3*ARG months.
1500 If ARG is negative the calendar is scrolled left. Maintains the relative
1501 position of the cursor with respect to the calendar as well as possible."
1502 (interactive "p")
1503 (scroll-calendar-left (* -3 arg)))
1504
1505 (defun calendar-current-date ()
1506 "Returns the current date in a list (month day year).
1507 If in the calendar buffer, also sets the current date local variables."
1508 (let* ((date (current-time-string))
1509 (garbage
1510 (string-match
1511 "^\\([A-Z][a-z]*\\) *\\([A-Z][a-z]*\\) *\\([0-9]*\\) .* \\([0-9]*\\)$"
1512 date))
1513 (month
1514 (cdr (assoc
1515 (substring date (match-beginning 2) (match-end 2))
1516 (calendar-make-alist
1517 calendar-month-name-array
1518 1
1519 '(lambda (x) (substring x 0 3))))))
1520 (day
1521 (string-to-int (substring date (match-beginning 3) (match-end 3))))
1522 (year
1523 (string-to-int (substring date (match-beginning 4) (match-end 4)))))
1524 (if (equal (current-buffer) (get-buffer calendar-buffer))
1525 (progn
1526 (setq current-month month)
1527 (setq current-day day)
1528 (setq current-year year)))
1529 (list month day year)))
1530
1531 (defun calendar-cursor-to-date ()
1532 "Returns a list of the month, day, and year of current cursor position.
1533 Returns nil if the cursor is not on a specific day."
1534 (if (and (looking-at "[*0-9]")
1535 (< 2 (count-lines (point-min) (point))))
1536 (save-excursion
1537 (re-search-backward "[^0-9]")
1538 (forward-char 1)
1539 (let*
1540 ((day (string-to-int (buffer-substring (point) (+ 3 (point)))))
1541 (day (if (= 0 day) current-day day));; Starred date.
1542 (segment (/ (current-column) 25))
1543 (month (% (+ displayed-month segment -1) 12))
1544 (month (if (= 0 month) 12 month))
1545 (year
1546 (cond
1547 ((and (= 12 month) (= segment 0)) (1- displayed-year))
1548 ((and (= 1 month) (= segment 2)) (1+ displayed-year))
1549 (t displayed-year))))
1550 (list month day year)))))
1551
1552 (defun calendar-cursor-to-nearest-date ()
1553 "Move the cursor to the closest date.
1554 The position of the cursor is unchanged if it is already on a date.
1555 Returns the list (month day year) giving the cursor position."
1556 (let ((date (calendar-cursor-to-date))
1557 (column (current-column)))
1558 (if date
1559 date
1560 (if (> 3 (count-lines (point-min) (point)))
1561 (progn
1562 (goto-line 3)
1563 (move-to-column column)))
1564 (if (not (looking-at "[0-9]"))
1565 (if (and (not (looking-at " *$"))
1566 (or (< column 25)
1567 (and (> column 27)
1568 (< column 50))
1569 (and (> column 52)
1570 (< column 75))))
1571 (progn
1572 (re-search-forward "[0-9]" nil t)
1573 (backward-char 1))
1574 (re-search-backward "[0-9]" nil t)))
1575 (calendar-cursor-to-date))))
1576
1577 (defun calendar-forward-day (arg)
1578 "Move the cursor forward ARG days.
1579 Moves backward if ARG is negative."
1580 (interactive "p")
1581 (if (/= 0 arg)
1582 (let*
1583 ((cursor-date (calendar-cursor-to-date))
1584 (cursor-date (if cursor-date
1585 cursor-date
1586 (if (> arg 0) (setq arg (1- arg)))
1587 (calendar-cursor-to-nearest-date)))
1588 (new-cursor-date
1589 (calendar-gregorian-from-absolute
1590 (+ (calendar-absolute-from-gregorian cursor-date) arg)))
1591 (new-display-month (extract-calendar-month new-cursor-date))
1592 (new-display-year (extract-calendar-year new-cursor-date)))
1593 ;; Put the new month on the screen, if needed, and go to the new date.
1594 (if (not (calendar-date-is-visible-p new-cursor-date))
1595 (calendar-other-month new-display-month new-display-year))
1596 (calendar-cursor-to-visible-date new-cursor-date))))
1597
1598 (defun calendar-backward-day (arg)
1599 "Move the cursor back ARG days.
1600 Moves forward if ARG is negative."
1601 (interactive "p")
1602 (calendar-forward-day (- arg)))
1603
1604 (defun calendar-forward-week (arg)
1605 "Move the cursor forward ARG weeks.
1606 Moves backward if ARG is negative."
1607 (interactive "p")
1608 (calendar-forward-day (* arg 7)))
1609
1610 (defun calendar-backward-week (arg)
1611 "Move the cursor back ARG weeks.
1612 Moves forward if ARG is negative."
1613 (interactive "p")
1614 (calendar-forward-day (* arg -7)))
1615
1616 (defun calendar-beginning-of-week (arg)
1617 "Move the cursor back ARG Sundays."
1618 (interactive "p")
1619 (calendar-cursor-to-nearest-date)
1620 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
1621 (calendar-backward-day
1622 (if (= day 0) (* 7 arg) (+ day (* 7 (1- arg)))))))
1623
1624 (defun calendar-end-of-week (arg)
1625 "Move the cursor forward ARG Saturdays."
1626 (interactive "p")
1627 (calendar-cursor-to-nearest-date)
1628 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
1629 (calendar-forward-day
1630 (if (= day 6) (* 7 arg) (+ (- 6 day) (* 7 (1- arg)))))))
1631
1632 (defun calendar-beginning-of-month (arg)
1633 "Move the cursor backward ARG month beginnings."
1634 (interactive "p")
1635 (calendar-cursor-to-nearest-date)
1636 (let* ((date (calendar-cursor-to-date))
1637 (month (extract-calendar-month date))
1638 (day (extract-calendar-day date))
1639 (year (extract-calendar-year date)))
1640 (if (= day 1)
1641 (calendar-backward-month arg)
1642 (calendar-cursor-to-visible-date (list month 1 year))
1643 (calendar-backward-month (1- arg)))))
1644
1645 (defun calendar-end-of-month (arg)
1646 "Move the cursor forward ARG month ends."
1647 (interactive "p")
1648 (calendar-cursor-to-nearest-date)
1649 (let* ((date (calendar-cursor-to-date))
1650 (month (extract-calendar-month date))
1651 (day (extract-calendar-day date))
1652 (year (extract-calendar-year date))
1653 (last-day (calendar-last-day-of-month month year)))
1654 (if (/= day last-day)
1655 (progn
1656 (calendar-cursor-to-visible-date (list month last-day year))
1657 (setq arg (1- arg))))
1658 (increment-calendar-month month year arg)
1659 (let ((last-day (list
1660 month
1661 (calendar-last-day-of-month month year)
1662 year)))
1663 (if (not (calendar-date-is-visible-p last-day))
1664 (calendar-other-month month year)
1665 (calendar-cursor-to-visible-date last-day)))))
1666
1667 (defun calendar-beginning-of-year (arg)
1668 "Move the cursor backward ARG year beginnings."
1669 (interactive "p")
1670 (calendar-cursor-to-nearest-date)
1671 (let* ((date (calendar-cursor-to-date))
1672 (month (extract-calendar-month date))
1673 (day (extract-calendar-day date))
1674 (year (extract-calendar-year date))
1675 (jan-first (list 1 1 year)))
1676 (if (and (= day 1) (= 1 month))
1677 (calendar-backward-month (* 12 arg))
1678 (if (and (= arg 1)
1679 (calendar-date-is-visible-p jan-first))
1680 (calendar-cursor-to-visible-date jan-first)
1681 (calendar-other-month 1 (- year (1- arg)))))))
1682
1683 (defun calendar-end-of-year (arg)
1684 "Move the cursor forward ARG year beginnings."
1685 (interactive "p")
1686 (calendar-cursor-to-nearest-date)
1687 (let* ((date (calendar-cursor-to-date))
1688 (month (extract-calendar-month date))
1689 (day (extract-calendar-day date))
1690 (year (extract-calendar-year date))
1691 (dec-31 (list 12 31 year)))
1692 (if (and (= day 31) (= 12 month))
1693 (calendar-forward-month (* 12 arg))
1694 (if (and (= arg 1)
1695 (calendar-date-is-visible-p dec-31))
1696 (calendar-cursor-to-visible-date dec-31)
1697 (calendar-other-month 12 (- year (1- arg)))
1698 (calendar-cursor-to-visible-date (list 12 31 displayed-year))))))
1699
1700 (defun calendar-gregorian-from-absolute (date)
1701 "Compute the list (month day year) corresponding to the absolute DATE.
1702 The absolute date is the number of days elapsed since the (imaginary)
1703 Gregorian date Sunday, December 31, 1 BC."
1704 (let* ((approx (/ date 366));; Approximation from below.
1705 (year ;; Search forward from the approximation.
1706 (+ approx
1707 (calendar-sum y approx
1708 (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y))))
1709 1)))
1710 (month ;; Search forward from January.
1711 (1+ (calendar-sum m 1
1712 (> date
1713 (calendar-absolute-from-gregorian
1714 (list m (calendar-last-day-of-month m year) year)))
1715 1)))
1716 (day ;; Calculate the day by subtraction.
1717 (- date
1718 (1- (calendar-absolute-from-gregorian (list month 1 year))))))
1719 (list month day year)))
1720
1721 (defun calendar-cursor-to-visible-date (date)
1722 "Move the cursor to DATE that is on the screen."
1723 (let ((month (extract-calendar-month date))
1724 (day (extract-calendar-day date))
1725 (year (extract-calendar-year date)))
1726 (goto-line (+ 3
1727 (/ (+ day -1
1728 (calendar-day-of-week (list month 1 year)))
1729 7)))
1730 (move-to-column (+ 6
1731 (* 25
1732 (1+ (calendar-interval
1733 displayed-month displayed-year month year)))
1734 (* 3 (calendar-day-of-week date))))))
1735
1736 (defun calendar-other-month (month year)
1737 "Display a three-month calendar centered around MONTH and YEAR."
1738 (interactive
1739 (let* ((completion-ignore-case t)
1740 (month (cdr (assoc
1741 (capitalize
1742 (completing-read
1743 "Month name: "
1744 (mapcar 'list (append calendar-month-name-array nil))
1745 nil t))
1746 (calendar-make-alist calendar-month-name-array))))
1747 (year (calendar-read
1748 "Year (>0): "
1749 '(lambda (x) (> x 0))
1750 (int-to-string current-year))))
1751 (list month year)))
1752 (if (and (= month displayed-month)
1753 (= year displayed-year))
1754 nil
1755 (let ((old-date (calendar-cursor-to-date))
1756 (today (calendar-current-date)))
1757 (regenerate-calendar-window
1758 (calendar-interval current-month current-year month year))
1759 (calendar-cursor-to-visible-date
1760 (cond
1761 ((calendar-date-is-visible-p old-date) old-date)
1762 ((calendar-date-is-visible-p today) today)
1763 (t (list month 1 year)))))))
1764
1765 (defun calendar-set-mark (arg)
1766 "Mark the date under the cursor, or jump to marked date.
1767 With no prefix argument, push current date onto marked date ring.
1768 With argument, jump to mark, pop it, and put point at end of ring."
1769 (interactive "P")
1770 (let ((date (or (calendar-cursor-to-date)
1771 (error "Cursor is not on a date!"))))
1772 (if (null arg)
1773 (progn
1774 (setq calendar-mark-ring (cons date calendar-mark-ring))
1775 ;; Since the top of the mark ring is the marked date in the
1776 ;; calendar, the mark ring in the calendar is one longer than
1777 ;; in other buffers to get the same effect.
1778 (if (> (length calendar-mark-ring) (1+ mark-ring-max))
1779 (setcdr (nthcdr mark-ring-max calendar-mark-ring) nil))
1780 (message "Mark set"))
1781 (if (null calendar-mark-ring)
1782 (error "No mark set in this buffer")
1783 (calendar-goto-date (car calendar-mark-ring))
1784 (setq calendar-mark-ring
1785 (cdr (nconc calendar-mark-ring (list date))))))))
1786
1787 (defun calendar-exchange-point-and-mark ()
1788 "Exchange the current cursor position with the marked date."
1789 (interactive)
1790 (let ((mark (car calendar-mark-ring))
1791 (date (or (calendar-cursor-to-date)
1792 (error "Cursor is not on a date!"))))
1793 (if (null mark)
1794 (error "No mark set in this buffer")
1795 (setq calendar-mark-ring (cons date (cdr calendar-mark-ring)))
1796 (calendar-goto-date mark))))
1797
1798 (defun calendar-count-days-region ()
1799 "Count the number of days (inclusive) between point and the mark."
1800 (interactive)
1801 (let* ((days (- (calendar-absolute-from-gregorian
1802 (or (calendar-cursor-to-date)
1803 (error "Cursor is not on a date!")))
1804 (calendar-absolute-from-gregorian
1805 (or (car calendar-mark-ring)
1806 (error "No mark set in this buffer")))))
1807 (days (1+ (if (> days 0) days (- days)))))
1808 (message "Region has %d day%s (inclusive)"
1809 days (if (> days 1) "s" ""))))
1810
1811 (defun calendar-not-implemented ()
1812 "Not implemented."
1813 (interactive)
1814 (error "%s not available in the calendar"
1815 (global-key-binding (this-command-keys))))
1816
1817 (defun calendar-read (prompt acceptable &optional initial-contents)
1818 "Return an object read from the minibuffer.
1819 Prompt with the string PROMPT and use the function ACCEPTABLE to decide if
1820 entered item is acceptable. If non-nil, optional third arg INITIAL-CONTENTS
1821 is a string to insert in the minibuffer before reading."
1822 (let ((value (read-minibuffer prompt initial-contents)))
1823 (while (not (funcall acceptable value))
1824 (setq value (read-minibuffer prompt initial-contents)))
1825 value))
1826
1827 (defun calendar-goto-date (date)
1828 "Move cursor to DATE."
1829 (interactive
1830 (let* ((year (calendar-read
1831 "Year (>0): "
1832 '(lambda (x) (> x 0))
1833 (int-to-string current-year)))
1834 (month-array calendar-month-name-array)
1835 (completion-ignore-case t)
1836 (month (cdr (assoc
1837 (capitalize
1838 (completing-read
1839 "Month name: "
1840 (mapcar 'list (append month-array nil))
1841 nil t))
1842 (calendar-make-alist month-array 1 'capitalize))))
1843 (last (calendar-last-day-of-month month year))
1844 (day (calendar-read
1845 (format "Day (1-%d): " last)
1846 '(lambda (x) (and (< 0 x) (<= x last))))))
1847 (list (list month day year))))
1848 (let ((month (extract-calendar-month date))
1849 (year (extract-calendar-year date)))
1850 (if (not (calendar-date-is-visible-p date))
1851 (calendar-other-month
1852 (if (and (= month 1) (= year 1))
1853 2
1854 month)
1855 year)))
1856 (calendar-cursor-to-visible-date date))
1857
1858 (defun calendar-goto-julian-date (date &optional noecho)
1859 "Move cursor to Julian DATE; echo Julian date unless NOECHO is t."
1860 (interactive
1861 (let* ((year (calendar-read
1862 "Julian calendar year (>0): "
1863 '(lambda (x) (> x 0))
1864 (int-to-string
1865 (extract-calendar-year
1866 (calendar-julian-from-absolute
1867 (calendar-absolute-from-gregorian
1868 (list current-month 1 current-year)))))))
1869 (month-array calendar-month-name-array)
1870 (completion-ignore-case t)
1871 (month (cdr (assoc
1872 (capitalize
1873 (completing-read
1874 "Julian calendar month name: "
1875 (mapcar 'list (append month-array nil))
1876 nil t))
1877 (calendar-make-alist month-array 1 'capitalize))))
1878 (last
1879 (if (and (zerop (% year 4)) (= month 2))
1880 29
1881 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
1882 (day (calendar-read
1883 (format "Julian calendar day (%d-%d): "
1884 (if (and (= year 1) (= month 1)) 3 1) last)
1885 '(lambda (x)
1886 (and (< (if (and (= year 1) (= month 1)) 2 0) x)
1887 (<= x last))))))
1888 (list (list month day year))))
1889 (calendar-goto-date (calendar-gregorian-from-absolute
1890 (calendar-absolute-from-julian date)))
1891 (or noecho (cursor-to-julian-calendar-date)))
1892
1893 (defun calendar-goto-hebrew-date (date &optional noecho)
1894 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is t."
1895 (interactive
1896 (let* ((year (calendar-read
1897 "Hebrew calendar year (>3760): "
1898 '(lambda (x) (> x 3760))
1899 (int-to-string
1900 (extract-calendar-year
1901 (calendar-hebrew-from-absolute
1902 (calendar-absolute-from-gregorian
1903 (list current-month 1 current-year)))))))
1904 (month-array (if (hebrew-calendar-leap-year-p year)
1905 calendar-hebrew-month-name-array-leap-year
1906 calendar-hebrew-month-name-array-common-year))
1907 (completion-ignore-case t)
1908 (month (cdr (assoc
1909 (capitalize
1910 (completing-read
1911 "Hebrew calendar month name: "
1912 (mapcar 'list (append month-array nil))
1913 (if (= year 3761)
1914 '(lambda (x)
1915 (let ((m (cdr
1916 (assoc
1917 (car x)
1918 (calendar-make-alist
1919 month-array)))))
1920 (< 0
1921 (calendar-absolute-from-hebrew
1922 (list m
1923 (hebrew-calendar-last-day-of-month
1924 m year)
1925 year))))))
1926
1927 t))
1928 (calendar-make-alist month-array 1 'capitalize))))
1929 (last (hebrew-calendar-last-day-of-month month year))
1930 (first (if (and (= year 3761) (= month 10))
1931 18 1))
1932 (day (calendar-read
1933 (format "Hebrew calendar day (%d-%d): "
1934 first last)
1935 '(lambda (x) (and (<= first x) (<= x last))))))
1936 (list (list month day year))))
1937 (calendar-goto-date (calendar-gregorian-from-absolute
1938 (calendar-absolute-from-hebrew date)))
1939 (or noecho (cursor-to-hebrew-calendar-date)))
1940
1941 (defun calendar-goto-islamic-date (date &optional noecho)
1942 "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is t."
1943 (interactive
1944 (let* ((year (calendar-read
1945 "Islamic calendar year (>0): "
1946 '(lambda (x) (> x 0))
1947 (int-to-string
1948 (extract-calendar-year
1949 (calendar-islamic-from-absolute
1950 (calendar-absolute-from-gregorian
1951 (list current-month 1 current-year)))))))
1952 (month-array calendar-islamic-month-name-array)
1953 (completion-ignore-case t)
1954 (month (cdr (assoc
1955 (capitalize
1956 (completing-read
1957 "Islamic calendar month name: "
1958 (mapcar 'list (append month-array nil))
1959 nil t))
1960 (calendar-make-alist month-array 1 'capitalize))))
1961 (last (islamic-calendar-last-day-of-month month year))
1962 (day (calendar-read
1963 (format "Islamic calendar day (1-%d): " last)
1964 '(lambda (x) (and (< 0 x) (<= x last))))))
1965 (list (list month day year))))
1966 (calendar-goto-date (calendar-gregorian-from-absolute
1967 (calendar-absolute-from-islamic date)))
1968 (or noecho (cursor-to-islamic-calendar-date)))
1969
1970 (defun calendar-goto-iso-date (date &optional noecho)
1971 "Move cursor to ISO DATE; echo ISO date unless NOECHO is t."
1972 (interactive
1973 (let* ((year (calendar-read
1974 "ISO calendar year (>0): "
1975 '(lambda (x) (> x 0))
1976 (int-to-string current-year)))
1977 (no-weeks (extract-calendar-month
1978 (calendar-iso-from-absolute
1979 (1-
1980 (calendar-dayname-on-or-before
1981 1 (calendar-absolute-from-gregorian
1982 (list 1 4 (1+ year))))))))
1983 (week (calendar-read
1984 (format "ISO calendar week (1-%d): " no-weeks)
1985 '(lambda (x) (and (> x 0) (<= x no-weeks)))))
1986 (day (calendar-read
1987 "ISO day (1-7): "
1988 '(lambda (x) (and (<= 1 x) (<= x 7))))))
1989 (list (list week day year))))
1990 (calendar-goto-date (calendar-gregorian-from-absolute
1991 (calendar-absolute-from-iso date)))
1992 (or noecho (cursor-to-iso-calendar-date)))
1993
1994 (defun calendar-interval (mon1 yr1 mon2 yr2)
1995 "The number of months difference between the two specified months."
1996 (+ (* 12 (- yr2 yr1))
1997 (- mon2 mon1)))
1998
1999 (defun calendar-day-name (date)
2000 "Returns a string with the name of the day of the week of DATE."
2001 (aref calendar-day-name-array (calendar-day-of-week date)))
2002
2003 (defconst calendar-day-name-array
2004 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
2005
2006 (defconst calendar-month-name-array
2007 ["January" "February" "March" "April" "May" "June"
2008 "July" "August" "September" "October" "November" "December"])
2009
2010 (defun calendar-make-alist (sequence &optional start-index filter)
2011 "Make an assoc list corresponding to SEQUENCE.
2012 Start at index 1, unless optional START-INDEX is provided.
2013 If FILTER is provided, apply it to each item in the list."
2014 (let ((index (if start-index (1- start-index) 0)))
2015 (mapcar
2016 '(lambda (x)
2017 (setq index (1+ index))
2018 (cons (if filter (funcall filter x) x)
2019 index))
2020 (append sequence nil))))
2021
2022 (defun calendar-month-name (month)
2023 "The name of MONTH."
2024 (aref calendar-month-name-array (1- month)))
2025
2026 (defun calendar-day-of-week (date)
2027 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
2028 (% (calendar-absolute-from-gregorian date) 7))
2029
2030 (defun calendar-unmark ()
2031 "Delete the diary and holiday marks from the calendar."
2032 (interactive)
2033 (setq mark-diary-entries-in-calendar nil)
2034 (setq mark-holidays-in-calendar nil)
2035 (save-excursion
2036 (goto-line 3)
2037 (beginning-of-line)
2038 (let ((buffer-read-only nil)
2039 (start (point))
2040 (star-date (search-forward "**" nil t))
2041 (star-point (point)))
2042 (if star-date
2043 (progn ;; Don't delete today as left by calendar-star-date
2044 (subst-char-in-region start (- star-point 2)
2045 (string-to-char diary-entry-marker) ? t)
2046 (subst-char-in-region start (- star-point 2)
2047 (string-to-char calendar-holiday-marker) ? t)
2048 (subst-char-in-region star-point (point-max)
2049 (string-to-char diary-entry-marker) ? t)
2050 (subst-char-in-region star-point (point-max)
2051 (string-to-char calendar-holiday-marker) ? t))
2052 (subst-char-in-region start (point-max)
2053 (string-to-char diary-entry-marker) ? t)
2054 (subst-char-in-region start (point-max)
2055 (string-to-char calendar-holiday-marker) ? t))
2056 (set-buffer-modified-p nil))))
2057
2058 (defun calendar-date-is-visible-p (date)
2059 "Returns t if DATE is legal and is visible in the calendar window."
2060 (let ((gap (calendar-interval
2061 displayed-month displayed-year
2062 (extract-calendar-month date) (extract-calendar-year date))))
2063 (and (calendar-date-is-legal-p date) (> 2 gap) (< -2 gap))))
2064
2065 (defun calendar-date-is-legal-p (date)
2066 "Returns t if DATE is a legal date."
2067 (let ((month (extract-calendar-month date))
2068 (day (extract-calendar-day date))
2069 (year (extract-calendar-year date)))
2070 (and (<= 1 month) (<= month 12)
2071 (<= 1 day) (<= day (calendar-last-day-of-month month year))
2072 (<= 1 year))))
2073
2074 (defun calendar-date-equal (date1 date2)
2075 "Returns t if the DATE1 and DATE2 are the same."
2076 (and
2077 (= (extract-calendar-month date1) (extract-calendar-month date2))
2078 (= (extract-calendar-day date1) (extract-calendar-day date2))
2079 (= (extract-calendar-year date1) (extract-calendar-year date2))))
2080
2081 (defun mark-visible-calendar-date (date &optional mark)
2082 "Leave mark DATE with MARK. MARK defaults to diary-entry-marker."
2083 (if (calendar-date-is-legal-p date)
2084 (save-excursion
2085 (set-buffer calendar-buffer)
2086 (calendar-cursor-to-visible-date date)
2087 (forward-char 1)
2088 (let ((buffer-read-only nil))
2089 (delete-char 1)
2090 (insert (if mark mark diary-entry-marker))
2091 (forward-char -2))
2092 (set-buffer-modified-p nil))))
2093
2094 (defun calendar-star-date ()
2095 "Replace the date under the cursor in the calendar window with asterisks.
2096 This function can be used with the today-visible-calendar-hook run after the
2097 calendar window has been prepared."
2098 (let ((buffer-read-only nil))
2099 (forward-char 1)
2100 (delete-char -2)
2101 (insert "**")
2102 (backward-char 1)
2103 (set-buffer-modified-p nil)))
2104
2105 (defun calendar-mark-today ()
2106 "Mark the date under the cursor in the calendar window with an equal sign.
2107 This function can be used with the today-visible-calendar-hook run after the
2108 calendar window has been prepared."
2109 (let ((buffer-read-only nil))
2110 (forward-char 1)
2111 (delete-char 1)
2112 (insert "=")
2113 (backward-char 2)
2114 (set-buffer-modified-p nil)))
2115
2116 (defun calendar-date-compare (date1 date2)
2117 "Returns t if DATE1 is before DATE2, nil otherwise.
2118 The actual dates are in the car of DATE1 and DATE2."
2119 (< (calendar-absolute-from-gregorian (car date1))
2120 (calendar-absolute-from-gregorian (car date2))))
2121
2122 (defun calendar-date-string (date &optional abbreviate nodayname)
2123 "A string form of DATE, driven by the variable `calendar-date-display-form'.
2124 An optional parameter ABBREVIATE, when t, causes the month and day names to be
2125 abbreviated to three characters. An optional parameter NODAYNAME, when t,
2126 omits the name of the day of the week."
2127 (let* ((dayname
2128 (if nodayname
2129 ""
2130 (if abbreviate
2131 (substring (calendar-day-name date) 0 3)
2132 (calendar-day-name date))))
2133 (month (extract-calendar-month date))
2134 (monthname
2135 (if abbreviate
2136 (substring
2137 (calendar-month-name month) 0 3)
2138 (calendar-month-name month)))
2139 (day (int-to-string (extract-calendar-day date)))
2140 (month (int-to-string month))
2141 (year (int-to-string (extract-calendar-year date))))
2142 (mapconcat 'eval calendar-date-display-form "")))
2143
2144 (defun calendar-dayname-on-or-before (dayname date)
2145 "Returns the absolute date of the DAYNAME on or before absolute DATE.
2146 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
2147
2148 Note: Applying this function to d+6 gives us the DAYNAME on or after an
2149 absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
2150 absolute date d, applying it to d-1 gives the DAYNAME previous to absolute
2151 date d, and applying it to d+7 gives the DAYNAME following absolute date d."
2152 (- date (% (- date dayname) 7)))
2153
2154 (defun calendar-nth-named-day (n dayname month year)
2155 "Returns the date of the Nth DAYNAME in MONTH, YEAR.
2156 A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0, the
2157 date returned is the Nth DAYNAME from the end of MONTH, YEAR (that is, -1 is
2158 the last DAYNAME, -2 is the penultimate DAYNAME, and so on."
2159 (calendar-gregorian-from-absolute
2160 (if (> n 0)
2161 (+ (calendar-dayname-on-or-before
2162 dayname (calendar-absolute-from-gregorian (list month 7 year)))
2163 (* 7 (1- n)))
2164 (+ (calendar-dayname-on-or-before
2165 dayname
2166 (calendar-absolute-from-gregorian
2167 (list month (calendar-last-day-of-month month year) year)))
2168 (* 7 (1+ n))))))
2169
2170 (defun cursor-to-calendar-day-of-year ()
2171 "Show the day number in the year and the number of days remaining in the
2172 year for the date under the cursor."
2173 (interactive)
2174 (let* ((date (or (calendar-cursor-to-date)
2175 (error "Cursor is not on a date!")))
2176 (year (extract-calendar-year date))
2177 (day (calendar-day-number date))
2178 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
2179 (message "Day %d of %d; %d day%s remaining in the year"
2180 day year days-remaining (if (= days-remaining 1) "" "s"))))
2181
2182 (defun calendar-absolute-from-iso (date)
2183 "The number of days elapsed between the Gregorian date 12/31/1 BC and
2184 DATE. The `ISO year' corresponds approximately to the Gregorian year, but
2185 weeks start on Monday and end on Sunday. The first week of the ISO year is
2186 the first such week in which at least 4 days are in a year. The ISO
2187 commercial DATE has the form (week day year) in which week is in the range
2188 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 =
2189 Sunday). The The Gregorian date Sunday, December 31, 1 BC is imaginary."
2190 (let* ((week (extract-calendar-month date))
2191 (day (extract-calendar-day date))
2192 (year (extract-calendar-year date)))
2193 (+ (calendar-dayname-on-or-before
2194 1 (+ 3 (calendar-absolute-from-gregorian (list 1 1 year))))
2195 (* 7 (1- week))
2196 (if (= day 0) 6 (1- day)))))
2197
2198 (defun calendar-iso-from-absolute (date)
2199 "Compute the `ISO commercial date' corresponding to the absolute DATE.
2200 The ISO year corresponds approximately to the Gregorian year, but weeks
2201 start on Monday and end on Sunday. The first week of the ISO year is the
2202 first such week in which at least 4 days are in a year. The ISO commercial
2203 date has the form (week day year) in which week is in the range 1..52 and
2204 day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = Sunday). The
2205 absolute date is the number of days elapsed since the (imaginary) Gregorian
2206 date Sunday, December 31, 1 BC."
2207 (let* ((approx (extract-calendar-year
2208 (calendar-gregorian-from-absolute (- date 3))))
2209 (year (+ approx
2210 (calendar-sum y approx
2211 (>= date (calendar-absolute-from-iso (list 1 1 (1+ y))))
2212 1))))
2213 (list
2214 (1+ (/ (- date (calendar-absolute-from-iso (list 1 1 year))) 7))
2215 (% date 7)
2216 year)))
2217
2218 (defun cursor-to-iso-calendar-date ()
2219 "Show the equivalent date on the `ISO commercial calendar' for the date
2220 under the cursor."
2221 (interactive)
2222 (let* ((greg-date
2223 (or (calendar-cursor-to-date)
2224 (error "Cursor is not on a date!")))
2225 (day (% (calendar-absolute-from-gregorian greg-date) 7))
2226 (iso-date (calendar-iso-from-absolute
2227 (calendar-absolute-from-gregorian greg-date))))
2228 (message "ISO date: Day %s of week %d of %d."
2229 (if (zerop day) 7 day)
2230 (extract-calendar-month iso-date)
2231 (extract-calendar-year iso-date))))
2232
2233 (defun calendar-julian-from-absolute (date)
2234 "Compute the Julian (month day year) corresponding to the absolute DATE.
2235 The absolute date is the number of days elapsed since the (imaginary)
2236 Gregorian date Sunday, December 31, 1 BC."
2237 (let* ((approx (/ (+ date 2) 366));; Approximation from below.
2238 (year ;; Search forward from the approximation.
2239 (+ approx
2240 (calendar-sum y approx
2241 (>= date (calendar-absolute-from-julian (list 1 1 (1+ y))))
2242 1)))
2243 (month ;; Search forward from January.
2244 (1+ (calendar-sum m 1
2245 (> date
2246 (calendar-absolute-from-julian
2247 (list m
2248 (if (and (= m 2) (= (% year 4) 0))
2249 29
2250 (aref [31 28 31 30 31 30 31 31 30 31 30 31]
2251 (1- m)))
2252 year)))
2253 1)))
2254 (day ;; Calculate the day by subtraction.
2255 (- date (1- (calendar-absolute-from-julian (list month 1 year))))))
2256 (list month day year)))
2257
2258 (defun calendar-absolute-from-julian (date)
2259 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
2260 The Gregorian date Sunday, December 31, 1 BC is imaginary."
2261 (let ((month (extract-calendar-month date))
2262 (day (extract-calendar-day date))
2263 (year (extract-calendar-year date)))
2264 (+ (calendar-day-number date)
2265 (if (and (= (% year 100) 0)
2266 (/= (% year 400) 0)
2267 (> month 2))
2268 1 0);; Correct for Julian but not Gregorian leap year.
2269 (* 365 (1- year))
2270 (/ (1- year) 4)
2271 -2)))
2272
2273 (defun cursor-to-julian-calendar-date ()
2274 "Show the Julian calendar equivalent of the date under the cursor."
2275 (interactive)
2276 (let ((calendar-date-display-form
2277 (if european-calendar-style
2278 '(day " " monthname " " year)
2279 '(monthname " " day ", " year))))
2280 (message "Julian date: %s"
2281 (calendar-date-string
2282 (calendar-julian-from-absolute
2283 (calendar-absolute-from-gregorian
2284 (or (calendar-cursor-to-date)
2285 (error "Cursor is not on a date!"))))))))
2286
2287 (defun islamic-calendar-leap-year-p (year)
2288 "Returns t if YEAR is a leap year on the Islamic calendar."
2289 (memq (% year 30)
2290 (list 2 5 7 10 13 16 18 21 24 26 29)))
2291
2292 (defun islamic-calendar-last-day-of-month (month year)
2293 "The last day in MONTH during YEAR on the Islamic calendar."
2294 (cond
2295 ((memq month (list 1 3 5 7 9 11)) 30)
2296 ((memq month (list 2 4 6 8 10)) 29)
2297 (t (if (islamic-calendar-leap-year-p year) 30 29))))
2298
2299 (defun islamic-calendar-day-number (date)
2300 "Return the day number within the year of the Islamic date DATE."
2301 (let* ((month (extract-calendar-month date))
2302 (day (extract-calendar-day date)))
2303 (+ (* 30 (/ month 2))
2304 (* 29 (/ (1- month) 2))
2305 day)))
2306
2307 (defun calendar-absolute-from-islamic (date)
2308 "Absolute date of Islamic DATE.
2309 The absolute date is the number of days elapsed since the (imaginary)
2310 Gregorian date Sunday, December 31, 1 BC."
2311 (let* ((month (extract-calendar-month date))
2312 (day (extract-calendar-day date))
2313 (year (extract-calendar-year date))
2314 (y (% year 30))
2315 (leap-years-in-cycle
2316 (cond
2317 ((< y 3) 0) ((< y 6) 1) ((< y 8) 2) ((< y 11) 3) ((< y 14) 4)
2318 ((< y 17) 5) ((< y 19) 6) ((< y 22) 7) ((< y 25) 8) ((< y 27) 9)
2319 (t 10))))
2320 (+ (islamic-calendar-day-number date);; days so far this year
2321 (* (1- year) 354) ;; days in all non-leap years
2322 (* 11 (/ year 30)) ;; leap days in complete cycles
2323 leap-years-in-cycle ;; leap days this cycle
2324 227014))) ;; days before start of calendar
2325
2326 (defun calendar-islamic-from-absolute (date)
2327 "Compute the Islamic date (month day year) corresponding to absolute DATE.
2328 The absolute date is the number of days elapsed since the (imaginary)
2329 Gregorian date Sunday, December 31, 1 BC."
2330 (if (< date 227015)
2331 (list 0 0 0);; pre-Islamic date
2332 (let* ((approx (/ (- date 227014) 355));; Approximation from below.
2333 (year ;; Search forward from the approximation.
2334 (+ approx
2335 (calendar-sum y approx
2336 (>= date (calendar-absolute-from-islamic
2337 (list 1 1 (1+ y))))
2338 1)))
2339 (month ;; Search forward from Muharram.
2340 (1+ (calendar-sum m 1
2341 (> date
2342 (calendar-absolute-from-islamic
2343 (list m
2344 (islamic-calendar-last-day-of-month
2345 m year)
2346 year)))
2347 1)))
2348 (day ;; Calculate the day by subtraction.
2349 (- date
2350 (1- (calendar-absolute-from-islamic (list month 1 year))))))
2351 (list month day year))))
2352
2353 (defconst calendar-islamic-month-name-array
2354 ["Muharram" "Safar" "Rabi I" "Rabi II" "Jumada I" "Jumada II"
2355 "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"])
2356
2357 (defun cursor-to-islamic-calendar-date ()
2358 "Show the Islamic calendar equivalent of the date under the cursor."
2359 (interactive)
2360 (let ((calendar-date-display-form
2361 (if european-calendar-style
2362 '(day " " monthname " " year)
2363 '(monthname " " day ", " year)))
2364 (calendar-month-name-array calendar-islamic-month-name-array)
2365 (islamic-date (calendar-islamic-from-absolute
2366 (calendar-absolute-from-gregorian
2367 (or (calendar-cursor-to-date)
2368 (error "Cursor is not on a date!"))))))
2369 (if (< (extract-calendar-year islamic-date) 1)
2370 (message "Date is pre-Islamic")
2371 (message "Islamic date: %s" (calendar-date-string islamic-date nil t)))))
2372
2373 (defun calendar-hebrew-from-absolute (date)
2374 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
2375 The absolute date is the number of days elapsed since the (imaginary)
2376 Gregorian date Sunday, December 31, 1 BC."
2377 (let* ((greg-date (calendar-gregorian-from-absolute date))
2378 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
2379 (1- (extract-calendar-month greg-date))))
2380 (day)
2381 (year (+ 3760 (extract-calendar-year greg-date))))
2382 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year))))
2383 (setq year (1+ year)))
2384 (let ((length (hebrew-calendar-last-month-of-year year)))
2385 (while (> date
2386 (calendar-absolute-from-hebrew
2387 (list month
2388 (hebrew-calendar-last-day-of-month month year)
2389 year)))
2390 (setq month (1+ (% month length)))))
2391 (setq day (1+
2392 (- date (calendar-absolute-from-hebrew (list month 1 year)))))
2393 (list month day year)))
2394
2395 (defun hebrew-calendar-leap-year-p (year)
2396 "t if YEAR is a Hebrew calendar leap year."
2397 (< (% (1+ (* 7 year)) 19) 7))
2398
2399 (defun hebrew-calendar-last-month-of-year (year)
2400 "The last month of the Hebrew calendar YEAR."
2401 (if (hebrew-calendar-leap-year-p year)
2402 13
2403 12))
2404
2405 (defun hebrew-calendar-last-day-of-month (month year)
2406 "The last day of MONTH in YEAR."
2407 (if (or (memq month (list 2 4 6 10 13))
2408 (and (= month 12) (not (hebrew-calendar-leap-year-p year)))
2409 (and (= month 8) (not (hebrew-calendar-long-heshvan-p year)))
2410 (and (= month 9) (hebrew-calendar-short-kislev-p year)))
2411 29
2412 30))
2413
2414 (defun hebrew-calendar-elapsed-days (year)
2415 "Number of days elapsed from the Sunday prior to the start of the Hebrew
2416 calendar to the mean conjunction of Tishri of Hebrew YEAR."
2417 (let* ((months-elapsed
2418 (+ (* 235 (/ (1- year) 19));; Months in complete cycles so far.
2419 (* 12 (% (1- year) 19)) ;; Regular months in this cycle
2420 (/ (1+ (* 7 (% (1- year) 19))) 19)));; Leap months this cycle
2421 (parts-elapsed (+ 204 (* 793 (% months-elapsed 1080))))
2422 (hours-elapsed (+ 5
2423 (* 12 months-elapsed)
2424 (* 793 (/ months-elapsed 1080))
2425 (/ parts-elapsed 1080)))
2426 (parts ;; Conjunction parts
2427 (+ (* 1080 (% hours-elapsed 24)) (% parts-elapsed 1080)))
2428 (day ;; Conjunction day
2429 (+ 1 (* 29 months-elapsed) (/ hours-elapsed 24)))
2430 (alternative-day
2431 (if (or (>= parts 19440) ;; If the new moon is at or after midday,
2432 (and (= (% day 7) 2);; ...or is on a Tuesday...
2433 (>= parts 9924) ;; at 9 hours, 204 parts or later...
2434 (not (hebrew-calendar-leap-year-p year)));; of a
2435 ;; common year,
2436 (and (= (% day 7) 1);; ...or is on a Monday...
2437 (>= parts 16789) ;; at 15 hours, 589 parts or later...
2438 (hebrew-calendar-leap-year-p (1- year))));; at the end
2439 ;; of a leap year
2440 ;; Then postpone Rosh HaShanah one day
2441 (1+ day)
2442 ;; Else
2443 day)))
2444 (if ;; If Rosh HaShanah would occur on Sunday, Wednesday, or Friday
2445 (memq (% alternative-day 7) (list 0 3 5))
2446 ;; Then postpone it one (more) day and return
2447 (1+ alternative-day)
2448 ;; Else return
2449 alternative-day)))
2450
2451 (defun hebrew-calendar-days-in-year (year)
2452 "Number of days in Hebrew YEAR."
2453 (- (hebrew-calendar-elapsed-days (1+ year))
2454 (hebrew-calendar-elapsed-days year)))
2455
2456 (defun hebrew-calendar-long-heshvan-p (year)
2457 "t if Heshvan is long in Hebrew YEAR."
2458 (= (% (hebrew-calendar-days-in-year year) 10) 5))
2459
2460 (defun hebrew-calendar-short-kislev-p (year)
2461 "t if Kislev is short in Hebrew YEAR."
2462 (= (% (hebrew-calendar-days-in-year year) 10) 3))
2463
2464 (defun calendar-absolute-from-hebrew (date)
2465 "Absolute date of Hebrew DATE.
2466 The absolute date is the number of days elapsed since the (imaginary)
2467 Gregorian date Sunday, December 31, 1 BC."
2468 (let* ((month (extract-calendar-month date))
2469 (day (extract-calendar-day date))
2470 (year (extract-calendar-year date)))
2471 (+ day ;; Days so far this month.
2472 (if (< month 7);; before Tishri
2473 ;; Then add days in prior months this year before and after Nisan
2474 (+ (calendar-sum
2475 m 7 (<= m (hebrew-calendar-last-month-of-year year))
2476 (hebrew-calendar-last-day-of-month m year))
2477 (calendar-sum
2478 m 1 (< m month)
2479 (hebrew-calendar-last-day-of-month m year)))
2480 ;; Else add days in prior months this year
2481 (calendar-sum
2482 m 7 (< m month)
2483 (hebrew-calendar-last-day-of-month m year)))
2484 (hebrew-calendar-elapsed-days year);; Days in prior years.
2485 -1373429))) ;; Days elapsed before absolute date 1.
2486
2487 (defconst calendar-hebrew-month-name-array-common-year
2488 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
2489 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"])
2490
2491 (defconst calendar-hebrew-month-name-array-leap-year
2492 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
2493 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"])
2494
2495 (defun cursor-to-hebrew-calendar-date ()
2496 "Show the Hebrew calendar equivalent of the date under the cursor."
2497 (interactive)
2498 (let* ((calendar-date-display-form
2499 (if european-calendar-style
2500 '(day " " monthname " " year)
2501 '(monthname " " day ", " year)))
2502 (hebrew-date (calendar-hebrew-from-absolute
2503 (calendar-absolute-from-gregorian
2504 (or (calendar-cursor-to-date)
2505 (error "Cursor is not on a date!")))))
2506 (calendar-month-name-array
2507 (if (hebrew-calendar-leap-year-p (extract-calendar-year hebrew-date))
2508 calendar-hebrew-month-name-array-leap-year
2509 calendar-hebrew-month-name-array-common-year)))
2510 (message "Hebrew date: %s" (calendar-date-string hebrew-date nil t))))
2511
2512 (defun hebrew-calendar-yahrzeit (death-date year)
2513 "Absolute date of the anniversary of Hebrew DEATH-DATE in Hebrew YEAR."
2514 (let* ((death-day (extract-calendar-day death-date))
2515 (death-month (extract-calendar-month death-date))
2516 (death-year (extract-calendar-year death-date)))
2517 (cond
2518 ;; If it's Heshvan 30 it depends on the first anniversary; if
2519 ;; that was not Heshvan 30, use the day before Kislev 1.
2520 ((and (= death-month 8)
2521 (= death-day 30)
2522 (not (hebrew-calendar-long-heshvan-p (1+ death-year))))
2523 (1- (calendar-absolute-from-hebrew (list 9 1 year))))
2524 ;; If it's Kislev 30 it depends on the first anniversary; if
2525 ;; that was not Kislev 30, use the day before Teveth 1.
2526 ((and (= death-month 9)
2527 (= death-day 30)
2528 (hebrew-calendar-short-kislev-p (1+ death-year)))
2529 (1- (calendar-absolute-from-hebrew (list 10 1 year))))
2530 ;; If it's Adar II, use the same day in last month of
2531 ;; year (Adar or Adar II).
2532 ((= death-month 13)
2533 (calendar-absolute-from-hebrew
2534 (list (last-month-of-hebrew-year year) death-day year)))
2535 ;; If it's the 30th in Adar I and $year$ is not a leap year
2536 ;; (so Adar has only 29 days), use the last day in Shevat.
2537 ((and (= death-day 30)
2538 (= death-month 12)
2539 (not (hebrew-calendar-leap-year-p death-year)))
2540 (calendar-absolute-from-hebrew (list 11 30 year)))
2541 ;; In all other cases, use the normal anniversary of the date of death.
2542 (t (calendar-absolute-from-hebrew
2543 (list death-month death-day year))))))
2544
2545 (defun list-yahrzeit-dates (death-date start-year end-year)
2546 "List of Yahrzeit dates for *Gregorian* DEATH-DATE
2547 from START-YEAR to END-YEAR. When called interactively
2548 the date of death is taken from the cursor in the calendar window."
2549 (interactive
2550 (let* ((death-date (calendar-cursor-to-date))
2551 (death-year (extract-calendar-year death-date))
2552 (start-year (calendar-read
2553 (format "Starting year of Yahrzeit table (>%d): "
2554 death-year)
2555 '(lambda (x) (> x death-year))
2556 (int-to-string (1+ death-year))))
2557 (end-year (calendar-read
2558 (format "Ending year of Yahrzeit table (>=%d): "
2559 start-year)
2560 '(lambda (x) (>= x start-year)))))
2561 (list death-date start-year end-year)))
2562 (message "Computing yahrzeits...")
2563 (let* ((yahrzeit-buffer "*Yahrzeits*")
2564 (h-date (calendar-hebrew-from-absolute
2565 (calendar-absolute-from-gregorian death-date)))
2566 (h-month (extract-calendar-month h-date))
2567 (h-day (extract-calendar-day h-date))
2568 (h-year (extract-calendar-year h-date)))
2569 (set-buffer (get-buffer-create yahrzeit-buffer))
2570 (setq buffer-read-only nil)
2571 (setq mode-line-format
2572 (format "------Yahrzeit dates for %s = %s%%-"
2573 (calendar-date-string death-date)
2574 (let ((calendar-month-name-array
2575 (if (hebrew-calendar-leap-year-p h-year)
2576 calendar-hebrew-month-name-array-leap-year
2577 calendar-hebrew-month-name-array-common-year))
2578 (calendar-date-display-form
2579 (if european-calendar-style
2580 '(day " " monthname " " year)
2581 '(monthname " " day ", " year))))
2582 (calendar-date-string h-date nil t))))
2583 (erase-buffer)
2584 (goto-char (point-min))
2585 (calendar-for-loop i from start-year to end-year do
2586 (insert
2587 (calendar-date-string
2588 (calendar-gregorian-from-absolute
2589 (hebrew-calendar-yahrzeit
2590 h-date
2591 (extract-calendar-year
2592 (calendar-hebrew-from-absolute
2593 (calendar-absolute-from-gregorian (list 1 1 i))))))) "\n"))
2594 (goto-char (point-min))
2595 (set-buffer-modified-p nil)
2596 (setq buffer-read-only t)
2597 (display-buffer yahrzeit-buffer)
2598 (message "Computing yahrzeits...done")))
2599
2600 (defun french-calendar-leap-year-p (year)
2601 "True if YEAR is a leap year on the French Revolutionary calendar.
2602 For Gregorian years 1793 to 1805, the years of actual operation of the
2603 calendar, uses historical practice based on equinoxes is followed (years 3, 7,
2604 and 11 were leap years; 15 and 20 would have been leap years). For later
2605 years uses the proposed rule of Romme (never adopted)--leap years fall every
2606 four years except century years not divisible 400 and century years that are
2607 multiples of 4000."
2608 (or (memq year '(3 7 11));; Actual practice--based on equinoxes
2609 (memq year '(15 20)) ;; Anticipated practice--based on equinoxes
2610 (and (> year 20) ;; Romme's proposal--never adopted
2611 (zerop (% year 4))
2612 (not (memq (% year 400) '(100 200 300)))
2613 (not (zerop (% year 4000))))))
2614
2615 (defun french-calendar-last-day-of-month (month year)
2616 "Last day of MONTH, YEAR on the French Revolutionary calendar.
2617 The 13th month is not really a month, but the 5 (6 in leap years) day period of
2618 `sansculottides' at the end of the year."
2619 (if (< month 13)
2620 30
2621 (if (french-calendar-leap-year-p year)
2622 6
2623 5)))
2624
2625 (defun calendar-absolute-from-french (date)
2626 "Absolute date of French Revolutionary DATE.
2627 The absolute date is the number of days elapsed since the (imaginary)
2628 Gregorian date Sunday, December 31, 1 BC."
2629 (let ((month (extract-calendar-month date))
2630 (day (extract-calendar-day date))
2631 (year (extract-calendar-year date)))
2632 (+ (* 365 (1- year));; Days in prior years
2633 ;; Leap days in prior years
2634 (if (< year 20)
2635 (/ year 4);; Actual and anticipated practice (years 3, 7, 11, 15)
2636 ;; Romme's proposed rule (using the Principle of Inclusion/Exclusion)
2637 (+ (/ (1- year) 4);; Luckily, there were 4 leap years before year 20
2638 (- (/ (1- year) 100))
2639 (/ (1- year) 400)
2640 (- (/ (1- year) 4000))))
2641 (* 30 (1- month));; Days in prior months this year
2642 day;; Days so far this month
2643 654414)));; Days before start of calendar (September 22, 1792).
2644
2645 (defun calendar-french-from-absolute (date)
2646 "Compute the French Revolutionary date (month day year) corresponding to
2647 absolute DATE. The absolute date is the number of days elapsed since the
2648 (imaginary) Gregorian date Sunday, December 31, 1 BC."
2649 (if (< date 654415)
2650 (list 0 0 0);; pre-French Revolutionary date
2651 (let* ((approx (/ (- date 654414) 366));; Approximation from below.
2652 (year ;; Search forward from the approximation.
2653 (+ approx
2654 (calendar-sum y approx
2655 (>= date (calendar-absolute-from-french (list 1 1 (1+ y))))
2656 1)))
2657 (month ;; Search forward from Vendemiaire.
2658 (1+ (calendar-sum m 1
2659 (> date
2660 (calendar-absolute-from-french
2661 (list m
2662 (french-calendar-last-day-of-month m year)
2663 year)))
2664 1)))
2665 (day ;; Calculate the day by subtraction.
2666 (- date
2667 (1- (calendar-absolute-from-french (list month 1 year))))))
2668 (list month day year))))
2669
2670 (defun cursor-to-french-calendar-date ()
2671 "Show the French Revolutionary calendar equivalent of the date under the
2672 cursor."
2673 (interactive)
2674 (let* ((french-date (calendar-french-from-absolute
2675 (calendar-absolute-from-gregorian
2676 (or (calendar-cursor-to-date)
2677 (error "Cursor is not on a date!")))))
2678 (y (extract-calendar-year french-date))
2679 (m (extract-calendar-month french-date))
2680 (d (extract-calendar-day french-date)))
2681 (if (< y 1)
2682 (message "Date is pre-French Revolution")
2683 (if (= m 13)
2684 (message "Jour %s de l'Annee %d de la Revolution"
2685 (aref french-calendar-special-days-array (1- d))
2686 y)
2687 (message "Decade %s, %s de %s de l'Annee %d de la Revolution"
2688 (make-string (1+ (/ (1- d) 10)) ?I)
2689 (aref french-calendar-day-name-array (% (1- d) 10))
2690 (aref french-calendar-month-name-array (1- m))
2691 y)))))
2692
2693 (defconst french-calendar-month-name-array
2694 ["Vendemiaire" "Brumaire" "Frimaire" "Nivose" "Pluviose" "Ventose" "Germinal"
2695 "Floreal" "Prairial" "Messidor" "Thermidor" "Fructidor"])
2696 ;; Very loosely translated as
2697 ;; Slippy, Nippy, Drippy, Freezy, Wheezy, Sneezy,
2698 ;; Showery, Flowery, Bowery, Heaty, Wheaty, Sweety.
2699
2700 (defconst french-calendar-day-name-array
2701 ["Primidi" "Duodi" "Tridi" "Quartidi" "Quintidi" "Sextidi" "Septidi"
2702 "Octidi" "Nonidi" "Decadi"])
2703
2704 (defconst french-calendar-special-days-array
2705 ["de la Vertu" "du Genie" "du Labour" "de la Raison" "de la Recompense"
2706 "de la Revolution"])
2707
2708 (provide 'calendar)
2709
2710 ;;; calendar.el ends here