comparison lisp/calendar/holidays.el @ 406:bd0533ed9b5a

Initial revision
author Jim Blandy <jimb@redhat.com>
date Fri, 23 Aug 1991 03:01:50 +0000
parents
children 4cd7543be581
comparison
equal deleted inserted replaced
405:698d5d6e8f8b 406:bd0533ed9b5a
1 ;; Holiday functions.
2 ;; Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
3
4 ;; This file is part of GNU Emacs.
5
6 ;; GNU Emacs is distributed in the hope that it will be useful,
7 ;; but WITHOUT ANY WARRANTY. No author or distributor
8 ;; accepts responsibility to anyone for the consequences of using it
9 ;; or for whether it serves any particular purpose or works at all,
10 ;; unless he says so in writing. Refer to the GNU Emacs General Public
11 ;; License for full details.
12
13 ;; Everyone is granted permission to copy, modify and redistribute
14 ;; GNU Emacs, but only under the conditions described in the
15 ;; GNU Emacs General Public License. A copy of this license is
16 ;; supposed to have been given to you along with GNU Emacs so you
17 ;; can know your rights and responsibilities. It should be in a
18 ;; file named COPYING. Among other things, the copyright notice
19 ;; and this notice must be preserved on all copies.
20
21 ;; This collection of functions implements the holiday features as described
22 ;; in calendar.el.
23
24 ;; Comments, corrections, and improvements should be sent to
25 ;; Edward M. Reingold Department of Computer Science
26 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
27 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
28 ;; Urbana, Illinois 61801
29
30 ;; Technical details of all the calendrical calculations can be found in
31 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
32 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
33 ;; pages 899-928.
34
35 (require 'calendar)
36 (provide 'holidays)
37
38 (defun holidays ()
39 "Display the holidays for last month, this month, and next month.
40 This function is suitable for execution in a .emacs file."
41 (interactive)
42 (save-excursion
43 (let* ((date (calendar-current-date))
44 (displayed-month (extract-calendar-month date))
45 (displayed-year (extract-calendar-year date)))
46 (list-calendar-holidays))))
47
48 (defun check-calendar-holidays (date)
49 "Check the list of holidays for any that occur on DATE.
50 The value returned is a list of strings of relevant holiday descriptions.
51 The holidays are those in the list calendar-holidays."
52 (let* ((displayed-month (extract-calendar-month date))
53 (displayed-year (extract-calendar-year date))
54 (h (calendar-holiday-list))
55 (holiday-list))
56 (while h
57 (if (calendar-date-equal date (car (car h)))
58 (setq holiday-list (append holiday-list (cdr (car h)))))
59 (setq h (cdr h)))
60 holiday-list))
61
62 (defun calendar-cursor-holidays ()
63 "Find holidays for the date specified by the cursor in the calendar window."
64 (interactive)
65 (message "Checking holidays...")
66 (let* ((date (calendar-cursor-to-date))
67 (date-string (calendar-date-string date))
68 (holiday-list (check-calendar-holidays date))
69 (holiday-string (mapconcat 'identity holiday-list "; "))
70 (msg (format "%s: %s" date-string holiday-string)))
71 (if (not holiday-list)
72 (message "No holidays known for %s" date-string)
73 (if (<= (length msg) (screen-width))
74 (message msg)
75 (set-buffer (get-buffer-create holiday-buffer))
76 (setq buffer-read-only nil)
77 (setq mode-line-format
78 (format "--------------------------%s%%-"
79 date-string))
80 (erase-buffer)
81 (insert (mapconcat 'identity holiday-list "\n"))
82 (goto-char (point-min))
83 (set-buffer-modified-p nil)
84 (setq buffer-read-only t)
85 (display-buffer holiday-buffer)
86 (message "Checking holidays...done")))))
87
88 (defun mark-calendar-holidays ()
89 "Mark notable days in the calendar window."
90 (interactive)
91 (setq mark-holidays-in-calendar t)
92 (message "Marking holidays...")
93 (let ((holiday-list (calendar-holiday-list)))
94 (while holiday-list
95 (mark-visible-calendar-date
96 (car (car holiday-list)) calendar-holiday-marker)
97 (setq holiday-list (cdr holiday-list))))
98 (message "Marking holidays...done"))
99
100 (defun list-calendar-holidays ()
101 "Create a buffer containing the holidays for the current calendar window.
102 The holidays are those in the list calendar-notable-days. Returns t if any
103 holidays are found, nil if not."
104 (interactive)
105 (message "Looking up holidays...")
106 (let ((holiday-list (calendar-holiday-list))
107 (m1 displayed-month)
108 (y1 displayed-year)
109 (m2 displayed-month)
110 (y2 displayed-year))
111 (if (not holiday-list)
112 (progn
113 (message "Looking up holidays...none found")
114 nil)
115 (set-buffer (get-buffer-create holiday-buffer))
116 (setq buffer-read-only nil)
117 (increment-calendar-month m1 y1 -1)
118 (increment-calendar-month m2 y2 1)
119 (setq mode-line-format
120 (format "-------------Notable Dates from %s, %d to %s, %d%%-"
121 (calendar-month-name m1) y1 (calendar-month-name m2) y2))
122 (erase-buffer)
123 (insert
124 (mapconcat
125 '(lambda (x) (concat (calendar-date-string (car x))
126 ": " (car (cdr x))))
127 holiday-list "\n"))
128 (goto-char (point-min))
129 (set-buffer-modified-p nil)
130 (setq buffer-read-only t)
131 (display-buffer holiday-buffer)
132 (message "Looking up holidays...done")
133 t)))
134
135 (defun calendar-holiday-list ()
136 "Form the list of holidays that occur on dates in the calendar window.
137 The holidays are those in the list calendar-holidays."
138 (let ((p calendar-holidays)
139 (holiday-list))
140 (while p
141 (let* ((function-name
142 (intern (format "calendar-holiday-function-%s" (car (car p)))))
143 (holidays
144 (if (cdr (car p));; optional arguments
145 (funcall function-name (cdr (car p)))
146 (funcall function-name))))
147 (if holidays
148 (setq holiday-list (append holidays holiday-list))))
149 (setq p (cdr p)))
150 (setq holiday-list (sort holiday-list 'calendar-date-compare))))
151
152 ;; Below are the functions that calculate the dates of holidays; these
153 ;; are called by the funcall in the function calendar-holiday-list. If you
154 ;; write other such functions, be sure to imitate the style used below,
155 ;; including the evaluation of each element in the list that constitutes
156 ;; the argument to the function. If you don't do this evaluation, the
157 ;; list calendar-holidays cannot contain expressions (as, for example, in
158 ;; the entry for the Islamic new year. Also remember that each function
159 ;; must return a list of items of the form ((month day year) string);
160 ;; the date (month day year) should be visible in the calendar window.
161
162 (defun calendar-holiday-function-fixed (x)
163 "Returns the corresponding Gregorian date, if visible in the window, to
164 month, year where month is (car X) and year is (car (cdr X)). If it is
165 visible, the value returned is the list (((month day year) string)) where
166 string is (car (nthcdr 2 X)). Returns nil if it is not visible in the
167 current calendar window."
168 (let* ((month (eval (car x)))
169 (day (eval (car (cdr x))))
170 (string (eval (car (nthcdr 2 x))))
171 (m displayed-month)
172 (y displayed-year))
173 (increment-calendar-month m y (- 11 month))
174 (if (> m 9)
175 (list (list (list month day y) string)))))
176
177 (defun calendar-holiday-function-float (x)
178 "Returns the corresponding Gregorian date, if visible in the window, to the
179 n-th occurrence (negative counts from the end of the month) of dayname in
180 month, year where month is (car X), year is (car (cdr X)), n is
181 \(car \(nthcdr 2 X\)\). If it is visible, the value returned is the list
182 \(\(\(month day year)\ string\)\) where string is (car (nthcdr 3 X)).
183 Returns nil if it is not visible in the current calendar window."
184 (let* ((month (eval (car x)))
185 (dayname (eval (car (cdr x))))
186 (n (eval (car (nthcdr 2 x))))
187 (string (eval (car (nthcdr 3 x))))
188 (m displayed-month)
189 (y displayed-year))
190 (increment-calendar-month m y (- 11 month))
191 (if (> m 9)
192 (list (list (calendar-nth-named-day n dayname month y) string)))))
193
194 (defun calendar-holiday-function-julian (x)
195 "Returns the corresponding Gregorian date, if visible in the window, to the
196 Julian date month, year where month is (car X) and year is (car (cdr X)).
197 If it is visible, the value returned is the list (((month day year) string))
198 where string is (car (nthcdr 2 X)). Returns nil if it is not visible in the
199 current calendar window."
200 (let* ((month (eval (car x)))
201 (day (eval (car (cdr x))))
202 (string (eval (car (nthcdr 2 x))))
203 (m1 displayed-month)
204 (y1 displayed-year)
205 (m2 displayed-month)
206 (y2 displayed-year)
207 (year))
208 (increment-calendar-month m1 y1 -1)
209 (increment-calendar-month m2 y2 1)
210 (let* ((start-date (calendar-absolute-from-gregorian
211 (list m1 1 y1)))
212 (end-date (calendar-absolute-from-gregorian
213 (list m2 (calendar-last-day-of-month m2 y2) y2)))
214 (julian-start (calendar-julian-from-absolute start-date))
215 (julian-end (calendar-julian-from-absolute end-date))
216 (julian-y1 (extract-calendar-year julian-start))
217 (julian-y2 (extract-calendar-year julian-end)))
218 (setq year (if (< 10 month) julian-y1 julian-y2))
219 (let ((date (calendar-gregorian-from-absolute
220 (calendar-absolute-from-julian
221 (list month day year)))))
222 (if (calendar-date-is-visible-p date)
223 (list (list date string)))))))
224
225 (defun calendar-holiday-function-islamic (x)
226 "Returns the corresponding Gregorian date, if visible in the window, to the
227 Islamic date month, day where month is (car X) and day is (car (cdr X)).
228 If it is visible, the value returned is the list (((month day year) string))
229 where string is (car (nthcdr 2 X)). Returns nil if it is not visible in
230 the current calendar window."
231 (let* ((month (eval (car x)))
232 (day (eval (car (cdr x))))
233 (string (eval (car (nthcdr 2 x))))
234 (islamic-date (calendar-islamic-from-absolute
235 (calendar-absolute-from-gregorian
236 (list displayed-month 15 displayed-year))))
237 (m (extract-calendar-month islamic-date))
238 (y (extract-calendar-year islamic-date))
239 (date))
240 (if (< m 1)
241 nil;; Islamic calendar doesn't apply.
242 (increment-calendar-month m y (- 10 month))
243 (if (> m 7);; Islamic date might be visible
244 (let ((date (calendar-gregorian-from-absolute
245 (calendar-absolute-from-islamic (list month day y)))))
246 (if (calendar-date-is-visible-p date)
247 (list (list date string))))))))
248
249 (defun calendar-holiday-function-hebrew (x)
250 "Returns the corresponding Gregorian date, if visible in the window, to the
251 Hebrew date month, day where month is (car X) and day is (car (cdr X)).
252 If it is visible, the value returned is the list (((month day year) string))
253 where string is (car (nthcdr 2 X)). Returns nil if it is not visible in
254 the current calendar window."
255 (let* ((month (eval (car x)))
256 (day (eval (car (cdr x))))
257 (string (eval (car (nthcdr 2 x)))))
258 (if (memq displayed-month;; This test is only to speed things up a bit;
259 (list ;; it works fine without the test too.
260 (if (< 11 month) (- month 11) (+ month 1))
261 (if (< 10 month) (- month 10) (+ month 2))
262 (if (< 9 month) (- month 9) (+ month 3))
263 (if (< 8 month) (- month 8) (+ month 4))
264 (if (< 7 month) (- month 7) (+ month 5))))
265 (let ((m1 displayed-month)
266 (y1 displayed-year)
267 (m2 displayed-month)
268 (y2 displayed-year)
269 (year))
270 (increment-calendar-month m1 y1 -1)
271 (increment-calendar-month m2 y2 1)
272 (let* ((start-date (calendar-absolute-from-gregorian
273 (list m1 1 y1)))
274 (end-date (calendar-absolute-from-gregorian
275 (list m2 (calendar-last-day-of-month m2 y2) y2)))
276 (hebrew-start (calendar-hebrew-from-absolute start-date))
277 (hebrew-end (calendar-hebrew-from-absolute end-date))
278 (hebrew-y1 (extract-calendar-year hebrew-start))
279 (hebrew-y2 (extract-calendar-year hebrew-end)))
280 (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
281 (let ((date (calendar-gregorian-from-absolute
282 (calendar-absolute-from-hebrew
283 (list month day year)))))
284 (if (calendar-date-is-visible-p date)
285 (list (list date string)))))))))
286
287 (defun calendar-holiday-function-if (x)
288 "Conditional holiday for dates in the calendar window.
289 The boolean condition is (car X). If t, the holiday (car (cdr X)) is
290 checked. If nil, the holiday (car (cdr (cdr X))), if there, is checked."
291 (let* ((boolean (eval (car x)))
292 (h (if boolean (car (cdr x)) (car (cdr (cdr x))))))
293 (if h
294 (let* ((function-name
295 (intern (format "calendar-holiday-function-%s" (car h))))
296 (holidays
297 (if (cdr h);; optional arguments
298 (funcall function-name (cdr h))
299 (funcall function-name))))
300 holidays))))
301
302 (defun calendar-holiday-function-advent ()
303 "Date of Advent, if visible in calendar window."
304 (let ((year displayed-year)
305 (month displayed-month))
306 (increment-calendar-month month year -1)
307 (let ((advent (calendar-gregorian-from-absolute
308 (calendar-dayname-on-or-before 0
309 (calendar-absolute-from-gregorian
310 (list 12 3 year))))))
311 (if (calendar-date-is-visible-p advent)
312 (list (list advent "Advent"))))))
313
314 (defun calendar-holiday-function-easter-etc ()
315 "List of dates related to Easter, as visible in calendar window."
316 (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
317 nil;; Ash Wednesday, Good Friday, and Easter are not visible.
318 (let* ((century (1+ (/ displayed-year 100)))
319 (shifted-epact ;; Age of moon for April 5...
320 (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule
321 (- ;; ...corrected for the Gregorian century rule
322 (/ (* 3 century) 4))
323 (/ ;; ...corrected for Metonic cycle inaccuracy.
324 (+ 5 (* 8 century)) 25)
325 (* 30 century));; Keeps value positive.
326 30))
327 (adjusted-epact ;; Adjust for 29.5 day month.
328 (if (or (= shifted-epact 0)
329 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
330 (1+ shifted-epact)
331 shifted-epact))
332 (paschal-moon ;; Day after the full moon on or after March 21.
333 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
334 adjusted-epact))
335 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
336 (mandatory
337 (list
338 (list (calendar-gregorian-from-absolute abs-easter)
339 "Easter Sunday")
340 (list (calendar-gregorian-from-absolute (- abs-easter 2))
341 "Good Friday")
342 (list (calendar-gregorian-from-absolute (- abs-easter 46))
343 "Ash Wednesday")))
344 (optional
345 (list
346 (list (calendar-gregorian-from-absolute (- abs-easter 63))
347 "Septuagesima Sunday")
348 (list (calendar-gregorian-from-absolute (- abs-easter 56))
349 "Sexagesima Sunday")
350 (list (calendar-gregorian-from-absolute (- abs-easter 49))
351 "Shrove Sunday")
352 (list (calendar-gregorian-from-absolute (- abs-easter 48))
353 "Shrove Monday")
354 (list (calendar-gregorian-from-absolute (- abs-easter 47))
355 "Shrove Tuesday")
356 (list (calendar-gregorian-from-absolute (- abs-easter 14))
357 "Passion Sunday")
358 (list (calendar-gregorian-from-absolute (- abs-easter 7))
359 "Palm Sunday")
360 (list (calendar-gregorian-from-absolute (- abs-easter 3))
361 "Maundy Thursday")
362 (list (calendar-gregorian-from-absolute (+ abs-easter 35))
363 "Rogation Sunday")
364 (list (calendar-gregorian-from-absolute (+ abs-easter 39))
365 "Ascension Sunday")
366 (list (calendar-gregorian-from-absolute (+ abs-easter 49))
367 "Pentecost (Whitsunday)")
368 (list (calendar-gregorian-from-absolute (+ abs-easter 50))
369 "Whitmunday")
370 (list (calendar-gregorian-from-absolute (+ abs-easter 56))
371 "Trinity Sunday")
372 (list (calendar-gregorian-from-absolute (+ abs-easter 60))
373 "Corpus Christi")))
374 (output-list
375 (filter-visible-calendar-holidays mandatory)))
376 (if all-christian-calendar-holidays
377 (setq output-list
378 (append
379 (filter-visible-calendar-holidays optional)
380 output-list)))
381 output-list)))
382
383 (defun calendar-holiday-function-rosh-hashanah-etc ()
384 "List of dates related to Rosh Hashanah, as visible in calendar window."
385 (if (or (< displayed-month 8)
386 (> displayed-month 11))
387 nil;; None of the dates is visible
388 (let* ((abs-r-h (calendar-absolute-from-hebrew
389 (list 7 1 (+ displayed-year 3761))))
390 (mandatory
391 (list
392 (list (calendar-gregorian-from-absolute abs-r-h)
393 (format "Rosh HaShanah %d" (+ 3761 displayed-year)))
394 (list (calendar-gregorian-from-absolute (+ abs-r-h 9))
395 "Yom Kippur")
396 (list (calendar-gregorian-from-absolute (+ abs-r-h 14))
397 "Sukkot")
398 (list (calendar-gregorian-from-absolute (+ abs-r-h 21))
399 "Shemini Atzeret")
400 (list (calendar-gregorian-from-absolute (+ abs-r-h 22))
401 "Simchat Torah")))
402 (optional
403 (list
404 (list (calendar-gregorian-from-absolute
405 (calendar-dayname-on-or-before 6 (- abs-r-h 4)))
406 "Selichot (night)")
407 (list (calendar-gregorian-from-absolute (1- abs-r-h))
408 "Erev Rosh HaShannah")
409 (list (calendar-gregorian-from-absolute (1+ abs-r-h))
410 "Rosh HaShanah (second day)")
411 (list (calendar-gregorian-from-absolute
412 (if (= (% abs-r-h 7) 4) (+ abs-r-h 3) (+ abs-r-h 2)))
413 "Tzom Gedaliah")
414 (list (calendar-gregorian-from-absolute
415 (calendar-dayname-on-or-before 6 (+ 7 abs-r-h)))
416 "Shabbat Shuvah")
417 (list (calendar-gregorian-from-absolute (+ abs-r-h 8))
418 "Erev Yom Kippur")
419 (list (calendar-gregorian-from-absolute (+ abs-r-h 13))
420 "Erev Sukkot")
421 (list (calendar-gregorian-from-absolute (+ abs-r-h 15))
422 "Sukkot (second day)")
423 (list (calendar-gregorian-from-absolute (+ abs-r-h 16))
424 "Hol Hamoed Sukkot (first day)")
425 (list (calendar-gregorian-from-absolute (+ abs-r-h 17))
426 "Hol Hamoed Sukkot (second day)")
427 (list (calendar-gregorian-from-absolute (+ abs-r-h 18))
428 "Hol Hamoed Sukkot (third day)")
429 (list (calendar-gregorian-from-absolute (+ abs-r-h 19))
430 "Hol Hamoed Sukkot (fourth day)")
431 (list (calendar-gregorian-from-absolute (+ abs-r-h 20))
432 "Hoshannah Rabbah")))
433 (output-list
434 (filter-visible-calendar-holidays mandatory)))
435 (if all-hebrew-calendar-holidays
436 (setq output-list
437 (append
438 (filter-visible-calendar-holidays optional)
439 output-list)))
440 output-list)))
441
442 (defun calendar-holiday-function-hanukkah ()
443 "List of dates related to Hanukkah, as visible in calendar window."
444 (if (memq displayed-month;; This test is only to speed things up a bit;
445 '(10 11 12 1 2));; it works fine without the test too.
446 (let ((m displayed-month)
447 (y displayed-year))
448 (increment-calendar-month m y 1)
449 (let* ((h-y (extract-calendar-year
450 (calendar-hebrew-from-absolute
451 (calendar-absolute-from-gregorian
452 (list m (calendar-last-day-of-month m y) y)))))
453 (abs-h (calendar-absolute-from-hebrew (list 9 25 h-y))))
454 (filter-visible-calendar-holidays
455 (list
456 (list (calendar-gregorian-from-absolute (1- abs-h))
457 "Erev Hanukkah")
458 (list (calendar-gregorian-from-absolute abs-h)
459 "Hanukkah (first day)")
460 (list (calendar-gregorian-from-absolute (1+ abs-h))
461 "Hanukkah (second day)")
462 (list (calendar-gregorian-from-absolute (+ abs-h 2))
463 "Hanukkah (third day)")
464 (list (calendar-gregorian-from-absolute (+ abs-h 3))
465 "Hanukkah (fourth day)")
466 (list (calendar-gregorian-from-absolute (+ abs-h 4))
467 "Hanukkah (fifth day)")
468 (list (calendar-gregorian-from-absolute (+ abs-h 5))
469 "Hanukkah (sixth day)")
470 (list (calendar-gregorian-from-absolute (+ abs-h 6))
471 "Hanukkah (seventh day)")
472 (list (calendar-gregorian-from-absolute (+ abs-h 7))
473 "Hanukkah (eighth day)")))))))
474
475 (defun calendar-holiday-function-passover-etc ()
476 "List of dates related to Passover, as visible in calendar window."
477 (if (< 7 displayed-month)
478 nil;; None of the dates is visible
479 (let* ((abs-p (calendar-absolute-from-hebrew
480 (list 1 15 (+ displayed-year 3760))))
481 (mandatory
482 (list
483 (list (calendar-gregorian-from-absolute abs-p)
484 "Passover")
485 (list (calendar-gregorian-from-absolute (+ abs-p 50))
486 "Shavuot")))
487 (optional
488 (list
489 (list (calendar-gregorian-from-absolute
490 (calendar-dayname-on-or-before 6 (- abs-p 43)))
491 "Shabbat Shekalim")
492 (list (calendar-gregorian-from-absolute
493 (calendar-dayname-on-or-before 6 (- abs-p 30)))
494 "Shabbat Zachor")
495 (list (calendar-gregorian-from-absolute
496 (if (= (% abs-p 7) 2) (- abs-p 33) (- abs-p 31)))
497 "Fast of Esther")
498 (list (calendar-gregorian-from-absolute (- abs-p 31))
499 "Erev Purim")
500 (list (calendar-gregorian-from-absolute (- abs-p 30))
501 "Purim")
502 (list (calendar-gregorian-from-absolute
503 (if (zerop (% abs-p 7)) (- abs-p 28) (- abs-p 29)))
504 "Shushan Purim")
505 (list (calendar-gregorian-from-absolute
506 (- (calendar-dayname-on-or-before 6 (- abs-p 14)) 7))
507 "Shabbat Parah")
508 (list (calendar-gregorian-from-absolute
509 (calendar-dayname-on-or-before 6 (- abs-p 14)))
510 "Shabbat HaHodesh")
511 (list (calendar-gregorian-from-absolute
512 (calendar-dayname-on-or-before 6 (1- abs-p)))
513 "Shabbat HaGadol")
514 (list (calendar-gregorian-from-absolute (1- abs-p))
515 "Erev Passover")
516 (list (calendar-gregorian-from-absolute (1+ abs-p))
517 "Passover (second day)")
518 (list (calendar-gregorian-from-absolute (+ abs-p 2))
519 "Hol Hamoed Passover (first day)")
520 (list (calendar-gregorian-from-absolute (+ abs-p 3))
521 "Hol Hamoed Passover (second day)")
522 (list (calendar-gregorian-from-absolute (+ abs-p 4))
523 "Hol Hamoed Passover (third day)")
524 (list (calendar-gregorian-from-absolute (+ abs-p 5))
525 "Hol Hamoed Passover (fourth day)")
526 (list (calendar-gregorian-from-absolute (+ abs-p 6))
527 "Passover (seventh day)")
528 (list (calendar-gregorian-from-absolute (+ abs-p 7))
529 "Passover (eighth day)")
530 (list (calendar-gregorian-from-absolute (+ abs-p 12))
531 "Yom HaShoah")
532 (list (calendar-gregorian-from-absolute
533 (if (zerop (% abs-p 7))
534 (+ abs-p 18)
535 (if (= (% abs-p 7) 6)
536 (+ abs-p 19)
537 (+ abs-p 20))))
538 "Yom HaAtzma'ut")
539 (list (calendar-gregorian-from-absolute (+ abs-p 33))
540 "Lag BaOmer")
541 (list (calendar-gregorian-from-absolute (+ abs-p 43))
542 "Yom Yerushalim")
543 (list (calendar-gregorian-from-absolute (+ abs-p 49))
544 "Erev Shavuot")
545 (list (calendar-gregorian-from-absolute (+ abs-p 51))
546 "Shavuot (second day)")))
547 (output-list
548 (filter-visible-calendar-holidays mandatory)))
549 (if all-hebrew-calendar-holidays
550 (setq output-list
551 (append
552 (filter-visible-calendar-holidays optional)
553 output-list)))
554 output-list)))
555
556 (defun calendar-holiday-function-tisha-b-av-etc ()
557 "List of dates around Tisha B'Av, as visible in calendar window."
558 (if (or (< displayed-month 5)
559 (> displayed-month 9))
560 nil;; None of the dates is visible
561 (let* ((abs-t-a (calendar-absolute-from-hebrew
562 (list 5 9 (+ displayed-year 3760)))))
563
564 (filter-visible-calendar-holidays
565 (list
566 (list (calendar-gregorian-from-absolute
567 (if (= (% abs-t-a 7) 6) (- abs-t-a 20) (- abs-t-a 21)))
568 "Tzom Tammuz")
569 (list (calendar-gregorian-from-absolute
570 (calendar-dayname-on-or-before 6 abs-t-a))
571 "Shabbat Hazon")
572 (list (calendar-gregorian-from-absolute
573 (if (= (% abs-t-a 7) 6) (1+ abs-t-a) abs-t-a))
574 "Tisha B'Av")
575 (list (calendar-gregorian-from-absolute
576 (calendar-dayname-on-or-before 6 (+ abs-t-a 7)))
577 "Shabbat Nahamu"))))))
578
579 (defun filter-visible-calendar-holidays (l)
580 "Return a list of all visible holidays of those on L."
581 (let ((visible)
582 (p l))
583 (while p
584 (if (calendar-date-is-visible-p (car (car p)))
585 (setq visible (append (list (car p)) visible)))
586 (setq p (cdr p)))
587 visible))