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