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