Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / calendar / holidays.el
blob488f8cda8f6fd368412e4e660d86fd99feb1b716
1 ;;; holidays.el --- holiday functions for the calendar package
3 ;; Copyright (C) 1989-1990, 1992-1994, 1997, 2001-2014 Free Software
4 ;; Foundation, Inc.
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: holidays, calendar
9 ;; Package: calendar
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; See calendar.el.
30 ;;; Code:
32 (require 'calendar)
33 (load "hol-loaddefs" nil t)
35 (defgroup holidays nil
36 "Holidays support in calendar."
37 :group 'calendar
38 :prefix "holidays-"
39 :group 'local)
41 ;; The various holiday variables are autoloaded because people
42 ;; are used to using them to set calendar-holidays without having to
43 ;; explicitly load this file.
45 ;;;###autoload
46 (define-obsolete-variable-alias 'general-holidays
47 'holiday-general-holidays "23.1")
48 ;;;###autoload
49 (defcustom holiday-general-holidays
50 (mapcar 'purecopy
51 '((holiday-fixed 1 1 "New Year's Day")
52 (holiday-float 1 1 3 "Martin Luther King Day")
53 (holiday-fixed 2 2 "Groundhog Day")
54 (holiday-fixed 2 14 "Valentine's Day")
55 (holiday-float 2 1 3 "President's Day")
56 (holiday-fixed 3 17 "St. Patrick's Day")
57 (holiday-fixed 4 1 "April Fools' Day")
58 (holiday-float 5 0 2 "Mother's Day")
59 (holiday-float 5 1 -1 "Memorial Day")
60 (holiday-fixed 6 14 "Flag Day")
61 (holiday-float 6 0 3 "Father's Day")
62 (holiday-fixed 7 4 "Independence Day")
63 (holiday-float 9 1 1 "Labor Day")
64 (holiday-float 10 1 2 "Columbus Day")
65 (holiday-fixed 10 31 "Halloween")
66 (holiday-fixed 11 11 "Veteran's Day")
67 (holiday-float 11 4 4 "Thanksgiving")))
68 "General holidays. Default value is for the United States.
69 See the documentation for `calendar-holidays' for details."
70 :type 'sexp
71 :group 'holidays)
72 ;;;###autoload
73 (put 'holiday-general-holidays 'risky-local-variable t)
75 ;;;###autoload
76 (define-obsolete-variable-alias 'oriental-holidays
77 'holiday-oriental-holidays "23.1")
78 ;;;###autoload
79 (defcustom holiday-oriental-holidays
80 (mapcar 'purecopy
81 '((holiday-chinese-new-year)
82 (if calendar-chinese-all-holidays-flag
83 (append
84 (holiday-chinese 1 15 "Lantern Festival")
85 (holiday-chinese-qingming)
86 (holiday-chinese 5 5 "Dragon Boat Festival")
87 (holiday-chinese 7 7 "Double Seventh Festival")
88 (holiday-chinese 8 15 "Mid-Autumn Festival")
89 (holiday-chinese 9 9 "Double Ninth Festival")
90 (holiday-chinese-winter-solstice)
91 ))))
92 "Oriental holidays.
93 See the documentation for `calendar-holidays' for details."
94 :version "23.1" ; added more holidays
95 :type 'sexp
96 :group 'holidays)
97 ;;;###autoload
98 (put 'holiday-oriental-holidays 'risky-local-variable t)
100 ;;;###autoload
101 (define-obsolete-variable-alias 'local-holidays 'holiday-local-holidays "23.1")
102 ;;;###autoload
103 (defcustom holiday-local-holidays nil
104 "Local holidays.
105 See the documentation for `calendar-holidays' for details."
106 :type 'sexp
107 :group 'holidays)
108 ;;;###autoload
109 (put 'holiday-local-holidays 'risky-local-variable t)
111 ;;;###autoload
112 (define-obsolete-variable-alias 'other-holidays 'holiday-other-holidays "23.1")
113 ;;;###autoload
114 (defcustom holiday-other-holidays nil
115 "User defined holidays.
116 See the documentation for `calendar-holidays' for details."
117 :type 'sexp
118 :group 'holidays)
119 ;;;###autoload
120 (put 'holiday-other-holidays 'risky-local-variable t)
122 ;;;###autoload
123 (defvar hebrew-holidays-1
124 (mapcar 'purecopy
125 '((holiday-hebrew-rosh-hashanah)
126 (if calendar-hebrew-all-holidays-flag
127 (holiday-julian
129 (let ((m displayed-month)
130 (y displayed-year)
131 year)
132 (calendar-increment-month m y -1)
133 (setq year (calendar-extract-year
134 (calendar-julian-from-absolute
135 (calendar-absolute-from-gregorian (list m 1 y)))))
136 (if (zerop (% (1+ year) 4))
138 21)) "\"Tal Umatar\" (evening)"))))
139 "Component of the old default value of `holiday-hebrew-holidays'.")
140 ;;;###autoload
141 (put 'hebrew-holidays-1 'risky-local-variable t)
142 (make-obsolete-variable 'hebrew-holidays-1 'hebrew-holidays "23.1")
144 ;;;###autoload
145 (defvar hebrew-holidays-2
146 (mapcar 'purecopy
147 '((holiday-hebrew-hanukkah) ; respects calendar-hebrew-all-holidays-flag
148 (if calendar-hebrew-all-holidays-flag
149 (holiday-hebrew
151 (let ((h-year (calendar-extract-year
152 (calendar-hebrew-from-absolute
153 (calendar-absolute-from-gregorian
154 (list displayed-month 28 displayed-year))))))
155 (if (= 6 (% (calendar-hebrew-to-absolute (list 10 10 h-year))
157 11 10))
158 "Tzom Teveth"))
159 (if calendar-hebrew-all-holidays-flag
160 (holiday-hebrew 11 15 "Tu B'Shevat"))))
161 "Component of the old default value of `holiday-hebrew-holidays'.")
162 ;;;###autoload
163 (put 'hebrew-holidays-2 'risky-local-variable t)
164 (make-obsolete-variable 'hebrew-holidays-2 'hebrew-holidays "23.1")
166 ;;;###autoload
167 (defvar hebrew-holidays-3
168 (mapcar 'purecopy
169 '((if calendar-hebrew-all-holidays-flag
170 (holiday-hebrew
172 (let* ((m displayed-month)
173 (y displayed-year)
174 (h-year (progn
175 (calendar-increment-month m y 1)
176 (calendar-extract-year
177 (calendar-hebrew-from-absolute
178 (calendar-absolute-from-gregorian
179 (list m (calendar-last-day-of-month m y) y))))))
180 (s-s
181 (calendar-hebrew-from-absolute
182 (if (= 6
183 (% (calendar-hebrew-to-absolute
184 (list 7 1 h-year))
186 (calendar-dayname-on-or-before
187 6 (calendar-hebrew-to-absolute
188 (list 11 17 h-year)))
189 (calendar-dayname-on-or-before
190 6 (calendar-hebrew-to-absolute
191 (list 11 16 h-year))))))
192 (day (calendar-extract-day s-s)))
193 day)
194 "Shabbat Shirah"))))
195 "Component of the old default value of `holiday-hebrew-holidays'.")
196 ;;;###autoload
197 (put 'hebrew-holidays-3 'risky-local-variable t)
198 (make-obsolete-variable 'hebrew-holidays-3 'hebrew-holidays "23.1")
200 ;;;###autoload
201 (defvar hebrew-holidays-4
202 (mapcar 'purecopy
203 '((holiday-hebrew-passover)
204 (and calendar-hebrew-all-holidays-flag
205 (let* ((m displayed-month)
206 (y displayed-year)
207 (year (progn
208 (calendar-increment-month m y -1)
209 (calendar-extract-year
210 (calendar-julian-from-absolute
211 (calendar-absolute-from-gregorian (list m 1 y)))))))
212 (= 21 (% year 28)))
213 (holiday-julian 3 26 "Kiddush HaHamah"))
214 (if calendar-hebrew-all-holidays-flag
215 (holiday-hebrew-tisha-b-av))))
216 "Component of the old default value of `holiday-hebrew-holidays'.")
217 ;;;###autoload
218 (put 'hebrew-holidays-4 'risky-local-variable t)
219 (make-obsolete-variable 'hebrew-holidays-4 'hebrew-holidays "23.1")
221 ;;;###autoload
222 (define-obsolete-variable-alias 'hebrew-holidays
223 'holiday-hebrew-holidays "23.1")
224 ;;;###autoload
225 (defcustom holiday-hebrew-holidays
226 (mapcar 'purecopy
227 '((holiday-hebrew-passover)
228 (holiday-hebrew-rosh-hashanah)
229 (holiday-hebrew-hanukkah)
230 (if calendar-hebrew-all-holidays-flag
231 (append
232 (holiday-hebrew-tisha-b-av)
233 (holiday-hebrew-misc)))))
234 "Jewish holidays.
235 See the documentation for `calendar-holidays' for details."
236 :type 'sexp
237 :version "23.1" ; removed dependency on hebrew-holidays-N
238 :group 'holidays)
239 ;;;###autoload
240 (put 'holiday-hebrew-holidays 'risky-local-variable t)
242 ;;;###autoload
243 (define-obsolete-variable-alias 'christian-holidays
244 'holiday-christian-holidays "23.1")
245 ;;;###autoload
246 (defcustom holiday-christian-holidays
247 (mapcar 'purecopy
248 '((holiday-easter-etc) ; respects calendar-christian-all-holidays-flag
249 (holiday-fixed 12 25 "Christmas")
250 (if calendar-christian-all-holidays-flag
251 (append
252 (holiday-fixed 1 6 "Epiphany")
253 (holiday-julian 12 25 "Christmas (Julian calendar)")
254 (holiday-greek-orthodox-easter)
255 (holiday-fixed 8 15 "Assumption")
256 (holiday-advent 0 "Advent")))))
257 "Christian holidays.
258 See the documentation for `calendar-holidays' for details."
259 :type 'sexp
260 :group 'holidays)
261 ;;;###autoload
262 (put 'holiday-christian-holidays 'risky-local-variable t)
264 ;;;###autoload
265 (define-obsolete-variable-alias 'islamic-holidays
266 'holiday-islamic-holidays "23.1")
267 ;;;###autoload
268 (defcustom holiday-islamic-holidays
269 (mapcar 'purecopy
270 '((holiday-islamic-new-year)
271 (holiday-islamic 9 1 "Ramadan Begins")
272 (if calendar-islamic-all-holidays-flag
273 (append
274 (holiday-islamic 1 10 "Ashura")
275 (holiday-islamic 3 12 "Mulad-al-Nabi")
276 (holiday-islamic 7 26 "Shab-e-Mi'raj")
277 (holiday-islamic 8 15 "Shab-e-Bara't")
278 (holiday-islamic 9 27 "Shab-e Qadr")
279 (holiday-islamic 10 1 "Id-al-Fitr")
280 (holiday-islamic 12 10 "Id-al-Adha")))))
281 "Islamic holidays.
282 See the documentation for `calendar-holidays' for details."
283 :type 'sexp
284 :group 'holidays)
285 ;;;###autoload
286 (put 'holiday-islamic-holidays 'risky-local-variable t)
288 ;;;###autoload
289 (define-obsolete-variable-alias 'bahai-holidays 'holiday-bahai-holidays "23.1")
290 ;;;###autoload
291 (defcustom holiday-bahai-holidays
292 (mapcar 'purecopy
293 '((holiday-bahai-new-year)
294 (holiday-bahai-ridvan) ; respects calendar-bahai-all-holidays-flag
295 (holiday-fixed 5 23 "Declaration of the Báb")
296 (holiday-fixed 5 29 "Ascension of Bahá'u'lláh")
297 (holiday-fixed 7 9 "Martyrdom of the Báb")
298 (holiday-fixed 10 20 "Birth of the Báb")
299 (holiday-fixed 11 12 "Birth of Bahá'u'lláh")
300 (if calendar-bahai-all-holidays-flag
301 (append
302 (holiday-fixed 11 26 "Day of the Covenant")
303 (holiday-fixed 11 28 "Ascension of `Abdu'l-Bahá")))))
304 "Bahá'í holidays.
305 See the documentation for `calendar-holidays' for details."
306 :type 'sexp
307 :group 'holidays)
308 ;;;###autoload
309 (put 'holiday-bahai-holidays 'risky-local-variable t)
311 ;;;###autoload
312 (define-obsolete-variable-alias 'solar-holidays 'holiday-solar-holidays "23.1")
313 ;;;###autoload
314 (defcustom holiday-solar-holidays
315 (mapcar 'purecopy
316 '((solar-equinoxes-solstices)
317 (holiday-sexp calendar-daylight-savings-starts
318 (format "Daylight Saving Time Begins %s"
319 (solar-time-string
320 (/ calendar-daylight-savings-starts-time (float 60))
321 calendar-standard-time-zone-name)))
322 (holiday-sexp calendar-daylight-savings-ends
323 (format "Daylight Saving Time Ends %s"
324 (solar-time-string
325 (/ calendar-daylight-savings-ends-time (float 60))
326 calendar-daylight-time-zone-name)))))
327 "Sun-related holidays.
328 See the documentation for `calendar-holidays' for details."
329 :type 'sexp
330 :group 'holidays)
331 ;;;###autoload
332 (put 'holiday-solar-holidays 'risky-local-variable t)
334 ;; This one should not be autoloaded, else .emacs changes of
335 ;; holiday-general-holidays etc have no effect.
336 ;; FIXME should have some :set-after.
337 (defcustom calendar-holidays
338 (append holiday-general-holidays holiday-local-holidays
339 holiday-other-holidays holiday-christian-holidays
340 holiday-hebrew-holidays holiday-islamic-holidays
341 holiday-bahai-holidays holiday-oriental-holidays
342 holiday-solar-holidays)
343 "List of notable days for the command \\[holidays].
345 Additional holidays are easy to add to the list, just put them in the
346 list `holiday-other-holidays' in your init file. Similarly, by setting
347 any of `holiday-general-holidays', `holiday-local-holidays',
348 `holiday-christian-holidays', `holiday-hebrew-holidays',
349 `holiday-islamic-holidays', `holiday-bahai-holidays',
350 `holiday-oriental-holidays', or `holiday-solar-holidays' to nil in your
351 init file, you can eliminate unwanted categories of holidays.
353 The aforementioned variables control the holiday choices offered
354 by the function `holiday-list' when it is called interactively.
356 They also initialize the default value of `calendar-holidays',
357 which is the default list of holidays used by the function
358 `holiday-list' in the non-interactive case. Note that these
359 variables have no effect on `calendar-holidays' after it has been
360 set (e.g. after the calendar is loaded). In that case, customize
361 `calendar-holidays' directly.
363 The intention is that (in the US) `holiday-local-holidays' be set in
364 site-init.el and `holiday-other-holidays' be set by the user.
366 Entries on the list are expressions that return (possibly empty) lists of
367 items of the form ((month day year) string) of a holiday in the
368 three-month period centered around `displayed-month' of `displayed-year'.
369 Several basic functions are provided for this purpose:
371 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar
372 (holiday-float MONTH DAYNAME K STRING &optional DAY) is the Kth DAYNAME
373 (0 for Sunday, etc.) after/before Gregorian
374 MONTH DAY. K<0 means count back from the end
375 of the month. Optional DAY defaults to 1 if
376 K>0, and MONTH's last day otherwise.
377 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
378 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
379 (holiday-bahai MONTH DAY STRING) a fixed date on the Bahá'í calendar
380 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar
381 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
382 in the variable `year'; if it evaluates to
383 a visible date, that's the holiday; if it
384 evaluates to nil, there's no holiday. STRING
385 is an expression in the variable `date'.
387 For example, to add Bastille Day, celebrated in France on July 14, add
389 (holiday-fixed 7 14 \"Bastille Day\")
391 to the list. To add Hurricane Supplication Day, celebrated in the Virgin
392 Islands on the fourth Monday in August, add
394 (holiday-float 8 1 4 \"Hurricane Supplication Day\")
396 to the list (the last Monday would be specified with `-1' instead of `4').
397 To add the last day of Hanukkah to the list, use
399 (holiday-hebrew 10 2 \"Last day of Hanukkah\")
401 since the Hebrew months are numbered with 1 starting from Nisan.
402 To add the Islamic feast celebrating Mohammed's birthday, use
404 (holiday-islamic 3 12 \"Mohammed's Birthday\")
406 since the Islamic months are numbered from 1 starting with Muharram.
407 To add an entry for the Bahá'í festival of Ridvan, use
409 (holiday-bahai 2 13 \"Festival of Ridvan\")
411 since the Bahá'í months are numbered from 1 starting with Bahá.
412 To add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
414 (holiday-julian 4 2 \"Jefferson's Birthday\")
416 To include a holiday conditionally, use the sexp form or a conditional. For
417 example, to include American presidential elections, which occur on the first
418 Tuesday after the first Monday in November of years divisible by 4, add
420 (holiday-sexp
421 '(if (zerop (% year 4))
422 (calendar-gregorian-from-absolute
423 (1+ (calendar-dayname-on-or-before
424 1 (+ 6 (calendar-absolute-from-gregorian
425 (list 11 1 year)))))))
426 \"US Presidential Election\")
430 (if (zerop (% displayed-year 4))
431 (holiday-fixed 11
432 (calendar-extract-day
433 (calendar-gregorian-from-absolute
434 (1+ (calendar-dayname-on-or-before
435 1 (+ 6 (calendar-absolute-from-gregorian
436 (list 11 1 displayed-year)))))))
437 \"US Presidential Election\"))
439 to the list. To include the phases of the moon, add
441 (lunar-phases)
443 to the holiday list, where `lunar-phases' is an Emacs-Lisp function that
444 you've written to return a (possibly empty) list of the relevant VISIBLE dates
445 with descriptive strings such as
447 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )."
448 :type 'sexp
449 :group 'holidays)
450 ;;;###autoload
451 (put 'calendar-holidays 'risky-local-variable t)
453 ;;; End of user options.
456 ;; FIXME name that makes sense
457 ;;;###diary-autoload
458 (defun calendar-holiday-list ()
459 "Form the list of holidays that occur on dates in the calendar window.
460 The holidays are those in the list `calendar-holidays'."
461 (let (res h err)
462 (sort
463 (dolist (p calendar-holidays res)
464 (if (setq h (if calendar-debug-sexp
465 (let ((debug-on-error t))
466 (eval p))
467 (condition-case err
468 (eval p)
469 (error
470 (display-warning
471 :error
472 (format "Bad holiday list item: %s\nError: %s\n"
473 p err))
474 nil))))
475 (setq res (append h res))))
476 'calendar-date-compare)))
478 (defvar displayed-month) ; from calendar-generate
479 (defvar displayed-year)
481 ;; FIXME name that makes sense
482 ;;;###cal-autoload
483 (defun calendar-list-holidays (&optional event)
484 "Create a buffer containing the holidays for the current calendar window.
485 The holidays are those in the list `calendar-notable-days'.
486 Returns non-nil if any holidays are found.
487 If EVENT is non-nil, it's an event indicating the buffer position to
488 use instead of point."
489 (interactive (list last-nonmenu-event))
490 ;; If called from a menu, with the calendar window not selected.
491 (with-current-buffer
492 (if event (window-buffer (posn-window (event-start event)))
493 (current-buffer))
494 (message "Looking up holidays...")
495 (let ((holiday-list (calendar-holiday-list))
496 (m1 displayed-month)
497 (y1 displayed-year)
498 (m2 displayed-month)
499 (y2 displayed-year))
500 (if (not holiday-list)
501 (message "Looking up holidays...none found")
502 (calendar-in-read-only-buffer holiday-buffer
503 (calendar-increment-month m1 y1 -1)
504 (calendar-increment-month m2 y2 1)
505 (calendar-set-mode-line
506 (if (= y1 y2)
507 (format "Notable Dates from %s to %s, %d%%-"
508 (calendar-month-name m1) (calendar-month-name m2) y2)
509 (format "Notable Dates from %s, %d to %s, %d%%-"
510 (calendar-month-name m1) y1 (calendar-month-name m2) y2)))
511 (insert
512 (mapconcat
513 (lambda (x) (concat (calendar-date-string (car x))
514 ": " (cadr x)))
515 holiday-list "\n")))
516 (message "Looking up holidays...done"))
517 holiday-list)))
519 (define-obsolete-function-alias
520 'list-calendar-holidays 'calendar-list-holidays "23.1")
522 ;;;###autoload
523 (defun holidays (&optional arg)
524 "Display the holidays for last month, this month, and next month.
525 If called with an optional prefix argument ARG, prompts for month and year.
526 This function is suitable for execution in a init file."
527 (interactive "P")
528 (save-excursion
529 (let* ((completion-ignore-case t)
530 (date (if arg (calendar-read-date t)
531 (calendar-current-date)))
532 (displayed-month (calendar-extract-month date))
533 (displayed-year (calendar-extract-year date)))
534 (calendar-list-holidays))))
536 ;; rms: "Emacs commands to display a list of something generally start
537 ;; with `list-'. Please make `list-holidays' the principal name."
538 ;;;###autoload
539 (defun list-holidays (y1 &optional y2 l label)
540 "Display holidays for years Y1 to Y2 (inclusive).
541 Y2 defaults to Y1. The optional list of holidays L defaults to
542 `calendar-holidays'. If you want to control what holidays are
543 displayed, use a different list. For example,
545 (list-holidays 2006 2006
546 (append holiday-general-holidays holiday-local-holidays))
548 will display holidays for the year 2006 defined in the two
549 mentioned lists, and nothing else.
551 When called interactively, this command offers a choice of
552 holidays, based on the variables `holiday-solar-holidays' etc. See the
553 documentation of `calendar-holidays' for a list of the variables
554 that control the choices, as well as a description of the format
555 of a holiday list.
557 The optional LABEL is used to label the buffer created."
558 (interactive
559 (let* ((start-year (calendar-read
560 "Starting year of holidays (>0): "
561 (lambda (x) (> x 0))
562 (number-to-string (calendar-extract-year
563 (calendar-current-date)))))
564 (end-year (calendar-read
565 (format "Ending year (inclusive) of holidays (>=%s): "
566 start-year)
567 (lambda (x) (>= x start-year))
568 (number-to-string start-year)))
569 (completion-ignore-case t)
570 (lists
571 (list
572 (cons "All" calendar-holidays)
573 (cons "Equinoxes/Solstices"
574 (list (list 'solar-equinoxes-solstices)))
575 (if holiday-general-holidays
576 (cons "General" holiday-general-holidays))
577 (if holiday-local-holidays
578 (cons "Local" holiday-local-holidays))
579 (if holiday-other-holidays
580 (cons "Other" holiday-other-holidays))
581 (if holiday-christian-holidays
582 (cons "Christian" holiday-christian-holidays))
583 (if holiday-hebrew-holidays
584 (cons "Hebrew" holiday-hebrew-holidays))
585 (if holiday-islamic-holidays
586 (cons "Islamic" holiday-islamic-holidays))
587 (if holiday-bahai-holidays
588 (cons "Bahá'í" holiday-bahai-holidays))
589 (if holiday-oriental-holidays
590 (cons "Oriental" holiday-oriental-holidays))
591 (if holiday-solar-holidays
592 (cons "Solar" holiday-solar-holidays))
593 (cons "Ask" nil)))
594 (choice (capitalize
595 (completing-read "List (TAB for choices): " lists nil t)))
596 (which (if (string-equal choice "Ask")
597 (eval (read-variable "Enter list name: "))
598 (cdr (assoc choice lists))))
599 (name (if (string-equal choice "Equinoxes/Solstices")
600 choice
601 (if (member choice '("Ask" ""))
602 "Holidays"
603 (format "%s Holidays" choice)))))
604 (list start-year end-year which name)))
605 (unless y2 (setq y2 y1))
606 (message "Computing holidays...")
607 (let ((calendar-holidays (or l calendar-holidays))
608 (title (or label "Holidays"))
609 (s (calendar-absolute-from-gregorian (list 2 1 y1)))
610 (e (calendar-absolute-from-gregorian (list 11 1 y2)))
611 (displayed-month 2)
612 (displayed-year y1)
613 holiday-list)
614 (while (<= s e)
615 (setq holiday-list (append holiday-list (calendar-holiday-list)))
616 (calendar-increment-month displayed-month displayed-year 3)
617 (setq s (calendar-absolute-from-gregorian
618 (list displayed-month 1 displayed-year))))
619 (save-excursion
620 (calendar-in-read-only-buffer holiday-buffer
621 (calendar-set-mode-line
622 (if (= y1 y2)
623 (format "%s for %s" title y1)
624 (format "%s for %s-%s" title y1 y2)))
625 (insert
626 (mapconcat
627 (lambda (x) (concat (calendar-date-string (car x))
628 ": " (cadr x)))
629 holiday-list "\n")))
630 (message "Computing holidays...done"))))
632 ;;;###autoload
633 (defalias 'holiday-list 'list-holidays)
635 ;;;###diary-autoload
636 (defun calendar-check-holidays (date)
637 "Check the list of holidays for any that occur on DATE.
638 DATE is a list (month day year). This function considers the
639 holidays from the list `calendar-holidays', and returns a list of
640 strings describing those holidays that apply on DATE, or nil if none do."
641 (let ((displayed-month (calendar-extract-month date))
642 (displayed-year (calendar-extract-year date))
643 holiday-list)
644 (dolist (h (calendar-holiday-list) holiday-list)
645 (if (calendar-date-equal date (car h))
646 (setq holiday-list (append holiday-list (cdr h)))))))
648 (define-obsolete-function-alias
649 'check-calendar-holidays 'calendar-check-holidays "23.1")
652 ;; Formerly cal-tex-list-holidays.
653 (defun holiday-in-range (d1 d2)
654 "Generate a list of all holidays in range from absolute date D1 to D2."
655 (let* ((start (calendar-gregorian-from-absolute d1))
656 (displayed-month (calendar-extract-month start))
657 (displayed-year (calendar-extract-year start))
658 (end (calendar-gregorian-from-absolute d2))
659 (end-month (calendar-extract-month end))
660 (end-year (calendar-extract-year end))
661 (number-of-intervals
662 (1+ (/ (calendar-interval displayed-month displayed-year
663 end-month end-year)
664 3)))
665 holidays in-range a)
666 (calendar-increment-month displayed-month displayed-year 1)
667 (dotimes (_idummy number-of-intervals)
668 (setq holidays (append holidays (calendar-holiday-list)))
669 (calendar-increment-month displayed-month displayed-year 3))
670 (dolist (hol holidays)
671 (and (car hol)
672 (setq a (calendar-absolute-from-gregorian (car hol)))
673 (and (<= d1 a) (<= a d2))
674 (setq in-range (append (list hol) in-range))))
675 in-range))
678 (declare-function x-popup-menu "menu.c" (position menu))
680 ;;;###cal-autoload
681 (defun calendar-cursor-holidays (&optional date event)
682 "Find holidays for the date specified by the cursor in the calendar window.
683 Optional DATE is a list (month day year) to use instead of the
684 cursor position. EVENT specifies a buffer position to use for a date."
685 (interactive (list nil last-nonmenu-event))
686 (message "Checking holidays...")
687 (or date (setq date (calendar-cursor-to-date t event)))
688 (let ((date-string (calendar-date-string date))
689 (holiday-list (calendar-check-holidays date))
690 selection msg)
691 (if (mouse-event-p event)
692 (and (setq selection (cal-menu-x-popup-menu event
693 (format "Holidays for %s" date-string)
694 (if holiday-list
695 (mapcar 'list holiday-list)
696 '("None"))))
697 (call-interactively selection))
698 (if (not holiday-list)
699 (message "No holidays known for %s" date-string)
700 (if (<= (length (setq msg
701 (format "%s: %s" date-string
702 (mapconcat 'identity holiday-list "; "))))
703 (frame-width))
704 (message "%s" msg)
705 (calendar-in-read-only-buffer holiday-buffer
706 (calendar-set-mode-line date-string)
707 (insert (mapconcat 'identity holiday-list "\n")))
708 (message "Checking holidays...done"))))))
710 ;; FIXME move to calendar?
711 ;;;###cal-autoload
712 (defun calendar-mark-holidays (&optional event)
713 "Mark notable days in the calendar window.
714 If EVENT is non-nil, it's an event indicating the buffer position to
715 use instead of point."
716 (interactive (list last-nonmenu-event))
717 ;; If called from a menu, with the calendar window not selected.
718 (with-current-buffer
719 (if event (window-buffer (posn-window (event-start event)))
720 (current-buffer))
721 (setq calendar-mark-holidays-flag t)
722 (message "Marking holidays...")
723 (dolist (holiday (calendar-holiday-list))
724 (calendar-mark-visible-date (car holiday) calendar-holiday-marker))
725 (message "Marking holidays...done")))
727 (define-obsolete-function-alias
728 'mark-calendar-holidays 'calendar-mark-holidays "23.1")
730 ;; Below are the functions that calculate the dates of holidays; these
731 ;; are eval'ed in the function calendar-holiday-list. If you
732 ;; write other such functions, be sure to imitate the style used below.
733 ;; Remember that each function must return a list of items of the form
734 ;; ((month day year) string) of VISIBLE dates in the calendar window.
736 (defun holiday-fixed (month day string)
737 "Holiday on MONTH, DAY (Gregorian) called STRING.
738 If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year)
739 STRING)). Returns nil if it is not visible in the current calendar window."
740 ;; This determines whether a given month is visible in the calendar.
741 ;; cf calendar-date-is-visible-p (which also checks the year part).
742 ;; The day is irrelevant since only full months are displayed.
743 ;; Since the calendar displays three months at a time, month N
744 ;; is visible if displayed-month = N-1, N, N+1.
745 ;; In particular, November is visible if d-m = 10, 11, 12.
746 ;; This is useful, because we can do a one-sided test:
747 ;; November is visible if d-m > 9. (Similarly, February is visible if
748 ;; d-m < 4.)
749 ;; To determine if December is visible, we can shift the calendar
750 ;; back a month and ask if November is visible; to determine if
751 ;; October is visible, we can shift it forward a month and ask if
752 ;; November is visible; etc.
753 (let ((m displayed-month)
754 (y displayed-year))
755 (calendar-increment-month m y (- 11 month))
756 (if (> m 9) ; Is November visible?
757 (list (list (list month day y) string)))))
759 (defun holiday-float (month dayname n string &optional day)
760 "Holiday called STRING on the Nth DAYNAME after/before MONTH DAY.
761 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
762 If N>0, use the Nth DAYNAME after MONTH DAY.
763 If N<0, use the Nth DAYNAME before MONTH DAY.
764 DAY defaults to 1 if N>0, and MONTH's last day otherwise.
765 If the holiday is visible in the calendar window, returns a
766 list (((month day year) STRING)). Otherwise returns nil."
767 ;; This is messy because the holiday may be visible, while the date
768 ;; on which it is based is not. For example, the first Monday after
769 ;; December 30 may be visible when January is not. For large values
770 ;; of |n| the problem is more grotesque. If we didn't have to worry
771 ;; about such cases, we could just use the original version of this
772 ;; function:
773 ;; (let ((m displayed-month)
774 ;; (y displayed-year))
775 ;; (calendar-increment-month m y (- 11 month))
776 ;; (if (> m 9); month in year y is visible
777 ;; (list (list (calendar-nth-named-day n dayname month y day) string)))))
778 (let* ((m1 displayed-month)
779 (y1 displayed-year)
780 (m2 displayed-month)
781 (y2 displayed-year)
782 (d1 (progn ; first possible base date for holiday
783 (calendar-increment-month m1 y1 -1)
784 (+ (calendar-nth-named-absday 1 dayname m1 y1)
785 (* -7 n)
786 (if (> n 0) 1 -7))))
787 (d2 ; last possible base date for holiday
788 (progn
789 (calendar-increment-month m2 y2 1)
790 (+ (calendar-nth-named-absday -1 dayname m2 y2)
791 (* -7 n)
792 (if (> n 0) 7 -1))))
793 (y1 (calendar-extract-year (calendar-gregorian-from-absolute d1)))
794 (y2 (calendar-extract-year (calendar-gregorian-from-absolute d2)))
795 (y ; year of base date
796 (if (or (= y1 y2) (> month 9))
798 y2))
799 (d ; day of base date
800 (or day (if (> n 0)
802 (calendar-last-day-of-month month y))))
803 (date ; base date for holiday
804 (calendar-absolute-from-gregorian (list month d y))))
805 (and (<= d1 date) (<= date d2)
806 (list (list (calendar-nth-named-day n dayname month y d)
807 string)))))
809 (defun holiday-filter-visible-calendar (hlist)
810 "Filter list of holidays HLIST, and return only the visible ones.
811 HLIST is a list of elements of the form (DATE) TEXT."
812 (delq nil (mapcar (lambda (p)
813 (and (car p) (calendar-date-is-visible-p (car p)) p))
814 hlist)))
816 (define-obsolete-function-alias
817 'filter-visible-calendar-holidays 'holiday-filter-visible-calendar "23.1")
819 (defun holiday-sexp (sexp string)
820 "Sexp holiday for dates in the calendar window.
821 SEXP is an expression in variable `year' that is evaluated to
822 give `date'. STRING is an expression in `date' that evaluates to
823 the holiday description of `date'. If `date' is visible in the
824 calendar window, the holiday STRING is on that date. If date is
825 nil, or if the date is not visible, there is no holiday."
826 (let ((m displayed-month)
827 (y displayed-year)
828 year date)
829 (calendar-increment-month m y -1)
830 (holiday-filter-visible-calendar
831 (list
832 (progn
833 (setq year y
834 date (eval sexp))
835 (list date (if date (eval string))))
836 (progn
837 (setq year (1+ y)
838 date (eval sexp))
839 (list date (if date (eval string))))))))
842 (defun holiday-advent (&optional n string)
843 "Date of Nth day after advent (named STRING), if visible in calendar window.
844 Negative values of N are interpreted as days before advent.
845 STRING is used purely for display purposes. The return value has
846 the form ((MONTH DAY YEAR) STRING), where the date is that of the
847 Nth day before or after advent.
849 For backwards compatibility, if this function is called with no
850 arguments, then it returns the value appropriate for advent itself."
851 ;; Backwards compatibility layer.
852 (if (not n)
853 (holiday-advent 0 "Advent")
854 (let* ((year displayed-year)
855 (month displayed-month)
856 (advent (progn
857 (calendar-increment-month month year -1)
858 (calendar-gregorian-from-absolute
859 (+ n
860 (calendar-dayname-on-or-before
862 (calendar-absolute-from-gregorian
863 (list 12 3 year))))))))
864 (if (calendar-date-is-visible-p advent)
865 (list (list advent string))))))
867 (defun holiday-easter-etc (&optional n string)
868 "Date of Nth day after Easter (named STRING), if visible in calendar window.
869 Negative values of N are interpreted as days before Easter.
870 STRING is used purely for display purposes. The return value has
871 the form ((MONTH DAY YEAR) STRING), where the date is that of the
872 Nth day before or after Easter.
874 For backwards compatibility, if this function is called with no
875 arguments, then it returns a list of \"standard\" Easter-related
876 holidays (with more entries if `calendar-christian-all-holidays-flag'
877 is non-nil)."
878 ;; Backwards compatibility layer.
879 (if (not n)
880 (apply 'append
881 (mapcar (lambda (e)
882 (apply 'holiday-easter-etc e))
883 ;; The combined list is not in order.
884 (append
885 (if calendar-christian-all-holidays-flag
886 '((-63 "Septuagesima Sunday")
887 (-56 "Sexagesima Sunday")
888 (-49 "Shrove Sunday")
889 (-48 "Shrove Monday")
890 (-47 "Shrove Tuesday")
891 (-14 "Passion Sunday")
892 (-7 "Palm Sunday")
893 (-3 "Maundy Thursday")
894 (35 "Rogation Sunday")
895 (39 "Ascension Day")
896 (49 "Pentecost (Whitsunday)")
897 (50 "Whitmonday")
898 (56 "Trinity Sunday")
899 (60 "Corpus Christi")))
900 '((-46 "Ash Wednesday")
901 (-2 "Good Friday")
902 (0 "Easter Sunday")))))
903 (let* ((century (1+ (/ displayed-year 100)))
904 (shifted-epact ; age of moon for April 5...
905 (% (+ 14 (* 11 (% displayed-year 19)) ; ...by Nicaean rule
906 (- ; ...corrected for the Gregorian century rule
907 (/ (* 3 century) 4))
908 (/ ; ...corrected for Metonic cycle inaccuracy
909 (+ 5 (* 8 century)) 25)
910 (* 30 century)) ; keeps value positive
911 30))
912 (adjusted-epact ; adjust for 29.5 day month
913 (if (or (zerop shifted-epact)
914 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
915 (1+ shifted-epact)
916 shifted-epact))
917 (paschal-moon ; day after the full moon on or after March 21
918 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
919 adjusted-epact))
920 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
921 (greg (calendar-gregorian-from-absolute (+ abs-easter n))))
922 (if (calendar-date-is-visible-p greg)
923 (list (list greg string))))))
925 ;; Prior call to calendar-julian-from-absolute will autoload cal-julian.
926 (declare-function calendar-julian-to-absolute "cal-julian" (date))
928 (defun holiday-greek-orthodox-easter ()
929 "Date of Easter according to the rule of the Council of Nicaea."
930 (let* ((m displayed-month)
931 (y displayed-year)
932 (julian-year (progn
933 (calendar-increment-month m y 1)
934 (calendar-extract-year
935 (calendar-julian-from-absolute
936 (calendar-absolute-from-gregorian
937 (list m (calendar-last-day-of-month m y) y))))))
938 (shifted-epact ; age of moon for April 5
939 (% (+ 14
940 (* 11 (% julian-year 19)))
941 30))
942 (paschal-moon ; day after full moon on or after March 21
943 (- (calendar-julian-to-absolute (list 4 19 julian-year))
944 shifted-epact))
945 (nicaean-easter ; Sunday following the Paschal moon
946 (calendar-gregorian-from-absolute
947 (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))))
948 (if (calendar-date-is-visible-p nicaean-easter)
949 (list (list nicaean-easter "Pascha (Greek Orthodox Easter)")))))
951 (provide 'holidays)
953 ;; Local Variables:
954 ;; coding: utf-8
955 ;; End:
957 ;;; holidays.el ends here