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