0
|
1 ;;; calendar.el --- Calendar functions. -*-byte-compile-dynamic: t;-*-
|
|
2
|
|
3 ;;; Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994 Free Software
|
|
4 ;;; Foundation, Inc.
|
|
5
|
|
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
|
|
7 ;; Keywords: calendar
|
|
8 ;; Human-Keywords: calendar, Gregorian calendar, Julian calendar,
|
|
9 ;; Hebrew calendar, Islamic calendar, ISO calendar, Julian day number,
|
|
10 ;; diary, holidays
|
|
11
|
|
12 ;; This file is part of XEmacs.
|
|
13
|
|
14 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
15 ;; under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
|
18
|
|
19 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
16
|
25 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
0
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This collection of functions implements a calendar window. It
|
|
32 ;; generates a calendar for the current month, together with the previous
|
|
33 ;; and coming months, or for any other three-month period. The calendar
|
|
34 ;; can be scrolled forward and backward in the window to show months in
|
|
35 ;; the past or future; the cursor can move forward and backward by days,
|
|
36 ;; weeks, or months, making it possible, for instance, to jump to the
|
|
37 ;; date a specified number of days, weeks, or months from the date under
|
|
38 ;; the cursor. The user can display a list of holidays and other notable
|
|
39 ;; days for the period shown; the notable days can be marked on the
|
|
40 ;; calendar, if desired. The user can also specify that dates having
|
|
41 ;; corresponding diary entries (in a file that the user specifies) be
|
|
42 ;; marked; the diary entries for any date can be viewed in a separate
|
|
43 ;; window. The diary and the notable days can be viewed independently of
|
|
44 ;; the calendar. Dates can be translated from the (usual) Gregorian
|
|
45 ;; calendar to the day of the year/days remaining in year, to the ISO
|
|
46 ;; commercial calendar, to the Julian (old style) calendar, to the Hebrew
|
|
47 ;; calendar, to the Islamic calendar, to the French Revolutionary calendar,
|
|
48 ;; to the Mayan calendar, and to the astronomical (Julian) day number.
|
|
49 ;; When floating point is available, times of sunrise/sunset can be displayed,
|
|
50 ;; as can the phases of the moon. Appointment notification for diary entries
|
|
51 ;; is available.
|
|
52
|
|
53 ;; The following files are part of the calendar/diary code:
|
|
54
|
|
55 ;; cal-menu.el Menu support
|
|
56 ;; cal-x.el X-windows dedicated frame functions
|
|
57 ;; diary-lib.el, diary-ins.el Diary functions
|
|
58 ;; holidays.el Holiday functions
|
|
59 ;; cal-french.el French Revolutionary calendar
|
|
60 ;; cal-mayan.el Mayan calendars
|
|
61 ;; cal-dst.el Daylight savings time rules
|
|
62 ;; solar.el Sunrise/sunset, equinoxes/solstices
|
|
63 ;; lunar.el Phases of the moon
|
|
64 ;; appt.el Appointment notification
|
|
65
|
|
66 ;; Comments, corrections, and improvements should be sent to
|
|
67 ;; Edward M. Reingold Department of Computer Science
|
|
68 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
|
|
69 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
|
|
70 ;; Urbana, Illinois 61801
|
|
71
|
|
72 ;; GNU Emacs users too numerous to list pointed out a variety of problems
|
|
73 ;; with earlier forms of the `infinite' sliding calendar and suggested some
|
|
74 ;; of the features included in this package. Especially significant in this
|
|
75 ;; regard was the suggestion of mark-diary-entries and view-diary-entries,
|
|
76 ;; together ideas for their implementation, by
|
|
77 ;; Michael S. Littman Cognitive Science Research Group
|
|
78 ;; (201) 829-5155 Bell Communications Research
|
|
79 ;; mlittman@wind.bellcore.com 445 South St. Box 1961 (2L-331)
|
|
80 ;; Morristown, NJ 07960
|
|
81
|
|
82 ;; The algorithms for the Hebrew calendar are those of the Rambam (Rabbi Moses
|
|
83 ;; Maimonides), from his Mishneh Torah, as implemented by
|
|
84 ;; Nachum Dershowitz Department of Computer Science
|
|
85 ;; (217) 333-4219 University of Illinois at Urbana-Champaign
|
|
86 ;; nachum@cs.uiuc.edu 1304 West Springfield Avenue
|
|
87 ;; Urbana, Illinois 61801
|
|
88
|
|
89 ;; Technical details of all the calendrical calculations can be found in
|
|
90
|
|
91 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
|
|
92 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
|
|
93 ;; pages 899-928. ``Calendrical Calculations, Part II: Three Historical
|
|
94 ;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
|
|
95 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
|
|
96 ;; pages 383-404.
|
|
97
|
|
98 ;; Hard copies of these two papers can be obtained by sending email to
|
|
99 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
|
|
100 ;; the message BODY containing your mailing address (snail).
|
|
101
|
|
102 ;;; Code:
|
|
103
|
|
104 (defun calendar-version ()
|
|
105 (interactive)
|
|
106 (message "Version 5.3, January 25, 1994"))
|
|
107
|
|
108 ;;;###autoload
|
|
109 (defvar calendar-week-start-day 0
|
|
110 "*The day of the week on which a week in the calendar begins.
|
|
111 0 means Sunday (default), 1 means Monday, and so on.")
|
|
112
|
|
113 ;;;###autoload
|
|
114 (defvar calendar-offset 0
|
|
115 "*The offset of the principal month from the center of the calendar window.
|
|
116 0 means the principal month is in the center (default), -1 means on the left,
|
|
117 +1 means on the right. Larger (or smaller) values push the principal month off
|
|
118 the screen.")
|
|
119
|
|
120 ;;;###autoload
|
|
121 (defvar view-diary-entries-initially nil
|
|
122 "*Non-nil means display current date's diary entries on entry.
|
|
123 The diary is displayed in another window when the calendar is first displayed,
|
|
124 if the current date is visible. The number of days of diary entries displayed
|
|
125 is governed by the variable `number-of-diary-entries'.")
|
|
126
|
|
127 ;;;###autoload
|
|
128 (defvar number-of-diary-entries 1
|
|
129 "*Specifies how many days of diary entries are to be displayed initially.
|
|
130 This variable affects the diary display when the command M-x diary is used,
|
|
131 or if the value of the variable `view-diary-entries-initially' is t. For
|
|
132 example, if the default value 1 is used, then only the current day's diary
|
|
133 entries will be displayed. If the value 2 is used, then both the current
|
|
134 day's and the next day's entries will be displayed.
|
|
135
|
|
136 The value can also be a vector such as [0 2 2 2 2 4 1]; this value
|
|
137 says to display no diary entries on Sunday, the display the entries
|
|
138 for the current date and the day after on Monday through Thursday,
|
|
139 display Friday through Monday's entries on Friday, and display only
|
|
140 Saturday's entries on Saturday.
|
|
141
|
|
142 This variable does not affect the diary display with the `d' command
|
|
143 from the calendar; in that case, the prefix argument controls the
|
|
144 number of days of diary entries displayed.")
|
|
145
|
|
146 ;;;###autoload
|
|
147 (defvar mark-diary-entries-in-calendar nil
|
|
148 "*Non-nil means mark dates with diary entries, in the calendar window.
|
|
149 The marking symbol is specified by the variable `diary-entry-marker'.")
|
|
150
|
|
151 (defvar diary-entry-marker
|
|
152 (progn
|
|
153 (make-face 'diary-face)
|
|
154 (cond ((face-differs-from-default-p 'diary-face) nil)
|
|
155 (t (set-face-foreground 'diary-face "red" 'global '(x color))
|
|
156 (set-face-highlight-p 'diary-face t 'global 'tty)
|
|
157 ;; avoid a weird problem when byte-compiling appt.el
|
|
158 ;; in batch mode.
|
|
159 (if (and (not noninteractive) (fboundp 'x-make-font-bold))
|
|
160 (let ((bfont (x-make-font-bold
|
|
161 (face-font-instance 'default)))
|
|
162 (mono-tag (list 'x 'mono))
|
|
163 (gray-tag (list 'x 'grayscale)))
|
|
164 (if bfont
|
|
165 (progn
|
|
166 (set-face-font 'diary-face bfont 'global mono-tag)
|
|
167 (set-face-font 'diary-face bfont 'global
|
|
168 gray-tag)))))))
|
|
169 'diary-face)
|
|
170 "*Used to mark dates that have diary entries.
|
|
171 Can be either a single-character string or a face.")
|
|
172
|
|
173 (defvar calendar-today-marker
|
|
174 (progn
|
|
175 (make-face 'calendar-today-face)
|
|
176 (if (not (face-differs-from-default-p 'calendar-today-face))
|
|
177 (set-face-underline-p 'calendar-today-face t))
|
|
178 'calendar-today-face)
|
|
179 "*Used to mark today's date.
|
|
180 Can be either a single-character string or a face.")
|
|
181
|
|
182 (defvar calendar-holiday-marker
|
|
183 (progn
|
|
184 (make-face 'holiday-face)
|
|
185 (cond ((face-differs-from-default-p 'holiday-face) nil)
|
|
186 (t (let ((color-tag (list 'x 'color))
|
|
187 (mono-tag (list 'x 'mono))
|
|
188 (gray-tag (list 'x 'grayscale)))
|
|
189 (set-face-background 'holiday-face [default foreground] 'global
|
|
190 mono-tag)
|
|
191 (set-face-foreground 'holiday-face [default background] 'global
|
|
192 mono-tag)
|
|
193 (set-face-background 'holiday-face [default foreground] 'global
|
|
194 gray-tag)
|
|
195 (set-face-foreground 'holiday-face [default background] 'global
|
|
196 gray-tag)
|
|
197 (set-face-background 'holiday-face "pink" 'global color-tag)
|
|
198 (set-face-reverse-p 'holiday-face t 'global 'tty))))
|
|
199 'holiday-face)
|
|
200 "*Used to mark notable dates in the calendar.
|
|
201 Can be either a single-character string or a face.")
|
|
202
|
|
203 ;;;###autoload
|
|
204 (defvar view-calendar-holidays-initially nil
|
|
205 "*Non-nil means display holidays for current three month period on entry.
|
|
206 The holidays are displayed in another window when the calendar is first
|
|
207 displayed.")
|
|
208
|
|
209 ;;;###autoload
|
|
210 (defvar mark-holidays-in-calendar nil
|
|
211 "*Non-nil means mark dates of holidays in the calendar window.
|
|
212 The marking symbol is specified by the variable `calendar-holiday-marker'.")
|
|
213
|
|
214 ;;;###autoload
|
|
215 (defvar all-hebrew-calendar-holidays nil
|
|
216 "*If nil, show only major holidays from the Hebrew calendar.
|
|
217 This means only those Jewish holidays that appear on secular calendars.
|
|
218
|
|
219 If t, show all the holidays that would appear in a complete Hebrew calendar.")
|
|
220
|
|
221 ;;;###autoload
|
|
222 (defvar all-christian-calendar-holidays nil
|
|
223 "*If nil, show only major holidays from the Christian calendar.
|
|
224 This means only those Christian holidays that appear on secular calendars.
|
|
225
|
|
226 If t, show all the holidays that would appear in a complete Christian
|
|
227 calendar.")
|
|
228
|
|
229 ;;;###autoload
|
|
230 (defvar all-islamic-calendar-holidays nil
|
|
231 "*If nil, show only major holidays from the Islamic calendar.
|
|
232 This means only those Islamic holidays that appear on secular calendars.
|
|
233
|
|
234 If t, show all the holidays that would appear in a complete Islamic
|
|
235 calendar.")
|
|
236
|
|
237 ;;;###autoload
|
|
238 (defvar calendar-load-hook nil
|
|
239 "*List of functions to be called after the calendar is first loaded.
|
|
240 This is the place to add key bindings to `calendar-mode-map'.")
|
|
241
|
|
242 ;;;###autoload
|
|
243 (defvar initial-calendar-window-hook nil
|
|
244 "*List of functions to be called when the calendar window is first opened.
|
|
245 The functions invoked are called after the calendar window is opened, but
|
|
246 once opened is never called again. Leaving the calendar with the `q' command
|
|
247 and reentering it will cause these functions to be called again.")
|
|
248
|
|
249 ;;;###autoload
|
|
250 (defvar today-visible-calendar-hook nil
|
|
251 "*List of functions called whenever the current date is visible.
|
|
252 This can be used, for example, to replace today's date with asterisks; a
|
|
253 function `calendar-star-date' is included for this purpose:
|
|
254 (setq today-visible-calendar-hook 'calendar-star-date)
|
|
255 It can also be used to mark the current date with `calendar-today-marker';
|
|
256 a function is also provided for this:
|
|
257 (setq today-visible-calendar-hook 'calendar-mark-today)
|
|
258
|
|
259 The corresponding variable `today-invisible-calendar-hook' is the list of
|
|
260 functions called when the calendar function was called when the current
|
|
261 date is not visible in the window.
|
|
262
|
|
263 Other than the use of the provided functions, the changing of any
|
|
264 characters in the calendar buffer by the hooks may cause the failure of the
|
|
265 functions that move by days and weeks.")
|
|
266
|
|
267 ;;;###autoload
|
|
268 (defvar today-invisible-calendar-hook nil
|
|
269 "*List of functions called whenever the current date is not visible.
|
|
270
|
|
271 The corresponding variable `today-visible-calendar-hook' is the list of
|
|
272 functions called when the calendar function was called when the current
|
|
273 date is visible in the window.
|
|
274
|
|
275 Other than the use of the provided functions, the changing of any
|
|
276 characters in the calendar buffer by the hooks may cause the failure of the
|
|
277 functions that move by days and weeks.")
|
|
278
|
|
279 ;;;###autoload
|
|
280 (defvar diary-file "~/diary"
|
|
281 "*Name of the file in which one's personal diary of dates is kept.
|
|
282
|
|
283 The file's entries are lines in any of the forms
|
|
284
|
|
285 MONTH/DAY
|
|
286 MONTH/DAY/YEAR
|
|
287 MONTHNAME DAY
|
|
288 MONTHNAME DAY, YEAR
|
|
289 DAYNAME
|
|
290
|
|
291 at the beginning of the line; the remainder of the line is the diary entry
|
|
292 string for that date. MONTH and DAY are one or two digit numbers, YEAR is
|
|
293 a number and may be written in full or abbreviated to the final two digits.
|
|
294 If the date does not contain a year, it is generic and applies to any year.
|
|
295 DAYNAME entries apply to any date on which is on that day of the week.
|
|
296 MONTHNAME and DAYNAME can be spelled in full, abbreviated to three
|
|
297 characters (with or without a period), capitalized or not. Any of DAY,
|
|
298 MONTH, or MONTHNAME, YEAR can be `*' which matches any day, month, or year,
|
|
299 respectively.
|
|
300
|
|
301 The European style (in which the day precedes the month) can be used
|
|
302 instead, if you execute `european-calendar' when in the calendar, or set
|
|
303 `european-calendar-style' to t in your .emacs file. The European forms are
|
|
304
|
|
305 DAY/MONTH
|
|
306 DAY/MONTH/YEAR
|
|
307 DAY MONTHNAME
|
|
308 DAY MONTHNAME YEAR
|
|
309 DAYNAME
|
|
310
|
|
311 To revert to the default American style from the European style, execute
|
|
312 `american-calendar' in the calendar.
|
|
313
|
|
314 A diary entry can be preceded by the character
|
|
315 `diary-nonmarking-symbol' (ordinarily `&') to make that entry
|
|
316 nonmarking--that is, it will not be marked on dates in the calendar
|
|
317 window but will appear in a diary window.
|
|
318
|
|
319 Multiline diary entries are made by indenting lines after the first with
|
|
320 either a TAB or one or more spaces.
|
|
321
|
|
322 Lines not in one the above formats are ignored. Here are some sample diary
|
|
323 entries (in the default American style):
|
|
324
|
|
325 12/22/1988 Twentieth wedding anniversary!!
|
|
326 &1/1. Happy New Year!
|
|
327 10/22 Ruth's birthday.
|
|
328 21: Payday
|
|
329 Tuesday--weekly meeting with grad students at 10am
|
|
330 Supowit, Shen, Bitner, and Kapoor to attend.
|
|
331 1/13/89 Friday the thirteenth!!
|
|
332 &thu 4pm squash game with Lloyd.
|
|
333 mar 16 Dad's birthday
|
|
334 April 15, 1989 Income tax due.
|
|
335 &* 15 time cards due.
|
|
336
|
|
337 If the first line of a diary entry consists only of the date or day name with
|
|
338 no trailing blanks or punctuation, then that line is not displayed in the
|
|
339 diary window; only the continuation lines is shown. For example, the
|
|
340 single diary entry
|
|
341
|
|
342 02/11/1989
|
|
343 Bill Blattner visits Princeton today
|
|
344 2pm Cognitive Studies Committee meeting
|
|
345 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
|
|
346 4:00pm Jamie Tappenden
|
|
347 7:30pm Dinner at George and Ed's for Alan Ryan
|
|
348 7:30-10:00pm dance at Stewart Country Day School
|
|
349
|
|
350 will appear in the diary window without the date line at the beginning. This
|
|
351 facility allows the diary window to look neater, but can cause confusion if
|
|
352 used with more than one day's entries displayed.
|
|
353
|
|
354 Diary entries can be based on Lisp sexps. For example, the diary entry
|
|
355
|
|
356 %%(diary-block 11 1 1990 11 10 1990) Vacation
|
|
357
|
|
358 causes the diary entry \"Vacation\" to appear from November 1 through November
|
|
359 10, 1990. Other functions available are `diary-float', `diary-anniversary',
|
|
360 `diary-cyclic', `diary-day-of-year', `diary-iso-date', `diary-french-date',
|
|
361 `diary-hebrew-date', `diary-islamic-date', `diary-mayan-date',
|
|
362 `diary-yahrzeit', `diary-sunrise-sunset', `diary-phases-of-moon',
|
|
363 `diary-parasha', `diary-omer', `diary-rosh-hodesh', and
|
|
364 `diary-sabbath-candles'. See the documentation for the function
|
|
365 `list-sexp-diary-entries' for more details.
|
|
366
|
|
367 Diary entries based on the Hebrew and/or the Islamic calendar are also
|
|
368 possible, but because these are somewhat slow, they are ignored
|
|
369 unless you set the `nongregorian-diary-listing-hook' and the
|
|
370 `nongregorian-diary-marking-hook' appropriately. See the documentation
|
|
371 for these functions for details.
|
|
372
|
|
373 Diary files can contain directives to include the contents of other files; for
|
|
374 details, see the documentation for the variable `list-diary-entries-hook'.")
|
|
375
|
|
376 ;;;###autoload
|
|
377 (defvar diary-nonmarking-symbol "&"
|
|
378 "*Symbol indicating that a diary entry is not to be marked in the calendar.")
|
|
379
|
|
380 ;;;###autoload
|
|
381 (defvar hebrew-diary-entry-symbol "H"
|
|
382 "*Symbol indicating a diary entry according to the Hebrew calendar.")
|
|
383
|
|
384 ;;;###autoload
|
|
385 (defvar islamic-diary-entry-symbol "I"
|
|
386 "*Symbol indicating a diary entry according to the Islamic calendar.")
|
|
387
|
|
388 ;;;###autoload
|
|
389 (defvar diary-include-string "#include"
|
|
390 "*The string indicating inclusion of another file of diary entries.
|
|
391 See the documentation for the function `include-other-diary-files'.")
|
|
392
|
|
393 ;;;###autoload
|
|
394 (defvar sexp-diary-entry-symbol "%%"
|
|
395 "*The string used to indicate a sexp diary entry in diary-file.
|
|
396 See the documentation for the function `list-sexp-diary-entries'.")
|
|
397
|
|
398 ;;;###autoload
|
|
399 (defvar abbreviated-calendar-year t
|
|
400 "*Interpret a two-digit year DD in a diary entry as either 19DD or 20DD.
|
|
401 For the Gregorian calendar; similarly for the Hebrew and Islamic calendars.
|
|
402 If this variable is nil, years must be written in full.")
|
|
403
|
|
404 ;;;###autoload
|
|
405 (defvar european-calendar-style nil
|
|
406 "*Use the European style of dates in the diary and in any displays.
|
|
407 If this variable is t, a date 1/2/1990 would be interpreted as February 1,
|
|
408 1990. The accepted European date styles are
|
|
409
|
|
410 DAY/MONTH
|
|
411 DAY/MONTH/YEAR
|
|
412 DAY MONTHNAME
|
|
413 DAY MONTHNAME YEAR
|
|
414 DAYNAME
|
|
415
|
|
416 Names can be capitalized or not, written in full, or abbreviated to three
|
|
417 characters with or without a period.")
|
|
418
|
|
419 ;;;###autoload
|
|
420 (defvar american-date-diary-pattern
|
|
421 '((month "/" day "[^/0-9]")
|
|
422 (month "/" day "/" year "[^0-9]")
|
|
423 (monthname " *" day "[^,0-9]")
|
|
424 (monthname " *" day ", *" year "[^0-9]")
|
|
425 (dayname "\\W"))
|
|
426 "*List of pseudo-patterns describing the American patterns of date used.
|
|
427 See the documentation of `diary-date-forms' for an explanation.")
|
|
428
|
|
429 ;;;###autoload
|
|
430 (defvar european-date-diary-pattern
|
|
431 '((day "/" month "[^/0-9]")
|
|
432 (day "/" month "/" year "[^0-9]")
|
|
433 (backup day " *" monthname "\\W+\\<[^*0-9]")
|
|
434 (day " *" monthname " *" year "[^0-9]")
|
|
435 (dayname "\\W"))
|
|
436 "*List of pseudo-patterns describing the European patterns of date used.
|
|
437 See the documentation of `diary-date-forms' for an explanation.")
|
|
438
|
|
439 (defvar diary-date-forms
|
|
440 (if european-calendar-style
|
|
441 european-date-diary-pattern
|
|
442 american-date-diary-pattern)
|
|
443 "*List of pseudo-patterns describing the forms of date used in the diary.
|
|
444 The patterns on the list must be MUTUALLY EXCLUSIVE and must should not match
|
|
445 any portion of the diary entry itself, just the date component.
|
|
446
|
|
447 A pseudo-pattern is a list of regular expressions and the keywords `month',
|
|
448 `day', `year', `monthname', and `dayname'. The keyword `monthname' will
|
|
449 match the name of the month, capitalized or not, or its three-letter
|
|
450 abbreviation, followed by a period or not; it will also match `*'.
|
|
451 Similarly, `dayname' will match the name of the day, capitalized or not, or
|
|
452 its three-letter abbreviation, followed by a period or not. The keywords
|
|
453 `month', `day', and `year' will match those numerical values, preceded by
|
|
454 arbitrarily many zeros; they will also match `*'.
|
|
455
|
|
456 The matching of the diary entries with the date forms is done with the
|
|
457 standard syntax table from Fundamental mode, but with the `*' changed so
|
|
458 that it is a word constituent.
|
|
459
|
|
460 If, to be mutually exclusive, a pseudo-pattern must match a portion of the
|
|
461 diary entry itself, the first element of the pattern MUST be `backup'. This
|
|
462 directive causes the date recognizer to back up to the beginning of the
|
|
463 current word of the diary entry, so in no case can the pattern match more than
|
|
464 a portion of the first word of the diary entry.")
|
|
465
|
|
466 ;;;###autoload
|
|
467 (defvar european-calendar-display-form
|
|
468 '((if dayname (concat dayname ", ")) day " " monthname " " year)
|
|
469 "*Pseudo-pattern governing the way a date appears in the European style.
|
|
470 See the documentation of calendar-date-display-form for an explanation.")
|
|
471
|
|
472 ;;;###autoload
|
|
473 (defvar american-calendar-display-form
|
|
474 '((if dayname (concat dayname ", ")) monthname " " day ", " year)
|
|
475 "*Pseudo-pattern governing the way a date appears in the American style.
|
|
476 See the documentation of `calendar-date-display-form' for an explanation.")
|
|
477
|
|
478 (defvar calendar-date-display-form
|
|
479 (if european-calendar-style
|
|
480 european-calendar-display-form
|
|
481 american-calendar-display-form)
|
|
482 "*Pseudo-pattern governing the way a date appears.
|
|
483
|
|
484 Used by the function `calendar-date-string', a pseudo-pattern is a list of
|
|
485 expressions that can involve the keywords `month', `day', and `year', all
|
|
486 numbers in string form, and `monthname' and `dayname', both alphabetic
|
|
487 strings. For example, the ISO standard would use the pseudo- pattern
|
|
488
|
|
489 '(year \"-\" month \"-\" day)
|
|
490
|
|
491 while a typical American form would be
|
|
492
|
|
493 '(month \"/\" day \"/\" (substring year -2))
|
|
494
|
|
495 and
|
|
496
|
|
497 '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
|
|
498
|
|
499 would give the usual American style in fixed-length fields.
|
|
500
|
|
501 See the documentation of the function `calendar-date-string'.")
|
|
502
|
|
503 (defun european-calendar ()
|
|
504 "Set the interpretation and display of dates to the European style."
|
|
505 (interactive)
|
|
506 (setq european-calendar-style t)
|
|
507 (setq calendar-date-display-form european-calendar-display-form)
|
|
508 (setq diary-date-forms european-date-diary-pattern)
|
|
509 (update-calendar-mode-line))
|
|
510
|
|
511 (defun american-calendar ()
|
|
512 "Set the interpretation and display of dates to the American style."
|
|
513 (interactive)
|
|
514 (setq european-calendar-style nil)
|
|
515 (setq calendar-date-display-form american-calendar-display-form)
|
|
516 (setq diary-date-forms american-date-diary-pattern)
|
|
517 (update-calendar-mode-line))
|
|
518
|
|
519 ;;;###autoload
|
|
520 (defvar print-diary-entries-hook 'lpr-buffer
|
|
521 "*List of functions called after a temporary diary buffer is prepared.
|
|
522 The buffer shows only the diary entries currently visible in the diary
|
|
523 buffer. The default just does the printing. Other uses might include, for
|
|
524 example, rearranging the lines into order by day and time, saving the buffer
|
|
525 instead of deleting it, or changing the function used to do the printing.")
|
|
526
|
|
527 ;;;###autoload
|
|
528 (defvar list-diary-entries-hook nil
|
|
529 "*List of functions called after diary file is culled for relevant entries.
|
|
530 It is to be used for diary entries that are not found in the diary file.
|
|
531
|
|
532 A function `include-other-diary-files' is provided for use as the value of
|
|
533 this hook. This function enables you to use shared diary files together
|
|
534 with your own. The files included are specified in the diary file by lines
|
|
535 of the form
|
|
536
|
|
537 #include \"filename\"
|
|
538
|
|
539 This is recursive; that is, #include directives in files thus included are
|
|
540 obeyed. You can change the \"#include\" to some other string by changing
|
|
541 the variable `diary-include-string'. When you use `include-other-diary-files'
|
|
542 as part of the list-diary-entries-hook, you will probably also want to use the
|
|
543 function `mark-included-diary-files' as part of `mark-diary-entries-hook'.
|
|
544
|
|
545 For example, you could use
|
|
546
|
|
547 (setq list-diary-entries-hook
|
|
548 '(include-other-diary-files sort-diary-entries))
|
|
549 (setq diary-display-hook 'fancy-diary-display)
|
|
550
|
|
551 in your `.emacs' file to cause the fancy diary buffer to be displayed with
|
|
552 diary entries from various included files, each day's entries sorted into
|
|
553 lexicographic order.")
|
|
554
|
|
555 ;;;###autoload
|
|
556 (defvar diary-hook nil
|
|
557 "*List of functions called after the display of the diary.
|
|
558 Can be used for appointment notification.")
|
|
559
|
|
560 ;;;###autoload
|
|
561 (defvar diary-display-hook nil
|
|
562 "*List of functions that handle the display of the diary.
|
|
563 If nil (the default), `simple-diary-display' is used. Use `ignore' for no
|
|
564 diary display.
|
|
565
|
|
566 Ordinarily, this just displays the diary buffer (with holidays indicated in
|
|
567 the mode line), if there are any relevant entries. At the time these
|
|
568 functions are called, the variable `diary-entries-list' is a list, in order
|
|
569 by date, of all relevant diary entries in the form of ((MONTH DAY YEAR)
|
|
570 STRING), where string is the diary entry for the given date. This can be
|
|
571 used, for example, a different buffer for display (perhaps combined with
|
|
572 holidays), or produce hard copy output.
|
|
573
|
|
574 A function `fancy-diary-display' is provided as an alternative
|
|
575 choice for this hook; this function prepares a special noneditable diary
|
|
576 buffer with the relevant diary entries that has neat day-by-day arrangement
|
|
577 with headings. The fancy diary buffer will show the holidays unless the
|
|
578 variable `holidays-in-diary-buffer' is set to nil. Ordinarily, the fancy
|
|
579 diary buffer will not show days for which there are no diary entries, even
|
|
580 if that day is a holiday; if you want such days to be shown in the fancy
|
|
581 diary buffer, set the variable `diary-list-include-blanks' to t.")
|
|
582
|
|
583 ;;;###autoload
|
|
584 (defvar nongregorian-diary-listing-hook nil
|
|
585 "*List of functions called for listing diary file and included files.
|
|
586 As the files are processed for diary entries, these functions are used to cull
|
|
587 relevant entries. You can use either or both of `list-hebrew-diary-entries'
|
|
588 and `list-islamic-diary-entries'. The documentation for these functions
|
|
589 describes the style of such diary entries.")
|
|
590
|
|
591 ;;;###autoload
|
|
592 (defvar mark-diary-entries-hook nil
|
|
593 "*List of functions called after marking diary entries in the calendar.
|
|
594
|
|
595 A function `mark-included-diary-files' is also provided for use as the
|
|
596 mark-diary-entries-hook; it enables you to use shared diary files together
|
|
597 with your own. The files included are specified in the diary file by lines
|
|
598 of the form
|
|
599 #include \"filename\"
|
|
600 This is recursive; that is, #include directives in files thus included are
|
|
601 obeyed. You can change the \"#include\" to some other string by changing the
|
|
602 variable `diary-include-string'. When you use `mark-included-diary-files' as
|
|
603 part of the mark-diary-entries-hook, you will probably also want to use the
|
|
604 function `include-other-diary-files' as part of `list-diary-entries-hook'.")
|
|
605
|
|
606 ;;;###autoload
|
|
607 (defvar nongregorian-diary-marking-hook nil
|
|
608 "*List of functions called for marking diary file and included files.
|
|
609 As the files are processed for diary entries, these functions are used to cull
|
|
610 relevant entries. You can use either or both of `mark-hebrew-diary-entries'
|
|
611 and `mark-islamic-diary-entries'. The documentation for these functions
|
|
612 describes the style of such diary entries.")
|
|
613
|
|
614 ;;;###autoload
|
|
615 (defvar diary-list-include-blanks nil
|
|
616 "*If nil, do not include days with no diary entry in the list of diary entries.
|
2
|
617 Such days will then not be shown in the fancy diary buffer, even if they
|
0
|
618 are holidays.")
|
|
619
|
|
620 ;;;###autoload
|
|
621 (defvar holidays-in-diary-buffer t
|
|
622 "*Non-nil means include holidays in the diary display.
|
|
623 The holidays appear in the mode line of the diary buffer, or in the
|
|
624 fancy diary buffer next to the date. This slows down the diary functions
|
|
625 somewhat; setting it to nil makes the diary display faster.")
|
|
626
|
|
627 (defvar calendar-mark-ring nil)
|
|
628
|
|
629 ;;;###autoload
|
|
630 (put 'general-holidays 'risky-local-variable t)
|
|
631 ;;;###autoload
|
|
632 (defvar general-holidays
|
|
633 '((holiday-fixed 1 1 "New Year's Day")
|
|
634 (holiday-float 1 1 3 "Martin Luther King Day")
|
|
635 (holiday-fixed 2 2 "Ground Hog Day")
|
|
636 (holiday-fixed 2 14 "Valentine's Day")
|
|
637 (holiday-float 2 1 3 "President's Day")
|
|
638 (holiday-fixed 3 17 "St. Patrick's Day")
|
|
639 (holiday-fixed 4 1 "April Fool's Day")
|
|
640 (holiday-float 5 0 2 "Mother's Day")
|
|
641 (holiday-float 5 1 -1 "Memorial Day")
|
|
642 (holiday-fixed 6 14 "Flag Day")
|
|
643 (holiday-float 6 0 3 "Father's Day")
|
|
644 (holiday-fixed 7 4 "Independence Day")
|
|
645 (holiday-float 9 1 1 "Labor Day")
|
|
646 (holiday-float 10 1 2 "Columbus Day")
|
|
647 (holiday-fixed 10 31 "Halloween")
|
|
648 (holiday-fixed 11 11 "Veteran's Day")
|
|
649 (holiday-float 11 4 4 "Thanksgiving"))
|
|
650 "*General holidays. Default value is for the United States.
|
|
651 See the documentation for `calendar-holidays' for details.")
|
|
652
|
|
653 ;;;###autoload
|
|
654 (put 'local-holidays 'risky-local-variable t)
|
|
655 ;;;###autoload
|
|
656 (defvar local-holidays nil
|
|
657 "*Local holidays.
|
|
658 See the documentation for `calendar-holidays' for details.")
|
|
659
|
|
660 ;;;###autoload
|
|
661 (put 'other-holidays 'risky-local-variable t)
|
|
662 ;;;###autoload
|
|
663 (defvar other-holidays nil
|
|
664 "*User defined holidays.
|
|
665 See the documentation for `calendar-holidays' for details.")
|
|
666
|
|
667 ;;;###autoload
|
|
668 (put 'hebrew-holidays-1 'risky-local-variable t)
|
|
669 ;;;###autoload
|
|
670 (defvar hebrew-holidays-1
|
|
671 '((holiday-rosh-hashanah-etc)
|
|
672 (if all-hebrew-calendar-holidays
|
|
673 (holiday-julian
|
|
674 11
|
|
675 (let* ((m displayed-month)
|
|
676 (y displayed-year)
|
|
677 (year))
|
|
678 (increment-calendar-month m y -1)
|
|
679 (let ((year (extract-calendar-year
|
|
680 (calendar-julian-from-absolute
|
|
681 (calendar-absolute-from-gregorian
|
|
682 (list m 1 y))))))
|
|
683 (if (zerop (% (1+ year) 4))
|
|
684 22
|
|
685 21))) "\"Tal Umatar\" (evening)"))))
|
|
686
|
|
687 ;;;###autoload
|
|
688 (put 'hebrew-holidays-2 'risky-local-variable t)
|
|
689 ;;;###autoload
|
|
690 (defvar hebrew-holidays-2
|
|
691 '((if all-hebrew-calendar-holidays
|
|
692 (holiday-hanukkah)
|
|
693 (holiday-hebrew 9 25 "Hanukkah"))
|
|
694 (if all-hebrew-calendar-holidays
|
|
695 (holiday-hebrew
|
|
696 10
|
|
697 (let ((h-year (extract-calendar-year
|
|
698 (calendar-hebrew-from-absolute
|
|
699 (calendar-absolute-from-gregorian
|
|
700 (list displayed-month 28 displayed-year))))))
|
|
701 (if (= (% (calendar-absolute-from-hebrew (list 10 10 h-year))
|
|
702 7)
|
|
703 6)
|
|
704 11 10))
|
|
705 "Tzom Teveth"))
|
|
706 (if all-hebrew-calendar-holidays
|
|
707 (holiday-hebrew 11 15 "Tu B'Shevat"))))
|
|
708
|
|
709 ;;;###autoload
|
|
710 (put 'hebrew-holidays-3 'risky-local-variable t)
|
|
711 ;;;###autoload
|
|
712 (defvar hebrew-holidays-3
|
|
713 '((if all-hebrew-calendar-holidays
|
|
714 (holiday-hebrew
|
|
715 11
|
|
716 (let ((m displayed-month)
|
|
717 (y displayed-year))
|
|
718 (increment-calendar-month m y 1)
|
|
719 (let* ((h-year (extract-calendar-year
|
|
720 (calendar-hebrew-from-absolute
|
|
721 (calendar-absolute-from-gregorian
|
|
722 (list m
|
|
723 (calendar-last-day-of-month m y)
|
|
724 y)))))
|
|
725 (s-s
|
|
726 (calendar-hebrew-from-absolute
|
|
727 (if (=
|
|
728 (% (calendar-absolute-from-hebrew
|
|
729 (list 7 1 h-year))
|
|
730 7)
|
|
731 6)
|
|
732 (calendar-dayname-on-or-before
|
|
733 6 (calendar-absolute-from-hebrew
|
|
734 (list 11 17 h-year)))
|
|
735 (calendar-dayname-on-or-before
|
|
736 6 (calendar-absolute-from-hebrew
|
|
737 (list 11 16 h-year))))))
|
|
738 (day (extract-calendar-day s-s)))
|
|
739 day))
|
|
740 "Shabbat Shirah"))))
|
|
741
|
|
742 ;;;###autoload
|
|
743 (put 'hebrew-holidays-4 'risky-local-variable t)
|
|
744 ;;;###autoload
|
|
745 (defvar hebrew-holidays-4
|
|
746 '((holiday-passover-etc)
|
|
747 (if (and all-hebrew-calendar-holidays
|
|
748 (let* ((m displayed-month)
|
|
749 (y displayed-year)
|
|
750 (year))
|
|
751 (increment-calendar-month m y -1)
|
|
752 (let ((year (extract-calendar-year
|
|
753 (calendar-julian-from-absolute
|
|
754 (calendar-absolute-from-gregorian
|
|
755 (list m 1 y))))))
|
|
756 (= 21 (% year 28)))))
|
|
757 (holiday-julian 3 26 "Kiddush HaHamah"))
|
|
758 (if all-hebrew-calendar-holidays
|
|
759 (holiday-tisha-b-av-etc))))
|
|
760
|
|
761 ;;;###autoload
|
|
762 (put 'hebrew-holidays 'risky-local-variable t)
|
|
763 ;;;###autoload
|
|
764 (defvar hebrew-holidays (append hebrew-holidays-1 hebrew-holidays-2
|
|
765 hebrew-holidays-3 hebrew-holidays-4)
|
|
766 "*Jewish holidays.
|
|
767 See the documentation for `calendar-holidays' for details.")
|
|
768
|
|
769 ;;;###autoload
|
|
770 (put 'christian-holidays 'risky-local-variable t)
|
|
771 ;;;###autoload
|
|
772 (defvar christian-holidays
|
|
773 '((if all-christian-calendar-holidays
|
|
774 (holiday-fixed 1 6 "Epiphany"))
|
|
775 (holiday-easter-etc)
|
|
776 (if all-christian-calendar-holidays
|
|
777 (holiday-greek-orthodox-easter))
|
|
778 (if all-christian-calendar-holidays
|
|
779 (holiday-fixed 8 15 "Assumption"))
|
|
780 (if all-christian-calendar-holidays
|
|
781 (holiday-advent))
|
|
782 (holiday-fixed 12 25 "Christmas")
|
|
783 (if all-christian-calendar-holidays
|
|
784 (holiday-julian 12 25 "Eastern Orthodox Christmas")))
|
|
785 "*Christian holidays.
|
|
786 See the documentation for `calendar-holidays' for details.")
|
|
787
|
|
788 ;;;###autoload
|
|
789 (put 'islamic-holidays 'risky-local-variable t)
|
|
790 ;;;###autoload
|
|
791 (defvar islamic-holidays
|
|
792 '((holiday-islamic
|
|
793 1 1
|
|
794 (format "Islamic New Year %d"
|
|
795 (let ((m displayed-month)
|
|
796 (y displayed-year))
|
|
797 (increment-calendar-month m y 1)
|
|
798 (extract-calendar-year
|
|
799 (calendar-islamic-from-absolute
|
|
800 (calendar-absolute-from-gregorian
|
|
801 (list
|
|
802 m (calendar-last-day-of-month m y) y)))))))
|
|
803 (if all-islamic-calendar-holidays
|
|
804 (holiday-islamic 1 10 "Ashura"))
|
|
805 (if all-islamic-calendar-holidays
|
|
806 (holiday-islamic 3 12 "Mulad-al-Nabi"))
|
|
807 (if all-islamic-calendar-holidays
|
|
808 (holiday-islamic 7 26 "Shab-e-Mi'raj"))
|
|
809 (if all-islamic-calendar-holidays
|
|
810 (holiday-islamic 8 15 "Shab-e-Bara't"))
|
|
811 (holiday-islamic 9 1 "Ramadan Begins")
|
|
812 (if all-islamic-calendar-holidays
|
|
813 (holiday-islamic 9 27 "Shab-e Qadr"))
|
|
814 (if all-islamic-calendar-holidays
|
|
815 (holiday-islamic 10 1 "Id-al-Fitr"))
|
|
816 (if all-islamic-calendar-holidays
|
|
817 (holiday-islamic 12 10 "Id-al-Adha")))
|
|
818 "*Islamic holidays.
|
|
819 See the documentation for `calendar-holidays' for details.")
|
|
820
|
|
821 ;;;###autoload
|
|
822 (put 'solar-holidays 'risky-local-variable t)
|
|
823 ;;;###autoload
|
|
824 (defvar solar-holidays
|
|
825 '((if (fboundp 'atan)
|
|
826 (solar-equinoxes-solstices))
|
|
827 (if (progn
|
|
828 (require 'cal-dst)
|
|
829 t)
|
|
830 (funcall
|
|
831 'holiday-sexp
|
|
832 calendar-daylight-savings-starts
|
|
833 '(format "Daylight Savings Time Begins %s"
|
|
834 (if (fboundp 'atan)
|
|
835 (solar-time-string
|
|
836 (/ calendar-daylight-savings-starts-time (float 60))
|
|
837 calendar-standard-time-zone-name)
|
|
838 ""))))
|
|
839 (funcall
|
|
840 'holiday-sexp
|
|
841 calendar-daylight-savings-ends
|
|
842 '(format "Daylight Savings Time Ends %s"
|
|
843 (if (fboundp 'atan)
|
|
844 (solar-time-string
|
|
845 (/ calendar-daylight-savings-ends-time (float 60))
|
|
846 calendar-daylight-time-zone-name)
|
|
847 ""))))
|
|
848 "*Sun-related holidays.
|
|
849 See the documentation for `calendar-holidays' for details.")
|
|
850
|
|
851 ;;;###autoload
|
|
852 (put 'calendar-holidays 'risky-local-variable t)
|
|
853 (defvar calendar-holidays
|
|
854 (append general-holidays local-holidays other-holidays
|
|
855 christian-holidays hebrew-holidays islamic-holidays
|
|
856 solar-holidays)
|
|
857 "*List of notable days for the command M-x holidays.
|
|
858
|
|
859 Additional holidays are easy to add to the list, just put them in the list
|
|
860 `other-holidays' in your .emacs file. Similarly, by setting any of
|
|
861 `general-holidays', `local-holidays' `christian-holidays', `hebrew-holidays',
|
|
862 `islamic-holidays', or `solar-holidays' to nil in your .emacs file, you can
|
|
863 eliminate unwanted categories of holidays. The intention is that (in the US)
|
|
864 `local-holidays' be set in site-init.el and `other-holidays' be set by the
|
|
865 user.
|
|
866
|
|
867 Entries on the list are expressions that return (possibly empty) lists of
|
|
868 items of the form ((month day year) string) of a holiday in the in the
|
|
869 three-month period centered around `displayed-month' of `displayed-year'.
|
|
870 Several basic functions are provided for this purpose:
|
|
871
|
|
872 (holiday-fixed MONTH DAY STRING) is a fixed date on the Gregorian calendar
|
|
873 (holiday-float MONTH DAYNAME K STRING &optional day) is the Kth DAYNAME in
|
|
874 MONTH on the Gregorian calendar (0 for Sunday,
|
|
875 etc.); K<0 means count back from the end of the
|
|
876 month. An optional parameter DAY means the Kth
|
|
877 DAYNAME after/before MONTH DAY.
|
|
878 (holiday-hebrew MONTH DAY STRING) a fixed date on the Hebrew calendar
|
|
879 (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
|
|
880 (holiday-julian MONTH DAY STRING) a fixed date on the Julian calendar
|
|
881 (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
|
|
882 in the variable `year'; if it evaluates to
|
|
883 a visible date, that's the holiday; if it
|
|
884 evaluates to nil, there's no holiday. STRING
|
|
885 is an expression in the variable `date'.
|
|
886
|
|
887 For example, to add Bastille Day, celebrated in France on July 14, add
|
|
888
|
|
889 (holiday-fixed 7 14 \"Bastille Day\")
|
|
890
|
|
891 to the list. To add Hurricane Supplication Day, celebrated in the Virgin
|
|
892 Islands on the fourth Monday in August, add
|
|
893
|
|
894 (holiday-float 8 1 4 \"Hurricane Supplication Day\")
|
|
895
|
|
896 to the list (the last Monday would be specified with `-1' instead of `4').
|
|
897 To add the last day of Hanukkah to the list, use
|
|
898
|
|
899 (holiday-hebrew 10 2 \"Last day of Hanukkah\")
|
|
900
|
|
901 since the Hebrew months are numbered with 1 starting from Nisan, while to
|
|
902 add the Islamic feast celebrating Mohammed's birthday use
|
|
903
|
|
904 (holiday-islamic 3 12 \"Mohammed's Birthday\")
|
|
905
|
|
906 since the Islamic months are numbered from 1 starting with Muharram. To
|
|
907 add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
|
|
908
|
|
909 (holiday-julian 4 2 \"Jefferson's Birthday\")
|
|
910
|
|
911 To include a holiday conditionally, use the sexp form or a conditional. For
|
|
912 example, to include American presidential elections, which occur on the first
|
|
913 Tuesday after the first Monday in November of years divisible by 4, add
|
|
914
|
|
915 (holiday-sexp
|
|
916 (if (zerop (% year 4))
|
|
917 (calendar-gregorian-from-absolute
|
|
918 (1+ (calendar-dayname-on-or-before
|
|
919 1 (+ 6 (calendar-absolute-from-gregorian
|
|
920 (list 11 1 year)))))))
|
|
921 \"US Presidential Election\")
|
|
922
|
|
923 or
|
|
924
|
|
925 (if (zerop (% displayed-year 4))
|
|
926 (holiday-fixed 11
|
|
927 (extract-calendar-day
|
|
928 (calendar-gregorian-from-absolute
|
|
929 (1+ (calendar-dayname-on-or-before
|
|
930 1 (+ 6 (calendar-absolute-from-gregorian
|
|
931 (list 11 1 displayed-year)))))))
|
|
932 \"US Presidential Election\"))
|
|
933
|
|
934 to the list. To include the phases of the moon, add
|
|
935
|
|
936 (lunar-phases)
|
|
937
|
|
938 to the holiday list, where `lunar-phases' is an Emacs-Lisp function that
|
|
939 you've written to return a (possibly empty) list of the relevant VISIBLE dates
|
|
940 with descriptive strings such as
|
|
941
|
|
942 (((2 6 1989) \"New Moon\") ((2 12 1989) \"First Quarter Moon\") ... ).")
|
|
943
|
|
944 (defconst calendar-buffer "*Calendar*"
|
|
945 "Name of the buffer used for the calendar.")
|
|
946
|
|
947 (defconst holiday-buffer "*Holidays*"
|
|
948 "Name of the buffer used for the displaying the holidays.")
|
|
949
|
|
950 (defconst fancy-diary-buffer "*Fancy Diary Entries*"
|
|
951 "Name of the buffer used for the optional fancy display of the diary.")
|
|
952
|
|
953 (defconst lunar-phases-buffer "*Phases of Moon*"
|
|
954 "Name of the buffer used for the lunar phases.")
|
|
955
|
|
956 (defmacro increment-calendar-month (mon yr n)
|
|
957 "Move the variables MON and YR to the month and year by N months.
|
|
958 Forward if N is positive or backward if N is negative."
|
|
959 (` (let (( macro-y (+ (* (, yr) 12) (, mon) -1 (, n) )))
|
|
960 (setq (, mon) (1+ (% macro-y 12) ))
|
|
961 (setq (, yr) (/ macro-y 12)))))
|
|
962
|
|
963 (defmacro calendar-for-loop (var from init to final do &rest body)
|
|
964 "Execute a for loop."
|
|
965 (` (let (( (, var) (1- (, init)) ))
|
|
966 (while (>= (, final) (setq (, var) (1+ (, var))))
|
|
967 (,@ body)))))
|
|
968
|
|
969 (defmacro calendar-sum (index initial condition expression)
|
|
970 "For INDEX = INITIAL et seq, as long as CONDITION holds, sum EXPRESSION."
|
|
971 (` (let (( (, index) (, initial))
|
|
972 (sum 0))
|
|
973 (while (, condition)
|
|
974 (setq sum (+ sum (, expression) ))
|
|
975 (setq (, index) (1+ (, index))))
|
|
976 sum)))
|
|
977
|
|
978 ;; The following are in-line for speed; they can be called thousands of times
|
|
979 ;; when looking up holidays or processing the diary. Here, for example, are
|
|
980 ;; the numbers of calls to calendar/diary/holiday functions in preparing the
|
|
981 ;; fancy diary display, for a moderately complex diary file, with functions
|
|
982 ;; used instead of macros. There were a total of 10000 such calls:
|
|
983 ;;
|
|
984 ;; 1934 extract-calendar-month
|
|
985 ;; 1852 extract-calendar-year
|
|
986 ;; 1819 extract-calendar-day
|
|
987 ;; 845 calendar-leap-year-p
|
|
988 ;; 837 calendar-day-number
|
|
989 ;; 775 calendar-absolute-from-gregorian
|
|
990 ;; 346 calendar-last-day-of-month
|
|
991 ;; 286 hebrew-calendar-last-day-of-month
|
|
992 ;; 188 hebrew-calendar-leap-year-p
|
|
993 ;; 180 hebrew-calendar-elapsed-days
|
|
994 ;; 163 hebrew-calendar-last-month-of-year
|
|
995 ;; 66 calendar-date-compare
|
|
996 ;; 65 hebrew-calendar-days-in-year
|
|
997 ;; 60 calendar-absolute-from-julian
|
|
998 ;; 50 calendar-absolute-from-hebrew
|
|
999 ;; 43 calendar-date-equal
|
|
1000 ;; 38 calendar-gregorian-from-absolute
|
|
1001 ;; .
|
|
1002 ;; .
|
|
1003 ;; .
|
|
1004 ;;
|
|
1005 ;; The use of these seven macros eliminates the overhead of 92% of the function
|
|
1006 ;; calls; it's faster this way.
|
|
1007
|
|
1008 (defsubst extract-calendar-month (date)
|
|
1009 "Extract the month part of DATE which has the form (month day year)."
|
|
1010 (car date))
|
|
1011
|
|
1012 (defsubst extract-calendar-day (date)
|
|
1013 "Extract the day part of DATE which has the form (month day year)."
|
|
1014 (car (cdr date)))
|
|
1015
|
|
1016 (defsubst extract-calendar-year (date)
|
|
1017 "Extract the year part of DATE which has the form (month day year)."
|
|
1018 (car (cdr (cdr date))))
|
|
1019
|
|
1020 (defsubst calendar-leap-year-p (year)
|
|
1021 "Returns t if YEAR is a Gregorian leap year."
|
|
1022 (and (zerop (% year 4))
|
|
1023 (or (not (zerop (% year 100)))
|
|
1024 (zerop (% year 400)))))
|
|
1025
|
|
1026 ;; The foregoing is a bit faster, but not as clear as the following:
|
|
1027 ;;
|
|
1028 ;;(defsubst calendar-leap-year-p (year)
|
|
1029 ;; "Returns t if YEAR is a Gregorian leap year."
|
|
1030 ;; (or
|
|
1031 ;; (and (= (% year 4) 0)
|
|
1032 ;; (/= (% year 100) 0))
|
|
1033 ;; (= (% year 400) 0)))
|
|
1034
|
|
1035 (defsubst calendar-last-day-of-month (month year)
|
|
1036 "The last day in MONTH during YEAR."
|
|
1037 (if (and (= month 2) (calendar-leap-year-p year))
|
|
1038 29
|
|
1039 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
|
|
1040
|
|
1041 ;; An explanation of the calculation can be found in PascAlgorithms by
|
|
1042 ;; Edward and Ruth Reingold, Scott-Foresman/Little, Brown, 1988.
|
|
1043
|
|
1044 (defsubst calendar-day-number (date)
|
|
1045 "Return the day number within the year of the date DATE.
|
|
1046 For example, (calendar-day-number '(1 1 1987)) returns the value 1,
|
|
1047 while (calendar-day-number '(12 31 1980)) returns 366."
|
|
1048 (let* ((month (extract-calendar-month date))
|
|
1049 (day (extract-calendar-day date))
|
|
1050 (year (extract-calendar-year date))
|
|
1051 (day-of-year (+ day (* 31 (1- month)))))
|
|
1052 (if (> month 2)
|
|
1053 (progn
|
|
1054 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
|
|
1055 (if (calendar-leap-year-p year)
|
|
1056 (setq day-of-year (1+ day-of-year)))))
|
|
1057 day-of-year))
|
|
1058
|
|
1059 (defsubst calendar-absolute-from-gregorian (date)
|
|
1060 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
|
|
1061 The Gregorian date Sunday, December 31, 1 BC is imaginary."
|
|
1062 (let ((prior-years (1- (extract-calendar-year date))))
|
|
1063 (+ (calendar-day-number date);; Days this year
|
|
1064 (* 365 prior-years);; + Days in prior years
|
|
1065 (/ prior-years 4);; + Julian leap years
|
|
1066 (- (/ prior-years 100));; - century years
|
|
1067 (/ prior-years 400))));; + Gregorian leap years
|
|
1068
|
|
1069 ;;;###autoload
|
|
1070 (defun calendar (&optional arg)
|
|
1071 "Display a three-month calendar in another window.
|
|
1072 The three months appear side by side, with the current month in the middle
|
|
1073 surrounded by the previous and next months. The cursor is put on today's date.
|
|
1074
|
|
1075 If called with an optional prefix argument, prompts for month and year.
|
|
1076
|
|
1077 This function is suitable for execution in a .emacs file; appropriate setting
|
|
1078 of the variable `view-diary-entries-initially' will cause the diary entries for
|
|
1079 the current date to be displayed in another window. The value of the variable
|
|
1080 `number-of-diary-entries' controls the number of days of diary entries
|
|
1081 displayed upon initial display of the calendar.
|
|
1082
|
|
1083 An optional prefix argument ARG causes the calendar displayed to be ARG
|
|
1084 months in the future if ARG is positive or in the past if ARG is negative;
|
|
1085 in this case the cursor goes on the first day of the month.
|
|
1086
|
|
1087 Once in the calendar window, future or past months can be moved into view.
|
|
1088 Arbitrary months can be displayed, or the calendar can be scrolled forward
|
|
1089 or backward.
|
|
1090
|
|
1091 The cursor can be moved forward or backward by one day, one week, one month,
|
|
1092 or one year. All of these commands take prefix arguments which, when negative,
|
|
1093 cause movement in the opposite direction. For convenience, the digit keys
|
|
1094 and the minus sign are automatically prefixes. The window is replotted as
|
|
1095 necessary to display the desired date.
|
|
1096
|
|
1097 Diary entries can be marked on the calendar or displayed in another window.
|
|
1098
|
|
1099 Use M-x describe-mode for details of the key bindings in the calendar window.
|
|
1100
|
|
1101 The Gregorian calendar is assumed.
|
|
1102
|
|
1103 After loading the calendar, the hooks given by the variable
|
|
1104 `calendar-load-hook' are run. This is the place to add key bindings to the
|
|
1105 calendar-mode-map.
|
|
1106
|
|
1107 After preparing the calendar window initially, the hooks given by the variable
|
|
1108 `initial-calendar-window-hook' are run.
|
|
1109
|
|
1110 The hooks given by the variable `today-visible-calendar-hook' are run
|
|
1111 everytime the calendar window gets scrolled, if the current date is visible
|
|
1112 in the window. If it is not visible, the hooks given by the variable
|
|
1113 `today-invisible-calendar-hook' are run. Thus, for example, setting
|
|
1114 `today-visible-calendar-hook' to 'calendar-star-date will cause today's date
|
|
1115 to be replaced by asterisks to highlight it whenever it is in the window."
|
|
1116 (interactive "P")
|
|
1117 (set-buffer (get-buffer-create calendar-buffer))
|
|
1118 (calendar-mode)
|
|
1119 (let* ((pop-up-windows t)
|
|
1120 (split-height-threshold 1000)
|
|
1121 (date (if arg
|
|
1122 (calendar-read-date t)
|
|
1123 (calendar-current-date)))
|
|
1124 (month (extract-calendar-month date))
|
|
1125 (year (extract-calendar-year date)))
|
|
1126 (pop-to-buffer calendar-buffer)
|
|
1127 (increment-calendar-month month year (- calendar-offset))
|
|
1128 (generate-calendar-window month year)
|
|
1129 (if (and view-diary-entries-initially (calendar-date-is-visible-p date))
|
|
1130 (view-diary-entries
|
|
1131 (if (vectorp number-of-diary-entries)
|
|
1132 (aref number-of-diary-entries (calendar-day-of-week date))
|
|
1133 number-of-diary-entries))))
|
|
1134 (let* ((diary-buffer (get-file-buffer diary-file))
|
|
1135 (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
|
|
1136 (split-height-threshold (if diary-window 2 1000)))
|
|
1137 (if view-calendar-holidays-initially
|
|
1138 (list-calendar-holidays)))
|
|
1139 (run-hooks 'initial-calendar-window-hook))
|
|
1140
|
|
1141 (autoload 'view-diary-entries "diary-lib"
|
|
1142 "Prepare and display a buffer with diary entries.
|
|
1143 Searches your diary file for entries that match ARG days starting with
|
|
1144 the date indicated by the cursor position in the displayed three-month
|
|
1145 calendar."
|
|
1146 t)
|
|
1147
|
|
1148 (autoload 'calendar-sunrise-sunset "solar"
|
|
1149 "Local time of sunrise and sunset for date under cursor."
|
|
1150 t)
|
|
1151
|
|
1152 (autoload 'calendar-phases-of-moon "lunar"
|
|
1153 "Create a buffer of the phases of the moon for the current calendar window."
|
|
1154 t)
|
|
1155
|
|
1156 (autoload 'calendar-print-french-date "cal-french"
|
|
1157 "Show the French Revolutionary calendar equivalent of the date under the cursor."
|
|
1158 t)
|
|
1159
|
|
1160 (autoload 'calendar-goto-french-date "cal-french"
|
|
1161 "Move cursor to French Revolutionary date."
|
|
1162 t)
|
|
1163
|
|
1164 (autoload 'calendar-french-date-string "cal-french"
|
|
1165 "String of French Revolutionary date of Gregorian DATE."
|
|
1166 t)
|
|
1167
|
|
1168 (autoload 'calendar-mayan-date-string "cal-mayan"
|
|
1169 "String of Mayan date of Gregorian DATE."
|
|
1170 t)
|
|
1171
|
|
1172 (autoload 'calendar-print-mayan-date "cal-mayan"
|
|
1173 "Show the Mayan long count, Tzolkin, and Haab equivalents of the date under the cursor."
|
|
1174 t)
|
|
1175
|
|
1176 (autoload 'calendar-goto-mayan-long-count-date "cal-mayan"
|
|
1177 "Move cursor to Mayan long count date."
|
|
1178 t)
|
|
1179
|
|
1180 (autoload 'calendar-next-haab-date "cal-mayan"
|
|
1181 "Move cursor to next instance of Mayan Haab date."
|
|
1182 t)
|
|
1183
|
|
1184 (autoload 'calendar-previous-haab-date "cal-mayan"
|
|
1185 "Move cursor to previous instance of Mayan Haab date."
|
|
1186 t)
|
|
1187
|
|
1188 (autoload 'calendar-next-tzolkin-date "cal-mayan"
|
|
1189 "Move cursor to next instance of Mayan Tzolkin date."
|
|
1190 t)
|
|
1191
|
|
1192 (autoload 'calendar-previous-tzolkin-date "cal-mayan"
|
|
1193 "Move cursor to previous instance of Mayan Tzolkin date."
|
|
1194 t)
|
|
1195
|
|
1196 (autoload 'calendar-next-calendar-round-date "cal-mayan"
|
|
1197 "Move cursor to next instance of Mayan Haab/Tzoklin combination."
|
|
1198 t)
|
|
1199
|
|
1200 (autoload 'calendar-previous-calendar-round-date "cal-mayan"
|
|
1201 "Move cursor to previous instance of Mayan Haab/Tzoklin combination."
|
|
1202 t)
|
|
1203
|
|
1204 (autoload 'show-all-diary-entries "diary-lib"
|
|
1205 "Show all of the diary entries in the diary file.
|
|
1206 This function gets rid of the selective display of the diary file so that
|
|
1207 all entries, not just some, are visible. If there is no diary buffer, one
|
|
1208 is created."
|
|
1209 t)
|
|
1210
|
|
1211 (autoload 'mark-diary-entries "diary-lib"
|
|
1212 "Mark days in the calendar window that have diary entries.
|
|
1213 Each entry in diary file visible in the calendar window is marked."
|
|
1214 t)
|
|
1215
|
|
1216 (autoload 'insert-diary-entry "diary-ins"
|
|
1217 "Insert a diary entry for the date indicated by point."
|
|
1218 t)
|
|
1219
|
|
1220 (autoload 'insert-weekly-diary-entry "diary-ins"
|
|
1221 "Insert a weekly diary entry for the day of the week indicated by point."
|
|
1222 t)
|
|
1223
|
|
1224
|
|
1225 (autoload 'insert-monthly-diary-entry "diary-ins"
|
|
1226 "Insert a monthly diary entry for the day of the month indicated by point."
|
|
1227 t)
|
|
1228
|
|
1229 (autoload 'insert-yearly-diary-entry "diary-ins"
|
|
1230 "Insert an annual diary entry for the day of the year indicated by point."
|
|
1231 t)
|
|
1232
|
|
1233 (autoload 'insert-anniversary-diary-entry "diary-ins"
|
|
1234 "Insert an anniversary diary entry for the date indicated by point."
|
|
1235 t)
|
|
1236
|
|
1237 (autoload 'insert-block-diary-entry "diary-ins"
|
|
1238 "Insert a block diary entry for the dates indicated by point and mark."
|
|
1239 t)
|
|
1240
|
|
1241 (autoload 'insert-cyclic-diary-entry "diary-ins"
|
|
1242 "Insert a cyclic diary entry starting at the date indicated by point."
|
|
1243 t)
|
|
1244
|
|
1245 (autoload 'insert-hebrew-diary-entry "diary-ins"
|
|
1246 "Insert a diary entry for the Hebrew date corresponding to the date
|
|
1247 indicated by point."
|
|
1248 t)
|
|
1249
|
|
1250 (autoload 'insert-monthly-hebrew-diary-entry "diary-ins"
|
|
1251 "Insert a monthly diary entry for the day of the Hebrew month corresponding
|
|
1252 to the date indicated by point."
|
|
1253 t)
|
|
1254
|
|
1255 (autoload 'insert-yearly-hebrew-diary-entry "diary-ins"
|
|
1256 "Insert an annual diary entry for the day of the Hebrew year corresponding
|
|
1257 to the date indicated by point."
|
|
1258 t)
|
|
1259
|
|
1260 (autoload 'insert-islamic-diary-entry "diary-ins"
|
|
1261 "Insert a diary entry for the Islamic date corresponding to the date
|
|
1262 indicated by point."
|
|
1263 t)
|
|
1264
|
|
1265 (autoload 'insert-monthly-islamic-diary-entry "diary-ins"
|
|
1266 "Insert a monthly diary entry for the day of the Islamic month corresponding
|
|
1267 to the date indicated by point."
|
|
1268 t)
|
|
1269
|
|
1270 (autoload 'insert-yearly-islamic-diary-entry "diary-ins"
|
|
1271 "Insert an annual diary entry for the day of the Islamic year corresponding
|
|
1272 to the date indicated by point."
|
|
1273 t)
|
|
1274
|
|
1275 (autoload 'list-calendar-holidays "holidays"
|
|
1276 "Create a buffer containing the holidays for the current calendar window.
|
|
1277 The holidays are those in the list `calendar-notable-days'. Returns t if any
|
|
1278 holidays are found, nil if not."
|
|
1279 t)
|
|
1280
|
|
1281 (autoload 'mark-calendar-holidays "holidays"
|
|
1282 "Mark notable days in the calendar window."
|
|
1283 t)
|
|
1284
|
|
1285 (autoload 'calendar-cursor-holidays "holidays"
|
|
1286 "Find holidays for the date specified by the cursor in the calendar window."
|
|
1287 t)
|
|
1288
|
|
1289 (defun generate-calendar-window (&optional mon yr)
|
|
1290 "Generate the calendar window for the current date.
|
|
1291 Or, for optional MON, YR."
|
|
1292 (let* ((buffer-read-only nil)
|
|
1293 (today (calendar-current-date))
|
|
1294 (month (extract-calendar-month today))
|
|
1295 (day (extract-calendar-day today))
|
|
1296 (year (extract-calendar-year today))
|
|
1297 (today-visible
|
|
1298 (or (not mon)
|
|
1299 (let ((offset (calendar-interval mon yr month year)))
|
|
1300 (and (<= offset 1) (>= offset -1)))))
|
|
1301 (day-in-week (calendar-day-of-week today)))
|
|
1302 (update-calendar-mode-line)
|
|
1303 (if mon
|
|
1304 (generate-calendar mon yr)
|
|
1305 (generate-calendar month year))
|
|
1306 (calendar-cursor-to-visible-date
|
|
1307 (if today-visible today (list displayed-month 1 displayed-year)))
|
|
1308 (set-buffer-modified-p nil)
|
|
1309 (or (one-window-p t)
|
|
1310 (/= (frame-width) (window-width))
|
|
1311 (shrink-window (- (window-height) 9)))
|
|
1312 (sit-for 0)
|
|
1313 (and mark-holidays-in-calendar
|
|
1314 (mark-calendar-holidays)
|
|
1315 (sit-for 0))
|
|
1316 (unwind-protect
|
|
1317 (if mark-diary-entries-in-calendar (mark-diary-entries))
|
|
1318 (if today-visible
|
|
1319 (run-hooks 'today-visible-calendar-hook)
|
|
1320 (run-hooks 'today-invisible-calendar-hook)))))
|
|
1321
|
|
1322 (defun generate-calendar (month year)
|
|
1323 "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
|
|
1324 (if (< (+ month (* 12 (1- year))) 2)
|
|
1325 (error "Months before February, 1 AD are not available."))
|
|
1326 (setq displayed-month month)
|
|
1327 (setq displayed-year year)
|
|
1328 (erase-buffer)
|
|
1329 (increment-calendar-month month year -1)
|
|
1330 (calendar-for-loop i from 0 to 2 do
|
|
1331 (generate-calendar-month month year (+ 5 (* 25 i)))
|
|
1332 (increment-calendar-month month year 1)))
|
|
1333
|
|
1334 (defun generate-calendar-month (month year indent)
|
|
1335 "Produce a calendar for MONTH, YEAR on the Gregorian calendar.
|
|
1336 The calendar is inserted in the buffer starting at the line on which point
|
|
1337 is currently located, but indented INDENT spaces. The indentation is done
|
|
1338 from the first character on the line and does not disturb the first INDENT
|
|
1339 characters on the line."
|
|
1340 (let* ((blank-days;; at start of month
|
|
1341 (mod
|
|
1342 (- (calendar-day-of-week (list month 1 year))
|
|
1343 calendar-week-start-day)
|
|
1344 7))
|
|
1345 (last (calendar-last-day-of-month month year)))
|
|
1346 (goto-char (point-min))
|
|
1347 (calendar-insert-indented
|
|
1348 (calendar-string-spread
|
|
1349 (list "" (format "%s %d" (calendar-month-name month) year) "") ? 20)
|
|
1350 indent t)
|
|
1351 (calendar-insert-indented "" indent);; Go to proper spot
|
|
1352 (calendar-for-loop i from 0 to 6 do
|
|
1353 (insert (substring (aref calendar-day-name-array
|
|
1354 (mod (+ calendar-week-start-day i) 7))
|
|
1355 0 2))
|
|
1356 (insert " "))
|
|
1357 (calendar-insert-indented "" 0 t);; Force onto following line
|
|
1358 (calendar-insert-indented "" indent);; Go to proper spot
|
|
1359 ;; Add blank days before the first of the month
|
|
1360 (calendar-for-loop i from 1 to blank-days do (insert " "))
|
|
1361 ;; Put in the days of the month
|
|
1362 (calendar-for-loop i from 1 to last do
|
|
1363 (insert (format "%2d " i))
|
|
1364 (put-text-property (- (point) (if (< i 10) 2 3)) (1- (point))
|
|
1365 'highlight t)
|
|
1366 (and (zerop (mod (+ i blank-days) 7))
|
|
1367 (/= i last)
|
|
1368 (calendar-insert-indented "" 0 t) ;; Force onto following line
|
|
1369 (calendar-insert-indented "" indent)))));; Go to proper spot
|
|
1370
|
|
1371 (defun calendar-insert-indented (string indent &optional newline)
|
|
1372 "Insert STRING at column INDENT.
|
|
1373 If the optional parameter NEWLINE is t, leave point at start of next line,
|
|
1374 inserting a newline if there was no next line; otherwise, leave point after
|
|
1375 the inserted text. Value is always t."
|
|
1376 ;; Try to move to that column.
|
|
1377 (move-to-column indent)
|
|
1378 ;; If line is too short, indent out to that column.
|
|
1379 (if (< (current-column) indent)
|
|
1380 (indent-to indent))
|
|
1381 (insert string)
|
|
1382 ;; Advance to next line, if requested.
|
|
1383 (if newline
|
|
1384 (progn
|
|
1385 (end-of-line)
|
|
1386 (if (eobp)
|
|
1387 (newline)
|
|
1388 (forward-line 1))))
|
|
1389 t)
|
|
1390
|
|
1391 (defun redraw-calendar ()
|
|
1392 "Redraw the calendar display."
|
|
1393 (interactive)
|
|
1394 (let ((cursor-date (calendar-cursor-to-date)))
|
|
1395 (generate-calendar-window displayed-month displayed-year)
|
|
1396 (calendar-cursor-to-visible-date cursor-date)))
|
|
1397
|
|
1398 (defvar calendar-debug-sexp nil
|
|
1399 "*Turn debugging on when evaluating a sexp in the diary or holiday list.")
|
|
1400
|
|
1401 (defvar calendar-mode-map nil)
|
|
1402 (if calendar-mode-map
|
|
1403 nil
|
|
1404 (setq calendar-mode-map (make-sparse-keymap))
|
|
1405 (calendar-for-loop i from 0 to 9 do
|
|
1406 (define-key calendar-mode-map (int-to-string i) 'digit-argument))
|
|
1407 (let ((l (list 'narrow-to-region 'mark-word 'mark-sexp 'mark-paragraph
|
|
1408 'mark-defun 'mark-whole-buffer 'mark-page
|
|
1409 'downcase-region 'upcase-region 'kill-region
|
|
1410 'copy-region-as-kill 'capitalize-region 'write-region)))
|
|
1411 (while l
|
|
1412 (substitute-key-definition (car l) 'calendar-not-implemented
|
|
1413 calendar-mode-map)
|
|
1414 (setq l (cdr l))))
|
|
1415 (define-key calendar-mode-map "-" 'negative-argument)
|
|
1416 (define-key calendar-mode-map "\C-x>" 'scroll-calendar-right)
|
|
1417 (define-key calendar-mode-map '[prior] 'scroll-calendar-right-three-months)
|
|
1418 (define-key calendar-mode-map "\M-v" 'scroll-calendar-right-three-months)
|
|
1419 (define-key calendar-mode-map "\C-x<" 'scroll-calendar-left)
|
|
1420 (define-key calendar-mode-map '[next] 'scroll-calendar-left-three-months)
|
|
1421 (define-key calendar-mode-map "\C-v" 'scroll-calendar-left-three-months)
|
|
1422 (define-key calendar-mode-map "\C-b" 'calendar-backward-day)
|
|
1423 (define-key calendar-mode-map "\C-p" 'calendar-backward-week)
|
|
1424 (define-key calendar-mode-map "\M-{" 'calendar-backward-month)
|
|
1425 (define-key calendar-mode-map "\C-x[" 'calendar-backward-year)
|
|
1426 (define-key calendar-mode-map "\C-f" 'calendar-forward-day)
|
|
1427 (define-key calendar-mode-map "\C-n" 'calendar-forward-week)
|
|
1428 (define-key calendar-mode-map '[left] 'calendar-backward-day)
|
|
1429 (define-key calendar-mode-map '[up] 'calendar-backward-week)
|
|
1430 (define-key calendar-mode-map '[right] 'calendar-forward-day)
|
|
1431 (define-key calendar-mode-map '[down] 'calendar-forward-week)
|
|
1432 (define-key calendar-mode-map "\M-}" 'calendar-forward-month)
|
|
1433 (define-key calendar-mode-map "\C-x]" 'calendar-forward-year)
|
|
1434 (define-key calendar-mode-map "\C-a" 'calendar-beginning-of-week)
|
|
1435 (define-key calendar-mode-map "\C-e" 'calendar-end-of-week)
|
|
1436 (define-key calendar-mode-map "\M-a" 'calendar-beginning-of-month)
|
|
1437 (define-key calendar-mode-map "\M-e" 'calendar-end-of-month)
|
|
1438 (define-key calendar-mode-map "\M-<" 'calendar-beginning-of-year)
|
|
1439 (define-key calendar-mode-map "\M->" 'calendar-end-of-year)
|
|
1440 (define-key calendar-mode-map "\C-@" 'calendar-set-mark)
|
|
1441 ;; Many people are used to typing C-SPC and getting C-@.
|
|
1442 (define-key calendar-mode-map "\C- " 'calendar-set-mark)
|
|
1443 (define-key calendar-mode-map "\C-x\C-x" 'calendar-exchange-point-and-mark)
|
|
1444 (define-key calendar-mode-map "\M-=" 'calendar-count-days-region)
|
|
1445 (define-key calendar-mode-map "gd" 'calendar-goto-date)
|
|
1446 (define-key calendar-mode-map "gj" 'calendar-goto-julian-date)
|
|
1447 (define-key calendar-mode-map "ga" 'calendar-goto-astro-day-number)
|
|
1448 (define-key calendar-mode-map "gh" 'calendar-goto-hebrew-date)
|
|
1449 (define-key calendar-mode-map "gi" 'calendar-goto-islamic-date)
|
|
1450 (define-key calendar-mode-map "gc" 'calendar-goto-iso-date)
|
|
1451 (define-key calendar-mode-map "gf" 'calendar-goto-french-date)
|
|
1452 (define-key calendar-mode-map "gml" 'calendar-goto-mayan-long-count-date)
|
|
1453 (define-key calendar-mode-map "gmpc" 'calendar-previous-calendar-round-date)
|
|
1454 (define-key calendar-mode-map "gmnc" 'calendar-next-calendar-round-date)
|
|
1455 (define-key calendar-mode-map "gmph" 'calendar-previous-haab-date)
|
|
1456 (define-key calendar-mode-map "gmnh" 'calendar-next-haab-date)
|
|
1457 (define-key calendar-mode-map "gmpt" 'calendar-previous-tzolkin-date)
|
|
1458 (define-key calendar-mode-map "gmnt" 'calendar-next-tzolkin-date)
|
|
1459 (define-key calendar-mode-map "S" 'calendar-sunrise-sunset)
|
|
1460 (define-key calendar-mode-map "M" 'calendar-phases-of-moon)
|
|
1461 (define-key calendar-mode-map " " 'scroll-other-window)
|
|
1462 (define-key calendar-mode-map "\C-c\C-l" 'redraw-calendar)
|
|
1463 (define-key calendar-mode-map "." 'calendar-goto-today)
|
|
1464 (define-key calendar-mode-map "o" 'calendar-other-month)
|
|
1465 (define-key calendar-mode-map "q" 'exit-calendar)
|
|
1466 (define-key calendar-mode-map "a" 'list-calendar-holidays)
|
|
1467 (define-key calendar-mode-map "h" 'calendar-cursor-holidays)
|
|
1468 (define-key calendar-mode-map "x" 'mark-calendar-holidays)
|
|
1469 (define-key calendar-mode-map "u" 'calendar-unmark)
|
|
1470 (define-key calendar-mode-map "m" 'mark-diary-entries)
|
|
1471 (define-key calendar-mode-map "d" 'view-diary-entries)
|
|
1472 (define-key calendar-mode-map "D" 'view-other-diary-entries)
|
|
1473 (define-key calendar-mode-map "s" 'show-all-diary-entries)
|
|
1474 (define-key calendar-mode-map "pd" 'calendar-print-day-of-year)
|
|
1475 (define-key calendar-mode-map "pc" 'calendar-print-iso-date)
|
|
1476 (define-key calendar-mode-map "pj" 'calendar-print-julian-date)
|
|
1477 (define-key calendar-mode-map "pa" 'calendar-print-astro-day-number)
|
|
1478 (define-key calendar-mode-map "ph" 'calendar-print-hebrew-date)
|
|
1479 (define-key calendar-mode-map "pi" 'calendar-print-islamic-date)
|
|
1480 (define-key calendar-mode-map "pf" 'calendar-print-french-date)
|
|
1481 (define-key calendar-mode-map "pm" 'calendar-print-mayan-date)
|
|
1482 (define-key calendar-mode-map "id" 'insert-diary-entry)
|
|
1483 (define-key calendar-mode-map "iw" 'insert-weekly-diary-entry)
|
|
1484 (define-key calendar-mode-map "im" 'insert-monthly-diary-entry)
|
|
1485 (define-key calendar-mode-map "iy" 'insert-yearly-diary-entry)
|
|
1486 (define-key calendar-mode-map "ia" 'insert-anniversary-diary-entry)
|
|
1487 (define-key calendar-mode-map "ib" 'insert-block-diary-entry)
|
|
1488 (define-key calendar-mode-map "ic" 'insert-cyclic-diary-entry)
|
|
1489 (define-key calendar-mode-map "ihd" 'insert-hebrew-diary-entry)
|
|
1490 (define-key calendar-mode-map "ihm" 'insert-monthly-hebrew-diary-entry)
|
|
1491 (define-key calendar-mode-map "ihy" 'insert-yearly-hebrew-diary-entry)
|
|
1492 (define-key calendar-mode-map "iid" 'insert-islamic-diary-entry)
|
|
1493 (define-key calendar-mode-map "iim" 'insert-monthly-islamic-diary-entry)
|
|
1494 (define-key calendar-mode-map "iiy" 'insert-yearly-islamic-diary-entry)
|
|
1495 (define-key calendar-mode-map "?" 'calendar-goto-info-node))
|
|
1496
|
|
1497 (defun describe-calendar-mode ()
|
|
1498 "Create a help buffer with a brief description of the calendar-mode."
|
|
1499 (interactive)
|
|
1500 (with-output-to-temp-buffer "*Help*"
|
|
1501 (princ
|
|
1502 (format
|
|
1503 "Calendar Mode:\nFor a complete description, type %s\n%s\n"
|
|
1504 (substitute-command-keys
|
|
1505 "\\<calendar-mode-map>\\[describe-mode] from within the calendar")
|
|
1506 (substitute-command-keys "\\{calendar-mode-map}")))
|
|
1507 (save-excursion
|
|
1508 (set-buffer standard-output)
|
|
1509 (help-mode))
|
|
1510 (print-help-return-message)))
|
|
1511
|
|
1512 ;; Calendar mode is suitable only for specially formatted data.
|
|
1513 (put 'calendar-mode 'mode-class 'special)
|
|
1514
|
|
1515 (defvar calendar-mode-line-format
|
|
1516 (list
|
|
1517 (substitute-command-keys "\\<calendar-mode-map>\\[scroll-calendar-left]")
|
|
1518 "Calendar"
|
|
1519 (substitute-command-keys "\\<calendar-mode-map>\\[calendar-goto-info-node] info/\\[calendar-other-month] other/\\[calendar-goto-today] today")
|
|
1520 '(calendar-date-string (calendar-current-date) t)
|
|
1521 (substitute-command-keys "\\<calendar-mode-map>\\[scroll-calendar-right]"))
|
|
1522 "The mode line of the calendar buffer.")
|
|
1523
|
|
1524 (defun calendar-goto-info-node ()
|
|
1525 "Go to the info node for the calendar."
|
|
1526 (interactive)
|
|
1527 (require 'info)
|
|
1528 (let ((where (Info-find-emacs-command-nodes 'calendar)))
|
|
1529 (if (not where)
|
|
1530 (error "Couldn't find documentation for the calendar.")
|
|
1531 (save-window-excursion (info))
|
|
1532 (pop-to-buffer "*info*")
|
|
1533 (Info-find-node (car (car where)) (car (cdr (car where)))))))
|
|
1534
|
|
1535 (defun calendar-mode ()
|
|
1536 "A major mode for the calendar window.
|
|
1537
|
|
1538 For a complete description, type \
|
|
1539 \\<calendar-mode-map>\\[calendar-goto-info-node] from within the calendar.
|
|
1540
|
|
1541 \\<calendar-mode-map>\\{calendar-mode-map}"
|
|
1542
|
|
1543 (kill-all-local-variables)
|
|
1544 (setq major-mode 'calendar-mode)
|
|
1545 (setq mode-name "Calendar")
|
|
1546 (use-local-map calendar-mode-map)
|
|
1547 (setq buffer-read-only t)
|
|
1548 (setq indent-tabs-mode nil)
|
|
1549 (update-calendar-mode-line)
|
|
1550 (if (and (string-match "XEmacs" emacs-version) current-menubar)
|
|
1551 (progn
|
|
1552 (require 'cal-xemacs)
|
|
1553 (calendar-add-menus)
|
|
1554 (make-variable-buffer-local 'scroll-on-clipped-lines)
|
|
1555 (setq scroll-on-clipped-lines nil)))
|
|
1556 (make-local-variable 'calendar-mark-ring)
|
|
1557 (make-local-variable 'displayed-month);; Month in middle of window.
|
|
1558 (make-local-variable 'displayed-year));; Year in middle of window.
|
|
1559
|
|
1560 (defun calendar-string-spread (strings char length)
|
|
1561 "Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH
|
|
1562 There must be at least 2 strings. The effect is like mapconcat but the
|
|
1563 separating pieces are as balanced as possible. Each item of STRINGS is
|
|
1564 evaluated before concatenation so it can actually be an expression that
|
|
1565 evaluates to a string. If LENGTH is too short, the STRINGS are just
|
|
1566 concatenated and the result truncated."
|
|
1567 ;; The algorithm is based on equation (3.25) on page 85 of Concrete
|
|
1568 ;; Mathematics by Ronald L. Graham, Donald E. Knuth, and Oren Patashnik,
|
|
1569 ;; Addison-Wesley, Reading, MA, 1989
|
|
1570 (let* ((strings (mapcar 'eval strings))
|
|
1571 (n (- length (length (apply 'concat strings))))
|
|
1572 (m (1- (length strings)))
|
|
1573 (s (car strings))
|
|
1574 (strings (cdr strings))
|
|
1575 (i 0))
|
|
1576 (while strings
|
|
1577 (setq s (concat s
|
|
1578 (make-string (max 0 (/ (+ n i) m)) char)
|
|
1579 (car strings)))
|
|
1580 (setq i (1+ i))
|
|
1581 (setq strings (cdr strings)))
|
|
1582 (substring s 0 length)))
|
|
1583
|
|
1584 (defun update-calendar-mode-line ()
|
|
1585 "Update the calendar mode line with the current date and date style."
|
|
1586 (if (bufferp (get-buffer calendar-buffer))
|
|
1587 (save-excursion
|
|
1588 (set-buffer calendar-buffer)
|
|
1589 (setq mode-line-format
|
|
1590 (calendar-string-spread
|
|
1591 calendar-mode-line-format ? (frame-width))))))
|
|
1592
|
|
1593 (defun calendar-window-list ()
|
|
1594 "List of all calendar-related windows."
|
|
1595 (let ((calendar-buffers (calendar-buffer-list))
|
|
1596 list)
|
|
1597 (walk-windows '(lambda (w)
|
|
1598 (if (memq (window-buffer w) calendar-buffers)
|
|
1599 (setq list (cons w list))))
|
|
1600 nil t)
|
|
1601 list))
|
|
1602
|
|
1603 (defun calendar-buffer-list ()
|
|
1604 "List of all calendar-related buffers."
|
|
1605 (let* ((diary-buffer (get-file-buffer diary-file))
|
|
1606 (buffers (list "*Yahrzeits*" lunar-phases-buffer holiday-buffer
|
|
1607 fancy-diary-buffer diary-buffer calendar-buffer))
|
|
1608 (buffer-list nil)
|
|
1609 b)
|
|
1610 (while buffers
|
|
1611 (setq b (car buffers))
|
|
1612 (setq b (cond ((stringp b) (get-buffer b))
|
|
1613 ((bufferp b) b)
|
|
1614 (t nil)))
|
|
1615 (if b (setq buffer-list (cons b buffer-list)))
|
|
1616 (setq buffers (cdr buffers)))
|
|
1617 buffer-list))
|
|
1618
|
|
1619 (defun exit-calendar ()
|
|
1620 "Get out of the calendar window and hide it and related buffers."
|
|
1621 (interactive)
|
|
1622 (let* ((diary-buffer (get-file-buffer diary-file)))
|
|
1623 (if (and diary-buffer (buffer-modified-p diary-buffer)
|
|
1624 (not
|
|
1625 (yes-or-no-p
|
|
1626 "Diary modified; do you really want to exit the calendar? ")))
|
|
1627 (error)
|
|
1628 ;; Need to do this multiple times because one time can replace some
|
|
1629 ;; calendar-related buffers with other calendar-related buffers
|
|
1630 (mapcar (lambda (x)
|
|
1631 (mapcar 'calendar-hide-window (calendar-window-list)))
|
|
1632 (calendar-window-list)))))
|
|
1633
|
|
1634 (defun calendar-hide-window (window)
|
|
1635 "Hide WINDOW if it is calendar-related."
|
|
1636 (let ((buffer (if (window-live-p window) (window-buffer window))))
|
|
1637 (if (memq buffer (calendar-buffer-list))
|
|
1638 (cond
|
|
1639 ((and window-system
|
|
1640 (eq 'icon (cdr (assoc 'visibility
|
|
1641 (frame-parameters
|
|
1642 (window-frame window))))))
|
|
1643 nil)
|
|
1644 ((and window-system (window-dedicated-p window))
|
|
1645 (iconify-frame (window-frame window)))
|
|
1646 ((not (and (select-window window) (one-window-p window)))
|
|
1647 (delete-window window))
|
|
1648 (t (set-buffer buffer)
|
|
1649 (bury-buffer))))))
|
|
1650
|
|
1651 (defun calendar-goto-today ()
|
|
1652 "Reposition the calendar window so the current date is visible."
|
|
1653 (interactive)
|
|
1654 (let ((today (calendar-current-date)));; The date might have changed.
|
|
1655 (if (not (calendar-date-is-visible-p today))
|
|
1656 (generate-calendar-window)
|
|
1657 (update-calendar-mode-line)
|
|
1658 (calendar-cursor-to-visible-date today))))
|
|
1659
|
|
1660 (defun calendar-forward-month (arg)
|
|
1661 "Move the cursor forward ARG months.
|
|
1662 Movement is backward if ARG is negative."
|
|
1663 (interactive "p")
|
|
1664 (calendar-cursor-to-nearest-date)
|
|
1665 (let* ((cursor-date (calendar-cursor-to-date t))
|
|
1666 (month (extract-calendar-month cursor-date))
|
|
1667 (day (extract-calendar-day cursor-date))
|
|
1668 (year (extract-calendar-year cursor-date)))
|
|
1669 (increment-calendar-month month year arg)
|
|
1670 (let ((last (calendar-last-day-of-month month year)))
|
|
1671 (if (< last day)
|
|
1672 (setq day last)))
|
|
1673 ;; Put the new month on the screen, if needed, and go to the new date.
|
|
1674 (let ((new-cursor-date (list month day year)))
|
|
1675 (if (not (calendar-date-is-visible-p new-cursor-date))
|
|
1676 (calendar-other-month month year))
|
|
1677 (calendar-cursor-to-visible-date new-cursor-date))))
|
|
1678
|
|
1679 (defun calendar-forward-year (arg)
|
|
1680 "Move the cursor forward by ARG years.
|
|
1681 Movement is backward if ARG is negative."
|
|
1682 (interactive "p")
|
|
1683 (calendar-forward-month (* 12 arg)))
|
|
1684
|
|
1685 (defun calendar-backward-month (arg)
|
|
1686 "Move the cursor backward by ARG months.
|
|
1687 Movement is forward if ARG is negative."
|
|
1688 (interactive "p")
|
|
1689 (calendar-forward-month (- arg)))
|
|
1690
|
|
1691 (defun calendar-backward-year (arg)
|
|
1692 "Move the cursor backward ARG years.
|
|
1693 Movement is forward is ARG is negative."
|
|
1694 (interactive "p")
|
|
1695 (calendar-forward-month (* -12 arg)))
|
|
1696
|
|
1697 (defun scroll-calendar-left (arg)
|
|
1698 "Scroll the displayed calendar left by ARG months.
|
|
1699 If ARG is negative the calendar is scrolled right. Maintains the relative
|
|
1700 position of the cursor with respect to the calendar as well as possible."
|
|
1701 (interactive "p")
|
|
1702 (calendar-cursor-to-nearest-date)
|
|
1703 (let ((old-date (calendar-cursor-to-date))
|
|
1704 (today (calendar-current-date)))
|
|
1705 (if (/= arg 0)
|
|
1706 (progn
|
|
1707 (increment-calendar-month displayed-month displayed-year arg)
|
|
1708 (generate-calendar-window displayed-month displayed-year)
|
|
1709 (calendar-cursor-to-visible-date
|
|
1710 (cond
|
|
1711 ((calendar-date-is-visible-p old-date) old-date)
|
|
1712 ((calendar-date-is-visible-p today) today)
|
|
1713 (t (list displayed-month 1 displayed-year))))))))
|
|
1714
|
|
1715 (defun scroll-calendar-right (arg)
|
|
1716 "Scroll the displayed calendar window right by ARG months.
|
|
1717 If ARG is negative the calendar is scrolled left. Maintains the relative
|
|
1718 position of the cursor with respect to the calendar as well as possible."
|
|
1719 (interactive "p")
|
|
1720 (scroll-calendar-left (- arg)))
|
|
1721
|
|
1722 (defun scroll-calendar-left-three-months (arg)
|
|
1723 "Scroll the displayed calendar window left by 3*ARG months.
|
|
1724 If ARG is negative the calendar is scrolled right. Maintains the relative
|
|
1725 position of the cursor with respect to the calendar as well as possible."
|
|
1726 (interactive "p")
|
|
1727 (scroll-calendar-left (* 3 arg)))
|
|
1728
|
|
1729 (defun scroll-calendar-right-three-months (arg)
|
|
1730 "Scroll the displayed calendar window right by 3*ARG months.
|
|
1731 If ARG is negative the calendar is scrolled left. Maintains the relative
|
|
1732 position of the cursor with respect to the calendar as well as possible."
|
|
1733 (interactive "p")
|
|
1734 (scroll-calendar-left (* -3 arg)))
|
|
1735
|
|
1736 (defun calendar-current-date ()
|
|
1737 "Returns the current date in a list (month day year)."
|
|
1738 (let ((s (current-time-string)))
|
|
1739 (list (length (member (substring s 4 7)
|
|
1740 '("Dec" "Nov" "Oct" "Sep" "Aug" "Jul"
|
|
1741 "Jun" "May" "Apr" "Mar" "Feb" "Jan")))
|
|
1742 (string-to-number (substring s 8 10))
|
|
1743 (string-to-number (substring s 20 24)))))
|
|
1744
|
|
1745 (defun calendar-cursor-to-date (&optional error)
|
|
1746 "Returns a list (month day year) of current cursor position.
|
|
1747 If cursor is not on a specific date, signals an error if optional parameter
|
|
1748 ERROR is t, otherwise just returns nil."
|
|
1749 ;; #### This check is to avoid a race condition created by
|
|
1750 ;; pop-to-buffer's call to other-window interacting with the 19.13
|
|
1751 ;; changes allowing that to be in another frame.
|
|
1752 (if (not (number-or-marker-p displayed-month))
|
|
1753 nil
|
|
1754 (let* ((segment (/ (current-column) 25))
|
|
1755 (month (% (+ displayed-month segment -1) 12))
|
|
1756 (month (if (= 0 month) 12 month))
|
|
1757 (year
|
|
1758 (cond
|
|
1759 ((and (= 12 month) (= segment 0)) (1- displayed-year))
|
|
1760 ((and (= 1 month) (= segment 2)) (1+ displayed-year))
|
|
1761 (t displayed-year))))
|
|
1762 (if (and (looking-at "[0-9]")
|
|
1763 (< 2 (count-lines (point-min) (point))))
|
|
1764 (save-excursion
|
|
1765 (re-search-backward "[^0-9]")
|
|
1766 (list month
|
|
1767 (string-to-int (buffer-substring (1+ (point)) (+ 4 (point))))
|
|
1768 year))
|
|
1769 (if (looking-at "\\*")
|
|
1770 (save-excursion
|
|
1771 (re-search-backward "[^*]")
|
|
1772 (if (looking-at ".\\*\\*")
|
|
1773 (list month calendar-starred-day year)
|
|
1774 (if error (error "Not on a date!"))))
|
|
1775 (if error (error "Not on a date!")))))))
|
|
1776
|
|
1777 (defun calendar-cursor-to-nearest-date ()
|
|
1778 "Move the cursor to the closest date.
|
|
1779 The position of the cursor is unchanged if it is already on a date.
|
|
1780 Returns the list (month day year) giving the cursor position."
|
|
1781 (let ((date (calendar-cursor-to-date))
|
|
1782 (column (current-column)))
|
|
1783 (if date
|
|
1784 date
|
|
1785 (if (> 3 (count-lines (point-min) (point)))
|
|
1786 (progn
|
|
1787 (goto-line 3)
|
|
1788 (move-to-column column)))
|
|
1789 (if (not (looking-at "[0-9]"))
|
|
1790 (if (and (not (looking-at " *$"))
|
|
1791 (or (< column 25)
|
|
1792 (and (> column 27)
|
|
1793 (< column 50))
|
|
1794 (and (> column 52)
|
|
1795 (< column 75))))
|
|
1796 (progn
|
|
1797 (re-search-forward "[0-9]" nil t)
|
|
1798 (backward-char 1))
|
|
1799 (re-search-backward "[0-9]" nil t)))
|
|
1800 (calendar-cursor-to-date))))
|
|
1801
|
|
1802 (defun calendar-forward-day (arg)
|
|
1803 "Move the cursor forward ARG days.
|
|
1804 Moves backward if ARG is negative."
|
|
1805 (interactive "p")
|
|
1806 (if (/= 0 arg)
|
|
1807 (let*
|
|
1808 ((cursor-date (calendar-cursor-to-date))
|
|
1809 (cursor-date (if cursor-date
|
|
1810 cursor-date
|
|
1811 (if (> arg 0) (setq arg (1- arg)))
|
|
1812 (calendar-cursor-to-nearest-date)))
|
|
1813 (new-cursor-date
|
|
1814 (calendar-gregorian-from-absolute
|
|
1815 (+ (calendar-absolute-from-gregorian cursor-date) arg)))
|
|
1816 (new-display-month (extract-calendar-month new-cursor-date))
|
|
1817 (new-display-year (extract-calendar-year new-cursor-date)))
|
|
1818 ;; Put the new month on the screen, if needed, and go to the new date.
|
|
1819 (if (not (calendar-date-is-visible-p new-cursor-date))
|
|
1820 (calendar-other-month new-display-month new-display-year))
|
|
1821 (calendar-cursor-to-visible-date new-cursor-date))))
|
|
1822
|
|
1823 (defun calendar-backward-day (arg)
|
|
1824 "Move the cursor back ARG days.
|
|
1825 Moves forward if ARG is negative."
|
|
1826 (interactive "p")
|
|
1827 (calendar-forward-day (- arg)))
|
|
1828
|
|
1829 (defun calendar-forward-week (arg)
|
|
1830 "Move the cursor forward ARG weeks.
|
|
1831 Moves backward if ARG is negative."
|
|
1832 (interactive "p")
|
|
1833 (calendar-forward-day (* arg 7)))
|
|
1834
|
|
1835 (defun calendar-backward-week (arg)
|
|
1836 "Move the cursor back ARG weeks.
|
|
1837 Moves forward if ARG is negative."
|
|
1838 (interactive "p")
|
|
1839 (calendar-forward-day (* arg -7)))
|
|
1840
|
|
1841 (defun calendar-beginning-of-week (arg)
|
|
1842 "Move the cursor back ARG calendar-week-start-day's."
|
|
1843 (interactive "p")
|
|
1844 (calendar-cursor-to-nearest-date)
|
|
1845 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
|
|
1846 (calendar-backward-day
|
|
1847 (if (= day calendar-week-start-day)
|
|
1848 (* 7 arg)
|
|
1849 (+ (mod (- day calendar-week-start-day) 7)
|
|
1850 (* 7 (1- arg)))))))
|
|
1851
|
|
1852 (defun calendar-end-of-week (arg)
|
|
1853 "Move the cursor forward ARG calendar-week-start-day+6's."
|
|
1854 (interactive "p")
|
|
1855 (calendar-cursor-to-nearest-date)
|
|
1856 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
|
|
1857 (calendar-forward-day
|
|
1858 (if (= day (mod (1- calendar-week-start-day) 7))
|
|
1859 (* 7 arg)
|
|
1860 (+ (- 6 (mod (- day calendar-week-start-day) 7))
|
|
1861 (* 7 (1- arg)))))))
|
|
1862
|
|
1863 (defun calendar-beginning-of-month (arg)
|
|
1864 "Move the cursor backward ARG month beginnings."
|
|
1865 (interactive "p")
|
|
1866 (calendar-cursor-to-nearest-date)
|
|
1867 (let* ((date (calendar-cursor-to-date))
|
|
1868 (month (extract-calendar-month date))
|
|
1869 (day (extract-calendar-day date))
|
|
1870 (year (extract-calendar-year date)))
|
|
1871 (if (= day 1)
|
|
1872 (calendar-backward-month arg)
|
|
1873 (calendar-cursor-to-visible-date (list month 1 year))
|
|
1874 (calendar-backward-month (1- arg)))))
|
|
1875
|
|
1876 (defun calendar-end-of-month (arg)
|
|
1877 "Move the cursor forward ARG month ends."
|
|
1878 (interactive "p")
|
|
1879 (calendar-cursor-to-nearest-date)
|
|
1880 (let* ((date (calendar-cursor-to-date))
|
|
1881 (month (extract-calendar-month date))
|
|
1882 (day (extract-calendar-day date))
|
|
1883 (year (extract-calendar-year date))
|
|
1884 (last-day (calendar-last-day-of-month month year)))
|
|
1885 (if (/= day last-day)
|
|
1886 (progn
|
|
1887 (calendar-cursor-to-visible-date (list month last-day year))
|
|
1888 (setq arg (1- arg))))
|
|
1889 (increment-calendar-month month year arg)
|
|
1890 (let ((last-day (list
|
|
1891 month
|
|
1892 (calendar-last-day-of-month month year)
|
|
1893 year)))
|
|
1894 (if (not (calendar-date-is-visible-p last-day))
|
|
1895 (calendar-other-month month year)
|
|
1896 (calendar-cursor-to-visible-date last-day)))))
|
|
1897
|
|
1898 (defun calendar-beginning-of-year (arg)
|
|
1899 "Move the cursor backward ARG year beginnings."
|
|
1900 (interactive "p")
|
|
1901 (calendar-cursor-to-nearest-date)
|
|
1902 (let* ((date (calendar-cursor-to-date))
|
|
1903 (month (extract-calendar-month date))
|
|
1904 (day (extract-calendar-day date))
|
|
1905 (year (extract-calendar-year date))
|
|
1906 (jan-first (list 1 1 year)))
|
|
1907 (if (and (= day 1) (= 1 month))
|
|
1908 (calendar-backward-month (* 12 arg))
|
|
1909 (if (and (= arg 1)
|
|
1910 (calendar-date-is-visible-p jan-first))
|
|
1911 (calendar-cursor-to-visible-date jan-first)
|
|
1912 (calendar-other-month 1 (- year (1- arg)))))))
|
|
1913
|
|
1914 (defun calendar-end-of-year (arg)
|
|
1915 "Move the cursor forward ARG year beginnings."
|
|
1916 (interactive "p")
|
|
1917 (calendar-cursor-to-nearest-date)
|
|
1918 (let* ((date (calendar-cursor-to-date))
|
|
1919 (month (extract-calendar-month date))
|
|
1920 (day (extract-calendar-day date))
|
|
1921 (year (extract-calendar-year date))
|
|
1922 (dec-31 (list 12 31 year)))
|
|
1923 (if (and (= day 31) (= 12 month))
|
|
1924 (calendar-forward-month (* 12 arg))
|
|
1925 (if (and (= arg 1)
|
|
1926 (calendar-date-is-visible-p dec-31))
|
|
1927 (calendar-cursor-to-visible-date dec-31)
|
|
1928 (calendar-other-month 12 (- year (1- arg)))
|
|
1929 (calendar-cursor-to-visible-date (list 12 31 displayed-year))))))
|
|
1930
|
|
1931 ;; The following version of calendar-gregorian-from-absolute is preferred for
|
|
1932 ;; reasons of clarity, BUT it's much slower than the version that follows it.
|
|
1933
|
|
1934 ;;(defun calendar-gregorian-from-absolute (date)
|
|
1935 ;; "Compute the list (month day year) corresponding to the absolute DATE.
|
|
1936 ;;The absolute date is the number of days elapsed since the (imaginary)
|
|
1937 ;;Gregorian date Sunday, December 31, 1 BC."
|
|
1938 ;; (let* ((approx (/ date 366));; Approximation from below.
|
|
1939 ;; (year ;; Search forward from the approximation.
|
|
1940 ;; (+ approx
|
|
1941 ;; (calendar-sum y approx
|
|
1942 ;; (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y))))
|
|
1943 ;; 1)))
|
|
1944 ;; (month ;; Search forward from January.
|
|
1945 ;; (1+ (calendar-sum m 1
|
|
1946 ;; (> date
|
|
1947 ;; (calendar-absolute-from-gregorian
|
|
1948 ;; (list m (calendar-last-day-of-month m year) year)))
|
|
1949 ;; 1)))
|
|
1950 ;; (day ;; Calculate the day by subtraction.
|
|
1951 ;; (- date
|
|
1952 ;; (1- (calendar-absolute-from-gregorian (list month 1 year))))))
|
|
1953 ;; (list month day year)))
|
|
1954
|
|
1955 (defun calendar-gregorian-from-absolute (date)
|
|
1956 "Compute the list (month day year) corresponding to the absolute DATE.
|
|
1957 The absolute date is the number of days elapsed since the (imaginary)
|
|
1958 Gregorian date Sunday, December 31, 1 BC."
|
|
1959 ;; See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
1960 ;; Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
|
|
1961 ;; Clamen, Software--Practice and Experience, Volume 23, Number 4
|
|
1962 ;; (April, 1993), pages 383-404 for an explanation.
|
|
1963 (let* ((d0 (1- date))
|
|
1964 (n400 (/ d0 146097))
|
|
1965 (d1 (% d0 146097))
|
|
1966 (n100 (/ d1 36524))
|
|
1967 (d2 (% d1 36524))
|
|
1968 (n4 (/ d2 1461))
|
|
1969 (d3 (% d2 1461))
|
|
1970 (n1 (/ d3 365))
|
|
1971 (day (1+ (% d3 365)))
|
|
1972 (year (+ (* 400 n400) (* 100 n100) (* n4 4) n1)))
|
|
1973 (if (or (= n100 4) (= n1 4))
|
|
1974 (list 12 31 year)
|
|
1975 (let ((year (1+ year))
|
|
1976 (month 1))
|
|
1977 (while (let ((mdays (calendar-last-day-of-month month year)))
|
|
1978 (and (< mdays day)
|
|
1979 (setq day (- day mdays))))
|
|
1980 (setq month (1+ month)))
|
|
1981 (list month day year)))))
|
|
1982
|
|
1983 (defun calendar-cursor-to-visible-date (date)
|
|
1984 "Move the cursor to DATE that is on the screen."
|
|
1985 (let* ((month (extract-calendar-month date))
|
|
1986 (day (extract-calendar-day date))
|
|
1987 (year (extract-calendar-year date))
|
|
1988 (first-of-month-weekday (calendar-day-of-week (list month 1 year))))
|
|
1989 (goto-line (+ 3
|
|
1990 (/ (+ day -1
|
|
1991 (mod
|
|
1992 (- (calendar-day-of-week (list month 1 year))
|
|
1993 calendar-week-start-day)
|
|
1994 7))
|
|
1995 7)))
|
|
1996 (move-to-column (+ 6
|
|
1997 (* 25
|
|
1998 (1+ (calendar-interval
|
|
1999 displayed-month displayed-year month year)))
|
|
2000 (* 3 (mod
|
|
2001 (- (calendar-day-of-week date)
|
|
2002 calendar-week-start-day)
|
|
2003 7))))))
|
|
2004
|
|
2005 (defun calendar-other-month (month year)
|
|
2006 "Display a three-month calendar centered around MONTH and YEAR."
|
|
2007 (interactive (calendar-read-date 'noday))
|
|
2008 (if (and (= month displayed-month)
|
|
2009 (= year displayed-year))
|
|
2010 nil
|
|
2011 (let ((old-date (calendar-cursor-to-date))
|
|
2012 (today (calendar-current-date)))
|
|
2013 (generate-calendar-window month year)
|
|
2014 (calendar-cursor-to-visible-date
|
|
2015 (cond
|
|
2016 ((calendar-date-is-visible-p old-date) old-date)
|
|
2017 ((calendar-date-is-visible-p today) today)
|
|
2018 (t (list month 1 year)))))))
|
|
2019
|
|
2020 (defun calendar-set-mark (arg)
|
|
2021 "Mark the date under the cursor, or jump to marked date.
|
|
2022 With no prefix argument, push current date onto marked date ring.
|
|
2023 With argument, jump to mark, pop it, and put point at end of ring."
|
|
2024 (interactive "P")
|
|
2025 (let ((date (calendar-cursor-to-date t)))
|
|
2026 (if (null arg)
|
|
2027 (progn
|
|
2028 (setq calendar-mark-ring (cons date calendar-mark-ring))
|
|
2029 ;; Since the top of the mark ring is the marked date in the
|
|
2030 ;; calendar, the mark ring in the calendar is one longer than
|
|
2031 ;; in other buffers to get the same effect.
|
|
2032 (if (> (length calendar-mark-ring) (1+ mark-ring-max))
|
|
2033 (setcdr (nthcdr mark-ring-max calendar-mark-ring) nil))
|
|
2034 (message "Mark set"))
|
|
2035 (if (null calendar-mark-ring)
|
|
2036 (error "No mark set in this buffer")
|
|
2037 (calendar-goto-date (car calendar-mark-ring))
|
|
2038 (setq calendar-mark-ring
|
|
2039 (cdr (nconc calendar-mark-ring (list date))))))))
|
|
2040
|
|
2041 (defun calendar-exchange-point-and-mark ()
|
|
2042 "Exchange the current cursor position with the marked date."
|
|
2043 (interactive)
|
|
2044 (let ((mark (car calendar-mark-ring))
|
|
2045 (date (calendar-cursor-to-date t)))
|
|
2046 (if (null mark)
|
|
2047 (error "No mark set in this buffer")
|
|
2048 (setq calendar-mark-ring (cons date (cdr calendar-mark-ring)))
|
|
2049 (calendar-goto-date mark))))
|
|
2050
|
|
2051 (defun calendar-count-days-region ()
|
|
2052 "Count the number of days (inclusive) between point and the mark."
|
|
2053 (interactive)
|
|
2054 (let* ((days (- (calendar-absolute-from-gregorian
|
|
2055 (calendar-cursor-to-date t))
|
|
2056 (calendar-absolute-from-gregorian
|
|
2057 (or (car calendar-mark-ring)
|
|
2058 (error "No mark set in this buffer")))))
|
|
2059 (days (1+ (if (> days 0) days (- days)))))
|
|
2060 (message "Region has %d day%s (inclusive)"
|
|
2061 days (if (> days 1) "s" ""))))
|
|
2062
|
|
2063 (defun calendar-not-implemented ()
|
|
2064 "Not implemented."
|
|
2065 (interactive)
|
|
2066 (error "%s not available in the calendar"
|
|
2067 (global-key-binding (this-command-keys))))
|
|
2068
|
|
2069 (defun calendar-read (prompt acceptable &optional initial-contents)
|
|
2070 "Return an object read from the minibuffer.
|
|
2071 Prompt with the string PROMPT and use the function ACCEPTABLE to decide if
|
|
2072 entered item is acceptable. If non-nil, optional third arg INITIAL-CONTENTS
|
|
2073 is a string to insert in the minibuffer before reading."
|
|
2074 (let ((value (read-minibuffer prompt initial-contents)))
|
|
2075 (while (not (funcall acceptable value))
|
|
2076 (setq value (read-minibuffer prompt initial-contents)))
|
|
2077 value))
|
|
2078
|
|
2079 (defun calendar-read-date (&optional noday)
|
|
2080 "Prompt for Gregorian date. Returns a list (month day year).
|
|
2081 If optional NODAY is t, does not ask for day, but just returns
|
|
2082 (month nil year); if NODAY is any other non-nil value the value returned is
|
|
2083 (month year) "
|
|
2084 (let* ((year (calendar-read
|
|
2085 "Year (>0): "
|
|
2086 '(lambda (x) (> x 0))
|
|
2087 (int-to-string (extract-calendar-year
|
|
2088 (calendar-current-date)))))
|
|
2089 (month-array calendar-month-name-array)
|
|
2090 (completion-ignore-case t)
|
|
2091 (month (cdr (assoc
|
|
2092 (capitalize
|
|
2093 (completing-read
|
|
2094 "Month name: "
|
|
2095 (mapcar 'list (append month-array nil))
|
|
2096 nil t))
|
|
2097 (calendar-make-alist month-array 1 'capitalize))))
|
|
2098 (last (calendar-last-day-of-month month year)))
|
|
2099 (if noday
|
|
2100 (if (eq noday t)
|
|
2101 (list month nil year)
|
|
2102 (list month year))
|
|
2103 (list month
|
|
2104 (calendar-read (format "Day (1-%d): " last)
|
|
2105 '(lambda (x) (and (< 0 x) (<= x last))))
|
|
2106 year))))
|
|
2107
|
|
2108 (defun calendar-goto-date (date)
|
|
2109 "Move cursor to DATE."
|
|
2110 (interactive (list (calendar-read-date)))
|
|
2111 (let ((month (extract-calendar-month date))
|
|
2112 (year (extract-calendar-year date)))
|
|
2113 (if (not (calendar-date-is-visible-p date))
|
|
2114 (calendar-other-month
|
|
2115 (if (and (= month 1) (= year 1))
|
|
2116 2
|
|
2117 month)
|
|
2118 year)))
|
|
2119 (calendar-cursor-to-visible-date date))
|
|
2120
|
|
2121 (defun calendar-goto-julian-date (date &optional noecho)
|
|
2122 "Move cursor to Julian DATE; echo Julian date unless NOECHO is t."
|
|
2123 (interactive
|
|
2124 (let* ((today (calendar-current-date))
|
|
2125 (year (calendar-read
|
|
2126 "Julian calendar year (>0): "
|
|
2127 '(lambda (x) (> x 0))
|
|
2128 (int-to-string
|
|
2129 (extract-calendar-year
|
|
2130 (calendar-julian-from-absolute
|
|
2131 (calendar-absolute-from-gregorian
|
|
2132 today))))))
|
|
2133 (month-array calendar-month-name-array)
|
|
2134 (completion-ignore-case t)
|
|
2135 (month (cdr (assoc
|
|
2136 (capitalize
|
|
2137 (completing-read
|
|
2138 "Julian calendar month name: "
|
|
2139 (mapcar 'list (append month-array nil))
|
|
2140 nil t))
|
|
2141 (calendar-make-alist month-array 1 'capitalize))))
|
|
2142 (last
|
|
2143 (if (and (zerop (% year 4)) (= month 2))
|
|
2144 29
|
|
2145 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
|
|
2146 (day (calendar-read
|
|
2147 (format "Julian calendar day (%d-%d): "
|
|
2148 (if (and (= year 1) (= month 1)) 3 1) last)
|
|
2149 '(lambda (x)
|
|
2150 (and (< (if (and (= year 1) (= month 1)) 2 0) x)
|
|
2151 (<= x last))))))
|
|
2152 (list (list month day year))))
|
|
2153 (calendar-goto-date (calendar-gregorian-from-absolute
|
|
2154 (calendar-absolute-from-julian date)))
|
|
2155 (or noecho (calendar-print-julian-date)))
|
|
2156
|
|
2157 (defun calendar-goto-hebrew-date (date &optional noecho)
|
|
2158 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is t."
|
|
2159 (interactive
|
|
2160 (let* ((today (calendar-current-date))
|
|
2161 (year (calendar-read
|
|
2162 "Hebrew calendar year (>3760): "
|
|
2163 '(lambda (x) (> x 3760))
|
|
2164 (int-to-string
|
|
2165 (extract-calendar-year
|
|
2166 (calendar-hebrew-from-absolute
|
|
2167 (calendar-absolute-from-gregorian today))))))
|
|
2168 (month-array (if (hebrew-calendar-leap-year-p year)
|
|
2169 calendar-hebrew-month-name-array-leap-year
|
|
2170 calendar-hebrew-month-name-array-common-year))
|
|
2171 (completion-ignore-case t)
|
|
2172 (month (cdr (assoc
|
|
2173 (capitalize
|
|
2174 (completing-read
|
|
2175 "Hebrew calendar month name: "
|
|
2176 (mapcar 'list (append month-array nil))
|
|
2177 (if (= year 3761)
|
|
2178 '(lambda (x)
|
|
2179 (let ((m (cdr
|
|
2180 (assoc
|
|
2181 (car x)
|
|
2182 (calendar-make-alist
|
|
2183 month-array)))))
|
|
2184 (< 0
|
|
2185 (calendar-absolute-from-hebrew
|
|
2186 (list m
|
|
2187 (hebrew-calendar-last-day-of-month
|
|
2188 m year)
|
|
2189 year))))))
|
|
2190
|
|
2191 t))
|
|
2192 (calendar-make-alist month-array 1 'capitalize))))
|
|
2193 (last (hebrew-calendar-last-day-of-month month year))
|
|
2194 (first (if (and (= year 3761) (= month 10))
|
|
2195 18 1))
|
|
2196 (day (calendar-read
|
|
2197 (format "Hebrew calendar day (%d-%d): "
|
|
2198 first last)
|
|
2199 '(lambda (x) (and (<= first x) (<= x last))))))
|
|
2200 (list (list month day year))))
|
|
2201 (calendar-goto-date (calendar-gregorian-from-absolute
|
|
2202 (calendar-absolute-from-hebrew date)))
|
|
2203 (or noecho (calendar-print-hebrew-date)))
|
|
2204
|
|
2205 (defun calendar-goto-islamic-date (date &optional noecho)
|
|
2206 "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is t."
|
|
2207 (interactive
|
|
2208 (let* ((today (calendar-current-date))
|
|
2209 (year (calendar-read
|
|
2210 "Islamic calendar year (>0): "
|
|
2211 '(lambda (x) (> x 0))
|
|
2212 (int-to-string
|
|
2213 (extract-calendar-year
|
|
2214 (calendar-islamic-from-absolute
|
|
2215 (calendar-absolute-from-gregorian today))))))
|
|
2216 (month-array calendar-islamic-month-name-array)
|
|
2217 (completion-ignore-case t)
|
|
2218 (month (cdr (assoc
|
|
2219 (capitalize
|
|
2220 (completing-read
|
|
2221 "Islamic calendar month name: "
|
|
2222 (mapcar 'list (append month-array nil))
|
|
2223 nil t))
|
|
2224 (calendar-make-alist month-array 1 'capitalize))))
|
|
2225 (last (islamic-calendar-last-day-of-month month year))
|
|
2226 (day (calendar-read
|
|
2227 (format "Islamic calendar day (1-%d): " last)
|
|
2228 '(lambda (x) (and (< 0 x) (<= x last))))))
|
|
2229 (list (list month day year))))
|
|
2230 (calendar-goto-date (calendar-gregorian-from-absolute
|
|
2231 (calendar-absolute-from-islamic date)))
|
|
2232 (or noecho (calendar-print-islamic-date)))
|
|
2233
|
|
2234 (defun calendar-goto-iso-date (date &optional noecho)
|
|
2235 "Move cursor to ISO DATE; echo ISO date unless NOECHO is t."
|
|
2236 (interactive
|
|
2237 (let* ((today (calendar-current-date))
|
|
2238 (year (calendar-read
|
|
2239 "ISO calendar year (>0): "
|
|
2240 '(lambda (x) (> x 0))
|
|
2241 (int-to-string (extract-calendar-year today))))
|
|
2242 (no-weeks (extract-calendar-month
|
|
2243 (calendar-iso-from-absolute
|
|
2244 (1-
|
|
2245 (calendar-dayname-on-or-before
|
|
2246 1 (calendar-absolute-from-gregorian
|
|
2247 (list 1 4 (1+ year))))))))
|
|
2248 (week (calendar-read
|
|
2249 (format "ISO calendar week (1-%d): " no-weeks)
|
|
2250 '(lambda (x) (and (> x 0) (<= x no-weeks)))))
|
|
2251 (day (calendar-read
|
|
2252 "ISO day (1-7): "
|
|
2253 '(lambda (x) (and (<= 1 x) (<= x 7))))))
|
|
2254 (list (list week day year))))
|
|
2255 (calendar-goto-date (calendar-gregorian-from-absolute
|
|
2256 (calendar-absolute-from-iso date)))
|
|
2257 (or noecho (calendar-print-iso-date)))
|
|
2258
|
|
2259 (defun calendar-interval (mon1 yr1 mon2 yr2)
|
|
2260 "The number of months difference between MON1, YR1 and MON2, YR2."
|
|
2261 (+ (* 12 (- yr2 yr1))
|
|
2262 (- mon2 mon1)))
|
|
2263
|
|
2264 (defun calendar-day-name (date)
|
|
2265 "Returns a string with the name of the day of the week of DATE."
|
|
2266 (aref calendar-day-name-array (calendar-day-of-week date)))
|
|
2267
|
|
2268 (defvar calendar-day-name-array
|
|
2269 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
|
|
2270
|
|
2271 (defvar calendar-month-name-array
|
|
2272 ["January" "February" "March" "April" "May" "June"
|
|
2273 "July" "August" "September" "October" "November" "December"])
|
|
2274
|
|
2275 (defun calendar-make-alist (sequence &optional start-index filter)
|
|
2276 "Make an assoc list corresponding to SEQUENCE.
|
|
2277 Start at index 1, unless optional START-INDEX is provided.
|
|
2278 If FILTER is provided, apply it to each item in the list."
|
|
2279 (let ((index (if start-index (1- start-index) 0)))
|
|
2280 (mapcar
|
|
2281 '(lambda (x)
|
|
2282 (setq index (1+ index))
|
|
2283 (cons (if filter (funcall filter x) x)
|
|
2284 index))
|
|
2285 (append sequence nil))))
|
|
2286
|
|
2287 (defun calendar-month-name (month)
|
|
2288 "The name of MONTH."
|
|
2289 (aref calendar-month-name-array (1- month)))
|
|
2290
|
|
2291 (defun calendar-day-of-week (date)
|
|
2292 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
|
|
2293 (% (calendar-absolute-from-gregorian date) 7))
|
|
2294
|
|
2295 (defun calendar-unmark ()
|
|
2296 "Delete all diary/holiday marks/highlighting from the calendar."
|
|
2297 (interactive)
|
|
2298 (setq mark-holidays-in-calendar nil)
|
|
2299 (setq mark-diary-entries-in-calendar nil)
|
|
2300 (redraw-calendar))
|
|
2301
|
|
2302 (defun calendar-date-is-visible-p (date)
|
|
2303 "Returns t if DATE is legal and is visible in the calendar window."
|
|
2304 (let ((gap (calendar-interval
|
|
2305 displayed-month displayed-year
|
|
2306 (extract-calendar-month date) (extract-calendar-year date))))
|
|
2307 (and (calendar-date-is-legal-p date) (> 2 gap) (< -2 gap))))
|
|
2308
|
|
2309 (defun calendar-date-is-legal-p (date)
|
|
2310 "Returns t if DATE is a legal date."
|
|
2311 (let ((month (extract-calendar-month date))
|
|
2312 (day (extract-calendar-day date))
|
|
2313 (year (extract-calendar-year date)))
|
|
2314 (and (<= 1 month) (<= month 12)
|
|
2315 (<= 1 day) (<= day (calendar-last-day-of-month month year))
|
|
2316 (<= 1 year))))
|
|
2317
|
|
2318 (defun calendar-date-equal (date1 date2)
|
|
2319 "Returns t if the DATE1 and DATE2 are the same."
|
|
2320 (and
|
|
2321 (= (extract-calendar-month date1) (extract-calendar-month date2))
|
|
2322 (= (extract-calendar-day date1) (extract-calendar-day date2))
|
|
2323 (= (extract-calendar-year date1) (extract-calendar-year date2))))
|
|
2324
|
|
2325 (defun mark-visible-calendar-date (date &optional mark)
|
|
2326 "Mark DATE in the calendar window with MARK.
|
|
2327 MARK is either a single-character string or a face.
|
|
2328 MARK defaults to diary-entry-marker."
|
|
2329 (if (calendar-date-is-legal-p date)
|
|
2330 (save-excursion
|
|
2331 (set-buffer calendar-buffer)
|
|
2332 (calendar-cursor-to-visible-date date)
|
|
2333 (let ((mark (or mark diary-entry-marker)))
|
|
2334 (if (stringp mark)
|
|
2335 (let ((buffer-read-only nil))
|
|
2336 (forward-char 1)
|
|
2337 (delete-char 1)
|
|
2338 (insert mark)
|
|
2339 (forward-char -2))
|
|
2340
|
|
2341 (set-extent-property (make-extent (1- (point)) (1+ (point)))
|
|
2342 'face mark))))))
|
|
2343
|
|
2344 (defun calendar-star-date ()
|
|
2345 "Replace the date under the cursor in the calendar window with asterisks.
|
|
2346 This function can be used with the today-visible-calendar-hook run after the
|
|
2347 calendar window has been prepared."
|
|
2348 (let ((buffer-read-only nil))
|
|
2349 (make-variable-buffer-local 'calendar-starred-day)
|
|
2350 (forward-char 1)
|
|
2351 (setq calendar-starred-day
|
|
2352 (string-to-int
|
|
2353 (buffer-substring (point) (- (point) 2))))
|
|
2354 (delete-char -2)
|
|
2355 (insert "**")
|
|
2356 (backward-char 1)
|
|
2357 (set-buffer-modified-p nil)))
|
|
2358
|
|
2359 (defun calendar-mark-today ()
|
|
2360 "Mark the date under the cursor in the calendar window.
|
|
2361 The date is marked with calendar-today-marker. This function can be used with
|
|
2362 the today-visible-calendar-hook run after the calendar window has been
|
|
2363 prepared."
|
|
2364 (mark-visible-calendar-date
|
|
2365 (calendar-cursor-to-date)
|
|
2366 calendar-today-marker))
|
|
2367
|
|
2368 (defun calendar-date-compare (date1 date2)
|
|
2369 "Returns t if DATE1 is before DATE2, nil otherwise.
|
|
2370 The actual dates are in the car of DATE1 and DATE2."
|
|
2371 (< (calendar-absolute-from-gregorian (car date1))
|
|
2372 (calendar-absolute-from-gregorian (car date2))))
|
|
2373
|
|
2374 (defun calendar-date-string (date &optional abbreviate nodayname)
|
|
2375 "A string form of DATE, driven by the variable `calendar-date-display-form'.
|
|
2376 An optional parameter ABBREVIATE, when t, causes the month and day names to be
|
|
2377 abbreviated to three characters. An optional parameter NODAYNAME, when t,
|
|
2378 omits the name of the day of the week."
|
|
2379 (let* ((dayname
|
|
2380 (if nodayname
|
|
2381 nil
|
|
2382 (if abbreviate
|
|
2383 (substring (calendar-day-name date) 0 3)
|
|
2384 (calendar-day-name date))))
|
|
2385 (month (extract-calendar-month date))
|
|
2386 (monthname
|
|
2387 (if abbreviate
|
|
2388 (substring
|
|
2389 (calendar-month-name month) 0 3)
|
|
2390 (calendar-month-name month)))
|
|
2391 (day (int-to-string (extract-calendar-day date)))
|
|
2392 (month (int-to-string month))
|
|
2393 (year (int-to-string (extract-calendar-year date))))
|
|
2394 (mapconcat 'eval calendar-date-display-form "")))
|
|
2395
|
|
2396 (defun calendar-dayname-on-or-before (dayname date)
|
|
2397 "Returns the absolute date of the DAYNAME on or before absolute DATE.
|
|
2398 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
|
|
2399
|
|
2400 Note: Applying this function to d+6 gives us the DAYNAME on or after an
|
|
2401 absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
|
|
2402 absolute date d, applying it to d-1 gives the DAYNAME previous to absolute
|
|
2403 date d, and applying it to d+7 gives the DAYNAME following absolute date d."
|
|
2404 (- date (% (- date dayname) 7)))
|
|
2405
|
|
2406 (defun calendar-nth-named-absday (n dayname month year &optional day)
|
|
2407 "The absolute date of Nth DAYNAME in MONTH, YEAR before/after optional DAY.
|
|
2408 A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0,
|
|
2409 return the Nth DAYNAME before MONTH DAY, YEAR (inclusive).
|
|
2410 If N>0, return the Nth DAYNAME after MONTH DAY, YEAR (inclusive).
|
|
2411
|
|
2412 If DAY is omitted, it defaults to 1 if N>0, and MONTH's last day otherwise."
|
|
2413 (if (> n 0)
|
|
2414 (+ (* 7 (1- n))
|
|
2415 (calendar-dayname-on-or-before
|
|
2416 dayname
|
|
2417 (+ 6 (calendar-absolute-from-gregorian
|
|
2418 (list month (or day 1) year)))))
|
|
2419 (+ (* 7 (1+ n))
|
|
2420 (calendar-dayname-on-or-before
|
|
2421 dayname
|
|
2422 (calendar-absolute-from-gregorian
|
|
2423 (list month
|
|
2424 (or day (calendar-last-day-of-month month year))
|
|
2425 year))))))
|
|
2426
|
|
2427 (defun calendar-nth-named-day (n dayname month year &optional day)
|
|
2428 "The date of Nth DAYNAME in MONTH, YEAR before/after optional DAY.
|
|
2429 A DAYNAME of 0 means Sunday, 1 means Monday, and so on. If N<0,
|
|
2430 return the Nth DAYNAME before MONTH DAY, YEAR (inclusive).
|
|
2431 If N>0, return the Nth DAYNAME after MONTH DAY, YEAR (inclusive).
|
|
2432
|
|
2433 If DAY is omitted, it defaults to 1 if N>0, and MONTH's last day otherwise."
|
|
2434 (calendar-gregorian-from-absolute
|
|
2435 (calendar-nth-named-absday n dayname month year day)))
|
|
2436
|
|
2437 (defun calendar-day-of-year-string (&optional date)
|
|
2438 "String of day number of year of Gregorian DATE.
|
|
2439 Defaults to today's date if DATE is not given."
|
|
2440 (let* ((d (or date (calendar-current-date)))
|
|
2441 (year (extract-calendar-year d))
|
|
2442 (day (calendar-day-number d))
|
|
2443 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
|
|
2444 (format "Day %d of %d; %d day%s remaining in the year"
|
|
2445 day year days-remaining (if (= days-remaining 1) "" "s"))))
|
|
2446
|
|
2447 (defun calendar-print-day-of-year ()
|
|
2448 "Show day number in year/days remaining in year for date under the cursor."
|
|
2449 (interactive)
|
|
2450 (message (calendar-day-of-year-string (calendar-cursor-to-date t))))
|
|
2451
|
|
2452 (defun calendar-absolute-from-iso (date)
|
|
2453 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
|
|
2454 The `ISO year' corresponds approximately to the Gregorian year, but
|
|
2455 weeks start on Monday and end on Sunday. The first week of the ISO year is
|
|
2456 the first such week in which at least 4 days are in a year. The ISO
|
|
2457 commercial DATE has the form (week day year) in which week is in the range
|
|
2458 1..52 and day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 =
|
|
2459 Sunday). The Gregorian date Sunday, December 31, 1 BC is imaginary."
|
|
2460 (let* ((week (extract-calendar-month date))
|
|
2461 (day (extract-calendar-day date))
|
|
2462 (year (extract-calendar-year date)))
|
|
2463 (+ (calendar-dayname-on-or-before
|
|
2464 1 (+ 3 (calendar-absolute-from-gregorian (list 1 1 year))))
|
|
2465 (* 7 (1- week))
|
|
2466 (if (= day 0) 6 (1- day)))))
|
|
2467
|
|
2468 (defun calendar-iso-from-absolute (date)
|
|
2469 "Compute the `ISO commercial date' corresponding to the absolute DATE.
|
|
2470 The ISO year corresponds approximately to the Gregorian year, but weeks
|
|
2471 start on Monday and end on Sunday. The first week of the ISO year is the
|
|
2472 first such week in which at least 4 days are in a year. The ISO commercial
|
|
2473 date has the form (week day year) in which week is in the range 1..52 and
|
|
2474 day is in the range 0..6 (1 = Monday, 2 = Tuesday, ..., 0 = Sunday). The
|
|
2475 absolute date is the number of days elapsed since the (imaginary) Gregorian
|
|
2476 date Sunday, December 31, 1 BC."
|
|
2477 (let* ((approx (extract-calendar-year
|
|
2478 (calendar-gregorian-from-absolute (- date 3))))
|
|
2479 (year (+ approx
|
|
2480 (calendar-sum y approx
|
|
2481 (>= date (calendar-absolute-from-iso (list 1 1 (1+ y))))
|
|
2482 1))))
|
|
2483 (list
|
|
2484 (1+ (/ (- date (calendar-absolute-from-iso (list 1 1 year))) 7))
|
|
2485 (% date 7)
|
|
2486 year)))
|
|
2487
|
|
2488 (defun calendar-iso-date-string (&optional date)
|
|
2489 "String of ISO date of Gregorian DATE.
|
|
2490 Defaults to today's date if DATE is not given."
|
|
2491 (let* ((d (calendar-absolute-from-gregorian
|
|
2492 (or date (calendar-current-date))))
|
|
2493 (day (% d 7))
|
|
2494 (iso-date (calendar-iso-from-absolute d)))
|
|
2495 (format "Day %s of week %d of %d"
|
|
2496 (if (zerop day) 7 day)
|
|
2497 (extract-calendar-month iso-date)
|
|
2498 (extract-calendar-year iso-date))))
|
|
2499
|
|
2500 (defun calendar-print-iso-date ()
|
|
2501 "Show equivalent ISO date for the date under the cursor."
|
|
2502 (interactive)
|
|
2503 (message "ISO date: %s"
|
|
2504 (calendar-iso-date-string (calendar-cursor-to-date t))))
|
|
2505
|
|
2506 (defun calendar-julian-from-absolute (date)
|
|
2507 "Compute the Julian (month day year) corresponding to the absolute DATE.
|
|
2508 The absolute date is the number of days elapsed since the (imaginary)
|
|
2509 Gregorian date Sunday, December 31, 1 BC."
|
|
2510 (let* ((approx (/ (+ date 2) 366));; Approximation from below.
|
|
2511 (year ;; Search forward from the approximation.
|
|
2512 (+ approx
|
|
2513 (calendar-sum y approx
|
|
2514 (>= date (calendar-absolute-from-julian (list 1 1 (1+ y))))
|
|
2515 1)))
|
|
2516 (month ;; Search forward from January.
|
|
2517 (1+ (calendar-sum m 1
|
|
2518 (> date
|
|
2519 (calendar-absolute-from-julian
|
|
2520 (list m
|
|
2521 (if (and (= m 2) (= (% year 4) 0))
|
|
2522 29
|
|
2523 (aref [31 28 31 30 31 30 31 31 30 31 30 31]
|
|
2524 (1- m)))
|
|
2525 year)))
|
|
2526 1)))
|
|
2527 (day ;; Calculate the day by subtraction.
|
|
2528 (- date (1- (calendar-absolute-from-julian (list month 1 year))))))
|
|
2529 (list month day year)))
|
|
2530
|
|
2531 (defun calendar-absolute-from-julian (date)
|
|
2532 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
|
|
2533 The Gregorian date Sunday, December 31, 1 BC is imaginary."
|
|
2534 (let ((month (extract-calendar-month date))
|
|
2535 (day (extract-calendar-day date))
|
|
2536 (year (extract-calendar-year date)))
|
|
2537 (+ (calendar-day-number date)
|
|
2538 (if (and (= (% year 100) 0)
|
|
2539 (/= (% year 400) 0)
|
|
2540 (> month 2))
|
|
2541 1 0);; Correct for Julian but not Gregorian leap year.
|
|
2542 (* 365 (1- year))
|
|
2543 (/ (1- year) 4)
|
|
2544 -2)))
|
|
2545
|
|
2546 (defun calendar-julian-date-string (&optional date)
|
|
2547 "String of Julian date of Gregorian DATE.
|
|
2548 Defaults to today's date if DATE is not given.
|
|
2549 Driven by the variable `calendar-date-display-form'."
|
|
2550 (calendar-date-string
|
|
2551 (calendar-julian-from-absolute
|
|
2552 (calendar-absolute-from-gregorian
|
|
2553 (or date (calendar-current-date))))
|
|
2554 nil t))
|
|
2555
|
|
2556 (defun calendar-print-julian-date ()
|
|
2557 "Show the Julian calendar equivalent of the date under the cursor."
|
|
2558 (interactive)
|
|
2559 (message "Julian date: %s"
|
|
2560 (calendar-julian-date-string (calendar-cursor-to-date t))))
|
|
2561
|
|
2562 (defun islamic-calendar-leap-year-p (year)
|
|
2563 "Returns t if YEAR is a leap year on the Islamic calendar."
|
|
2564 (memq (% year 30)
|
|
2565 (list 2 5 7 10 13 16 18 21 24 26 29)))
|
|
2566
|
|
2567 (defun islamic-calendar-last-day-of-month (month year)
|
|
2568 "The last day in MONTH during YEAR on the Islamic calendar."
|
|
2569 (cond
|
|
2570 ((memq month (list 1 3 5 7 9 11)) 30)
|
|
2571 ((memq month (list 2 4 6 8 10)) 29)
|
|
2572 (t (if (islamic-calendar-leap-year-p year) 30 29))))
|
|
2573
|
|
2574 (defun islamic-calendar-day-number (date)
|
|
2575 "Return the day number within the year of the Islamic date DATE."
|
|
2576 (let* ((month (extract-calendar-month date))
|
|
2577 (day (extract-calendar-day date)))
|
|
2578 (+ (* 30 (/ month 2))
|
|
2579 (* 29 (/ (1- month) 2))
|
|
2580 day)))
|
|
2581
|
|
2582 (defun calendar-absolute-from-islamic (date)
|
|
2583 "Absolute date of Islamic DATE.
|
|
2584 The absolute date is the number of days elapsed since the (imaginary)
|
|
2585 Gregorian date Sunday, December 31, 1 BC."
|
|
2586 (let* ((month (extract-calendar-month date))
|
|
2587 (day (extract-calendar-day date))
|
|
2588 (year (extract-calendar-year date))
|
|
2589 (y (% year 30))
|
|
2590 (leap-years-in-cycle
|
|
2591 (cond
|
|
2592 ((< y 3) 0) ((< y 6) 1) ((< y 8) 2) ((< y 11) 3) ((< y 14) 4)
|
|
2593 ((< y 17) 5) ((< y 19) 6) ((< y 22) 7) ((< y 25) 8) ((< y 27) 9)
|
|
2594 (t 10))))
|
|
2595 (+ (islamic-calendar-day-number date);; days so far this year
|
|
2596 (* (1- year) 354) ;; days in all non-leap years
|
|
2597 (* 11 (/ year 30)) ;; leap days in complete cycles
|
|
2598 leap-years-in-cycle ;; leap days this cycle
|
|
2599 227014))) ;; days before start of calendar
|
|
2600
|
|
2601 (defun calendar-islamic-from-absolute (date)
|
|
2602 "Compute the Islamic date (month day year) corresponding to absolute DATE.
|
|
2603 The absolute date is the number of days elapsed since the (imaginary)
|
|
2604 Gregorian date Sunday, December 31, 1 BC."
|
|
2605 (if (< date 227015)
|
|
2606 (list 0 0 0);; pre-Islamic date
|
|
2607 (let* ((approx (/ (- date 227014) 355));; Approximation from below.
|
|
2608 (year ;; Search forward from the approximation.
|
|
2609 (+ approx
|
|
2610 (calendar-sum y approx
|
|
2611 (>= date (calendar-absolute-from-islamic
|
|
2612 (list 1 1 (1+ y))))
|
|
2613 1)))
|
|
2614 (month ;; Search forward from Muharram.
|
|
2615 (1+ (calendar-sum m 1
|
|
2616 (> date
|
|
2617 (calendar-absolute-from-islamic
|
|
2618 (list m
|
|
2619 (islamic-calendar-last-day-of-month
|
|
2620 m year)
|
|
2621 year)))
|
|
2622 1)))
|
|
2623 (day ;; Calculate the day by subtraction.
|
|
2624 (- date
|
|
2625 (1- (calendar-absolute-from-islamic (list month 1 year))))))
|
|
2626 (list month day year))))
|
|
2627
|
|
2628 (defvar calendar-islamic-month-name-array
|
|
2629 ["Muharram" "Safar" "Rabi I" "Rabi II" "Jumada I" "Jumada II"
|
|
2630 "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"])
|
|
2631
|
|
2632 (defun calendar-islamic-date-string (&optional date)
|
|
2633 "String of Islamic date before sunset of Gregorian DATE.
|
|
2634 Returns the empty string if DATE is pre-Islamic.
|
|
2635 Defaults to today's date if DATE is not given.
|
|
2636 Driven by the variable `calendar-date-display-form'."
|
|
2637 (let ((calendar-month-name-array calendar-islamic-month-name-array)
|
|
2638 (islamic-date (calendar-islamic-from-absolute
|
|
2639 (calendar-absolute-from-gregorian
|
|
2640 (or date (calendar-current-date))))))
|
|
2641 (if (< (extract-calendar-year islamic-date) 1)
|
|
2642 ""
|
|
2643 (calendar-date-string islamic-date nil t))))
|
|
2644
|
|
2645 (defun calendar-print-islamic-date ()
|
|
2646 "Show the Islamic calendar equivalent of the date under the cursor."
|
|
2647 (interactive)
|
|
2648 (let ((i (calendar-islamic-date-string (calendar-cursor-to-date t))))
|
|
2649 (if (string-equal i "")
|
|
2650 (message "Date is pre-Islamic")
|
|
2651 (message "Islamic date (until sunset): %s" i))))
|
|
2652
|
|
2653 (defun calendar-hebrew-from-absolute (date)
|
|
2654 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
|
|
2655 The absolute date is the number of days elapsed since the (imaginary)
|
|
2656 Gregorian date Sunday, December 31, 1 BC."
|
|
2657 (let* ((greg-date (calendar-gregorian-from-absolute date))
|
|
2658 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
|
|
2659 (1- (extract-calendar-month greg-date))))
|
|
2660 (day)
|
|
2661 (year (+ 3760 (extract-calendar-year greg-date))))
|
|
2662 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year))))
|
|
2663 (setq year (1+ year)))
|
|
2664 (let ((length (hebrew-calendar-last-month-of-year year)))
|
|
2665 (while (> date
|
|
2666 (calendar-absolute-from-hebrew
|
|
2667 (list month
|
|
2668 (hebrew-calendar-last-day-of-month month year)
|
|
2669 year)))
|
|
2670 (setq month (1+ (% month length)))))
|
|
2671 (setq day (1+
|
|
2672 (- date (calendar-absolute-from-hebrew (list month 1 year)))))
|
|
2673 (list month day year)))
|
|
2674
|
|
2675 (defun hebrew-calendar-leap-year-p (year)
|
|
2676 "t if YEAR is a Hebrew calendar leap year."
|
|
2677 (< (% (1+ (* 7 year)) 19) 7))
|
|
2678
|
|
2679 (defun hebrew-calendar-last-month-of-year (year)
|
|
2680 "The last month of the Hebrew calendar YEAR."
|
|
2681 (if (hebrew-calendar-leap-year-p year)
|
|
2682 13
|
|
2683 12))
|
|
2684
|
|
2685 (defun hebrew-calendar-last-day-of-month (month year)
|
|
2686 "The last day of MONTH in YEAR."
|
|
2687 (if (or (memq month (list 2 4 6 10 13))
|
|
2688 (and (= month 12) (not (hebrew-calendar-leap-year-p year)))
|
|
2689 (and (= month 8) (not (hebrew-calendar-long-heshvan-p year)))
|
|
2690 (and (= month 9) (hebrew-calendar-short-kislev-p year)))
|
|
2691 29
|
|
2692 30))
|
|
2693
|
|
2694 (defun hebrew-calendar-elapsed-days (year)
|
|
2695 "Days from Sun. prior to start of Hebrew calendar to mean conjunction of Tishri of Hebrew YEAR."
|
|
2696 (let* ((months-elapsed
|
|
2697 (+ (* 235 (/ (1- year) 19));; Months in complete cycles so far.
|
|
2698 (* 12 (% (1- year) 19)) ;; Regular months in this cycle
|
|
2699 (/ (1+ (* 7 (% (1- year) 19))) 19)));; Leap months this cycle
|
|
2700 (parts-elapsed (+ 204 (* 793 (% months-elapsed 1080))))
|
|
2701 (hours-elapsed (+ 5
|
|
2702 (* 12 months-elapsed)
|
|
2703 (* 793 (/ months-elapsed 1080))
|
|
2704 (/ parts-elapsed 1080)))
|
|
2705 (parts ;; Conjunction parts
|
|
2706 (+ (* 1080 (% hours-elapsed 24)) (% parts-elapsed 1080)))
|
|
2707 (day ;; Conjunction day
|
|
2708 (+ 1 (* 29 months-elapsed) (/ hours-elapsed 24)))
|
|
2709 (alternative-day
|
|
2710 (if (or (>= parts 19440) ;; If the new moon is at or after midday,
|
|
2711 (and (= (% day 7) 2);; ...or is on a Tuesday...
|
|
2712 (>= parts 9924) ;; at 9 hours, 204 parts or later...
|
|
2713 (not (hebrew-calendar-leap-year-p year)));; of a
|
|
2714 ;; common year,
|
|
2715 (and (= (% day 7) 1);; ...or is on a Monday...
|
|
2716 (>= parts 16789) ;; at 15 hours, 589 parts or later...
|
|
2717 (hebrew-calendar-leap-year-p (1- year))));; at the end
|
|
2718 ;; of a leap year
|
|
2719 ;; Then postpone Rosh HaShanah one day
|
|
2720 (1+ day)
|
|
2721 ;; Else
|
|
2722 day)))
|
|
2723 (if ;; If Rosh HaShanah would occur on Sunday, Wednesday, or Friday
|
|
2724 (memq (% alternative-day 7) (list 0 3 5))
|
|
2725 ;; Then postpone it one (more) day and return
|
|
2726 (1+ alternative-day)
|
|
2727 ;; Else return
|
|
2728 alternative-day)))
|
|
2729
|
|
2730 (defun hebrew-calendar-days-in-year (year)
|
|
2731 "Number of days in Hebrew YEAR."
|
|
2732 (- (hebrew-calendar-elapsed-days (1+ year))
|
|
2733 (hebrew-calendar-elapsed-days year)))
|
|
2734
|
|
2735 (defun hebrew-calendar-long-heshvan-p (year)
|
|
2736 "t if Heshvan is long in Hebrew YEAR."
|
|
2737 (= (% (hebrew-calendar-days-in-year year) 10) 5))
|
|
2738
|
|
2739 (defun hebrew-calendar-short-kislev-p (year)
|
|
2740 "t if Kislev is short in Hebrew YEAR."
|
|
2741 (= (% (hebrew-calendar-days-in-year year) 10) 3))
|
|
2742
|
|
2743 (defun calendar-absolute-from-hebrew (date)
|
|
2744 "Absolute date of Hebrew DATE.
|
|
2745 The absolute date is the number of days elapsed since the (imaginary)
|
|
2746 Gregorian date Sunday, December 31, 1 BC."
|
|
2747 (let* ((month (extract-calendar-month date))
|
|
2748 (day (extract-calendar-day date))
|
|
2749 (year (extract-calendar-year date)))
|
|
2750 (+ day ;; Days so far this month.
|
|
2751 (if (< month 7);; before Tishri
|
|
2752 ;; Then add days in prior months this year before and after Nisan
|
|
2753 (+ (calendar-sum
|
|
2754 m 7 (<= m (hebrew-calendar-last-month-of-year year))
|
|
2755 (hebrew-calendar-last-day-of-month m year))
|
|
2756 (calendar-sum
|
|
2757 m 1 (< m month)
|
|
2758 (hebrew-calendar-last-day-of-month m year)))
|
|
2759 ;; Else add days in prior months this year
|
|
2760 (calendar-sum
|
|
2761 m 7 (< m month)
|
|
2762 (hebrew-calendar-last-day-of-month m year)))
|
|
2763 (hebrew-calendar-elapsed-days year);; Days in prior years.
|
|
2764 -1373429))) ;; Days elapsed before absolute date 1.
|
|
2765
|
|
2766 (defvar calendar-hebrew-month-name-array-common-year
|
|
2767 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
|
|
2768 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"])
|
|
2769
|
|
2770 (defvar calendar-hebrew-month-name-array-leap-year
|
|
2771 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
|
|
2772 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"])
|
|
2773
|
|
2774 (defun calendar-hebrew-date-string (&optional date)
|
|
2775 "String of Hebrew date before sunset of Gregorian DATE.
|
|
2776 Defaults to today's date if DATE is not given.
|
|
2777 Driven by the variable `calendar-date-display-form'."
|
|
2778 (let* ((hebrew-date (calendar-hebrew-from-absolute
|
|
2779 (calendar-absolute-from-gregorian
|
|
2780 (or date (calendar-current-date)))))
|
|
2781 (calendar-month-name-array
|
|
2782 (if (hebrew-calendar-leap-year-p (extract-calendar-year hebrew-date))
|
|
2783 calendar-hebrew-month-name-array-leap-year
|
|
2784 calendar-hebrew-month-name-array-common-year)))
|
|
2785 (calendar-date-string hebrew-date nil t)))
|
|
2786
|
|
2787 (defun calendar-print-hebrew-date ()
|
|
2788 "Show the Hebrew calendar equivalent of the date under the cursor."
|
|
2789 (interactive)
|
|
2790 (message "Hebrew date (until sunset): %s"
|
|
2791 (calendar-hebrew-date-string (calendar-cursor-to-date t))))
|
|
2792
|
|
2793 (defun hebrew-calendar-yahrzeit (death-date year)
|
|
2794 "Absolute date of the anniversary of Hebrew DEATH-DATE in Hebrew YEAR."
|
|
2795 (let* ((death-day (extract-calendar-day death-date))
|
|
2796 (death-month (extract-calendar-month death-date))
|
|
2797 (death-year (extract-calendar-year death-date)))
|
|
2798 (cond
|
|
2799 ;; If it's Heshvan 30 it depends on the first anniversary; if
|
|
2800 ;; that was not Heshvan 30, use the day before Kislev 1.
|
|
2801 ((and (= death-month 8)
|
|
2802 (= death-day 30)
|
|
2803 (not (hebrew-calendar-long-heshvan-p (1+ death-year))))
|
|
2804 (1- (calendar-absolute-from-hebrew (list 9 1 year))))
|
|
2805 ;; If it's Kislev 30 it depends on the first anniversary; if
|
|
2806 ;; that was not Kislev 30, use the day before Teveth 1.
|
|
2807 ((and (= death-month 9)
|
|
2808 (= death-day 30)
|
|
2809 (hebrew-calendar-short-kislev-p (1+ death-year)))
|
|
2810 (1- (calendar-absolute-from-hebrew (list 10 1 year))))
|
|
2811 ;; If it's Adar II, use the same day in last month of
|
|
2812 ;; year (Adar or Adar II).
|
|
2813 ((= death-month 13)
|
|
2814 (calendar-absolute-from-hebrew
|
|
2815 (list (hebrew-calendar-last-month-of-year year) death-day year)))
|
|
2816 ;; If it's the 30th in Adar I and year is not a leap year
|
|
2817 ;; (so Adar has only 29 days), use the last day in Shevat.
|
|
2818 ((and (= death-day 30)
|
|
2819 (= death-month 12)
|
|
2820 (not (hebrew-calendar-leap-year-p year)))
|
|
2821 (calendar-absolute-from-hebrew (list 11 30 year)))
|
|
2822 ;; In all other cases, use the normal anniversary of the date of death.
|
|
2823 (t (calendar-absolute-from-hebrew
|
|
2824 (list death-month death-day year))))))
|
|
2825
|
|
2826 (defun calendar-set-mode-line (str)
|
|
2827 "Set mode line to STR, centered, surrounded by dashes."
|
|
2828 (setq mode-line-format
|
|
2829 (calendar-string-spread (list "" str "") ?- (frame-width))))
|
|
2830
|
|
2831 ;;;###autoload
|
|
2832 (defun list-yahrzeit-dates (death-date start-year end-year)
|
|
2833 "List Yahrzeit dates for *Gregorian* DEATH-DATE from START-YEAR to END-YEAR.
|
|
2834 When called interactively from the calendar window, the date of death is taken
|
|
2835 from the cursor position."
|
|
2836 (interactive
|
|
2837 (let* ((death-date
|
|
2838 (if (equal (current-buffer) (get-buffer calendar-buffer))
|
|
2839 (calendar-cursor-to-date)
|
|
2840 (let* ((today (calendar-current-date))
|
|
2841 (year (calendar-read
|
|
2842 "Year of death (>0): "
|
|
2843 '(lambda (x) (> x 0))
|
|
2844 (int-to-string (extract-calendar-year today))))
|
|
2845 (month-array calendar-month-name-array)
|
|
2846 (completion-ignore-case t)
|
|
2847 (month (cdr (assoc
|
|
2848 (capitalize
|
|
2849 (completing-read
|
|
2850 "Month of death (name): "
|
|
2851 (mapcar 'list (append month-array nil))
|
|
2852 nil t))
|
|
2853 (calendar-make-alist
|
|
2854 month-array 1 'capitalize))))
|
|
2855 (last (calendar-last-day-of-month month year))
|
|
2856 (day (calendar-read
|
|
2857 (format "Day of death (1-%d): " last)
|
|
2858 '(lambda (x) (and (< 0 x) (<= x last))))))
|
|
2859 (list month day year))))
|
|
2860 (death-year (extract-calendar-year death-date))
|
|
2861 (start-year (calendar-read
|
|
2862 (format "Starting year of Yahrzeit table (>%d): "
|
|
2863 death-year)
|
|
2864 '(lambda (x) (> x death-year))
|
|
2865 (int-to-string (1+ death-year))))
|
|
2866 (end-year (calendar-read
|
|
2867 (format "Ending year of Yahrzeit table (>=%d): "
|
|
2868 start-year)
|
|
2869 '(lambda (x) (>= x start-year)))))
|
|
2870 (list death-date start-year end-year)))
|
|
2871 (message "Computing yahrzeits...")
|
|
2872 (let* ((yahrzeit-buffer "*Yahrzeits*")
|
|
2873 (h-date (calendar-hebrew-from-absolute
|
|
2874 (calendar-absolute-from-gregorian death-date)))
|
|
2875 (h-month (extract-calendar-month h-date))
|
|
2876 (h-day (extract-calendar-day h-date))
|
|
2877 (h-year (extract-calendar-year h-date)))
|
|
2878 (set-buffer (get-buffer-create yahrzeit-buffer))
|
|
2879 (setq buffer-read-only nil)
|
|
2880 (calendar-set-mode-line
|
|
2881 (format "Yahrzeit dates for %s = %s"
|
|
2882 (calendar-date-string death-date)
|
|
2883 (let ((calendar-month-name-array
|
|
2884 (if (hebrew-calendar-leap-year-p h-year)
|
|
2885 calendar-hebrew-month-name-array-leap-year
|
|
2886 calendar-hebrew-month-name-array-common-year)))
|
|
2887 (calendar-date-string h-date nil t))))
|
|
2888 (erase-buffer)
|
|
2889 (goto-char (point-min))
|
|
2890 (calendar-for-loop i from start-year to end-year do
|
|
2891 (insert
|
|
2892 (calendar-date-string
|
|
2893 (calendar-gregorian-from-absolute
|
|
2894 (hebrew-calendar-yahrzeit
|
|
2895 h-date
|
|
2896 (extract-calendar-year
|
|
2897 (calendar-hebrew-from-absolute
|
|
2898 (calendar-absolute-from-gregorian (list 1 1 i))))))) "\n"))
|
|
2899 (goto-char (point-min))
|
|
2900 (set-buffer-modified-p nil)
|
|
2901 (setq buffer-read-only t)
|
|
2902 (display-buffer yahrzeit-buffer)
|
|
2903 (message "Computing yahrzeits...done")))
|
|
2904
|
|
2905 (defun calendar-astro-date-string (&optional date)
|
|
2906 "String of astronomical (Julian) day number of afternoon of Gregorian DATE.
|
|
2907 Defaults to today's date if DATE is not given."
|
|
2908 (int-to-string
|
|
2909 (+ 1721425 (calendar-absolute-from-gregorian
|
|
2910 (or date (calendar-current-date))))))
|
|
2911
|
|
2912 (defun calendar-print-astro-day-number ()
|
|
2913 "Show astronomical (Julian) day number of afternoon on date shown by cursor."
|
|
2914 (interactive)
|
|
2915 (message
|
|
2916 "Astronomical (Julian) day number after noon UTC: %s"
|
|
2917 (calendar-astro-date-string (calendar-cursor-to-date t))))
|
|
2918
|
|
2919 (defun calendar-goto-astro-day-number (daynumber &optional noecho)
|
|
2920 "Move cursor to astronomical (Julian) DAYNUMBER.
|
|
2921 Echo astronomical (Julian) day number unless NOECHO is t."
|
|
2922 (interactive (list (calendar-read
|
|
2923 "Astronomical (Julian) day number (>1721425): "
|
|
2924 '(lambda (x) (> x 1721425)))))
|
|
2925 (calendar-goto-date (calendar-gregorian-from-absolute (- daynumber 1721425)))
|
|
2926 (or noecho (calendar-print-astro-day-number)))
|
|
2927
|
|
2928 (run-hooks 'calendar-load-hook)
|
|
2929
|
|
2930 (provide 'calendar)
|
|
2931
|
|
2932 ;;; calendar.el ends here
|