annotate lisp/calendar/calendar.el @ 657:fec3f9a1e3e5

*** empty log message ***
author Eric S. Raymond <esr@snark.thyrsus.com>
date Sat, 30 May 1992 20:24:49 +0000
parents ab209803a494
children 85fd29f25c75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
628
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; Calendar functions.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is distributed in the hope that it will be useful,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; but WITHOUT ANY WARRANTY. No author or distributor
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; accepts responsibility to anyone for the consequences of using it
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; or for whether it serves any particular purpose or works at all,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; unless he says so in writing. Refer to the GNU Emacs General Public
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; License for full details.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; Everyone is granted permission to copy, modify and redistribute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs, but only under the conditions described in the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs General Public License. A copy of this license is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; supposed to have been given to you along with GNU Emacs so you
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; can know your rights and responsibilities. It should be in a
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; file named COPYING. Among other things, the copyright notice
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; and this notice must be preserved on all copies.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; This collection of functions implements a calendar window. It generates
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; generates a calendar for the current month, together with the previous and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; coming months, or for any other three-month period. The calendar can be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; scrolled forward and backward in the window to show months in the past or
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; future; the cursor can move forward and backward by days, weeks, or months,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; making it possible, for instance, to jump to the date a specified number of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; days, weeks, or months from the date under the cursor. The user can
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; display a list of holidays and other notable days for the period shown; the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; notable days can be marked on the calendar, if desired. The user can also
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; specify that dates having corresponding diary entries (in a file that the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; user specifies) be marked; the diary entries for any date can be viewed in
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; a separate window. The diary and the notable days can be viewed
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; independently of the calendar. Dates can be translated from the (usual)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Gregorian calendar to the day of the year/days remaining in year, to the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; ISO commercial calendar, to the Julian (old style) calendar, to the Hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; calendar, to the Islamic calendar, and to the French Revolutionary calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; The diary related functions are in diary.el; the holiday related functions
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; are in holiday.el
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; Comments, corrections, and improvements should be sent to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; Edward M. Reingold Department of Computer Science
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; Urbana, Illinois 61801
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; GNU Emacs users too numerous to list pointed out a variety of problems
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; with earlier forms of the `infinite' sliding calendar and suggested some
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; of the features included in this package. Especially significant in this
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; regard was the suggestion of mark-diary-entries and view-diary-entries,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; together ideas for their implementation, by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; Michael S. Littman Cognitive Science Research Group
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; (201) 829-5155 Bell Communications Research
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; mlittman@wind.bellcore.com 445 South St. Box 1961 (2L-331)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; Morristown, NJ 07960
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; The algorithms for the Hebrew calendar are those of the Rambam (Rabbi Moses
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; Maimonides), from his Mishneh Torah, as implemented by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; Nachum Dershowitz Department of Computer Science
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; (217) 333-4219 University of Illinois at Urbana-Champaign
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; nachum@cs.uiuc.edu 1304 West Springfield Avenue
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; Urbana, Illinois 61801
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; Technical details of all the calendrical calculations can be found in
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; pages 899-928.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (defconst calendar-version "Version 4.01, released August 20, 1991")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (defvar view-diary-entries-initially nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 "*If T, the diary entries for the current date will be displayed on entry.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 The diary is displayed in another window when the calendar is first displayed,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 if the current date is visible. The number of days of diary entries displayed
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 is governed by the variable `number-of-diary-entries'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (defvar number-of-diary-entries 1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "*Specifies how many days of diary entries are to be displayed initially.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 This variable affects the diary display when the command M-x diary is used,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 or if the value of the variable `view-diary-entries-initially' is t. For
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 example, if the default value 1 is used, then only the current day's diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 entries will be displayed. If the value 2 is used, then both the current
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 day's and the next day's entries will be displayed. The value can also be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 a vector such as [0 2 2 2 2 4 1]; this value will cause no diary entries to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 be displayed on Sunday, the current date's and the next day's diary entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 to be displayed Monday through Thursday, Friday through Monday's entries to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 be displayed on Friday, and only Saturday's entries to be displayed on
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 Saturday. This variable does not affect the diary display with the `d'
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 command from the calendar; in that case, the prefix argument controls the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 number of days of diary entries displayed.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defvar mark-diary-entries-in-calendar nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "*If t, dates with diary entries will be marked in the calendar window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 The marking symbol is specified by the variable `diary-entry-marker'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (defvar diary-entry-marker "+"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 "*The symbol used to mark dates that have diary entries.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defvar view-calendar-holidays-initially nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "*If t, the holidays for the current three month period will be displayed
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 on entry. The holidays are displayed in another window when the calendar is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 first displayed.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defvar mark-holidays-in-calendar nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 "*If t, dates of holidays will be marked in the calendar window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 The marking symbol is specified by the variable `calendar-holiday-marker'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defvar calendar-holiday-marker "*"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "*The symbol used to mark notable dates in the calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defvar all-hebrew-calendar-holidays nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "*If nil, the holidays from the Hebrew calendar that are shown will
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 include only those days of such major interest as to appear on secular
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 calendars. If t, the holidays shown in the calendar will include all
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 special days that would be shown on a complete Hebrew calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (defvar all-christian-calendar-holidays nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 "*If nil, the holidays from the Christian calendar that are shown will
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 include only those days of such major interest as to appear on secular
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 calendars. If t, the holidays shown in the calendar will include all
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 special days that would be shown on a complete Christian calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defvar all-islamic-calendar-holidays nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 "*If nil, the holidays from the Islamic calendar that are shown will
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 include only those days of such major interest as to appear on secular
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 calendars. If t, the holidays shown in the calendar will include all
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 special days that would be shown on a complete Islamic calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defvar initial-calendar-window-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 "*List of functions to be called when the calendar window is first opened.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 The functions invoked are called after the calendar window is opened, but
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 once opened is never called again. Leaving the calendar with the `q' command
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 and reentering it will cause these functions to be called again.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (defvar today-visible-calendar-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 "*List of functions called whenever the current date is visible.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 This can be used, for example, to replace today's date with asterisks; a
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 function `calendar-star-date' is included for this purpose:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (setq today-visible-calendar-hook 'calendar-star-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 It could also be used to mark the current date with `='; a function is also
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 provided for this:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (setq today-visible-calendar-hook 'calendar-mark-today)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 The corresponding variable `today-invisible-calendar-hook' is the list of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 functions called when the calendar function was called when the current
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 date is not visible in the window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 Other than the use of the provided functions, the changing of any
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 characters in the calendar buffer by the hooks may cause the failure of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 functions that move by days and weeks.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (defvar today-invisible-calendar-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 "*List of functions called whenever the current date is not visible.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 The corresponding variable `today-visible-calendar-hook' is the list of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 functions called when the calendar function was called when the current
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 date is visible in the window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 Other than the use of the provided functions, the changing of any
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 characters in the calendar buffer by the hooks may cause the failure of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 functions that move by days and weeks.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (defvar diary-file "~/diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 "*Name of the file in which one's personal diary of dates is kept.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 The file's entries are lines in any of the forms
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 MONTH/DAY
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 MONTH/DAY/YEAR
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 MONTHNAME DAY
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 MONTHNAME DAY, YEAR
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 DAYNAME
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 at the beginning of the line; the remainder of the line is the diary entry
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 string for that date. MONTH and DAY are one or two digit numbers, YEAR is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 a number and may be written in full or abbreviated to the final two digits.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 If the date does not contain a year, it is generic and applies to any year.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 DAYNAME entries apply to any date on which is on that day of the week.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 MONTHNAME and DAYNAME can be spelled in full, abbreviated to three
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 characters (with or without a period), capitalized or not. Any of DAY,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 MONTH, or MONTHNAME, YEAR can be `*' which matches any day, month, or year,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 respectively.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 The European style (in which the day precedes the month) can be used
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 instead, if you execute `european-calendar' when in the calendar, or set
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 `european-calendar-style' to t in your .emacs file. The European forms are
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 DAY/MONTH
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 DAY/MONTH/YEAR
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 DAY MONTHNAME
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 DAY MONTHNAME YEAR
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 DAYNAME
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 To revert to the default American style from the European style, execute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 `american-calendar' in the calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 A diary entry can be preceded by a diary-nonmarking-symbol (ordinarily `&')
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 to make that entry nonmarking--that is, it will not be marked on dates in
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 the calendar window but will appear in a diary window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 Multiline diary entries are made by indenting lines after the first with
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 either a TAB or one or more spaces.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 Lines not in one the above formats are ignored. Here are some sample diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 entries (in the default American style):
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 12/22/1988 Twentieth wedding anniversary!!
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 &1/1. Happy New Year!
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 10/22 Ruth's birthday.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 21: Payday
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 Tuesday--weekly meeting with grad students at 10am
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 Supowit, Shen, Bitner, and Kapoor to attend.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 1/13/89 Friday the thirteenth!!
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 &thu 4pm squash game with Lloyd.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 mar 16 Dad's birthday
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 April 15, 1989 Income tax due.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 &* 15 time cards due.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 If the first line of a diary entry consists only of the date or day name with
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 no trailing blanks or punctuation, then that line will not be displayed in the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 diary window; only the continuation lines will be shown. For example, the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 single diary entry
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 02/11/1989
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 Bill Blattner visits Princeton today
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 2pm Cognitive Studies Committee meeting
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 4:00pm Jamie Tappenden
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 7:30pm Dinner at George and Ed's for Alan Ryan
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 7:30-10:00pm dance at Stewart Country Day School
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 will appear in the diary window without the date line at the beginning. This
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 facility allows the diary window to look neater, but can cause confusion if
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 used with more than one day's entries displayed.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 Diary entries can be based on Lisp sexps. For example, the diary entry
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 %%(diary-block 11 1 1990 11 10 1990) Vacation
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 causes the diary entry \"Vacation\" to appear from November 1 through November
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 10, 1990. Other functions available are `diary-float', `diary-anniversary',
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 `diary-cyclic', `day-of-year', `iso-date', `commercial-date', `french-date',
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 `hebrew-date', `islamic-date', `parasha', `omer', and `rosh-hodesh'. See the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 documentation for the function `list-sexp-diary-entries' for more details.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 Diary entries based on the Hebrew and/or the Islamic calendar are also
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 possible, but because these are somewhat slow, they are ignored
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 unless you set the `nongregorian-diary-listing-hook' and the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 `nongregorian-diary-marking-hook' appropriately. See the documentation
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 for these functions for details.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 Diary files can contain directives to include the contents of other files; for
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 details, see the documentation for the variable `list-diary-entries-hook'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (defvar diary-nonmarking-symbol "&"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 "*The symbol used to indicate that a diary entry is not to be marked in the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 calendar window.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (defvar hebrew-diary-entry-symbol "H"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 "*The symbol used to indicate that a diary entry is according to the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 Hebrew calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (defvar islamic-diary-entry-symbol "I"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 "*The symbol used to indicate that a diary entry is according to the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 Islamic calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (defvar diary-include-string "#include"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 "*The string used to indicate the inclusion of another file of diary entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 in diary-file. See the documentation for the function
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 `include-other-diary-files'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (defvar sexp-diary-entry-symbol "%%"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 "*The string used to indicate a sexp diary entry in diary-file.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 See the documentation for the function `list-sexp-diary-entries'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (defvar abbreviated-calendar-year t
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 "*Interpret a two-digit year DD in a diary entry as being either 19DD or
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 20DD, as appropriate, for the Gregorian calendar; similarly for the Hebrew and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 Islamic calendars. If this variable is nil, years must be written in full.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (defvar european-calendar-style nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 "*Use the European style of dates in the diary and in any displays. If this
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 variable is t, a date 1/2/1990 would be interpreted as February 1, 1990.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 The accepted European date styles are
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 DAY/MONTH
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 DAY/MONTH/YEAR
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 DAY MONTHNAME
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 DAY MONTHNAME YEAR
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 DAYNAME
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 Names can be capitalized or not, written in full, or abbreviated to three
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 characters with or without a period.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (defvar american-date-diary-pattern
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 '((month "/" day "[^/0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (month "/" day "/" year "[^0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (monthname " *" day "[^,0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (monthname " *" day ", *" year "[^0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (dayname "\\W"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 "*List of pseudo-patterns describing the American patterns of date used.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 See the documentation of diary-date-forms for an explanantion.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (defvar european-date-diary-pattern
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 '((day "/" month "[^/0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (day "/" month "/" year "[^0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (backup day " *" monthname "\\W+\\<[^*0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (day " *" monthname " *" year "[^0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (dayname "\\W"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 "*List of pseudo-patterns describing the European patterns of date used.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 See the documentation of diary-date-forms for an explanantion.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (defvar diary-date-forms
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (if european-calendar-style
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 european-date-diary-pattern
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 american-date-diary-pattern)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 "*List of pseudo-patterns describing the forms of date used in the diary.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 The patterns on the list must be MUTUALLY EXCLUSIVE and must should not match
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 any portion of the diary entry itself, just the date component.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 A pseudo-pattern is a list of regular expressions and the keywords `month',
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 `day', `year', `monthname', and `dayname'. The keyword `monthname' will
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 match the name of the month, capitalized or not, or its three-letter
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 abbreviation, followed by a period or not; it will also match `*'.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 Similarly, `dayname' will match the name of the day, capitalized or not, or
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 its three-letter abbreviation, followed by a period or not. The keywords
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 `month', `day', and `year' will match those numerical values, preceded by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 arbitrarily many zeros; they will also match `*'.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 The matching of the diary entries with the date forms is done with the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 standard syntax table from Fundamental mode, but with the `*' changed so
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 that it is a word constituent.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 If, to be mutually exclusive, a pseudo-pattern must match a portion of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 diary entry itself, the first element of the pattern MUST be `backup'. This
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 directive causes the the date recognizer to back up to the beginning of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 current word of the diary entry, so in no case can the pattern match more
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 than a portion of the first word of the diary entry.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (defvar european-calendar-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 '(dayname ", " day " " monthname " " year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 "*The pseudo-pattern that governs the way a Gregorian date is formatted
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 in the European style. See the documentation of calendar-date-display-forms
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 for an explanantion.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (defvar american-calendar-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 '(dayname ", " monthname " " day ", " year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 "*The pseudo-pattern that governs the way a Gregorian date is formatted
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 in the American style. See the documentation of calendar-date-display-forms
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 for an explanantion.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (defvar calendar-date-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (if european-calendar-style
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 european-calendar-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 american-calendar-display-form)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 "*The pseudo-pattern that governs the way a Gregorian date is formatted
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 as a string by the function `calendar-date-string'. A pseudo-pattern is a
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 list of expressions that can involve the keywords `month', `day', and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 `year', all numbers in string form, and `monthname' and `dayname', both
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 alphabetic strings. For example, the ISO standard would use the pseudo-
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 pattern
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 '(year \"-\" month \"-\" day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 while a typical American form would be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 '(month \"/\" day \"/\" (substring year -2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 would give the usual American style in fixed-length fields.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 See the documentation of the function `calendar-date-string'.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (defun european-calendar ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 "Set the interpretation and display of dates to the European style."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (setq european-calendar-style t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (setq calendar-date-display-form european-calendar-display-form)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (setq diary-date-forms european-date-diary-pattern)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (update-calendar-mode-line))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (defun american-calendar ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 "Set the interpretation and display of dates to the American style."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (setq european-calendar-style nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (setq calendar-date-display-form american-calendar-display-form)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (setq diary-date-forms american-date-diary-pattern)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (update-calendar-mode-line))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (defvar print-diary-entries-hook
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 '(add-diary-heading lpr-buffer (lambda nil (kill-buffer temp-buffer)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 "*List of functions to be called after a temporary buffer is prepared
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 with the diary entries currently visible in the diary buffer. The default
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 value adds a heading (formed from the information in the mode line of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 diary buffer), does the printing, and kills the buffer. Other uses might
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 include, for example, rearranging the lines into order by day and time,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 saving the buffer instead of deleting it, or changing the function used to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 do the printing.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (defvar list-diary-entries-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 "*List of functions to be called after the diary file is culled for
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 relevant entries. It is to be used for diary entries that are not found in
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 the diary file.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 A function `include-other-diary-files' is provided for use as the value of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 this hook. This function enables you to use shared diary files together
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 with your own. The files included are specified in the diary-file by lines
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 of the form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 #include \"filename\"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 This is recursive; that is, #include directives in files thus included are
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 obeyed. You can change the \"#include\" to some other string by changing
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 the variable `diary-include-string'. When you use `include-other-diary-files'
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 as part of the list-diary-entries-hook, you will probably also want to use the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 function `mark-included-diary-files' as part of the mark-diary-entries-hook.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 For example, you could use
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq list-diary-entries-hook
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 '(include-other-diary-files
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (lambda nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (setq diary-entries-list
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (sort diary-entries-list 'diary-entry-compare)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (setq diary-display-hook 'fancy-diary-display)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 in your .emacs file to cause the fancy diary buffer to be displayed with
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 diary entries from various included files, each day's entries sorted into
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 lexicographic order.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (defvar diary-display-hook 'simple-diary-display
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 "*List of functions that handle the display of the diary.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 Ordinarily, this just displays the diary buffer (with holidays indicated in
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 the mode line), if there are any relevant entries. At the time these
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 functions are called, the variable `diary-entries-list' is a list, in order
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 by date, of all relevant diary entries in the form of ((MONTH DAY YEAR)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 STRING), where string is the diary entry for the given date. This can be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 used, for example, to handle appointment notification, prepare a different
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 buffer for display (perhaps combined with holidays), or produce hard copy
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 output.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 A function `fancy-diary-display' is provided as an alternative
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 choice for this hook; this function prepares a special noneditable diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 buffer with the relevant diary entries that has neat day-by-day arrangement
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 with headings. The fancy diary buffer will show the holidays unless the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 variable `holidays-in-diary-buffer' is set to nil. Ordinarily, the fancy
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 diary buffer will not show days for which there are no diary entries, even
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 if that day is a holiday; if you want such days to be shown in the fancy
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 diary buffer, set the variable `diary-list-include-blanks' to t.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (defvar nongregorian-diary-listing-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 "*List of functions to be called for the diary file and included files as
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 they are processed for listing diary entries. You can use any or all of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 `list-hebrew-diary-entries', `yahrzeit-diary-entry', and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 `list-islamic-diary-entries'. The documentation for these functions
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 describes the style of such diary entries.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (defvar mark-diary-entries-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 "*List of functions called after marking diary entries in the calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 A function `mark-included-diary-files' is also provided for use as the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 mark-diary-entries-hook; it enables you to use shared diary files together
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 with your own. The files included are specified in the diary-file by lines
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 of the form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 #include \"filename\"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 This is recursive; that is, #include directives in files thus included are
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 obeyed. You can change the \"#include\" to some other string by changing the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 variable `diary-include-string'. When you use `mark-included-diary-files' as
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 part of the mark-diary-entries-hook, you will probably also want to use the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 function `include-other-diary-files' as part of the list-diary-entries-hook.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (defvar nongregorian-diary-marking-hook nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 "*List of functions to be called as the diary file and included files are
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 processed for marking diary entries. You can use either or both of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 mark-hebrew-diary-entries and mark-islamic-diary-entries. The documentation
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 for these functions describes the style of such diary entries.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (defvar diary-list-include-blanks nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 "*If nil, do not include days with no diary entry in the list of diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 entries. Such days will then not be shown in the the fancy diary buffer,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 even if they are holidays.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (defvar holidays-in-diary-buffer t
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 "*If t, the holidays will be indicated in the mode line of the diary buffer
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (or in the fancy diary buffer next to the date). This slows down the diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 functions somewhat; setting it to nil will make the diary display faster.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (defvar calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 '(
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 ;; General Holidays (American)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (fixed 1 1 "New Year's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (float 1 1 3 "Martin Luther King Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (fixed 2 2 "Ground Hog Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (fixed 2 14 "Valentine's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (float 2 1 3 "President's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (fixed 3 17 "St. Patrick's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (fixed 4 1 "April Fool's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (float 4 0 1 "Daylight Savings Time Begins")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (float 5 0 2 "Mother's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (float 5 1 -1 "Memorial Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (fixed 6 14 "Flag Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (float 6 0 3 "Father's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (fixed 7 4 "Independence Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (float 9 1 1 "Labor Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (float 10 1 2 "Columbus Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (float 10 0 -1 "Daylight Savings Time Ends")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (fixed 10 31 "Halloween")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (fixed 11 11 "Veteran's Day")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (float 11 4 4 "Thanksgiving")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 ;; Christian Holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (if all-christian-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (fixed 1 6 "Epiphany"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (easter-etc)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (if all-christian-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (fixed 8 15 "Assumption"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (if all-christian-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (advent))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (fixed 12 25 "Christmas")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (if all-christian-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (julian 12 25 "Eastern Orthodox Christmas"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 ;; Jewish Holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (rosh-hashanah-etc)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (if all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (julian 11
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (let* ((m displayed-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (y displayed-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (increment-calendar-month m y -1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (let ((year (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (calendar-julian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (list m 1 y))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (if (zerop (% (1+ year) 4))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 22
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 21))) "\"Tal Umatar\" (evening)"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (if all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (hanukkah)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (hebrew 9 25 "Hanukkah"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (if all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (hebrew 10
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (let ((h-year (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (calendar-hebrew-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (list displayed-month 28 displayed-year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (if (= (% (calendar-absolute-from-hebrew (list 10 10 h-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 7)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 6)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 11 10))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 "Tzom Teveth"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (if all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (hebrew 11 15 "Tu B'Shevat"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (if all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 11
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (let ((m displayed-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (y displayed-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (increment-calendar-month m y 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (let* ((h-year (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (calendar-hebrew-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (list m
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (calendar-last-day-of-month m y)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 y)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (s-s
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (calendar-hebrew-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (if (=
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (% (calendar-absolute-from-hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (list 7 1 h-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 7)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 6)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 6 (calendar-absolute-from-hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (list 11 17 h-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 6 (calendar-absolute-from-hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (list 11 16 h-year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (day (extract-calendar-day s-s)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 day))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 "Shabbat Shirah"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (passover-etc)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (if (and all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (let* ((m displayed-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (y displayed-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (increment-calendar-month m y -1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 (let ((year (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (calendar-julian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (list m 1 y))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (= 21 (% year 28)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (julian 3 26 "Kiddush HaHamah"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (if all-hebrew-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (tisha-b-av-etc))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 ;; Islamic Holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (islamic 1 1 (format "Islamic New Year %d"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (let ((m displayed-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (y displayed-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (increment-calendar-month m y 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (calendar-islamic-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (list m (calendar-last-day-of-month m y) y)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (islamic 1 10 "Ashura"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (islamic 3 12 "Mulad-al-Nabi"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (islamic 7 26 "Shab-e-Mi'raj"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 (islamic 8 15 "Shab-e-Bara't"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (islamic 9 1 "Ramadan Begins")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (islamic 9 27 "Shab-e Qadr"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (islamic 10 1 "Id-al-Fitr"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (if all-islamic-calendar-holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (islamic 12 10 "Id-al-Adha")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 "List of notable days for the command M-x holidays.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 Additional holidays are easy to add to the list. The possible holiday-forms
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 are as follows:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 (fixed MONTH DAY STRING) a fixed date on the Gregorian calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (float MONTH DAYNAME K STRING) the Kth DAYNAME in MONTH on the Gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 calendar (0 for Sunday, etc.); K<0 means
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 count back from the end of the month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (islamic MONTH DAY STRING) a fixed date on the Islamic calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 (julian MONTH DAY STRING) a fixed date on the Julian calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (if BOOLEAN HOLIDAY-FORM &optional HOLIDAY-FORM) gives a choice between
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 two holidays based on the value of BOOLEAN
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (FUNCTION &optional ARGS) dates requiring special computation; ARGS,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 if any, are passed in a list to the function
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 `calendar-holiday-function-FUNCTION'
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 For example, to add Bastille Day, celebrated in France on July 14, add
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (fixed 7 14 \"Bastille Day\")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 to the list. To add Hurricane Supplication Day, celebrated in the Virgin
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 Islands on the fourth Monday in August, add
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (float 8 1 4 \"Hurricane Supplication Day\")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 to the list (the last Monday would be specified with `-1' instead of `4').
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 To add the last day of Hanukah to the list, use
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (hebrew 10 2 \"Last day of Hanukah\")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 since the Hebrew months are numbered with 1 starting from Nisan, while to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 add the Islamic feast celebrating Mohammed's birthday use
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (islamic 3 12 \"Mohammed's Birthday\")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 since the Islamic months are numbered from 1 starting with Muharram. To
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (julian 4 2 \"Jefferson's Birthday\")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 To include a holiday conditionally, use the if form. For example, to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 include American presidential elections, which occur on the first Tuesday
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 after the first Monday in November of years divisble by 4, add
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (if (zerop (% displayed-year 4))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (fixed 11
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (extract-calendar-day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (1+ (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 1 (+ 6 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (list 11 1 displayed-year)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 \"US Presidential Election\"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 to the list. To include the phases of the moon, add
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 (lunar-phases)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 to the holiday list, where `calendar-holiday-function-lunar-phases' is an
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 Emacs-Lisp function that you've written to return a (possibly empty) list of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 the relevant VISIBLE dates with descriptive strings such as
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... )
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 The fixed, float, hebrew, islamic, julian and if forms are implemented by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 the inclusion of the functions `calendar-holiday-function-fixed',
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 `calendar-holiday-function-float', `calendar-holiday-function-hebrew',
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 `calendar-holiday-function-islamic', `calendar-holiday-function-julian',
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 and `calendar-holiday-function-if', respectively.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 (defconst calendar-buffer "*Calendar*"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 "Name of the buffer used for the calendar.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (defconst holiday-buffer "*Holidays*"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 "Name of the buffer used for the displaying the holidays.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (defconst fancy-diary-buffer "*Fancy Diary Entries*"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 "Name of the buffer used for the optional fancy display of the diary.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 (defmacro increment-calendar-month (mon yr n)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 "Move the variables MON and YR to the month and year N months forward
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 if N is positive or backward if N is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (` (let (( macro-y (+ (* (, yr) 12) (, mon) -1 (, n) )))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (setq (, mon) (1+ (% macro-y 12) ))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (setq (, yr) (/ macro-y 12)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (defmacro calendar-for-loop (var from init to final do &rest body)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 "Execute a for loop."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (` (let (( (, var) (1- (, init)) ))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (while (>= (, final) (setq (, var) (1+ (, var))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (,@ body)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (defmacro calendar-sum (index initial condition expression)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 "For INDEX = INITIAL and successive integers, as long as CONDITION holds,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 sum EXPRESSION."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (` (let (( (, index) (, initial))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (sum 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (while (, condition)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (setq sum (+ sum (, expression) ))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (setq (, index) (1+ (, index))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 sum)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (defmacro extract-calendar-month (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 "Extract the month part of DATE which has the form (month day year)."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (` (car (, date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (defmacro extract-calendar-day (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 "Extract the day part of DATE which has the form (month day year)."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (` (car (cdr (, date)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (defmacro extract-calendar-year (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 "Extract the year part of DATE which has the form (month day year)."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (` (car (cdr (cdr (, date))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 (defun calendar (&optional arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 "Display a three-month calendar in another window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 The three months appear side by side, with the current month in the middle
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 surrounded by the previous and next months. The cursor is put on today's date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 This function is suitable for execution in a .emacs file; appropriate setting
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 of the variable `view-diary-entries-initially' will cause the diary entries for
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 the current date to be displayed in another window. The value of the variable
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 `number-of-diary-entries' controls the number of days of diary entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 displayed upon initial display of the calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 An optional prefix argument ARG causes the calendar displayed to be ARG
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 months in the future if ARG is positive or in the past if ARG is negative;
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 in this case the cursor goes on the first day of the month.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 Once in the calendar window, future or past months can be moved into view.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 Arbitrary months can be displayed, or the calendar can be scrolled forward
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 or backward.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 The cursor can be moved forward or backward by one day, one week, one month,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 or one year. All of these commands take prefix arguments which, when negative,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 cause movement in the opposite direction. For convenience, the digit keys
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 and the minus sign are automatically prefixes. The window is replotted as
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 necessary to display the desired date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 Diary entries can be marked on the calendar or displayed in another window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 Use M-x describe-mode for details of the key bindings in the calendar window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 The Gregorian calendar is assumed.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 After preparing the calendar window initially, the hooks given by the variable
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 `initial-calendar-window-hook' are run.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 The hooks given by the variable `today-visible-calendar-hook' are run
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 everytime the calendar window gets scrolled, if the current date is visible
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 in the window. If it is not visible, the hooks given by the variable
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 `today-invisible-calendar-hook' are run. Thus, for example, setting
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 `today-visible-calendar-hook' to 'calendar-star-date will cause today's date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 to be replaced by asterisks to highlight it whenever it is in the window."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (interactive "P")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 (setq arg (if arg (prefix-numeric-value arg) 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (set-buffer (get-buffer-create calendar-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (calendar-mode)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (setq calendar-window-configuration (current-window-configuration))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (let ((pop-up-windows t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (split-height-threshold 1000))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (pop-to-buffer calendar-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 (regenerate-calendar-window arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 (let ((date (list current-month current-day current-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (if (and view-diary-entries-initially (calendar-date-is-visible-p date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (view-diary-entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (if (vectorp number-of-diary-entries)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 (aref number-of-diary-entries (calendar-day-of-week date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 number-of-diary-entries))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (let* ((diary-buffer (get-file-buffer diary-file))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (split-height-threshold (if diary-window 2 1000)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (if view-calendar-holidays-initially
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 (list-calendar-holidays))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (run-hooks 'initial-calendar-window-hook))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (autoload 'view-diary-entries "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 "Prepare and display a buffer with diary entries.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 Searches the file diary-file for entries that match ARG days starting with
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 the date indicated by the cursor position in the displayed three-month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 calendar."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (autoload 'show-all-diary-entries "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 "Show all of the diary entries in the diary-file.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 This function gets rid of the selective display of the diary-file so that
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 all entries, not just some, are visible. If there is no diary buffer, one
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 is created."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (autoload 'mark-diary-entries "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 "Mark days in the calendar window that have diary entries.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 Each entry in diary-file visible in the calendar window is marked."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 (autoload 'insert-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 "Insert a diary entry for the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 (autoload 'insert-weekly-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 "Insert a weekly diary entry for the day of the week indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 (autoload 'insert-monthly-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 "Insert a monthly diary entry for the day of the month indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 (autoload 'insert-yearly-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 "Insert an annual diary entry for the day of the year indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 (autoload 'insert-anniversary-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 "Insert an anniversary diary entry for the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 (autoload 'insert-block-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 "Insert a block diary entry for the dates indicated by point and mark."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 (autoload 'insert-cyclic-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 "Insert a cyclic diary entry starting at the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 (autoload 'insert-hebrew-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850 "Insert a diary entry for the Hebrew date corresponding to the date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851 indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 (autoload 'insert-monthly-hebrew-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 "Insert a monthly diary entry for the day of the Hebrew month corresponding
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856 to the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 (autoload 'insert-yearly-hebrew-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 "Insert an annual diary entry for the day of the Hebrew year corresponding
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 to the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 (autoload 'insert-islamic-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 "Insert a diary entry for the Islamic date corresponding to the date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 (autoload 'insert-monthly-islamic-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870 "Insert a monthly diary entry for the day of the Islamic month corresponding
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871 to the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 (autoload 'insert-yearly-islamic-diary-entry "diary"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 "Insert an annual diary entry for the day of the Islamic year corresponding
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 to the date indicated by point."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
878
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 (autoload 'list-calendar-holidays "holidays"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 "Create a buffer containing the holidays for the current calendar window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 The holidays are those in the list `calendar-notable-days'. Returns t if any
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 holidays are found, nil if not."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885 (autoload 'mark-calendar-holidays "holidays"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 "Mark notable days in the calendar window."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 (autoload 'calendar-cursor-holidays "holidays"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 "Find holidays for the date specified by the cursor in the calendar window."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 (defun regenerate-calendar-window (&optional arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 "Generate the calendar window, offset from the current date by ARG months."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 (if (not arg) (setq arg 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 (let* ((buffer-read-only nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 (today-visible (and (<= arg 1) (>= arg -1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 (today (calendar-current-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 (month (extract-calendar-month today))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (day (extract-calendar-day today))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 (year (extract-calendar-year today))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 (day-in-week (calendar-day-of-week today)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 (update-calendar-mode-line)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 (setq current-month month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 (setq current-day day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 (setq current-year year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 (increment-calendar-month month year arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 (generate-calendar month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 (calendar-cursor-to-visible-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 (if today-visible today (list displayed-month 1 displayed-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 (set-buffer-modified-p nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 (or (one-window-p t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 (/= (screen-width) (window-width))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 (shrink-window (- (window-height) 9)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 (sit-for 0)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 (and mark-holidays-in-calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 (mark-calendar-holidays)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 (sit-for 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 (unwind-protect
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 (if mark-diary-entries-in-calendar (mark-diary-entries))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 (if today-visible
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 (run-hooks 'today-visible-calendar-hook)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 (run-hooks 'today-invisible-calendar-hook)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 (defun generate-calendar (month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 (if (< (+ month (* 12 (1- year))) 2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 (error "Months before February, 1 AD are not available."))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 (setq displayed-month month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 (setq displayed-year year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 (erase-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 (increment-calendar-month month year -1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 (calendar-for-loop i from 0 to 2 do
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 (generate-calendar-month month year (+ 5 (* 25 i)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 (increment-calendar-month month year 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 (defun generate-calendar-month (month year indent)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 "Produce a calendar for MONTH, YEAR on the Gregorian calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939 The calendar is inserted in the buffer starting at the line on which point
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 is currently located, but indented INDENT spaces. The indentation is done
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 from the first character on the line and does not disturb the first INDENT
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 characters on the line."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 (let* ((first-day-of-month (calendar-day-of-week (list month 1 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 (first-saturday (- 7 first-day-of-month))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 (last (calendar-last-day-of-month month year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 (goto-char (point-min))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947 (calendar-insert-indented
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 (format " %s %d" (calendar-month-name month) year) indent t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 (calendar-insert-indented " S M Tu W Th F S" indent t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (calendar-insert-indented "" indent);; Move to appropriate spot on line
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951 ;; Add blank days before the first of the month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 (calendar-for-loop i from 1 to first-day-of-month do
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 (insert " "))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 ;; Put in the days of the month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955 (calendar-for-loop i from 1 to last do
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 (insert (format "%2d " i))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 (and (= (% i 7) (% first-saturday 7))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 (/= i last)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 (calendar-insert-indented "" 0 t) ;; Force onto following line
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 (calendar-insert-indented "" indent)))));; Go to proper spot
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962 (defun calendar-insert-indented (string indent &optional newline)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
963 "Insert STRING at column INDENT.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
964 If the optional parameter NEWLINE is t, leave point at start of next line,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
965 inserting a newline if there was no next line; otherwise, leave point after
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 the inserted text. Value is always t."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967 ;; Try to move to that column.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968 (move-to-column indent)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
969 ;; If line is too short, indent out to that column.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 (if (< (current-column) indent)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 (indent-to indent))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 (insert string)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 ;; Advance to next line, if requested.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974 (if newline
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 (end-of-line)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977 (if (eobp)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 (newline)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 (forward-line 1))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 (defun redraw-calendar ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 "Redraw the calendar display."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 (let ((cursor-date (calendar-cursor-to-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 (regenerate-calendar-window
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 (calendar-interval current-month current-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 displayed-month displayed-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 (calendar-cursor-to-visible-date cursor-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 (defvar calendar-mode-map nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 (if calendar-mode-map
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 (setq calendar-mode-map (make-sparse-keymap))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 (calendar-for-loop i from 0 to 9 do
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (define-key calendar-mode-map (int-to-string i) 'digit-argument))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 (let ((l (list 'narrow-to-region 'mark-word 'mark-sexp 'mark-paragraph
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 'mark-defun 'mark-whole-buffer 'mark-page 'kill-region
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 'copy-region-as-kill 'downcase-region 'upcase-region
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 'capitalize-region 'write-region)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 (while (car l)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 (let ((k (where-is-internal (car l))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 (while (car k)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 (define-key calendar-mode-map (car k) 'calendar-not-implemented)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 (setq k (cdr k)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 (setq l (cdr l)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 (define-key calendar-mode-map "-" 'negative-argument)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 (define-key calendar-mode-map "\C-x>" 'scroll-calendar-right)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (define-key calendar-mode-map "\ev" 'scroll-calendar-right-three-months)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 (define-key calendar-mode-map "\C-x<" 'scroll-calendar-left)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 (define-key calendar-mode-map "\C-v" 'scroll-calendar-left-three-months)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 (define-key calendar-mode-map "\C-b" 'calendar-backward-day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 (define-key calendar-mode-map "\C-p" 'calendar-backward-week)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 (define-key calendar-mode-map "\e[" 'calendar-backward-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 (define-key calendar-mode-map "\C-x[" 'calendar-backward-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 (define-key calendar-mode-map "\C-f" 'calendar-forward-day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 (define-key calendar-mode-map "\C-n" 'calendar-forward-week)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 (define-key calendar-mode-map "\e]" 'calendar-forward-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (define-key calendar-mode-map "\C-x]" 'calendar-forward-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 (define-key calendar-mode-map "\C-a" 'calendar-beginning-of-week)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 (define-key calendar-mode-map "\C-e" 'calendar-end-of-week)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 (define-key calendar-mode-map "\ea" 'calendar-beginning-of-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 (define-key calendar-mode-map "\ee" 'calendar-end-of-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 (define-key calendar-mode-map "\e<" 'calendar-beginning-of-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 (define-key calendar-mode-map "\e>" 'calendar-end-of-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 (define-key calendar-mode-map "\C-@" 'calendar-set-mark)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 (define-key calendar-mode-map "\C-x\C-x" 'calendar-exchange-point-and-mark)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 (define-key calendar-mode-map "\e=" 'calendar-count-days-region)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 (define-key calendar-mode-map "gd" 'calendar-goto-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 (define-key calendar-mode-map "gJ" 'calendar-goto-julian-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 (define-key calendar-mode-map "gH" 'calendar-goto-hebrew-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 (define-key calendar-mode-map "gI" 'calendar-goto-islamic-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 (define-key calendar-mode-map "gC" 'calendar-goto-iso-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 (define-key calendar-mode-map " " 'scroll-other-window)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 (define-key calendar-mode-map "\C-c\C-l" 'redraw-calendar)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 (define-key calendar-mode-map "c" 'calendar-current-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1037 (define-key calendar-mode-map "o" 'calendar-other-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 (define-key calendar-mode-map "q" 'exit-calendar)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 (define-key calendar-mode-map "a" 'list-calendar-holidays)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 (define-key calendar-mode-map "h" 'calendar-cursor-holidays)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 (define-key calendar-mode-map "x" 'mark-calendar-holidays)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 (define-key calendar-mode-map "u" 'calendar-unmark)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 (define-key calendar-mode-map "m" 'mark-diary-entries)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 (define-key calendar-mode-map "d" 'view-diary-entries)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 (define-key calendar-mode-map "s" 'show-all-diary-entries)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 (define-key calendar-mode-map "D" 'cursor-to-calendar-day-of-year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 (define-key calendar-mode-map "C" 'cursor-to-iso-calendar-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 (define-key calendar-mode-map "J" 'cursor-to-julian-calendar-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 (define-key calendar-mode-map "H" 'cursor-to-hebrew-calendar-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 (define-key calendar-mode-map "I" 'cursor-to-islamic-calendar-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 (define-key calendar-mode-map "F" 'cursor-to-french-calendar-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 (define-key calendar-mode-map "\C-cd" 'insert-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 (define-key calendar-mode-map "\C-cw" 'insert-weekly-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 (define-key calendar-mode-map "\C-cm" 'insert-monthly-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055 (define-key calendar-mode-map "\C-cy" 'insert-yearly-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 (define-key calendar-mode-map "\C-ca" 'insert-anniversary-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 (define-key calendar-mode-map "\C-cb" 'insert-block-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 (define-key calendar-mode-map "\C-cc" 'insert-cyclic-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 (define-key calendar-mode-map "\C-cHd" 'insert-hebrew-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 (define-key calendar-mode-map "\C-cHm" 'insert-monthly-hebrew-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 (define-key calendar-mode-map "\C-cHy" 'insert-yearly-hebrew-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 (define-key calendar-mode-map "\C-cId" 'insert-islamic-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 (define-key calendar-mode-map "\C-cIm" 'insert-monthly-islamic-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 (define-key calendar-mode-map "\C-cIy" 'insert-yearly-islamic-diary-entry)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065 (define-key calendar-mode-map "?" 'describe-calendar-mode))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 (defun describe-calendar-mode ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068 "Create a help buffer with a brief description of the calendar-mode."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 (with-output-to-temp-buffer "*Help*"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 (princ
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072 (format
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 "Calendar Mode:\nFor a complete description, type %s\n%s\n"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 (substitute-command-keys
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 "\\<calendar-mode-map>\\[describe-mode] from within the calendar")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 (substitute-command-keys "\\{calendar-mode-map}")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 (print-help-return-message)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 ;; Calendar mode is suitable only for specially formatted data.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 (put 'calendar-mode 'mode-class 'special)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 (defvar calendar-mode-line-format
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (substitute-command-keys
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 "\\<calendar-mode-map>\\[scroll-calendar-left] Calendar \\[describe-calendar-mode] help/\\[calendar-other-month] other/\\[calendar-current-month] current %17s \\[scroll-calendar-right]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 "The mode line of the calendar buffer.")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (defun calendar-mode ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 "A major mode for the sliding calendar window and diary.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 The commands for cursor movement are:\\<calendar-mode-map>
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 \\[calendar-forward-day] one day forward \\[calendar-backward-day] one day backward
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 \\[calendar-forward-week] one week forward \\[calendar-backward-week] one week backward
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 \\[calendar-forward-month] one month forward \\[calendar-backward-month] one month backward
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 \\[calendar-forward-year] one year forward \\[calendar-backward-year] one year backward
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 \\[calendar-beginning-of-week] beginning of week \\[calendar-end-of-week] end of week
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 \\[calendar-beginning-of-month] beginning of month \\[calendar-end-of-month] end of month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 \\[calendar-beginning-of-year] beginning of year \\[calendar-end-of-year] end of year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 \\[calendar-goto-date] go to date \\[calendar-goto-julian-date] go to Julian date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 \\[calendar-goto-hebrew-date] go to Hebrew date \\[calendar-goto-islamic-date] go to Islamic date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 \\[calendar-goto-iso-date] go to ISO date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 You can mark a date in the calendar and switch the point and mark:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 \\[calendar-set-mark] mark date \\[calendar-exchange-point-and-mark] exchange point and mark
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 You can determine the number of days (inclusive) between the point and mark by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106 \\[calendar-count-days-region] count days in the region
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 The commands for calendar movement are:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 \\[scroll-calendar-right] scroll one month right \\[scroll-calendar-left] scroll one month left
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 \\[scroll-calendar-right-three-months] scroll 3 months right \\[scroll-calendar-left-three-months] scroll 3 months left
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112 \\[calendar-current-month] display current month \\[calendar-other-month] display another month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 Whenever it makes sense, the above commands take prefix arguments that
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115 multiply their affect. For convenience, the digit keys and the minus sign
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 are bound to digit-argument, so they need not be prefixed with ESC.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 If the calendar window somehow becomes corrupted, it can be regenerated with
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 \\[redraw-calendar] redraw the calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122 The following commands deal with holidays and other notable days:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 \\[calendar-cursor-holidays] give holidays for the date specified by the cursor
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 \\[mark-calendar-holidays] mark notable days
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 \\[calendar-unmark] unmark dates
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 \\[list-calendar-holidays] display notable days
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 The command M-x holidays causes the notable dates for the current month, and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 the preceding and succeeding months, to be displayed, independently of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 The following commands control the diary:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135 \\[mark-diary-entries] mark diary entries \\[calendar-unmark] unmark dates
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 \\[view-diary-entries] display diary entries \\[show-all-diary-entries] show all diary entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 \\[print-diary-entries] print diary entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 Displaying the diary entries causes the diary entries from the diary-file
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 (for the date indicated by the cursor in the calendar window) to be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 displayed in another window. This function takes an integer argument that
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 specifies the number of days of calendar entries to be displayed, starting
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 with the date indicated by the cursor.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 The command \\[print-diary-entries] prints the diary buffer (as it appears)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 on the line printer.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 The command M-x diary causes the diary entries for the current date to be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 displayed, independently of the calendar. The number of days of entries is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 governed by number-of-diary-entries.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152 The format of the entries in the diary file is described in the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 documentation string for the variable diary-file.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155 When diary entries are in view in the window, they can be edited. It is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 important to keep in mind that the buffer displayed contains the entire
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157 diary file, but with portions of it concealed from view. This means, for
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 instance, that the forward-char command can put the cursor at what appears
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 to be the end of the line, but what is in reality the middle of some
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 concealed line. BE CAREFUL WHEN EDITING THE DIARY ENTRIES! (Inserting
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 additional lines or adding/deleting characters in the middle of a visible
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162 line will not cause problems; watch out for end-of-line, however--it may
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 put you at the end of a concealed line far from where the cursor appears to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 be!) BEFORE EDITING THE DIARY IT IS BEST TO DISPLAY THE ENTIRE FILE WITH
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 show-all-diary-entries. BE SURE TO WRITE THE FILE BEFORE EXITING FROM THE
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 CALENDAR.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 The following commands assist in making diary entries:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 \\[insert-diary-entry] insert a diary entry for the selected date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 \\[insert-weekly-diary-entry] insert a diary entry for the selected day of the week
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 \\[insert-monthly-diary-entry] insert a diary entry for the selected day of the month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 \\[insert-yearly-diary-entry] insert a diary entry for the selected day of the year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 \\[insert-block-diary-entry] insert a diary entry for the block days between point and mark
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 \\[insert-anniversary-diary-entry] insert an anniversary diary entry for the selected date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 \\[insert-cyclic-diary-entry] insert a cyclic diary entry
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 There are corresponding commands to assist in making Hebrew- or Islamic-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 diary entries:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 \\[insert-hebrew-diary-entry] insert a diary entry for the Hebrew date corresponding
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 to the selected date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 \\[insert-monthly-hebrew-diary-entry] insert a diary entry for the day of the Hebrew month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 corresponding to the selected day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 \\[insert-yearly-hebrew-diary-entry] insert a diary entry for the day of the Hebrew year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 corresponding to the selected day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 \\[insert-islamic-diary-entry] insert a diary entry for the Islamic date corresponding
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 to the selected date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 \\[insert-monthly-islamic-diary-entry] insert a diary entry for the day of the Islamic month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 corresponding to the selected day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 \\[insert-yearly-islamic-diary-entry] insert a diary entry for the day of the Islamic year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 corresponding to the selected day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 All of the diary entry commands make nonmarking entries when given a prefix
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 argument; with no prefix argument, the diary entries are marking.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 The day number in the year and the number of days remaining in the year can be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 determined by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 \\[cursor-to-calendar-day-of-year] show day number and the number of days remaining in the year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 Equivalent dates on the ISO commercial, Julian, Hebrew, Islamic and French
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 Revolutionary calendars can be determined by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 \\[cursor-to-iso-calendar-date] show equivalent date on the ISO commercial calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 \\[cursor-to-julian-calendar-date] show equivalent date on the Julian calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 \\[cursor-to-hebrew-calendar-date] show equivalent date on the Hebrew calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 \\[cursor-to-islamic-calendar-date] show equivalent date on the Islamic calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 \\[cursor-to-french-calendar-date] show equivalent date on the French Revolutionary calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 To exit from the calendar use
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 \\[exit-calendar] exit from calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 The variable `view-diary-entries-initially', whose default is nil, can be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216 set to to t cause diary entries for the current date will be displayed in
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 another window when the calendar is first displayed, if the current date is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 visible. The variable `number-of-diary-entries' controls number of days of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 diary entries that will be displayed initially or with the command M-x
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 diary. For example, if the default value 1 is used, then only the current
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 day's diary entries will be displayed. If the value 2 is used, both the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 current day's and the next day's entries will be displayed. The value can
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 also be a vector: If the value is [0 2 2 2 2 4 1] then no diary entries
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 will be displayed on Sunday, the current date's and the next day's diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 entries will be displayed Monday through Thursday, Friday through Monday's
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 entries will be displayed on Friday, while on Saturday only that day's
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 entries will be displayed.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 The variable `view-calendar-holidays-initially' can be set to t to cause
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 the holidays for the current three month period will be displayed on entry
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 to the calendar. The holidays are displayed in another window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 The variable `mark-diary-entries-in-calendar' can be set to t to cause any
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 dates visible with calendar entries to be marked with the symbol specified
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 by the variable `diary-entry-marker', normally a plus sign.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 The variable `initial-calendar-window-hook', whose default value is nil,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 is list of functions to be called when the calendar window is first opened.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239 The functions invoked are called after the calendar window is opened, but
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 once opened is never called again. Leaving the calendar with the `q' command
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 and reentering it will cause these functions to be called again.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 The variable `today-visible-calendar-hook', whose default value is nil,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 is the list of functions called after the calendar buffer has been prepared
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 with the calendar when the current date is visible in the window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 This can be used, for example, to replace today's date with asterisks; a
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 function calendar-star-date is included for this purpose:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (setq today-visible-calendar-hook 'calendar-star-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 It could also be used to mark the current date with `*'; a function is also
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 provided for this:
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 (setq today-visible-calendar-hook 'calendar-mark-today)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253 The variable `today-invisible-calendar-hook', whose default value is nil,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 is the list of functions called after the calendar buffer has been prepared
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 with the calendar when the current date is not visible in the window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 The variable `diary-display-hook' is the list of functions called
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 after the diary buffer is prepared. The default value simply displays the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 diary file using selective-display to conceal irrelevant diary entries. An
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 alternative function `fancy-diary-display' is provided that, when
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261 used as the `diary-display-hook', causes a noneditable buffer to be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 prepared with a neatly organized day-by-day listing of relevant diary
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 entries, together with any known holidays. The inclusion of the holidays
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264 slows this fancy display of the diary; to speed it up, set the variable
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 `holidays-in-diary-buffer' to nil.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 The variable `print-diary-entries-hook' is the list of functions called
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 after a temporary buffer is prepared with the diary entries currently
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 visible in the diary buffer. The default value of this hook adds a heading
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1270 (composed from the diary buffer's mode line), does the printing with the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271 command lpr-buffer, and kills the temporary buffer. Other uses might
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272 include, for example, rearranging the lines into order by day and time.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 The Gregorian calendar is assumed."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 (kill-all-local-variables)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1277 (setq major-mode 'calendar-mode)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 (setq mode-name "Calendar")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 (use-local-map calendar-mode-map)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 (setq buffer-read-only t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281 (setq indent-tabs-mode nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 (make-local-variable 'calendar-window-configuration);; Windows on entry.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 (make-local-variable 'calendar-mark-ring)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (make-local-variable 'current-month) ;; Current month.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 (make-local-variable 'current-day) ;; Current day.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 (make-local-variable 'current-year) ;; Current year.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 (make-local-variable 'displayed-month);; Month in middle of window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288 (make-local-variable 'displayed-year));; Year in middle of window.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290 (defun update-calendar-mode-line ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291 "Update the calendar mode line with the current date and date style."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 (if (bufferp (get-buffer calendar-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 (save-excursion
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 (set-buffer calendar-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 (setq mode-line-format
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 (format calendar-mode-line-format
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 (calendar-date-string (calendar-current-date) t))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 (defun exit-calendar ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 "Get out of the calendar window and destroy it and related buffers."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 (let ((diary-buffer (get-file-buffer diary-file))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 (d-buffer (get-buffer fancy-diary-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 (h-buffer (get-buffer holiday-buffer)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (if (not diary-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 (set-window-configuration calendar-window-configuration)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (kill-buffer calendar-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 (if d-buffer (kill-buffer d-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 (if h-buffer (kill-buffer h-buffer)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 (if (or (not (buffer-modified-p diary-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 (yes-or-no-p "Diary modified; do you really want to exit the calendar? "))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 (set-window-configuration calendar-window-configuration)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 (kill-buffer calendar-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 (if d-buffer (kill-buffer d-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (if h-buffer (kill-buffer h-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 (set-buffer diary-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 (set-buffer-modified-p nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 (kill-buffer diary-buffer))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 (defun calendar-current-month ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 "Reposition the calendar window so the current date is visible."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 (let ((today (calendar-current-date)));; The date might have changed.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (if (not (calendar-date-is-visible-p today))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 (regenerate-calendar-window)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 (update-calendar-mode-line)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 (calendar-cursor-to-visible-date today))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 (defun calendar-forward-month (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 "Move the cursor forward ARG months.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 Movement is backward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1334 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1335 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1336 (let* ((cursor-date (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 (error "Cursor is not on a date!")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 (month (extract-calendar-month cursor-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 (day (extract-calendar-day cursor-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (year (extract-calendar-year cursor-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 (increment-calendar-month month year arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 (let ((last (calendar-last-day-of-month month year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 (if (< last day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 (setq day last)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345 ;; Put the new month on the screen, if needed, and go to the new date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 (let ((new-cursor-date (list month day year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 (if (not (calendar-date-is-visible-p new-cursor-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 (calendar-other-month month year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 (calendar-cursor-to-visible-date new-cursor-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 (defun calendar-forward-year (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 "Move the cursor forward by ARG years.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 Movement is backward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 (calendar-forward-month (* 12 arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (defun calendar-backward-month (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 "Move the cursor backward by ARG months.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 Movement is forward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 (calendar-forward-month (- arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 (defun calendar-backward-year (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 "Move the cursor backward ARG years.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 Movement is forward is ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (calendar-forward-month (* -12 arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (defun scroll-calendar-left (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 "Scroll the displayed calendar left by ARG months.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 If ARG is negative the calendar is scrolled right. Maintains the relative
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 position of the cursor with respect to the calendar as well as possible."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 (let ((old-date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 (today (calendar-current-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 (if (/= arg 0)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379 (regenerate-calendar-window
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 (+ arg (calendar-interval current-month current-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1381 displayed-month displayed-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1382 (calendar-cursor-to-visible-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383 (cond
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384 ((calendar-date-is-visible-p old-date) old-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385 ((calendar-date-is-visible-p today) today)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386 (t (list displayed-month 1 displayed-year))))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1387
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1388 (defun scroll-calendar-right (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 "Scroll the displayed calendar window right by ARG months.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 If ARG is negative the calendar is scrolled left. Maintains the relative
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1391 position of the cursor with respect to the calendar as well as possible."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393 (scroll-calendar-left (- arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395 (defun scroll-calendar-left-three-months (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396 "Scroll the displayed calendar window left by 3*ARG months.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1397 If ARG is negative the calendar is scrolled right. Maintains the relative
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1398 position of the cursor with respect to the calendar as well as possible."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1399 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400 (scroll-calendar-left (* 3 arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402 (defun scroll-calendar-right-three-months (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 "Scroll the displayed calendar window right by 3*ARG months.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 If ARG is negative the calendar is scrolled left. Maintains the relative
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 position of the cursor with respect to the calendar as well as possible."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407 (scroll-calendar-left (* -3 arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409 (defun calendar-current-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 "Returns the current date in a list (month day year).
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411 If in the calendar buffer, also sets the current date local variables."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412 (let* ((date (current-time-string))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413 (garbage
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 (string-match
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415 "^\\([A-Z][a-z]*\\) *\\([A-Z][a-z]*\\) *\\([0-9]*\\) .* \\([0-9]*\\)$"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417 (month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418 (cdr (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 (substring date (match-beginning 2) (match-end 2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 (calendar-make-alist
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1421 calendar-month-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422 1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423 '(lambda (x) (substring x 0 3))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 (day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425 (string-to-int (substring date (match-beginning 3) (match-end 3))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 (year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427 (string-to-int (substring date (match-beginning 4) (match-end 4)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (if (equal (current-buffer) (get-buffer calendar-buffer))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 (setq current-month month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431 (setq current-day day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1432 (setq current-year year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1433 (list month day year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1434
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1435 (defun calendar-cursor-to-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1436 "Returns a list of the month, day, and year of current cursor position.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 Returns nil if the cursor is not on a specific day."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438 (if (and (looking-at "[*0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 (< 2 (count-lines (point-min) (point))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 (save-excursion
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 (re-search-backward "[^0-9]")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 (forward-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443 (let*
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 ((day (string-to-int (buffer-substring (point) (+ 3 (point)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1445 (day (if (= 0 day) current-day day));; Starred date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1446 (segment (/ (current-column) 25))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1447 (month (% (+ displayed-month segment -1) 12))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448 (month (if (= 0 month) 12 month))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449 (year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1450 (cond
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1451 ((and (= 12 month) (= segment 0)) (1- displayed-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1452 ((and (= 1 month) (= segment 2)) (1+ displayed-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1453 (t displayed-year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1454 (list month day year)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 (defun calendar-cursor-to-nearest-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 "Move the cursor to the closest date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 The position of the cursor is unchanged if it is already on a date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 Returns the list (month day year) giving the cursor position."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (let ((date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 (column (current-column)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 (if date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464 (if (> 3 (count-lines (point-min) (point)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 (goto-line 3)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 (move-to-column column)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 (if (not (looking-at "[0-9]"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469 (if (and (not (looking-at " *$"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 (or (< column 25)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 (and (> column 27)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 (< column 50))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 (and (> column 52)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 (< column 75))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (re-search-forward "[0-9]" nil t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 (backward-char 1))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (re-search-backward "[0-9]" nil t)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479 (calendar-cursor-to-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 (defun calendar-forward-day (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 "Move the cursor forward ARG days.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 Moves backward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 (if (/= 0 arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 (let*
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487 ((cursor-date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1488 (cursor-date (if cursor-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1489 cursor-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490 (if (> arg 0) (setq arg (1- arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1491 (calendar-cursor-to-nearest-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1492 (new-cursor-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1493 (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494 (+ (calendar-absolute-from-gregorian cursor-date) arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1495 (new-display-month (extract-calendar-month new-cursor-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496 (new-display-year (extract-calendar-year new-cursor-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1497 ;; Put the new month on the screen, if needed, and go to the new date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 (if (not (calendar-date-is-visible-p new-cursor-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 (calendar-other-month new-display-month new-display-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500 (calendar-cursor-to-visible-date new-cursor-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 (defun calendar-backward-day (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503 "Move the cursor back ARG days.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1504 Moves forward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1505 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1506 (calendar-forward-day (- arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 (defun calendar-forward-week (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 "Move the cursor forward ARG weeks.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1510 Moves backward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1511 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1512 (calendar-forward-day (* arg 7)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1513
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 (defun calendar-backward-week (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1515 "Move the cursor back ARG weeks.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 Moves forward if ARG is negative."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1518 (calendar-forward-day (* arg -7)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1520 (defun calendar-beginning-of-week (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521 "Move the cursor back ARG Sundays."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1522 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525 (calendar-backward-day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526 (if (= day 0) (* 7 arg) (+ day (* 7 (1- arg)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1527
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1528 (defun calendar-end-of-week (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1529 "Move the cursor forward ARG Saturdays."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1530 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1531 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1533 (calendar-forward-day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1534 (if (= day 6) (* 7 arg) (+ (- 6 day) (* 7 (1- arg)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1535
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1536 (defun calendar-beginning-of-month (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1537 "Move the cursor backward ARG month beginnings."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540 (let* ((date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 (month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1543 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 (if (= day 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 (calendar-backward-month arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 (calendar-cursor-to-visible-date (list month 1 year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1547 (calendar-backward-month (1- arg)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (defun calendar-end-of-month (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 "Move the cursor forward ARG month ends."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1553 (let* ((date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554 (month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 (year (extract-calendar-year date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1557 (last-day (calendar-last-day-of-month month year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 (if (/= day last-day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560 (calendar-cursor-to-visible-date (list month last-day year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1561 (setq arg (1- arg))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1562 (increment-calendar-month month year arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1563 (let ((last-day (list
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1565 (calendar-last-day-of-month month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567 (if (not (calendar-date-is-visible-p last-day))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1568 (calendar-other-month month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1569 (calendar-cursor-to-visible-date last-day)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1570
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1571 (defun calendar-beginning-of-year (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1572 "Move the cursor backward ARG year beginnings."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1573 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1574 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1575 (let* ((date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1576 (month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1577 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1578 (year (extract-calendar-year date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579 (jan-first (list 1 1 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1580 (if (and (= day 1) (= 1 month))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1581 (calendar-backward-month (* 12 arg))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1582 (if (and (= arg 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1583 (calendar-date-is-visible-p jan-first))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1584 (calendar-cursor-to-visible-date jan-first)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1585 (calendar-other-month 1 (- year (1- arg)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1586
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1587 (defun calendar-end-of-year (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1588 "Move the cursor forward ARG year beginnings."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589 (interactive "p")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1590 (calendar-cursor-to-nearest-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1591 (let* ((date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1592 (month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1593 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1594 (year (extract-calendar-year date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1595 (dec-31 (list 12 31 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1596 (if (and (= day 31) (= 12 month))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597 (calendar-forward-month (* 12 arg))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598 (if (and (= arg 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1599 (calendar-date-is-visible-p dec-31))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1600 (calendar-cursor-to-visible-date dec-31)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1601 (calendar-other-month 12 (- year (1- arg)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1602 (calendar-cursor-to-visible-date (list 12 31 displayed-year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1603
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1604 (defun calendar-gregorian-from-absolute (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1605 "Compute the list (month day year) corresponding to the absolute DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1606 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1607 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1608 (let* ((approx (/ date 366));; Approximation from below.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1609 (year ;; Search forward from the approximation.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610 (+ approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611 (calendar-sum y approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1612 (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1614 (month ;; Search forward from January.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615 (1+ (calendar-sum m 1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1616 (> date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1617 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 (list m (calendar-last-day-of-month m year) year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 (day ;; Calculate the day by subtraction.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621 (- date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622 (1- (calendar-absolute-from-gregorian (list month 1 year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623 (list month day year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1624
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625 (defun calendar-cursor-to-visible-date (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1626 "Move the cursor to DATE that is on the screen."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1627 (let ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1628 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1629 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1630 (goto-line (+ 3
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1631 (/ (+ day -1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1632 (calendar-day-of-week (list month 1 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1633 7)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1634 (move-to-column (+ 6
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1635 (* 25
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636 (1+ (calendar-interval
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1637 displayed-month displayed-year month year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1638 (* 3 (calendar-day-of-week date))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1639
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1640 (defun calendar-other-month (month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1641 "Display a three-month calendar centered around MONTH and YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1642 (interactive
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1643 (let* ((completion-ignore-case t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1644 (month (cdr (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1645 (capitalize
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1646 (completing-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1647 "Month name: "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1648 (mapcar 'list (append calendar-month-name-array nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1649 nil t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1650 (calendar-make-alist calendar-month-name-array))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1651 (year (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1652 "Year (>0): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1653 '(lambda (x) (> x 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1654 (int-to-string current-year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1655 (list month year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1656 (if (and (= month displayed-month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1657 (= year displayed-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1658 nil
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1659 (let ((old-date (calendar-cursor-to-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1660 (today (calendar-current-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1661 (regenerate-calendar-window
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1662 (calendar-interval current-month current-year month year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1663 (calendar-cursor-to-visible-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1664 (cond
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1665 ((calendar-date-is-visible-p old-date) old-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1666 ((calendar-date-is-visible-p today) today)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1667 (t (list month 1 year)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1668
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1669 (defun calendar-set-mark (arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1670 "Mark the date under the cursor, or jump to marked date.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1671 With no prefix argument, push current date onto marked date ring.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1672 With argument, jump to mark, pop it, and put point at end of ring."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1673 (interactive "P")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1674 (let ((date (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1675 (error "Cursor is not on a date!"))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1676 (if (null arg)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1677 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1678 (setq calendar-mark-ring (cons date calendar-mark-ring))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1679 ;; Since the top of the mark ring is the marked date in the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1680 ;; calendar, the mark ring in the calendar is one longer than
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1681 ;; in other buffers to get the same effect.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1682 (if (> (length calendar-mark-ring) (1+ mark-ring-max))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1683 (setcdr (nthcdr mark-ring-max calendar-mark-ring) nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1684 (message "Mark set"))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685 (if (null calendar-mark-ring)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1686 (error "No mark set in this buffer")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1687 (calendar-goto-date (car calendar-mark-ring))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1688 (setq calendar-mark-ring
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1689 (cdr (nconc calendar-mark-ring (list date))))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1690
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1691 (defun calendar-exchange-point-and-mark ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1692 "Exchange the current cursor position with the marked date."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1693 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1694 (let ((mark (car calendar-mark-ring))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1695 (date (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1696 (error "Cursor is not on a date!"))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1697 (if (null mark)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1698 (error "No mark set in this buffer")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1699 (setq calendar-mark-ring (cons date (cdr calendar-mark-ring)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1700 (calendar-goto-date mark))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1701
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1702 (defun calendar-count-days-region ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1703 "Count the number of days (inclusive) between point and the mark."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1704 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1705 (let* ((days (- (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1706 (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1707 (error "Cursor is not on a date!")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1708 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1709 (or (car calendar-mark-ring)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1710 (error "No mark set in this buffer")))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1711 (days (1+ (if (> days 0) days (- days)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1712 (message "Region has %d day%s (inclusive)"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1713 days (if (> days 1) "s" ""))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1714
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1715 (defun calendar-not-implemented ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1716 "Not implemented."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1717 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1718 (error "%s not available in the calendar"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1719 (global-key-binding (this-command-keys))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1720
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1721 (defun calendar-read (prompt acceptable &optional initial-contents)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1722 "Return an object read from the minibuffer.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1723 Prompt with the string PROMPT and use the function ACCEPTABLE to decide if
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1724 entered item is acceptable. If non-nil, optional third arg INITIAL-CONTENTS
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1725 is a string to insert in the minibuffer before reading."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1726 (let ((value (read-minibuffer prompt initial-contents)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1727 (while (not (funcall acceptable value))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728 (setq value (read-minibuffer prompt initial-contents)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1729 value))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1730
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1731 (defun calendar-goto-date (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1732 "Move cursor to DATE."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1733 (interactive
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1734 (let* ((year (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1735 "Year (>0): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1736 '(lambda (x) (> x 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1737 (int-to-string current-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1738 (month-array calendar-month-name-array)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739 (completion-ignore-case t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 (month (cdr (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741 (capitalize
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 (completing-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 "Month name: "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 (mapcar 'list (append month-array nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 nil t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746 (calendar-make-alist month-array 1 'capitalize))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1747 (last (calendar-last-day-of-month month year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748 (day (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1749 (format "Day (1-%d): " last)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1750 '(lambda (x) (and (< 0 x) (<= x last))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1751 (list (list month day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1752 (let ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1753 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1754 (if (not (calendar-date-is-visible-p date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1755 (calendar-other-month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1756 (if (and (= month 1) (= year 1))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1757 2
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1758 month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1759 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1760 (calendar-cursor-to-visible-date date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1761
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1762 (defun calendar-goto-julian-date (date &optional noecho)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1763 "Move cursor to Julian DATE; echo Julian date unless NOECHO is t."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1764 (interactive
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1765 (let* ((year (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1766 "Julian calendar year (>0): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1767 '(lambda (x) (> x 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1768 (int-to-string
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1769 (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1770 (calendar-julian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1771 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1772 (list current-month 1 current-year)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1773 (month-array calendar-month-name-array)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1774 (completion-ignore-case t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1775 (month (cdr (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1776 (capitalize
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1777 (completing-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1778 "Julian calendar month name: "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1779 (mapcar 'list (append month-array nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1780 nil t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1781 (calendar-make-alist month-array 1 'capitalize))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1782 (last
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1783 (if (and (zerop (% year 4)) (= month 2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784 29
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 (day (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 (format "Julian calendar day (%d-%d): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 (if (and (= year 1) (= month 1)) 3 1) last)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789 '(lambda (x)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1790 (and (< (if (and (= year 1) (= month 1)) 2 0) x)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1791 (<= x last))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1792 (list (list month day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793 (calendar-goto-date (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1794 (calendar-absolute-from-julian date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 (or noecho (cursor-to-julian-calendar-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1797 (defun calendar-goto-hebrew-date (date &optional noecho)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1798 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is t."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1799 (interactive
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1800 (let* ((year (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1801 "Hebrew calendar year (>3760): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1802 '(lambda (x) (> x 3760))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1803 (int-to-string
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1804 (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1805 (calendar-hebrew-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1806 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1807 (list current-month 1 current-year)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1808 (month-array (if (hebrew-calendar-leap-year-p year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1809 calendar-hebrew-month-name-array-leap-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1810 calendar-hebrew-month-name-array-common-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1811 (completion-ignore-case t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1812 (month (cdr (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1813 (capitalize
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1814 (completing-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1815 "Hebrew calendar month name: "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1816 (mapcar 'list (append month-array nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1817 (if (= year 3761)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1818 '(lambda (x)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1819 (let ((m (cdr
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1820 (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1821 (car x)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1822 (calendar-make-alist
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1823 month-array)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1824 (< 0
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1825 (calendar-absolute-from-hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1826 (list m
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1827 (hebrew-calendar-last-day-of-month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1828 m year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1829 year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1830
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1831 t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1832 (calendar-make-alist month-array 1 'capitalize))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1833 (last (hebrew-calendar-last-day-of-month month year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1834 (first (if (and (= year 3761) (= month 10))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1835 18 1))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1836 (day (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1837 (format "Hebrew calendar day (%d-%d): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1838 first last)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1839 '(lambda (x) (and (<= first x) (<= x last))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1840 (list (list month day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1841 (calendar-goto-date (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1842 (calendar-absolute-from-hebrew date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1843 (or noecho (cursor-to-hebrew-calendar-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1844
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1845 (defun calendar-goto-islamic-date (date &optional noecho)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1846 "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is t."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1847 (interactive
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1848 (let* ((year (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1849 "Islamic calendar year (>0): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1850 '(lambda (x) (> x 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851 (int-to-string
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852 (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1853 (calendar-islamic-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1854 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1855 (list current-month 1 current-year)))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1856 (month-array calendar-islamic-month-name-array)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1857 (completion-ignore-case t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1858 (month (cdr (assoc
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1859 (capitalize
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1860 (completing-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1861 "Islamic calendar month name: "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1862 (mapcar 'list (append month-array nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1863 nil t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1864 (calendar-make-alist month-array 1 'capitalize))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1865 (last (islamic-calendar-last-day-of-month month year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1866 (day (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1867 (format "Islamic calendar day (1-%d): " last)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1868 '(lambda (x) (and (< 0 x) (<= x last))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1869 (list (list month day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1870 (calendar-goto-date (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1871 (calendar-absolute-from-islamic date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1872 (or noecho (cursor-to-islamic-calendar-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1873
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1874 (defun calendar-goto-iso-date (date &optional noecho)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1875 "Move cursor to ISO DATE; echo ISO date unless NOECHO is t."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1876 (interactive
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1877 (let* ((year (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1878 "ISO calendar year (>0): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1879 '(lambda (x) (> x 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1880 (int-to-string current-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1881 (no-weeks (extract-calendar-month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1882 (calendar-iso-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1883 (1-
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1884 (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1885 1 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1886 (list 1 4 (1+ year))))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1887 (week (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1888 (format "ISO calendar week (1-%d): " no-weeks)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1889 '(lambda (x) (and (> x 0) (<= x no-weeks)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1890 (day (calendar-read
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1891 "ISO day (1-7): "
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1892 '(lambda (x) (and (<= 1 x) (<= x 7))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1893 (list (list week day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1894 (calendar-goto-date (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1895 (calendar-absolute-from-iso date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1896 (or noecho (cursor-to-iso-calendar-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1897
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1898 (defun calendar-interval (mon1 yr1 mon2 yr2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1899 "The number of months difference between the two specified months."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1900 (+ (* 12 (- yr2 yr1))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1901 (- mon2 mon1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1902
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1903 (defun calendar-leap-year-p (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1904 "Returns t if YEAR is a Gregorian leap year."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1905 (or
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1906 (and (= (% year 4) 0)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1907 (/= (% year 100) 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1908 (= (% year 400) 0)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1909
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1910 (defun calendar-day-number (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1911 "Return the day number within the year of the date DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1912 For example, (calendar-day-number '(1 1 1987)) returns the value 1,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1913 while (calendar-day-number '(12 31 1980)) returns 366."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1914 ;;
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1915 ;; An explanation of the calculation can be found in PascAlgorithms by
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1916 ;; Edward and Ruth Reingold, Scott-Foresman/Little, Brown, 1988.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1917 ;;
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1918 (let* ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1919 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1920 (year (extract-calendar-year date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1921 (day-of-year (+ day (* 31 (1- month)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1922 (if (> month 2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1923 (progn
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1924 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1925 (if (calendar-leap-year-p year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1926 (setq day-of-year (1+ day-of-year)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1927 day-of-year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1928
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1929 (defun calendar-day-name (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1930 "Returns a string with the name of the day of the week of DATE."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1931 (aref calendar-day-name-array (calendar-day-of-week date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1932
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1933 (defconst calendar-day-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1934 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1935
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1936 (defun calendar-last-day-of-month (month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1937 "The last day in MONTH during YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1938 (if (and (calendar-leap-year-p year) (= month 2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1939 29
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1940 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1941
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1942 (defconst calendar-month-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1943 ["January" "February" "March" "April" "May" "June"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1944 "July" "August" "September" "October" "November" "December"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1945
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1946 (defun calendar-make-alist (sequence &optional start-index filter)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1947 "Make an assoc list corresponding to SEQUENCE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1948 Start at index 1, unless optional START-INDEX is provided.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1949 If FILTER is provided, apply it to each item in the list."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1950 (let ((index (if start-index (1- start-index) 0)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1951 (mapcar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1952 '(lambda (x)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1953 (setq index (1+ index))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1954 (cons (if filter (funcall filter x) x)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1955 index))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1956 (append sequence nil))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1957
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1958 (defun calendar-month-name (month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1959 "The name of MONTH."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1960 (aref calendar-month-name-array (1- month)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1961
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1962 (defun calendar-day-of-week (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1963 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1964 (% (calendar-absolute-from-gregorian date) 7))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1965
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1966 (defun calendar-absolute-from-gregorian (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1967 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1968 The Gregorian date Sunday, December 31, 1 BC is imaginary."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1969 (let ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1970 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1971 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1972 (+ (calendar-day-number date);; Days this year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1973 (* 365 (1- year));; + Days in prior years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1974 (/ (1- year) 4);; + Julian leap years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1975 (- (/ (1- year) 100));; - century years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1976 (/ (1- year) 400))));; + Gregorian leap years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1977
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1978 (defun calendar-unmark ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1979 "Delete the diary and holiday marks from the calendar."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1980 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1981 (setq mark-diary-entries-in-calendar nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1982 (setq mark-holidays-in-calendar nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1983 (save-excursion
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1984 (goto-line 3)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1985 (beginning-of-line)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1986 (let ((buffer-read-only nil)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1987 (start (point))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1988 (star-date (search-forward "**" nil t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1989 (star-point (point)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1990 (if star-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1991 (progn ;; Don't delete today as left by calendar-star-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1992 (subst-char-in-region start (- star-point 2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1993 (string-to-char diary-entry-marker) ? t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1994 (subst-char-in-region start (- star-point 2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1995 (string-to-char calendar-holiday-marker) ? t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1996 (subst-char-in-region star-point (point-max)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1997 (string-to-char diary-entry-marker) ? t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1998 (subst-char-in-region star-point (point-max)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1999 (string-to-char calendar-holiday-marker) ? t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2000 (subst-char-in-region start (point-max)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2001 (string-to-char diary-entry-marker) ? t)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2002 (subst-char-in-region start (point-max)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2003 (string-to-char calendar-holiday-marker) ? t))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2004 (set-buffer-modified-p nil))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2005
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2006 (defun calendar-date-is-visible-p (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2007 "Returns t if DATE is legal and is visible in the calendar window."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2008 (let ((gap (calendar-interval
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2009 displayed-month displayed-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2010 (extract-calendar-month date) (extract-calendar-year date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2011 (and (calendar-date-is-legal-p date) (> 2 gap) (< -2 gap))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2012
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2013 (defun calendar-date-is-legal-p (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2014 "Returns t if DATE is a legal date."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2015 (let ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2016 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2017 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2018 (and (<= 1 month) (<= month 12)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2019 (<= 1 day) (<= day (calendar-last-day-of-month month year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2020 (<= 1 year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2021
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2022 (defun calendar-date-equal (date1 date2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2023 "Returns t if the DATE1 and DATE2 are the same."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2024 (and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2025 (= (extract-calendar-month date1) (extract-calendar-month date2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2026 (= (extract-calendar-day date1) (extract-calendar-day date2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2027 (= (extract-calendar-year date1) (extract-calendar-year date2))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2028
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2029 (defun mark-visible-calendar-date (date &optional mark)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2030 "Leave mark DATE with MARK. MARK defaults to diary-entry-marker."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2031 (if (calendar-date-is-legal-p date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2032 (save-excursion
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2033 (set-buffer calendar-buffer)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2034 (calendar-cursor-to-visible-date date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2035 (forward-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2036 (let ((buffer-read-only nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2037 (delete-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2038 (insert (if mark mark diary-entry-marker))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2039 (forward-char -2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2040 (set-buffer-modified-p nil))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2041
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2042 (defun calendar-star-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2043 "Replace the date under the cursor in the calendar window with asterisks.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2044 This function can be used with the today-visible-calendar-hook run after the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2045 calendar window has been prepared."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2046 (let ((buffer-read-only nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2047 (forward-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2048 (delete-char -2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2049 (insert "**")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2050 (backward-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2051 (set-buffer-modified-p nil)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2052
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2053 (defun calendar-mark-today ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2054 "Mark the date under the cursor in the calendar window with an equal sign.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2055 This function can be used with the today-visible-calendar-hook run after the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2056 calendar window has been prepared."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2057 (let ((buffer-read-only nil))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2058 (forward-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2059 (delete-char 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2060 (insert "=")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2061 (backward-char 2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2062 (set-buffer-modified-p nil)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2063
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2064 (defun calendar-date-compare (date1 date2)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2065 "Returns t if DATE1 is before DATE2, nil otherwise.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2066 The actual dates are in the car of DATE1 and DATE2."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2067 (< (calendar-absolute-from-gregorian (car date1))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2068 (calendar-absolute-from-gregorian (car date2))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2069
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2070 (defun calendar-date-string (date &optional abbreviate nodayname)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2071 "A string form of DATE, driven by the variable `calendar-date-display-form'.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2072 An optional parameter ABBREVIATE, when t, causes the month and day names to be
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2073 abbreviated to three characters. An optional parameter NODAYNAME, when t,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2074 omits the name of the day of the week."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2075 (let* ((dayname
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2076 (if nodayname
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2077 ""
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2078 (if abbreviate
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2079 (substring (calendar-day-name date) 0 3)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2080 (calendar-day-name date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2081 (month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2082 (monthname
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2083 (if abbreviate
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2084 (substring
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2085 (calendar-month-name month) 0 3)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2086 (calendar-month-name month)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2087 (day (int-to-string (extract-calendar-day date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2088 (month (int-to-string month))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2089 (year (int-to-string (extract-calendar-year date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2090 (mapconcat 'eval calendar-date-display-form "")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2091
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2092 (defun calendar-dayname-on-or-before (dayname date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2093 "Returns the absolute date of the DAYNAME on or before absolute DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2094 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2095
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2096 Note: Applying this function to d+6 gives us the DAYNAME on or after an
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2097 absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2098 absolute date d, applying it to d-1 gives the DAYNAME previous to absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2099 date d, and applying it to d+7 gives the DAYNAME following absolute date d."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2100 (- date (% (- date dayname) 7)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2101
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2102 (defun calendar-nth-named-day (n dayname month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2103 "Returns the date of the Nth DAYNAME in MONTH, YEAR.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2104 A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0, the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2105 date returned is the Nth DAYNAME from the end of MONTH, YEAR (that is, -1 is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2106 the last DAYNAME, -2 is the penultimate DAYNAME, and so on."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2107 (calendar-gregorian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2108 (if (> n 0)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2109 (+ (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2110 dayname (calendar-absolute-from-gregorian (list month 7 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2111 (* 7 (1- n)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2112 (+ (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2113 dayname
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2114 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2115 (list month (calendar-last-day-of-month month year) year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2116 (* 7 (1+ n))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2117
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2118 (defun cursor-to-calendar-day-of-year ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2119 "Show the day number in the year and the number of days remaining in the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2120 year for the date under the cursor."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2121 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2122 (let* ((date (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2123 (error "Cursor is not on a date!")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2124 (year (extract-calendar-year date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2125 (day (calendar-day-number date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2126 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2127 (message "Day %d of %d; %d day%s remaining in the year"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2128 day year days-remaining (if (= days-remaining 1) "" "s"))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2129
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2130 (defun calendar-absolute-from-iso (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2131 "The number of days elapsed between the Gregorian date 12/31/1 BC and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2132 DATE. The `ISO year' corresponds approximately to the Gregorian year, but
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2133 weeks start on Monday and end on Sunday. The first week of the ISO year is
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2134 the first such week in which at least 4 days are in a year. The ISO
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2135 commercial DATE has the form (week day year) in which week is in the range
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2136 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 =
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2137 Sunday). The The Gregorian date Sunday, December 31, 1 BC is imaginary."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2138 (let* ((week (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2139 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2140 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2141 (+ (calendar-dayname-on-or-before
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2142 1 (+ 3 (calendar-absolute-from-gregorian (list 1 1 year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2143 (* 7 (1- week))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2144 (if (= day 0) 6 (1- day)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2145
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2146 (defun calendar-iso-from-absolute (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2147 "Compute the `ISO commercial date' corresponding to the absolute DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2148 The ISO year corresponds approximately to the Gregorian year, but weeks
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2149 start on Monday and end on Sunday. The first week of the ISO year is the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2150 first such week in which at least 4 days are in a year. The ISO commercial
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2151 date has the form (week day year) in which week is in the range 1..52 and
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2152 day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = Sunday). The
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2153 absolute date is the number of days elapsed since the (imaginary) Gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2154 date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2155 (let* ((approx (extract-calendar-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2156 (calendar-gregorian-from-absolute (- date 3))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2157 (year (+ approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2158 (calendar-sum y approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2159 (>= date (calendar-absolute-from-iso (list 1 1 (1+ y))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2160 1))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2161 (list
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2162 (1+ (/ (- date (calendar-absolute-from-iso (list 1 1 year))) 7))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2163 (% date 7)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2164 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2165
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2166 (defun cursor-to-iso-calendar-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2167 "Show the equivalent date on the `ISO commercial calendar' for the date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2168 under the cursor."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2169 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2170 (let* ((greg-date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2171 (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2172 (error "Cursor is not on a date!")))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2173 (day (% (calendar-absolute-from-gregorian greg-date) 7))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2174 (iso-date (calendar-iso-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2175 (calendar-absolute-from-gregorian greg-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2176 (message "ISO date: Day %s of week %d of %d."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2177 (if (zerop day) 7 day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2178 (extract-calendar-month iso-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2179 (extract-calendar-year iso-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2180
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2181 (defun calendar-julian-from-absolute (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2182 "Compute the Julian (month day year) corresponding to the absolute DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2183 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2184 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2185 (let* ((approx (/ (+ date 2) 366));; Approximation from below.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2186 (year ;; Search forward from the approximation.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2187 (+ approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2188 (calendar-sum y approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2189 (>= date (calendar-absolute-from-julian (list 1 1 (1+ y))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2190 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2191 (month ;; Search forward from January.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2192 (1+ (calendar-sum m 1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2193 (> date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2194 (calendar-absolute-from-julian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2195 (list m
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2196 (if (and (= m 2) (= (% year 4) 0))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2197 29
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2198 (aref [31 28 31 30 31 30 31 31 30 31 30 31]
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2199 (1- m)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2200 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2201 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2202 (day ;; Calculate the day by subtraction.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2203 (- date (1- (calendar-absolute-from-julian (list month 1 year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2204 (list month day year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2205
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2206 (defun calendar-absolute-from-julian (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2207 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2208 The Gregorian date Sunday, December 31, 1 BC is imaginary."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2209 (let ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2210 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2211 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2212 (+ (calendar-day-number date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2213 (if (and (= (% year 100) 0)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2214 (/= (% year 400) 0)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2215 (> month 2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2216 1 0);; Correct for Julian but not Gregorian leap year.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2217 (* 365 (1- year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2218 (/ (1- year) 4)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2219 -2)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2220
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2221 (defun cursor-to-julian-calendar-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2222 "Show the Julian calendar equivalent of the date under the cursor."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2223 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2224 (let ((calendar-date-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2225 (if european-calendar-style
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2226 '(day " " monthname " " year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2227 '(monthname " " day ", " year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2228 (message "Julian date: %s"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2229 (calendar-date-string
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2230 (calendar-julian-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2231 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2232 (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2233 (error "Cursor is not on a date!"))))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2234
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2235 (defun islamic-calendar-leap-year-p (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2236 "Returns t if YEAR is a leap year on the Islamic calendar."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2237 (memq (% year 30)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2238 (list 2 5 7 10 13 16 18 21 24 26 29)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2239
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2240 (defun islamic-calendar-last-day-of-month (month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2241 "The last day in MONTH during YEAR on the Islamic calendar."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2242 (cond
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2243 ((memq month (list 1 3 5 7 9 11)) 30)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2244 ((memq month (list 2 4 6 8 10)) 29)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2245 (t (if (islamic-calendar-leap-year-p year) 30 29))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2246
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2247 (defun islamic-calendar-day-number (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2248 "Return the day number within the year of the Islamic date DATE."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2249 (let* ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2250 (day (extract-calendar-day date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2251 (+ (* 30 (/ month 2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2252 (* 29 (/ (1- month) 2))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2253 day)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2254
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2255 (defun calendar-absolute-from-islamic (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2256 "Absolute date of Islamic DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2257 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2258 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2259 (let* ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2260 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2261 (year (extract-calendar-year date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2262 (y (% year 30))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2263 (leap-years-in-cycle
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2264 (cond
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2265 ((< y 3) 0) ((< y 6) 1) ((< y 8) 2) ((< y 11) 3) ((< y 14) 4)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2266 ((< y 17) 5) ((< y 19) 6) ((< y 22) 7) ((< y 25) 8) ((< y 27) 9)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2267 (t 10))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2268 (+ (islamic-calendar-day-number date);; days so far this year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2269 (* (1- year) 354) ;; days in all non-leap years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2270 (* 11 (/ year 30)) ;; leap days in complete cycles
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2271 leap-years-in-cycle ;; leap days this cycle
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2272 227014))) ;; days before start of calendar
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2273
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2274 (defun calendar-islamic-from-absolute (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2275 "Compute the Islamic date (month day year) corresponding to absolute DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2276 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2277 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2278 (if (< date 227015)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2279 (list 0 0 0);; pre-Islamic date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2280 (let* ((approx (/ (- date 227014) 355));; Approximation from below.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2281 (year ;; Search forward from the approximation.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2282 (+ approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2283 (calendar-sum y approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2284 (>= date (calendar-absolute-from-islamic
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2285 (list 1 1 (1+ y))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2286 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2287 (month ;; Search forward from Muharram.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2288 (1+ (calendar-sum m 1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2289 (> date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2290 (calendar-absolute-from-islamic
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2291 (list m
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2292 (islamic-calendar-last-day-of-month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2293 m year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2294 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2295 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2296 (day ;; Calculate the day by subtraction.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2297 (- date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2298 (1- (calendar-absolute-from-islamic (list month 1 year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2299 (list month day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2300
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2301 (defconst calendar-islamic-month-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2302 ["Muharram" "Safar" "Rabi I" "Rabi II" "Jumada I" "Jumada II"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2303 "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2304
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2305 (defun cursor-to-islamic-calendar-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2306 "Show the Islamic calendar equivalent of the date under the cursor."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2307 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2308 (let ((calendar-date-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2309 (if european-calendar-style
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2310 '(day " " monthname " " year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2311 '(monthname " " day ", " year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2312 (calendar-month-name-array calendar-islamic-month-name-array)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2313 (islamic-date (calendar-islamic-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2314 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2315 (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2316 (error "Cursor is not on a date!"))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2317 (if (< (extract-calendar-year islamic-date) 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2318 (message "Date is pre-Islamic")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2319 (message "Islamic date: %s" (calendar-date-string islamic-date nil t)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2320
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2321 (defun calendar-hebrew-from-absolute (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2322 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2323 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2324 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2325 (let* ((greg-date (calendar-gregorian-from-absolute date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2326 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2327 (1- (extract-calendar-month greg-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2328 (day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2329 (year (+ 3760 (extract-calendar-year greg-date))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2330 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2331 (setq year (1+ year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2332 (let ((length (hebrew-calendar-last-month-of-year year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2333 (while (> date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2334 (calendar-absolute-from-hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2335 (list month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2336 (hebrew-calendar-last-day-of-month month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2337 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2338 (setq month (1+ (% month length)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2339 (setq day (1+
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2340 (- date (calendar-absolute-from-hebrew (list month 1 year)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2341 (list month day year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2342
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2343 (defun hebrew-calendar-leap-year-p (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2344 "t if YEAR is a Hebrew calendar leap year."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2345 (< (% (1+ (* 7 year)) 19) 7))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2346
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2347 (defun hebrew-calendar-last-month-of-year (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2348 "The last month of the Hebrew calendar YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2349 (if (hebrew-calendar-leap-year-p year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2350 13
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2351 12))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2352
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2353 (defun hebrew-calendar-last-day-of-month (month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2354 "The last day of MONTH in YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2355 (if (or (memq month (list 2 4 6 10 13))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2356 (and (= month 12) (not (hebrew-calendar-leap-year-p year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2357 (and (= month 8) (not (hebrew-calendar-long-heshvan-p year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2358 (and (= month 9) (hebrew-calendar-short-kislev-p year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2359 29
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2360 30))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2361
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2362 (defun hebrew-calendar-elapsed-days (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2363 "Number of days elapsed from the Sunday prior to the start of the Hebrew
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2364 calendar to the mean conjunction of Tishri of Hebrew YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2365 (let* ((months-elapsed
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2366 (+ (* 235 (/ (1- year) 19));; Months in complete cycles so far.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2367 (* 12 (% (1- year) 19)) ;; Regular months in this cycle
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2368 (/ (1+ (* 7 (% (1- year) 19))) 19)));; Leap months this cycle
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2369 (parts-elapsed (+ 204 (* 793 (% months-elapsed 1080))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2370 (hours-elapsed (+ 5
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2371 (* 12 months-elapsed)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2372 (* 793 (/ months-elapsed 1080))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2373 (/ parts-elapsed 1080)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2374 (parts ;; Conjunction parts
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2375 (+ (* 1080 (% hours-elapsed 24)) (% parts-elapsed 1080)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2376 (day ;; Conjunction day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2377 (+ 1 (* 29 months-elapsed) (/ hours-elapsed 24)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2378 (alternative-day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2379 (if (or (>= parts 19440) ;; If the new moon is at or after midday,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2380 (and (= (% day 7) 2);; ...or is on a Tuesday...
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2381 (>= parts 9924) ;; at 9 hours, 204 parts or later...
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2382 (not (hebrew-calendar-leap-year-p year)));; of a
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2383 ;; common year,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2384 (and (= (% day 7) 1);; ...or is on a Monday...
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2385 (>= parts 16789) ;; at 15 hours, 589 parts or later...
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2386 (hebrew-calendar-leap-year-p (1- year))));; at the end
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2387 ;; of a leap year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2388 ;; Then postpone Rosh HaShanah one day
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2389 (1+ day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2390 ;; Else
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2391 day)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2392 (if ;; If Rosh HaShanah would occur on Sunday, Wednesday, or Friday
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2393 (memq (% alternative-day 7) (list 0 3 5))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2394 ;; Then postpone it one (more) day and return
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2395 (1+ alternative-day)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2396 ;; Else return
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2397 alternative-day)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2398
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2399 (defun hebrew-calendar-days-in-year (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2400 "Number of days in Hebrew YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2401 (- (hebrew-calendar-elapsed-days (1+ year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2402 (hebrew-calendar-elapsed-days year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2403
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2404 (defun hebrew-calendar-long-heshvan-p (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2405 "t if Heshvan is long in Hebrew YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2406 (= (% (hebrew-calendar-days-in-year year) 10) 5))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2407
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2408 (defun hebrew-calendar-short-kislev-p (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2409 "t if Kislev is short in Hebrew YEAR."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2410 (= (% (hebrew-calendar-days-in-year year) 10) 3))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2411
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2412 (defun calendar-absolute-from-hebrew (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2413 "Absolute date of Hebrew DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2414 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2415 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2416 (let* ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2417 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2418 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2419 (+ day ;; Days so far this month.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2420 (if (< month 7);; before Tishri
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2421 ;; Then add days in prior months this year before and after Nisan
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2422 (+ (calendar-sum
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2423 m 7 (<= m (hebrew-calendar-last-month-of-year year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2424 (hebrew-calendar-last-day-of-month m year))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2425 (calendar-sum
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2426 m 1 (< m month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2427 (hebrew-calendar-last-day-of-month m year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2428 ;; Else add days in prior months this year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2429 (calendar-sum
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2430 m 7 (< m month)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2431 (hebrew-calendar-last-day-of-month m year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2432 (hebrew-calendar-elapsed-days year);; Days in prior years.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2433 -1373429))) ;; Days elapsed before absolute date 1.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2434
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2435 (defconst calendar-hebrew-month-name-array-common-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2436 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2437 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2438
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2439 (defconst calendar-hebrew-month-name-array-leap-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2440 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2441 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2442
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2443 (defun cursor-to-hebrew-calendar-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2444 "Show the Hebrew calendar equivalent of the date under the cursor."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2445 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2446 (let* ((calendar-date-display-form
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2447 (if european-calendar-style
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2448 '(day " " monthname " " year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2449 '(monthname " " day ", " year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2450 (hebrew-date (calendar-hebrew-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2451 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2452 (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2453 (error "Cursor is not on a date!")))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2454 (calendar-month-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2455 (if (hebrew-calendar-leap-year-p (extract-calendar-year hebrew-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2456 calendar-hebrew-month-name-array-leap-year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2457 calendar-hebrew-month-name-array-common-year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2458 (message "Hebrew date: %s" (calendar-date-string hebrew-date nil t))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2459
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2460 (defun french-calendar-leap-year-p (year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2461 "True if YEAR is a leap year on the French Revolutionary calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2462 For Gregorian years 1793 to 1805, the years of actual operation of the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2463 calendar, uses historical practice based on equinoxes is followed (years 3, 7,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2464 and 11 were leap years; 15 and 20 would have been leap years). For later
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2465 years uses the proposed rule of Romme (never adopted)--leap years fall every
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2466 four years except century years not divisible 400 and century years that are
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2467 multiples of 4000."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2468 (or (memq year '(3 7 11));; Actual practice--based on equinoxes
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2469 (memq year '(15 20)) ;; Anticipated practice--based on equinoxes
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2470 (and (> year 20) ;; Romme's proposal--never adopted
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2471 (zerop (% year 4))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2472 (not (memq (% year 400) '(100 200 300)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2473 (not (zerop (% year 4000))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2474
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2475 (defun french-calendar-last-day-of-month (month year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2476 "Last day of MONTH, YEAR on the French Revolutionary calendar.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2477 The 13th month is not really a month, but the 5 (6 in leap years) day period of
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2478 `sansculottides' at the end of the year."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2479 (if (< month 13)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2480 30
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2481 (if (french-calendar-leap-year-p year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2482 6
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2483 5)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2484
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2485 (defun calendar-absolute-from-french (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2486 "Absolute date of French Revolutionary DATE.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2487 The absolute date is the number of days elapsed since the (imaginary)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2488 Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2489 (let ((month (extract-calendar-month date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2490 (day (extract-calendar-day date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2491 (year (extract-calendar-year date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2492 (+ (* 365 (1- year));; Days in prior years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2493 ;; Leap days in prior years
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2494 (if (< year 20)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2495 (/ year 4);; Actual and anticipated practice (years 3, 7, 11, 15)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2496 ;; Romme's proposed rule (using the Principle of Inclusion/Exclusion)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2497 (+ (/ (1- year) 4);; Luckily, there were 4 leap years before year 20
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2498 (- (/ (1- year) 100))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2499 (/ (1- year) 400)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2500 (- (/ (1- year) 4000))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2501 (* 30 (1- month));; Days in prior months this year
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2502 day;; Days so far this month
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2503 654414)));; Days before start of calendar (September 22, 1792).
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2504
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2505 (defun calendar-french-from-absolute (date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2506 "Compute the French Revolutionary date (month day year) corresponding to
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2507 absolute DATE. The absolute date is the number of days elapsed since the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2508 (imaginary) Gregorian date Sunday, December 31, 1 BC."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2509 (if (< date 654415)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2510 (list 0 0 0);; pre-French Revolutionary date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2511 (let* ((approx (/ (- date 654414) 366));; Approximation from below.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2512 (year ;; Search forward from the approximation.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2513 (+ approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2514 (calendar-sum y approx
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2515 (>= date (calendar-absolute-from-french (list 1 1 (1+ y))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2516 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2517 (month ;; Search forward from Vendemiaire.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2518 (1+ (calendar-sum m 1
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2519 (> date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2520 (calendar-absolute-from-french
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2521 (list m
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2522 (french-calendar-last-day-of-month m year)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2523 year)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2524 1)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2525 (day ;; Calculate the day by subtraction.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2526 (- date
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2527 (1- (calendar-absolute-from-french (list month 1 year))))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2528 (list month day year))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2529
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2530 (defun cursor-to-french-calendar-date ()
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2531 "Show the French Revolutionary calendar equivalent of the date under the
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2532 cursor."
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2533 (interactive)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2534 (let* ((french-date (calendar-french-from-absolute
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2535 (calendar-absolute-from-gregorian
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2536 (or (calendar-cursor-to-date)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2537 (error "Cursor is not on a date!")))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2538 (y (extract-calendar-year french-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2539 (m (extract-calendar-month french-date))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2540 (d (extract-calendar-day french-date)))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2541 (if (< y 1)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2542 (message "Date is pre-French Revolution")
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2543 (if (= m 13)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2544 (message "Jour %s de l'Annee %d de la Revolution"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2545 (aref french-calendar-special-days-array (1- d))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2546 y)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2547 (message "Decade %s, %s de %s de l'Annee %d de la Revolution"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2548 (make-string (1+ (/ (1- d) 10)) ?I)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2549 (aref french-calendar-day-name-array (% (1- d) 10))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2550 (aref french-calendar-month-name-array (1- m))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2551 y)))))
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2552
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2553 (defconst french-calendar-month-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2554 ["Vendemiaire" "Brumaire" "Frimaire" "Nivose" "Pluviose" "Ventose" "Germinal"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2555 "Floreal" "Prairial" "Messidor" "Thermidor" "Fructidor"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2556 ;; Very loosely translated as
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2557 ;; Slippy, Nippy, Drippy, Freezy, Wheezy, Sneezy,
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2558 ;; Showery, Flowery, Bowery, Heaty, Wheaty, Sweety.
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2559
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2560 (defconst french-calendar-day-name-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2561 ["Primidi" "Duodi" "Tridi" "Quartidi" "Quintidi" "Sextidi" "Septidi"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2562 "Octidi" "Nonidi" "Decadi"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2563
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2564 (defconst french-calendar-special-days-array
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2565 ["de la Vertu" "du Genie" "du Labour" "de la Raison" "de la Recompense"
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2566 "de la Revolution"])
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2567
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2568 (provide 'calendar)
ab209803a494 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2569