Mercurial > emacs
annotate lisp/calendar/holidays.el @ 34360:c6d74397e65f
(tparam1): Change the way buffers are reallocated to be
portable and less obfuscated.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 08 Dec 2000 09:58:48 +0000 |
parents | d179de7ad92e |
children | 6098465deff0 |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; holidays.el --- holiday functions for the calendar package |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
2 |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
3 ;; Copyright (C) 1989, 90, 92, 93, 94, 1997 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> |
957 | 6 ;; Keywords: holidays, calendar |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
7 |
406 | 8 ;; This file is part of GNU Emacs. |
9 | |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
13 ;; any later version. |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
14 |
406 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
18 ;; GNU General Public License for more details. |
406 | 19 |
6736
3e1323443b1a
Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents:
5831
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
406 | 24 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
25 ;;; Commentary: |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
26 |
406 | 27 ;; This collection of functions implements the holiday features as described |
28 ;; in calendar.el. | |
29 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
30 ;; Technical details of all the calendrical calculations can be found in |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
31 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold, |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
32 ;; Cambridge University Press (1997). |
406 | 33 |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
34 ;; An earlier version of the technical details appeared in |
406 | 35 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold, |
36 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990), | |
957 | 37 ;; pages 899-928. ``Calendrical Calculations, Part II: Three Historical |
38 ;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen, | |
2945
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
957
diff
changeset
|
39 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993), |
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
957
diff
changeset
|
40 ;; pages 383-404. |
957 | 41 |
42 ;; Hard copies of these two papers can be obtained by sending email to | |
43 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and | |
44 ;; the message BODY containing your mailing address (snail). | |
406 | 45 |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
46 ;; Comments, corrections, and improvements should be sent to |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
47 ;; Edward M. Reingold Department of Computer Science |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
48 ;; (217) 333-6733 University of Illinois at Urbana-Champaign |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
49 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
50 ;; Urbana, Illinois 61801 |
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
17891
diff
changeset
|
51 |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
52 ;;; Code: |
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
53 |
406 | 54 (require 'calendar) |
732 | 55 |
13043
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
56 (autoload 'holiday-julian "cal-julian" |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
57 "Holiday on MONTH, DAY (Julian) called STRING." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
58 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
59 |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
60 (autoload 'holiday-hebrew "cal-hebrew" |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
61 "Holiday on MONTH, DAY (Hebrew) called STRING." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
62 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
63 |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
64 (autoload 'holiday-rosh-hashanah-etc "cal-hebrew" |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
65 "List of dates related to Rosh Hashanah, as visible in calendar window." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
66 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
67 |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
68 (autoload 'holiday-hanukkah "cal-hebrew" |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
69 "List of dates related to Hanukkah, as visible in calendar window." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
70 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
71 |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
72 (autoload 'holiday-passover-etc "cal-hebrew" |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
73 "List of dates related to Passover, as visible in calendar window." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
74 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
75 |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
76 (autoload 'holiday-tisha-b-av-etc "cal-hebrew" |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
77 "List of dates around Tisha B'Av, as visible in calendar window." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
78 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
79 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14318
diff
changeset
|
80 (autoload 'holiday-islamic "cal-islam" |
13043
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
81 "Holiday on MONTH, DAY (Islamic) called STRING." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
82 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
83 |
14687
0d4ff7e4d6a3
Use the new file names in autoloads.
Karl Heuer <kwzh@gnu.org>
parents:
14318
diff
changeset
|
84 (autoload 'holiday-chinese-new-year "cal-china" |
13043
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
85 "Date of Chinese New Year." |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
86 t) |
2072d3ab4119
Moved stuff to other files.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
9712
diff
changeset
|
87 |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
88 (autoload 'solar-equinoxes-solstices "solar" |
957 | 89 "Date and time of equinoxes and solstices, if visible in the calendar window. |
90 Requires floating point." | |
91 t) | |
92 | |
93 (defun holidays (&optional arg) | |
406 | 94 "Display the holidays for last month, this month, and next month. |
957 | 95 If called with an optional prefix argument, prompts for month and year. |
96 | |
406 | 97 This function is suitable for execution in a .emacs file." |
957 | 98 (interactive "P") |
406 | 99 (save-excursion |
957 | 100 (let* ((completion-ignore-case t) |
9712
275845a98fa8
Use new form of calendar-read-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7639
diff
changeset
|
101 (date (if arg |
275845a98fa8
Use new form of calendar-read-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7639
diff
changeset
|
102 (calendar-read-date t) |
275845a98fa8
Use new form of calendar-read-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7639
diff
changeset
|
103 (calendar-current-date))) |
275845a98fa8
Use new form of calendar-read-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7639
diff
changeset
|
104 (displayed-month (extract-calendar-month date)) |
275845a98fa8
Use new form of calendar-read-date.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
7639
diff
changeset
|
105 (displayed-year (extract-calendar-year date))) |
406 | 106 (list-calendar-holidays)))) |
107 | |
17388
5c4602f0c45d
(list-holidays): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
17385
diff
changeset
|
108 ;;;###autoload |
17385
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
109 (defun list-holidays (y1 y2 &optional l label) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
110 "Display holidays for years Y1 to Y2 (inclusive). |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
111 |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
112 The optional list of holidays L defaults to `calendar-holidays'. See the |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
113 documentation for that variable for a description of holiday lists. |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
114 |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
115 The optional LABEL is used to label the buffer created." |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
116 (interactive |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
117 (let* ((start-year (calendar-read |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
118 "Starting year of holidays (>0): " |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
119 '(lambda (x) (> x 0)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
120 (int-to-string (extract-calendar-year |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
121 (calendar-current-date))))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
122 (end-year (calendar-read |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
123 (format "Ending year (inclusive) of holidays (>=%s): " |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
124 start-year) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
125 '(lambda (x) (>= x start-year)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
126 (int-to-string start-year))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
127 (completion-ignore-case t) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
128 (lists |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
129 (list |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
130 (cons "All" calendar-holidays) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
131 (if (fboundp 'atan) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
132 (cons "Equinoxes/Solstices" |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
133 (list (list 'solar-equinoxes-solstices)))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
134 (if general-holidays (cons "General" general-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
135 (if local-holidays (cons "Local" local-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
136 (if other-holidays (cons "Other" other-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
137 (if christian-holidays (cons "Christian" christian-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
138 (if hebrew-holidays (cons "Hebrew" hebrew-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
139 (if islamic-holidays (cons "Islamic" islamic-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
140 (if oriental-holidays (cons "Oriental" oriental-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
141 (if solar-holidays (cons "Solar" solar-holidays)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
142 (cons "Ask" nil))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
143 (choice (capitalize |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
144 (completing-read "List (TAB for choices): " lists nil t))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
145 (which (if (string-equal choice "Ask") |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
146 (eval (read-variable "Enter list name: ")) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
147 (cdr (assoc choice lists)))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
148 (name (if (string-equal choice "Equinoxes/Solstices") |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
149 choice |
17643
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
150 (if (member choice '("Ask" "")) |
17385
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
151 "Holidays" |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
152 (format "%s Holidays" choice))))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
153 (list start-year end-year which name))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
154 (message "Computing holidays...") |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
155 (let* ((holiday-buffer "*Holidays*") |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
156 (calendar-holidays (if l l calendar-holidays)) |
17643
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
157 (title (or label "Holidays")) |
17385
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
158 (holiday-list nil) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
159 (s (calendar-absolute-from-gregorian (list 2 1 y1))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
160 (e (calendar-absolute-from-gregorian (list 11 1 y2))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
161 (d s) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
162 (never t) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
163 (displayed-month 2) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
164 (displayed-year y1)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
165 (while (or never (<= d e)) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
166 (setq holiday-list (append holiday-list (calendar-holiday-list))) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
167 (setq never nil) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
168 (increment-calendar-month displayed-month displayed-year 3) |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
169 (setq d (calendar-absolute-from-gregorian |
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
170 (list displayed-month 1 displayed-year)))) |
17643
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
171 (save-excursion |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
172 (set-buffer (get-buffer-create holiday-buffer)) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
173 (setq buffer-read-only nil) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
174 (calendar-set-mode-line |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
175 (if (= y1 y2) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
176 (format "%s for %s" title y1) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
177 (format "%s for %s-%s" title y1 y2))) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
178 (erase-buffer) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
179 (goto-char (point-min)) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
180 (insert |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
181 (mapconcat |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
182 '(lambda (x) (concat (calendar-date-string (car x)) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
183 ": " (car (cdr x)))) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
184 holiday-list "\n")) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
185 (goto-char (point-min)) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
186 (set-buffer-modified-p nil) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
187 (setq buffer-read-only t) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
188 (display-buffer holiday-buffer) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
189 (message "Computing holidays...done")))) |
fd27882450bd
(list-holidays): Fix buffer title when list is
Richard M. Stallman <rms@gnu.org>
parents:
17388
diff
changeset
|
190 |
17385
259d4c9aae0e
(list-holidays): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14687
diff
changeset
|
191 |
406 | 192 (defun check-calendar-holidays (date) |
193 "Check the list of holidays for any that occur on DATE. | |
194 The value returned is a list of strings of relevant holiday descriptions. | |
195 The holidays are those in the list calendar-holidays." | |
196 (let* ((displayed-month (extract-calendar-month date)) | |
197 (displayed-year (extract-calendar-year date)) | |
198 (h (calendar-holiday-list)) | |
199 (holiday-list)) | |
200 (while h | |
201 (if (calendar-date-equal date (car (car h))) | |
202 (setq holiday-list (append holiday-list (cdr (car h))))) | |
203 (setq h (cdr h))) | |
204 holiday-list)) | |
205 | |
206 (defun calendar-cursor-holidays () | |
207 "Find holidays for the date specified by the cursor in the calendar window." | |
208 (interactive) | |
209 (message "Checking holidays...") | |
5831
7a4647230b22
(calendar-cursor-holidays): Use new error arg
Richard M. Stallman <rms@gnu.org>
parents:
5696
diff
changeset
|
210 (let* ((date (calendar-cursor-to-date t)) |
406 | 211 (date-string (calendar-date-string date)) |
212 (holiday-list (check-calendar-holidays date)) | |
213 (holiday-string (mapconcat 'identity holiday-list "; ")) | |
214 (msg (format "%s: %s" date-string holiday-string))) | |
215 (if (not holiday-list) | |
216 (message "No holidays known for %s" date-string) | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
217 (if (<= (length msg) (frame-width)) |
14318
faae84d059c1
(calendar-cursor-holidays): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
218 (message "%s" msg) |
406 | 219 (set-buffer (get-buffer-create holiday-buffer)) |
220 (setq buffer-read-only nil) | |
957 | 221 (calendar-set-mode-line date-string) |
406 | 222 (erase-buffer) |
223 (insert (mapconcat 'identity holiday-list "\n")) | |
224 (goto-char (point-min)) | |
225 (set-buffer-modified-p nil) | |
226 (setq buffer-read-only t) | |
227 (display-buffer holiday-buffer) | |
228 (message "Checking holidays...done"))))) | |
229 | |
230 (defun mark-calendar-holidays () | |
231 "Mark notable days in the calendar window." | |
232 (interactive) | |
233 (setq mark-holidays-in-calendar t) | |
234 (message "Marking holidays...") | |
235 (let ((holiday-list (calendar-holiday-list))) | |
236 (while holiday-list | |
237 (mark-visible-calendar-date | |
238 (car (car holiday-list)) calendar-holiday-marker) | |
239 (setq holiday-list (cdr holiday-list)))) | |
240 (message "Marking holidays...done")) | |
241 | |
242 (defun list-calendar-holidays () | |
243 "Create a buffer containing the holidays for the current calendar window. | |
244 The holidays are those in the list calendar-notable-days. Returns t if any | |
245 holidays are found, nil if not." | |
246 (interactive) | |
247 (message "Looking up holidays...") | |
248 (let ((holiday-list (calendar-holiday-list)) | |
249 (m1 displayed-month) | |
250 (y1 displayed-year) | |
251 (m2 displayed-month) | |
252 (y2 displayed-year)) | |
253 (if (not holiday-list) | |
254 (progn | |
255 (message "Looking up holidays...none found") | |
256 nil) | |
257 (set-buffer (get-buffer-create holiday-buffer)) | |
258 (setq buffer-read-only nil) | |
259 (increment-calendar-month m1 y1 -1) | |
260 (increment-calendar-month m2 y2 1) | |
957 | 261 (calendar-set-mode-line |
5696
baab03aaf3b9
(list-calendar-holidays): Fix mode line.
Richard M. Stallman <rms@gnu.org>
parents:
4864
diff
changeset
|
262 (if (= y1 y2) |
baab03aaf3b9
(list-calendar-holidays): Fix mode line.
Richard M. Stallman <rms@gnu.org>
parents:
4864
diff
changeset
|
263 (format "Notable Dates from %s to %s, %d%%-" |
baab03aaf3b9
(list-calendar-holidays): Fix mode line.
Richard M. Stallman <rms@gnu.org>
parents:
4864
diff
changeset
|
264 (calendar-month-name m1) (calendar-month-name m2) y2) |
baab03aaf3b9
(list-calendar-holidays): Fix mode line.
Richard M. Stallman <rms@gnu.org>
parents:
4864
diff
changeset
|
265 (format "Notable Dates from %s, %d to %s, %d%%-" |
baab03aaf3b9
(list-calendar-holidays): Fix mode line.
Richard M. Stallman <rms@gnu.org>
parents:
4864
diff
changeset
|
266 (calendar-month-name m1) y1 (calendar-month-name m2) y2))) |
406 | 267 (erase-buffer) |
268 (insert | |
269 (mapconcat | |
270 '(lambda (x) (concat (calendar-date-string (car x)) | |
271 ": " (car (cdr x)))) | |
272 holiday-list "\n")) | |
273 (goto-char (point-min)) | |
274 (set-buffer-modified-p nil) | |
275 (setq buffer-read-only t) | |
276 (display-buffer holiday-buffer) | |
277 (message "Looking up holidays...done") | |
278 t))) | |
279 | |
280 (defun calendar-holiday-list () | |
281 "Form the list of holidays that occur on dates in the calendar window. | |
282 The holidays are those in the list calendar-holidays." | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
283 (let ((p calendar-holidays) |
406 | 284 (holiday-list)) |
285 (while p | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
286 (let* ((holidays |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
287 (if calendar-debug-sexp |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
288 (let ((stack-trace-on-error t)) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
289 (eval (car p))) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
290 (condition-case nil |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
291 (eval (car p)) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
292 (error (beep) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
293 (message "Bad holiday list item: %s" (car p)) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
294 (sleep-for 2)))))) |
406 | 295 (if holidays |
296 (setq holiday-list (append holidays holiday-list)))) | |
297 (setq p (cdr p))) | |
298 (setq holiday-list (sort holiday-list 'calendar-date-compare)))) | |
299 | |
300 ;; Below are the functions that calculate the dates of holidays; these | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
301 ;; are eval'ed in the function calendar-holiday-list. If you |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
302 ;; write other such functions, be sure to imitate the style used below. |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
303 ;; Remember that each function must return a list of items of the form |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
304 ;; ((month day year) string) of VISIBLE dates in the calendar window. |
406 | 305 |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
306 (defun holiday-fixed (month day string) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
307 "Holiday on MONTH, DAY (Gregorian) called STRING. |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
308 If MONTH, DAY is visible, the value returned is the list (((MONTH DAY year) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
309 STRING)). Returns nil if it is not visible in the current calendar window." |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
310 (let ((m displayed-month) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
311 (y displayed-year)) |
406 | 312 (increment-calendar-month m y (- 11 month)) |
313 (if (> m 9) | |
314 (list (list (list month day y) string))))) | |
315 | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
316 (defun holiday-float (month dayname n string &optional day) |
17891
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
317 "Holiday on MONTH, DAYNAME (Nth occurrence) called STRING. |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
318 If the Nth DAYNAME in MONTH is visible, the value returned is the list |
7639 | 319 \(((MONTH DAY year) STRING)). |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
320 |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
321 If N<0, count backward from the end of MONTH. |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
322 |
17891
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
323 An optional parameter DAY means the Nth DAYNAME on or after/before MONTH DAY. |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
324 |
406 | 325 Returns nil if it is not visible in the current calendar window." |
17891
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
326 ;; This is messy because the holiday may be visible, while the date on which |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
327 ;; it is based is not. For example, the first Monday after December 30 may be |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
328 ;; visible when January is not. For large values of |n| the problem is more |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
329 ;; grotesque. If we didn't have to worry about such cases, we could just use |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
330 |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
331 ;; (let ((m displayed-month) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
332 ;; (y displayed-year)) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
333 ;; (increment-calendar-month m y (- 11 month)) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
334 ;; (if (> m 9); month in year y is visible |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
335 ;; (list (list (calendar-nth-named-day n dayname month y day) string))))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
336 |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
337 ;; which is the way the function was originally written. |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
338 |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
339 (let* ((m1 displayed-month) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
340 (y1 displayed-year) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
341 (m2 m1) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
342 (y2 y1)) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
343 (increment-calendar-month m1 y1 -1) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
344 (increment-calendar-month m2 y2 1) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
345 (let* ((d1; first possible base date for holiday |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
346 (+ (calendar-nth-named-absday 1 dayname m1 y1) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
347 (* -7 n) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
348 (if (> n 0) 1 -7))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
349 (d2; last possible base date for holiday |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
350 (+ (calendar-nth-named-absday -1 dayname m2 y2) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
351 (* -7 n) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
352 (if (> n 0) 7 -1))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
353 (y1 (extract-calendar-year (calendar-gregorian-from-absolute d1))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
354 (y2 (extract-calendar-year (calendar-gregorian-from-absolute d2))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
355 (y; year of base date |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
356 (if (or (= y1 y2) (> month 9)) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
357 y1 |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
358 y2)) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
359 (d; day of base date |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
360 (or day (if (> n 0) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
361 1 |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
362 (calendar-last-day-of-month month y)))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
363 (date; base date for holiday |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
364 (calendar-absolute-from-gregorian (list month d y)))) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
365 (if (and (<= d1 date) (<= date d2)) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
366 (list (list (calendar-nth-named-day n dayname month y d) |
6eb7095ca7ab
(holiday-float): Rewritten to fix bug when base date
Richard M. Stallman <rms@gnu.org>
parents:
17643
diff
changeset
|
367 string)))))) |
406 | 368 |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
369 (defun holiday-sexp (sexp string) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
370 "Sexp holiday for dates in the calendar window. |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
371 SEXP is an expression in variable `year' evaluates to `date'. |
406 | 372 |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
373 STRING is an expression in `date' that evaluates to the holiday description |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
374 of `date'. |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
375 |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
376 If `date' is visible in the calendar window, the holiday STRING is on that |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
377 date. If date is nil, or if the date is not visible, there is no holiday." |
957 | 378 (let ((m displayed-month) |
379 (y displayed-year)) | |
380 (increment-calendar-month m y -1) | |
381 (filter-visible-calendar-holidays | |
382 (append | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
383 (let* ((year y) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
384 (date (eval sexp)) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
385 (string (if date (eval string)))) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
386 (list (list date string))) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
387 (let* ((year (1+ y)) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
388 (date (eval sexp)) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
389 (string (if date (eval string)))) |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
390 (list (list date string))))))) |
957 | 391 |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
392 (defun holiday-advent () |
406 | 393 "Date of Advent, if visible in calendar window." |
394 (let ((year displayed-year) | |
395 (month displayed-month)) | |
396 (increment-calendar-month month year -1) | |
397 (let ((advent (calendar-gregorian-from-absolute | |
398 (calendar-dayname-on-or-before 0 | |
399 (calendar-absolute-from-gregorian | |
400 (list 12 3 year)))))) | |
401 (if (calendar-date-is-visible-p advent) | |
402 (list (list advent "Advent")))))) | |
403 | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
404 (defun holiday-easter-etc () |
406 | 405 "List of dates related to Easter, as visible in calendar window." |
406 (if (and (> displayed-month 5) (not all-christian-calendar-holidays)) | |
407 nil;; Ash Wednesday, Good Friday, and Easter are not visible. | |
408 (let* ((century (1+ (/ displayed-year 100))) | |
409 (shifted-epact ;; Age of moon for April 5... | |
410 (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule | |
411 (- ;; ...corrected for the Gregorian century rule | |
412 (/ (* 3 century) 4)) | |
413 (/ ;; ...corrected for Metonic cycle inaccuracy. | |
414 (+ 5 (* 8 century)) 25) | |
415 (* 30 century));; Keeps value positive. | |
416 30)) | |
417 (adjusted-epact ;; Adjust for 29.5 day month. | |
418 (if (or (= shifted-epact 0) | |
419 (and (= shifted-epact 1) (< 10 (% displayed-year 19)))) | |
420 (1+ shifted-epact) | |
421 shifted-epact)) | |
422 (paschal-moon ;; Day after the full moon on or after March 21. | |
423 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year)) | |
424 adjusted-epact)) | |
425 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7))) | |
426 (mandatory | |
427 (list | |
428 (list (calendar-gregorian-from-absolute abs-easter) | |
429 "Easter Sunday") | |
430 (list (calendar-gregorian-from-absolute (- abs-easter 2)) | |
431 "Good Friday") | |
432 (list (calendar-gregorian-from-absolute (- abs-easter 46)) | |
433 "Ash Wednesday"))) | |
434 (optional | |
435 (list | |
436 (list (calendar-gregorian-from-absolute (- abs-easter 63)) | |
437 "Septuagesima Sunday") | |
438 (list (calendar-gregorian-from-absolute (- abs-easter 56)) | |
439 "Sexagesima Sunday") | |
440 (list (calendar-gregorian-from-absolute (- abs-easter 49)) | |
441 "Shrove Sunday") | |
442 (list (calendar-gregorian-from-absolute (- abs-easter 48)) | |
443 "Shrove Monday") | |
444 (list (calendar-gregorian-from-absolute (- abs-easter 47)) | |
445 "Shrove Tuesday") | |
446 (list (calendar-gregorian-from-absolute (- abs-easter 14)) | |
447 "Passion Sunday") | |
448 (list (calendar-gregorian-from-absolute (- abs-easter 7)) | |
449 "Palm Sunday") | |
450 (list (calendar-gregorian-from-absolute (- abs-easter 3)) | |
451 "Maundy Thursday") | |
452 (list (calendar-gregorian-from-absolute (+ abs-easter 35)) | |
453 "Rogation Sunday") | |
454 (list (calendar-gregorian-from-absolute (+ abs-easter 39)) | |
4864
4bfa62882154
(holiday-easter-etc): Fix Ascension Day string.
Richard M. Stallman <rms@gnu.org>
parents:
3870
diff
changeset
|
455 "Ascension Day") |
406 | 456 (list (calendar-gregorian-from-absolute (+ abs-easter 49)) |
457 "Pentecost (Whitsunday)") | |
458 (list (calendar-gregorian-from-absolute (+ abs-easter 50)) | |
13669
e411b827878f
(holiday-easter-etc): Fix misspelling of "Whitmonday".
Paul Eggert <eggert@twinsun.com>
parents:
13043
diff
changeset
|
459 "Whitmonday") |
406 | 460 (list (calendar-gregorian-from-absolute (+ abs-easter 56)) |
461 "Trinity Sunday") | |
462 (list (calendar-gregorian-from-absolute (+ abs-easter 60)) | |
463 "Corpus Christi"))) | |
464 (output-list | |
465 (filter-visible-calendar-holidays mandatory))) | |
466 (if all-christian-calendar-holidays | |
467 (setq output-list | |
468 (append | |
469 (filter-visible-calendar-holidays optional) | |
470 output-list))) | |
471 output-list))) | |
472 | |
3870
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
473 (defun holiday-greek-orthodox-easter () |
4acdfdf2a7c9
* holidays.el (calendar-holiday-function-fixed,
Jim Blandy <jimb@redhat.com>
parents:
3728
diff
changeset
|
474 "Date of Easter according to the rule of the Council of Nicaea." |
957 | 475 (let ((m displayed-month) |
476 (y displayed-year)) | |
477 (increment-calendar-month m y 1) | |
478 (let* ((julian-year | |
479 (extract-calendar-year | |
480 (calendar-julian-from-absolute | |
481 (calendar-absolute-from-gregorian | |
482 (list m (calendar-last-day-of-month m y) y))))) | |
483 (shifted-epact ;; Age of moon for April 5. | |
484 (% (+ 14 | |
485 (* 11 (% julian-year 19))) | |
486 30)) | |
487 (paschal-moon ;; Day after full moon on or after March 21. | |
488 (- (calendar-absolute-from-julian (list 4 19 julian-year)) | |
489 shifted-epact)) | |
490 (nicaean-easter;; Sunday following the Paschal moon | |
491 (calendar-gregorian-from-absolute | |
492 (calendar-dayname-on-or-before 0 (+ paschal-moon 7))))) | |
493 (if (calendar-date-is-visible-p nicaean-easter) | |
494 (list (list nicaean-easter "Pascha (Greek Orthodox Easter)")))))) | |
495 | |
406 | 496 (defun filter-visible-calendar-holidays (l) |
497 "Return a list of all visible holidays of those on L." | |
498 (let ((visible) | |
499 (p l)) | |
500 (while p | |
2945
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
957
diff
changeset
|
501 (and (car (car p)) |
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
957
diff
changeset
|
502 (calendar-date-is-visible-p (car (car p))) |
2c1f0215fcc3
* holidays.el: Update reference to the papers in S-P&E.
Jim Blandy <jimb@redhat.com>
parents:
957
diff
changeset
|
503 (setq visible (append (list (car p)) visible))) |
406 | 504 (setq p (cdr p))) |
505 visible)) | |
584 | 506 |
507 (provide 'holidays) | |
508 | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
509 ;;; holidays.el ends here |