]> code.delx.au - gnu-emacs/blob - lisp/calendar/calendar.el
Merge from emacs-24; up to 2014-05-15T16:55:18Z!jan.h.d@swipnet.se
[gnu-emacs] / lisp / calendar / calendar.el
1 ;;; calendar.el --- calendar functions
2
3 ;; Copyright (C) 1988-1995, 1997, 2000-2014 Free Software Foundation,
4 ;; Inc.
5
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: calendar
9 ;; Human-Keywords: calendar, Gregorian calendar, diary, holidays
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This collection of functions implements a calendar window. It
29 ;; generates a calendar for the current month, together with the
30 ;; previous and coming months, or for any other three-month period.
31 ;; The calendar can be scrolled forward and backward in the window to
32 ;; show months in the past or future; the cursor can move forward and
33 ;; backward by days, weeks, or months, making it possible, for
34 ;; instance, to jump to the date a specified number of days, weeks, or
35 ;; months from the date under the cursor. The user can display a list
36 ;; of holidays and other notable days for the period shown; the
37 ;; notable days can be marked on the calendar, if desired. The user
38 ;; can also specify that dates having corresponding diary entries (in
39 ;; a file that the user specifies) be marked; the diary entries for
40 ;; any date can be viewed in a separate window. The diary and the
41 ;; notable days can be viewed independently of the calendar. Dates
42 ;; can be translated from the (usual) Gregorian calendar to the day of
43 ;; the year/days remaining in year, to the ISO commercial calendar, to
44 ;; the Julian (old style) calendar, to the Hebrew calendar, to the
45 ;; Islamic calendar, to the Bahá'í calendar, to the French
46 ;; Revolutionary calendar, to the Mayan calendar, to the Chinese
47 ;; calendar, to the Coptic calendar, to the Ethiopic calendar, and to
48 ;; the astronomical (Julian) day number. Times of sunrise/sunset can
49 ;; be displayed, as can the phases of the moon. Appointment
50 ;; notification for diary entries is available. Calendar printing via
51 ;; LaTeX is available.
52
53 ;; The following files are part of the calendar/diary code:
54
55 ;; appt.el Appointment notification
56 ;; cal-bahai.el Bahá'í calendar
57 ;; cal-china.el Chinese calendar
58 ;; cal-coptic.el Coptic/Ethiopic calendars
59 ;; cal-dst.el Daylight saving time rules
60 ;; cal-french.el French revolutionary calendar
61 ;; cal-hebrew.el Hebrew calendar
62 ;; cal-html.el Calendars in HTML
63 ;; cal-islam.el Islamic calendar
64 ;; cal-iso.el ISO calendar
65 ;; cal-julian.el Julian/astronomical calendars
66 ;; cal-mayan.el Mayan calendars
67 ;; cal-menu.el Menu support
68 ;; cal-move.el Movement in the calendar
69 ;; cal-persia.el Persian calendar
70 ;; cal-tex.el Calendars in LaTeX
71 ;; cal-x.el Dedicated frame functions
72 ;; calendar.el This file
73 ;; diary-lib.el Diary functions
74 ;; holidays.el Holiday functions
75 ;; lunar.el Phases of the moon
76 ;; solar.el Sunrise/sunset, equinoxes/solstices
77
78 ;; Technical details of all the calendrical calculations can be found in
79 ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
80 ;; and Nachum Dershowitz, Cambridge University Press (2001).
81
82 ;; An earlier version of the technical details appeared in
83 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
84 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
85 ;; pages 899-928, and in ``Calendrical Calculations, Part II: Three Historical
86 ;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
87 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
88 ;; pages 383-404.
89
90 ;; Hard copies of these two papers can be obtained by sending email to
91 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
92 ;; the message BODY containing your mailing address (snail).
93
94
95 ;; A note on free variables:
96
97 ;; The calendar passes around a few dynamically bound variables, which
98 ;; unfortunately have rather common names. They are meant to be
99 ;; available for external functions, so the names can't be changed.
100
101 ;; displayed-month, displayed-year: bound in calendar-generate, the
102 ;; central month of the 3 month calendar window
103 ;; original-date, number: bound in diary-list-entries, the arguments
104 ;; with which that function was called.
105 ;; date, entry: bound in diary-list-sexp-entries (qv)
106
107 ;; Bound in diary-list-entries:
108 ;; diary-entries-list: use in d-l, appt.el, and by diary-add-to-list
109 ;; diary-saved-point: only used in diary-lib.el, passed to the display func
110 ;; date-string: only used in diary-lib.el
111 ;; list-only: don't modify the diary-buffer, just return a list of entries
112 ;; file-glob-attrs: yuck
113
114 ;;; Code:
115
116 (load "cal-loaddefs" nil t)
117
118 ;; Avoid recursive load of calendar when loading cal-menu. Yuck.
119 (provide 'calendar)
120 (require 'cal-menu)
121
122 (defgroup calendar nil
123 "Calendar and time management support."
124 :prefix "calendar-"
125 :group 'applications)
126
127 (defgroup calendar-hooks nil
128 "Calendar hooks."
129 :prefix "calendar-"
130 :group 'calendar)
131
132 (defgroup calendar-faces nil
133 "Calendar faces."
134 :prefix "calendar-"
135 :group 'calendar)
136
137 (defcustom calendar-offset 0
138 "The offset of the principal month from the center of the calendar window.
139 0 means the principal month is in the center (default), -1 means on the left,
140 +1 means on the right. Larger (or smaller) values push the principal month off
141 the screen."
142 :type 'integer
143 :group 'calendar)
144
145 (defcustom calendar-setup nil
146 "The frame setup of the calendar.
147 The choices are: `one-frame' (calendar and diary together in one separate,
148 dedicated frame); `two-frames' (calendar and diary in separate, dedicated
149 frames); `calendar-only' (calendar in a separate, dedicated frame); with
150 any other value the current frame is used. Using any of the first
151 three options overrides the value of `calendar-view-diary-initially-flag'."
152 :type '(choice
153 (const :tag "calendar and diary in separate frame" one-frame)
154 (const :tag "calendar and diary each in own frame" two-frames)
155 (const :tag "calendar in separate frame" calendar-only)
156 (const :tag "use current frame" nil))
157 :group 'calendar)
158
159 (defcustom calendar-minimum-window-height 8
160 "Minimum height `calendar-generate-window' should use for calendar window."
161 :type 'integer
162 :version "22.1"
163 :group 'calendar)
164
165 ;; See discussion in bug#1806.
166 (defcustom calendar-split-width-threshold nil
167 "Value to use for `split-width-threshold' when creating a calendar.
168 This only affects frames wider than the default value of
169 `split-width-threshold'."
170 :type '(choice (const nil)
171 (integer))
172 :version "23.2"
173 :group 'calendar)
174
175 (defcustom calendar-week-start-day 0
176 "The day of the week on which a week in the calendar begins.
177 0 means Sunday (default), 1 means Monday, and so on.
178
179 If you change this variable directly (without using customize)
180 after starting `calendar', you should call `calendar-redraw' to
181 update the calendar display to reflect the change, otherwise
182 movement commands will not work correctly."
183 :type 'integer
184 ;; Change the initialize so that if you reload calendar.el, it will not
185 ;; cause a redraw (which may fail, e.g. with "invalid byte-code in
186 ;; calendar.elc" because of the "byte-compile-dynamic").
187 :initialize 'custom-initialize-default
188 :set (lambda (sym val)
189 (set sym val)
190 (calendar-redraw))
191 :group 'calendar)
192
193 (define-obsolete-variable-alias 'view-diary-entries-initially
194 'calendar-view-diary-initially-flag "23.1")
195
196 (defcustom calendar-view-diary-initially-flag nil
197 "Non-nil means display current date's diary entries on entry to calendar.
198 The diary is displayed in another window when the calendar is first displayed,
199 if the current date is visible. The number of days of diary entries displayed
200 is governed by the variable `diary-number-of-entries'. This variable can
201 be overridden by the value of `calendar-setup'."
202 :type 'boolean
203 :group 'diary)
204
205 (define-obsolete-variable-alias 'mark-diary-entries-in-calendar
206 'calendar-mark-diary-entries-flag "23.1")
207
208 ;; FIXME :set
209 (defcustom calendar-mark-diary-entries-flag nil
210 "Non-nil means mark dates with diary entries, in the calendar window.
211 The marking symbol is specified by the variable `diary-entry-marker'."
212 :type 'boolean
213 :group 'diary)
214
215 (defcustom calendar-remove-frame-by-deleting t
216 "Determine how the calendar mode removes a frame no longer needed.
217 If nil, make an icon of the frame. If non-nil, delete the frame."
218 :type 'boolean
219 :version "23.1" ; changed from nil to t
220 :group 'view
221 :group 'calendar)
222
223 (defface calendar-today
224 '((t (:underline t)))
225 "Face for indicating today's date in the calendar.
226 See the variable `calendar-today-marker'."
227 :group 'calendar-faces)
228
229 (define-obsolete-face-alias 'calendar-today-face 'calendar-today "22.1")
230
231 (defface diary
232 '((((min-colors 88) (class color) (background light))
233 :foreground "red1")
234 (((class color) (background light))
235 :foreground "red")
236 (((min-colors 88) (class color) (background dark))
237 :foreground "yellow1")
238 (((class color) (background dark))
239 :foreground "yellow")
240 (t
241 :weight bold))
242 "Face for highlighting diary entries.
243 Used to mark diary entries in the calendar (see `diary-entry-marker'),
244 and to highlight the date header in the fancy diary."
245 :group 'calendar-faces)
246
247 (define-obsolete-face-alias 'diary-face 'diary "22.1")
248
249 (defface holiday
250 '((((class color) (background light))
251 :background "pink")
252 (((class color) (background dark))
253 :background "chocolate4")
254 (t
255 :inverse-video t))
256 "Face for indicating in the calendar dates that have holidays.
257 See `calendar-holiday-marker'."
258 :group 'calendar-faces)
259
260 (define-obsolete-face-alias 'holiday-face 'holiday "22.1")
261
262 (defface calendar-weekday-header '((t :inherit font-lock-constant-face))
263 "Face used for weekday column headers in the calendar.
264 See also the face `calendar-weekend-header'."
265 :version "24.4"
266 :group 'calendar-faces)
267
268 (defface calendar-weekend-header '((t :inherit font-lock-comment-face))
269 "Face used for weekend column headers in the calendar.
270 See also the face `calendar-weekday-header'."
271 :version "24.4"
272 :group 'calendar-faces)
273
274 (defface calendar-month-header '((t :inherit font-lock-function-name-face))
275 "Face used for month headers in the calendar."
276 :version "24.4"
277 :group 'calendar-faces)
278
279 ;; These briefly checked font-lock-mode, but that is broken, since it
280 ;; is a buffer-local variable, and which buffer happens to be current
281 ;; when this file is loaded shouldn't make a difference. One could
282 ;; perhaps check global-font-lock-mode, or font-lock-global-modes; but
283 ;; this feature doesn't use font-lock, so there's no real reason it
284 ;; should respect those either. See bug#2199.
285 ;; They also used to check display-color-p, but that is a problem if
286 ;; loaded from --daemon. Since BW displays are rare now, this was
287 ;; also taken out. The way to keep it would be to have nil mean do a
288 ;; runtime check whenever this variable is used.
289 (defcustom diary-entry-marker 'diary
290 "How to mark dates that have diary entries.
291 The value can be either a single-character string (e.g. \"+\") or a face."
292 :type '(choice (string :tag "Single character string") face)
293 :group 'diary
294 :version "23.1")
295
296 (defcustom calendar-today-marker 'calendar-today
297 "How to mark today's date in the calendar.
298 The value can be either a single-character string (e.g. \"=\") or a face.
299 Used by `calendar-mark-today'."
300 :type '(choice (string :tag "Single character string") face)
301 :group 'calendar
302 :version "23.1")
303
304 (defcustom calendar-holiday-marker 'holiday
305 "How to mark notable dates in the calendar.
306 The value can be either a single-character string (e.g. \"*\") or a face."
307 :type '(choice (string :tag "Single character string") face)
308 :group 'holidays
309 :version "23.1")
310
311 (define-obsolete-variable-alias 'view-calendar-holidays-initially
312 'calendar-view-holidays-initially-flag "23.1")
313
314 (defcustom calendar-view-holidays-initially-flag nil
315 "Non-nil means display holidays for current three month period on entry.
316 The holidays are displayed in another window when the calendar is first
317 displayed."
318 :type 'boolean
319 :group 'holidays)
320
321 (define-obsolete-variable-alias 'mark-holidays-in-calendar
322 'calendar-mark-holidays-flag "23.1")
323
324 ;; FIXME :set
325 (defcustom calendar-mark-holidays-flag nil
326 "Non-nil means mark dates of holidays in the calendar window.
327 The marking symbol is specified by the variable `calendar-holiday-marker'."
328 :type 'boolean
329 :group 'holidays)
330
331 (defcustom calendar-mode-hook nil
332 "Hook run when entering `calendar-mode'."
333 :type 'hook
334 :group 'calendar-hooks)
335
336 (defcustom calendar-load-hook nil
337 "List of functions to be called after the calendar is first loaded.
338 This is the place to add key bindings to `calendar-mode-map'."
339 :type 'hook
340 :group 'calendar-hooks)
341
342 (define-obsolete-variable-alias 'initial-calendar-window-hook
343 'calendar-initial-window-hook "23.1")
344
345 (defcustom calendar-initial-window-hook nil
346 "List of functions to be called when the calendar window is created.
347 Quitting the calendar and re-entering it will cause these functions
348 to be called again."
349 :type 'hook
350 :group 'calendar-hooks)
351
352 (define-obsolete-variable-alias 'today-visible-calendar-hook
353 'calendar-today-visible-hook "23.1")
354
355 (defcustom calendar-today-visible-hook nil
356 "List of functions called whenever the current date is visible.
357 To mark today's date, add the function `calendar-mark-today'.
358 To replace the date with asterisks, add the function `calendar-star-date'.
359 See also `calendar-today-invisible-hook'.
360
361 In general, be careful about changing characters in the calendar buffer,
362 since it may cause the movement commands to fail."
363 :type 'hook
364 :options '(calendar-mark-today calendar-star-date)
365 :group 'calendar-hooks)
366
367 (define-obsolete-variable-alias 'today-invisible-calendar-hook
368 'calendar-today-invisible-hook "23.1")
369
370 (defcustom calendar-today-invisible-hook nil
371 "List of functions called whenever the current date is not visible.
372 See also `calendar-today-visible-hook'."
373 :type 'hook
374 :group 'calendar-hooks)
375
376 (defcustom calendar-move-hook nil
377 "List of functions called whenever the cursor moves in the calendar.
378 For example,
379
380 (add-hook 'calendar-move-hook (lambda () (diary-view-entries 1)))
381
382 redisplays the diary for whatever date the cursor is moved to."
383 :type 'hook
384 :options '(calendar-update-mode-line)
385 :group 'calendar-hooks)
386
387 (defcustom calendar-date-echo-text
388 "mouse-2: general menu\nmouse-3: menu for this date"
389 "String displayed when the cursor is over a date in the calendar.
390 Can be either a fixed string, or a lisp expression that returns one.
391 When this expression is evaluated, DAY, MONTH, and YEAR are
392 integers appropriate to the relevant date. For example, to
393 display the ISO date:
394
395 (setq calendar-date-echo-text '(format \"ISO date: %s\"
396 (calendar-iso-date-string
397 (list month day year))))
398 Changing this variable without using customize has no effect on
399 pre-existing calendar windows."
400 :group 'calendar
401 :initialize 'custom-initialize-default
402 :risky t
403 :set (lambda (sym val)
404 (set sym val)
405 (calendar-redraw))
406 :type '(choice (string :tag "Fixed string")
407 (sexp :value
408 (format "ISO date: %s"
409 (calendar-iso-date-string
410 (list month day year)))))
411 :version "23.1")
412
413
414 (defvar calendar-month-digit-width nil
415 "Width of the region with numbers in each month in the calendar.")
416
417 (defvar calendar-month-width nil
418 "Full width of each month in the calendar.")
419
420 (defvar calendar-right-margin nil
421 "Right margin of the calendar.")
422
423 (defvar calendar-month-edges nil
424 "Alist of month edge columns.
425 Each element has the form (N LEFT FIRST LAST RIGHT), where
426 LEFT is the leftmost column associated with month segment N,
427 FIRST and LAST are the first and last columns with day digits in,
428 and LAST is the rightmost column.")
429
430 (defun calendar-month-edges (segment)
431 "Compute the month edge columns for month SEGMENT.
432 Returns a list (LEFT FIRST LAST RIGHT), where LEFT is the
433 leftmost column associated with a month, FIRST and LAST are the
434 first and last columns with day digits in, and LAST is the
435 rightmost column."
436 ;; The leftmost column with a digit in it in this month segment.
437 (let* ((first (+ calendar-left-margin
438 (* segment calendar-month-width)))
439 ;; The rightmost column with a digit in it in this month segment.
440 (last (+ first (1- calendar-month-digit-width)))
441 (left (if (eq segment 0)
442 0
443 (+ calendar-left-margin
444 (* segment calendar-month-width)
445 (- (/ calendar-intermonth-spacing 2)))))
446 ;; The rightmost edge of this month segment, dividing the
447 ;; space between months in two.
448 (right (+ calendar-left-margin
449 (* (1+ segment) calendar-month-width)
450 (- (/ calendar-intermonth-spacing 2)))))
451 (list left first last right)))
452
453 (defun calendar-recompute-layout-variables ()
454 "Recompute some layout-related calendar \"constants\"."
455 (setq calendar-month-digit-width (+ (* 6 calendar-column-width)
456 calendar-day-digit-width)
457 calendar-month-width (+ (* 7 calendar-column-width)
458 calendar-intermonth-spacing)
459 calendar-right-margin (+ calendar-left-margin
460 (* 3 (* 7 calendar-column-width))
461 (* 2 calendar-intermonth-spacing))
462 calendar-month-edges nil)
463 (dotimes (i 3)
464 (push (cons i (calendar-month-edges i)) calendar-month-edges))
465 (setq calendar-month-edges (reverse calendar-month-edges)))
466
467 (defun calendar-set-layout-variable (symbol value &optional minmax)
468 "Set SYMBOL's value to VALUE, an integer.
469 A positive/negative MINMAX enforces a minimum/maximum value.
470 Then redraw the calendar, if necessary."
471 (let ((oldvalue (symbol-value symbol)))
472 (custom-set-default symbol (if minmax
473 (if (< minmax 0)
474 (min value (- minmax))
475 (max value minmax))
476 value))
477 (unless (equal value oldvalue)
478 (calendar-recompute-layout-variables)
479 (calendar-redraw))))
480
481 (defcustom calendar-left-margin 5
482 "Empty space to the left of the first month in the calendar."
483 :group 'calendar
484 :initialize 'custom-initialize-default
485 :set 'calendar-set-layout-variable
486 :type 'integer
487 :version "23.1")
488
489 ;; Or you can view it as columns of width 2, with 1 space, no space
490 ;; after the last column, and a 5 space gap between month.
491 ;; FIXME check things work if this is odd.
492 (defcustom calendar-intermonth-spacing 4
493 "Space between months in the calendar. Minimum value is 1."
494 :group 'calendar
495 :initialize 'custom-initialize-default
496 :set (lambda (sym val)
497 (calendar-set-layout-variable sym val 1))
498 :type 'integer
499 :version "23.1")
500
501 ;; FIXME calendar-month-column-width?
502 (defcustom calendar-column-width 3
503 "Width of each day column in the calendar. Minimum value is 3."
504 :initialize 'custom-initialize-default
505 :set (lambda (sym val)
506 (calendar-set-layout-variable sym val 3))
507 :type 'integer
508 :version "23.1")
509
510 (defun calendar-day-header-construct (&optional width)
511 "Return the default value for `calendar-day-header-array'.
512 WIDTH defaults to `calendar-day-header-width'."
513 (or width (setq width calendar-day-header-width))
514 (calendar-abbrev-construct (if (<= width calendar-abbrev-length)
515 calendar-day-abbrev-array
516 calendar-day-name-array)
517 width))
518
519 ;; FIXME better to use a format spec?
520 (defcustom calendar-day-header-width 2
521 "Width of the day column headers in the calendar.
522 Must be at least one less than `calendar-column-width'."
523 :group 'calendar
524 :initialize 'custom-initialize-default
525 :set (lambda (sym val)
526 (or (calendar-customized-p 'calendar-day-header-array)
527 (setq calendar-day-header-array
528 (calendar-day-header-construct val)))
529 (calendar-set-layout-variable sym val (- 1 calendar-column-width)))
530 :type 'integer
531 :version "23.1")
532
533 ;; FIXME a format specifier instead?
534 (defcustom calendar-day-digit-width 2
535 "Width of the day digits in the calendar. Minimum value is 2."
536 :group 'calendar
537 :initialize 'custom-initialize-default
538 :set (lambda (sym val)
539 (calendar-set-layout-variable sym val 2))
540 :type 'integer
541 :version "23.1")
542
543 (defcustom calendar-intermonth-header nil
544 "Header text to display in the space to the left of each calendar month.
545 See `calendar-intermonth-text'."
546 :group 'calendar
547 :initialize 'custom-initialize-default
548 :risky t
549 :set (lambda (sym val)
550 (set sym val)
551 (calendar-redraw))
552 :type '(choice (const nil :tag "Nothing")
553 (string :tag "Fixed string")
554 (sexp :value
555 (propertize "WK" 'font-lock-face
556 'font-lock-function-name-face)))
557 :version "23.1")
558
559 (defcustom calendar-intermonth-text nil
560 "Text to display in the space to the left of each calendar month.
561 Can be nil, a fixed string, or a lisp expression that returns a string.
562 When the expression is evaluated, the variables DAY, MONTH and YEAR
563 are integers appropriate for the first day in each week.
564 Will be truncated to the smaller of `calendar-left-margin' and
565 `calendar-intermonth-spacing'. The last character is forced to be a space.
566 For example, to display the ISO week numbers:
567
568 (setq calendar-week-start-day 1
569 calendar-intermonth-text
570 '(propertize
571 (format \"%2d\"
572 (car
573 (calendar-iso-from-absolute
574 (calendar-absolute-from-gregorian (list month day year)))))
575 'font-lock-face 'font-lock-function-name-face))
576
577 See also `calendar-intermonth-header'."
578 :group 'calendar
579 :initialize 'custom-initialize-default
580 :risky t
581 :set (lambda (sym val)
582 (set sym val)
583 (calendar-redraw))
584 :type '(choice (const nil :tag "Nothing")
585 (string :tag "Fixed string")
586 (sexp :value
587 (propertize
588 (format "%2d"
589 (car
590 (calendar-iso-from-absolute
591 (calendar-absolute-from-gregorian
592 (list month day year)))))
593 'font-lock-face 'font-lock-function-name-face)))
594 :version "23.1")
595
596 (defcustom diary-file "~/diary"
597 "Name of the file in which one's personal diary of dates is kept.
598
599 The file's entries are lines beginning with any of the forms
600 specified by the variable `diary-date-forms', which by default
601 uses the forms of `diary-american-date-forms':
602
603 MONTH/DAY
604 MONTH/DAY/YEAR
605 MONTHNAME DAY
606 MONTHNAME DAY, YEAR
607 DAYNAME
608
609 with the remainder of the line being the diary entry string for
610 that date. MONTH and DAY are one or two digit numbers, YEAR is a
611 number and may be written in full or abbreviated to the final two
612 digits (if `diary-abbreviated-year-flag' is non-nil). MONTHNAME
613 and DAYNAME can be spelled in full (as specified by the variables
614 `calendar-month-name-array' and `calendar-day-name-array'), or
615 abbreviated (as specified by `calendar-month-abbrev-array' and
616 `calendar-day-abbrev-array') with or without a period. Case is
617 ignored. Any of DAY, MONTH, or MONTHNAME, YEAR can be `*' which
618 matches any day, month, or year, respectively. If the date does
619 not contain a year, it is generic and applies to any year. A
620 DAYNAME entry applies to the appropriate day of the week in every week.
621
622 You can customize `diary-date-forms' to your preferred format.
623 Three default styles are provided: `diary-american-date-forms',
624 `diary-european-date-forms', and `diary-iso-date-forms'.
625 You can choose between these by setting `calendar-date-style' in your
626 init file, or by using `calendar-set-date-style' when in the calendar.
627
628 A diary entry can be preceded by the character `diary-nonmarking-symbol'
629 \(ordinarily `&') to make that entry nonmarking--that is, it will not be
630 marked on dates in the calendar window but will appear in a diary window.
631
632 Multiline diary entries are made by indenting lines after the first with
633 either a TAB or one or more spaces.
634
635 Lines not in one the above formats are ignored. Here are some sample diary
636 entries (in the default American style):
637
638 12/22/1988 Twentieth wedding anniversary!!
639 &1/1. Happy New Year!
640 10/22 Ruth's birthday.
641 21: Payday
642 Tuesday--weekly meeting with grad students at 10am
643 Supowit, Shen, Bitner, and Kapoor to attend.
644 1/13/89 Friday the thirteenth!!
645 &thu 4pm squash game with Lloyd.
646 mar 16 Dad's birthday
647 April 15, 1989 Income tax due.
648 &* 15 time cards due.
649
650 If the first line of a diary entry consists only of the date or day name with
651 no trailing blanks or punctuation, then that line is not displayed in the
652 diary window; only the continuation lines is shown. For example, the
653 single diary entry
654
655 02/11/1989
656 Bill Blattner visits Princeton today
657 2pm Cognitive Studies Committee meeting
658 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
659 4:00pm Jamie Tappenden
660 7:30pm Dinner at George and Ed's for Alan Ryan
661 7:30-10:00pm dance at Stewart Country Day School
662
663 will appear in the diary window without the date line at the beginning. This
664 facility allows the diary window to look neater, but can cause confusion if
665 used with more than one day's entries displayed.
666
667 Diary entries can be based on Lisp sexps. For example, the diary entry
668
669 %%(diary-block 11 1 1990 11 10 1990) Vacation
670
671 causes the diary entry \"Vacation\" to appear from November 1 through
672 November 10, 1990. See the documentation for the function
673 `diary-list-sexp-entries' for more details.
674
675 Diary entries based on the Hebrew, the Islamic and/or the Bahá'í
676 calendar are also possible, but because these are somewhat slow, they
677 are ignored unless you set the `diary-nongregorian-listing-hook' and
678 the `diary-nongregorian-marking-hook' appropriately. See the
679 documentation of these hooks for details.
680
681 Diary files can contain directives to include the contents of other files; for
682 details, see the documentation for the variable `diary-list-entries-hook'."
683 :type 'file
684 :group 'diary)
685
686 ;; FIXME do these have to be single characters?
687 (defcustom diary-nonmarking-symbol "&"
688 "Symbol indicating that a diary entry is not to be marked in the calendar."
689 :type 'string
690 :group 'diary)
691
692 (defcustom diary-chinese-entry-symbol "C"
693 "Symbol indicating a diary entry according to the Chinese calendar."
694 :type 'string
695 :group 'diary
696 :version "24.5")
697
698 (define-obsolete-variable-alias 'hebrew-diary-entry-symbol
699 'diary-hebrew-entry-symbol "23.1")
700
701 (defcustom diary-hebrew-entry-symbol "H"
702 "Symbol indicating a diary entry according to the Hebrew calendar."
703 :type 'string
704 :group 'diary)
705
706 (define-obsolete-variable-alias 'islamic-diary-entry-symbol
707 'diary-islamic-entry-symbol "23.1")
708
709 (defcustom diary-islamic-entry-symbol "I"
710 "Symbol indicating a diary entry according to the Islamic calendar."
711 :type 'string
712 :group 'diary)
713
714 (define-obsolete-variable-alias 'bahai-diary-entry-symbol
715 'diary-bahai-entry-symbol "23.1")
716
717 (defcustom diary-bahai-entry-symbol "B"
718 "Symbol indicating a diary entry according to the Bahá'í calendar."
719 :type 'string
720 :group 'diary)
721
722 (defcustom european-calendar-style nil
723 "Non-nil means use the European style of dates in the diary and display.
724 In this case, a date like 1/2/1990 would be interpreted as
725 February 1, 1990. See `diary-european-date-forms' for the
726 default European diary date styles.
727
728 Setting this variable directly does not take effect (if the
729 calendar package is already loaded). Rather, use either
730 \\[customize] or the function `calendar-set-date-style'."
731 :type 'boolean
732 ;; Without :initialize (require 'calendar) throws an error because
733 ;; calendar-set-date-style is undefined at this point.
734 :initialize 'custom-initialize-default
735 :set (lambda (symbol value)
736 (if value
737 (calendar-set-date-style 'european)
738 (calendar-set-date-style 'american)))
739 :group 'calendar)
740
741 (make-obsolete-variable 'european-calendar-style 'calendar-date-style "23.1")
742
743 ;; If this is autoloaded, c-d-s gets set before any customization of e-c-s.
744 (defcustom calendar-date-style (if european-calendar-style 'european
745 'american)
746 "Your preferred style for writing dates.
747 The options are:
748 `american' - month/day/year
749 `european' - day/month/year
750 `iso' - year/month/day
751 This affects how dates written in your diary are interpreted.
752 It also affects date display, as well as those calendar and diary
753 functions that take a date as an argument, e.g. `diary-date', by
754 changing the order in which the arguments are interpreted.
755
756 Setting this variable directly does not take effect (if the
757 calendar package is already loaded). Rather, use either
758 \\[customize] or the function `calendar-set-date-style'."
759 :version "23.1"
760 :type '(choice (const american :tag "Month/Day/Year")
761 (const european :tag "Day/Month/Year")
762 (const iso :tag "Year/Month/Day"))
763 :initialize 'custom-initialize-default
764 :set (lambda (symbol value)
765 (calendar-set-date-style value))
766 :group 'calendar)
767
768 ;; Next three are provided to aid in setting diary-date-forms.
769 ;; FIXME move to diary-lib?
770 (defcustom diary-iso-date-forms
771 '((month "[-/]" day "[^-/0-9]")
772 (year "[-/]" month "[-/]" day "[^0-9]")
773 ;; Cannot allow [-/] as separators here, since it would also match
774 ;; the first element (bug#7377).
775 (monthname " *" day "[^-0-9]")
776 (year " *" monthname " *" day "[^0-9]")
777 (dayname "\\W"))
778 "List of pseudo-patterns describing the ISO style of dates.
779 The defaults are: MONTH[-/]DAY; YEAR[-/]MONTH[-/]DAY; MONTHNAME DAY;
780 YEAR MONTHNAME DAY; DAYNAME. Normally you should not customize this,
781 but `diary-date-forms' (which see)."
782 :version "23.3" ; bug#7377
783 :type '(repeat (choice (cons :tag "Backup"
784 :value (backup . nil)
785 (const backup)
786 (repeat (list :inline t :format "%v"
787 (symbol :tag "Keyword")
788 (choice symbol regexp))))
789 (repeat (list :inline t :format "%v"
790 (symbol :tag "Keyword")
791 (choice symbol regexp)))))
792 :group 'diary)
793
794 (define-obsolete-variable-alias 'american-date-diary-pattern
795 'diary-american-date-forms "23.1")
796
797 (defcustom diary-american-date-forms
798 '((month "/" day "[^/0-9]")
799 (month "/" day "/" year "[^0-9]")
800 (monthname " *" day "[^,0-9]")
801 (monthname " *" day ", *" year "[^0-9]")
802 (dayname "\\W"))
803 "List of pseudo-patterns describing the American style of dates.
804 The defaults are: MONTH/DAY; MONTH/DAY/YEAR; MONTHNAME DAY;
805 MONTHNAME DAY, YEAR; DAYNAME. Normally you should not customize this,
806 but `diary-date-forms' (which see)."
807 :type '(repeat (choice (cons :tag "Backup"
808 :value (backup . nil)
809 (const backup)
810 (repeat (list :inline t :format "%v"
811 (symbol :tag "Keyword")
812 (choice symbol regexp))))
813 (repeat (list :inline t :format "%v"
814 (symbol :tag "Keyword")
815 (choice symbol regexp)))))
816 :group 'diary)
817
818 (define-obsolete-variable-alias 'european-date-diary-pattern
819 'diary-european-date-forms "23.1")
820
821 (defcustom diary-european-date-forms
822 '((day "/" month "[^/0-9]")
823 (day "/" month "/" year "[^0-9]")
824 (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
825 (day " *" monthname " *" year "[^0-9]")
826 (dayname "\\W"))
827 "List of pseudo-patterns describing the European style of dates.
828 The defaults are: DAY/MONTH; DAY/MONTH/YEAR; DAY MONTHNAME;
829 DAY MONTHNAME YEAR; DAYNAME. Normally you should not customize this, but
830 `diary-date-forms' (which see)."
831 :type '(repeat (choice (cons :tag "Backup"
832 :value (backup . nil)
833 (const backup)
834 (repeat (list :inline t :format "%v"
835 (symbol :tag "Keyword")
836 (choice symbol regexp))))
837 (repeat (list :inline t :format "%v"
838 (symbol :tag "Keyword")
839 (choice symbol regexp)))))
840 :group 'diary)
841
842 (defvar diary-font-lock-keywords)
843
844 (defcustom diary-date-forms (cond ((eq calendar-date-style 'iso)
845 diary-iso-date-forms)
846 ((eq calendar-date-style 'european)
847 diary-european-date-forms)
848 (t diary-american-date-forms))
849 "List of pseudo-patterns describing the forms of date used in the diary.
850 The patterns on the list must be MUTUALLY EXCLUSIVE and should not match
851 any portion of the diary entry itself, just the date component.
852
853 A pseudo-pattern is a list of regular expressions and the keywords `month',
854 `day', `year', `monthname', and `dayname'. The keyword `monthname' will
855 match the name of the month (see `calendar-month-name-array'), capitalized
856 or not, or its user-specified abbreviation (see `calendar-month-abbrev-array'),
857 followed by a period or not; it will also match `*'. Similarly, `dayname'
858 will match the name of the day (see `calendar-day-name-array'), capitalized or
859 not, or its user-specified abbreviation (see `calendar-day-abbrev-array'),
860 followed by a period or not. The keywords `month', `day', and `year' will
861 match those numerical values, preceded by arbitrarily many zeros; they will
862 also match `*'.
863
864 The matching of the diary entries with the date forms is done with the
865 standard syntax table from Fundamental mode, but with the `*' changed so
866 that it is a word constituent.
867
868 If, to be mutually exclusive, a pseudo-pattern must match a portion of the
869 diary entry itself, the first element of the pattern MUST be `backup'. This
870 directive causes the date recognizer to back up to the beginning of the
871 current word of the diary entry, so in no case can the pattern match more than
872 a portion of the first word of the diary entry.
873
874 For examples of three common styles, see `diary-american-date-forms',
875 `diary-european-date-forms', and `diary-iso-date-forms'."
876 :type '(repeat (choice (cons :tag "Backup"
877 :value (backup . nil)
878 (const backup)
879 (repeat (list :inline t :format "%v"
880 (symbol :tag "Keyword")
881 (choice symbol regexp))))
882 (repeat (list :inline t :format "%v"
883 (symbol :tag "Keyword")
884 (choice symbol regexp)))))
885 :set-after '(calendar-date-style diary-iso-date-forms
886 diary-european-date-forms
887 diary-american-date-forms)
888 :initialize 'custom-initialize-default
889 :set (lambda (symbol value)
890 (unless (equal value (eval symbol))
891 (custom-set-default symbol value)
892 (setq diary-font-lock-keywords (diary-font-lock-keywords))
893 ;; Need to redraw not just to get new font-locking, but also
894 ;; to pick up any newly recognized entries.
895 (and (diary-live-p)
896 (diary))))
897 :group 'diary)
898
899 ;; Next three are provided to aid in setting calendar-date-display-form.
900 (defcustom calendar-iso-date-display-form '((format "%s-%.2d-%.2d" year
901 (string-to-number month)
902 (string-to-number day)))
903 "Pseudo-pattern governing the way a date appears in the ISO style.
904 Normally you should not customize this, but `calendar-date-display-form'
905 \(which see)."
906 :type 'sexp
907 :version "23.1"
908 :group 'calendar)
909
910 (define-obsolete-variable-alias 'european-calendar-display-form
911 'calendar-european-date-display-form "23.1")
912
913 (defcustom calendar-european-date-display-form
914 '((if dayname (concat dayname ", ")) day " " monthname " " year)
915 "Pseudo-pattern governing the way a date appears in the European style.
916 Normally you should not customize this, but `calendar-date-display-form'
917 \(which see)."
918 :type 'sexp
919 :group 'calendar)
920
921 (define-obsolete-variable-alias 'american-calendar-display-form
922 'calendar-american-date-display-form "23.1")
923
924 (defcustom calendar-american-date-display-form
925 '((if dayname (concat dayname ", ")) monthname " " day ", " year)
926 "Pseudo-pattern governing the way a date appears in the American style.
927 Normally you should not customize this, but `calendar-date-display-form'
928 \(which see)."
929 :type 'sexp
930 :group 'calendar)
931
932 (defcustom calendar-date-display-form
933 (cond ((eq calendar-date-style 'iso)
934 calendar-iso-date-display-form)
935 ((eq calendar-date-style 'european)
936 calendar-european-date-display-form)
937 (t calendar-american-date-display-form))
938 "Pseudo-pattern governing the way a calendar date appears.
939 Used by the function `calendar-date-string' (which see), a pseudo-pattern
940 is a list of expressions that can involve the keywords `month', `day',
941 and `year' (all numbers in string form), and `monthname' and `dayname'
942 \(both alphabetic strings). For example, a typical American form would be
943
944 '(month \"/\" day \"/\" (substring year -2))
945
946 whereas
947
948 '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
949
950 would give the usual American style in fixed-length fields. The variables
951 `calendar-iso-date-display-form', `calendar-european-date-display-form', and
952 `calendar-american-date-display-form' provide some defaults for three common
953 styles."
954 :type 'sexp
955 :set-after '(calendar-date-style calendar-iso-date-display-form
956 calendar-european-date-display-form
957 calendar-american-date-display-form)
958 :group 'calendar)
959
960 (defcustom calendar-american-month-header
961 '(propertize (format "%s %d" (calendar-month-name month) year)
962 'font-lock-face 'calendar-month-header)
963 "Default format for calendar month headings with the American date style.
964 Normally you should not customize this, but `calender-month-header'."
965 :group 'calendar
966 :risky t
967 :type 'sexp
968 :version "24.4") ; font-lock-function-name-face -> calendar-month-header
969
970 (defcustom calendar-european-month-header
971 '(propertize (format "%s %d" (calendar-month-name month) year)
972 'font-lock-face 'calendar-month-header)
973 "Default format for calendar month headings with the European date style.
974 Normally you should not customize this, but `calender-month-header'."
975 :group 'calendar
976 :risky t
977 :type 'sexp
978 :version "24.4") ; font-lock-function-name-face -> calendar-month-header
979
980 (defcustom calendar-iso-month-header
981 '(propertize (format "%d %s" year (calendar-month-name month))
982 'font-lock-face 'calendar-month-header)
983 "Default format for calendar month headings with the ISO date style.
984 Normally you should not customize this, but `calender-month-header'."
985 :group 'calendar
986 :risky t
987 :type 'sexp
988 :version "24.4") ; font-lock-function-name-face -> calendar-month-header
989
990 (defcustom calendar-month-header
991 (cond ((eq calendar-date-style 'iso)
992 calendar-iso-month-header)
993 ((eq calendar-date-style 'european)
994 calendar-european-month-header)
995 (t calendar-american-month-header))
996 "Expression to evaluate to return the calendar month headings.
997 When this expression is evaluated, the variables MONTH and YEAR are
998 integers appropriate to the relevant month. The result is padded
999 to the width of `calendar-month-digit-width'.
1000
1001 For examples of three common styles, see `calendar-american-month-header',
1002 `calendar-european-month-header', and `calendar-iso-month-header'.
1003
1004 Changing this variable without using customize has no effect on
1005 pre-existing calendar windows."
1006 :group 'calendar
1007 :initialize 'custom-initialize-default
1008 :risky t
1009 :set (lambda (sym val)
1010 (set sym val)
1011 (calendar-redraw))
1012 :set-after '(calendar-date-style calendar-american-month-header
1013 calendar-european-month-header
1014 calendar-iso-month-header)
1015 :type 'sexp
1016 :version "24.3")
1017
1018 (defun calendar-set-date-style (style)
1019 "Set the style of calendar and diary dates to STYLE (a symbol).
1020 The valid styles are described in the documentation of `calendar-date-style'."
1021 (interactive (list (intern
1022 (completing-read "Date style: "
1023 '("american" "european" "iso") nil t
1024 nil nil "american"))))
1025 (or (memq style '(american european iso))
1026 (setq style 'american))
1027 (setq calendar-date-style style
1028 calendar-date-display-form
1029 (symbol-value (intern-soft
1030 (format "calendar-%s-date-display-form" style)))
1031 calendar-month-header
1032 (symbol-value (intern-soft (format "calendar-%s-month-header" style)))
1033 diary-date-forms
1034 (symbol-value (intern-soft (format "diary-%s-date-forms" style))))
1035 (calendar-redraw)
1036 (calendar-update-mode-line))
1037
1038 (defun european-calendar ()
1039 "Set the interpretation and display of dates to the European style."
1040 (declare (obsolete calendar-set-date-style "23.1"))
1041 (interactive)
1042 (calendar-set-date-style 'european))
1043
1044 (defun american-calendar ()
1045 "Set the interpretation and display of dates to the American style."
1046 (declare (obsolete calendar-set-date-style "23.1"))
1047 (interactive)
1048 (calendar-set-date-style 'american))
1049
1050 (define-obsolete-variable-alias 'holidays-in-diary-buffer
1051 'diary-show-holidays-flag "23.1")
1052
1053 (defcustom diary-show-holidays-flag t
1054 "Non-nil means include holidays in the diary display.
1055 The holidays appear in the mode line of the diary buffer, or in the
1056 fancy diary buffer next to the date. This slows down the diary functions
1057 somewhat; setting it to nil makes the diary display faster."
1058 :type 'boolean
1059 :group 'holidays)
1060
1061 (defcustom calendar-debug-sexp nil
1062 "Turn debugging on when evaluating a sexp in the diary or holiday list."
1063 :type 'boolean
1064 :group 'calendar)
1065
1066 (define-obsolete-variable-alias 'all-hebrew-calendar-holidays
1067 'calendar-hebrew-all-holidays-flag "23.1")
1068
1069 (defcustom calendar-hebrew-all-holidays-flag nil
1070 "If nil, show only major holidays from the Hebrew calendar.
1071 This means only those Jewish holidays that appear on secular calendars.
1072 Otherwise, show all the holidays that would appear in a complete Hebrew
1073 calendar."
1074 :type 'boolean
1075 :group 'holidays)
1076
1077 (define-obsolete-variable-alias 'all-christian-calendar-holidays
1078 'calendar-christian-all-holidays-flag "23.1")
1079
1080 (defcustom calendar-christian-all-holidays-flag nil
1081 "If nil, show only major holidays from the Christian calendar.
1082 This means only those Christian holidays that appear on secular calendars.
1083 Otherwise, show all the holidays that would appear in a complete Christian
1084 calendar."
1085 :type 'boolean
1086 :group 'holidays)
1087
1088 (define-obsolete-variable-alias 'all-islamic-calendar-holidays
1089 'calendar-islamic-all-holidays-flag "23.1")
1090
1091 (defcustom calendar-islamic-all-holidays-flag nil
1092 "If nil, show only major holidays from the Islamic calendar.
1093 This means only those Islamic holidays that appear on secular calendars.
1094 Otherwise, show all the holidays that would appear in a complete Islamic
1095 calendar."
1096 :type 'boolean
1097 :group 'holidays)
1098
1099 (define-obsolete-variable-alias 'all-bahai-calendar-holidays
1100 'calendar-bahai-all-holidays-flag "23.1")
1101
1102 (defcustom calendar-bahai-all-holidays-flag nil
1103 "If nil, show only major holidays from the Bahá'í calendar.
1104 These are the days on which work and school must be suspended.
1105 Otherwise, show all the holidays that would appear in a complete Bahá'í
1106 calendar."
1107 :type 'boolean
1108 :group 'holidays)
1109
1110 (defcustom calendar-chinese-all-holidays-flag nil
1111 "If nil, show only the major holidays from the Chinese calendar."
1112 :version "23.1"
1113 :type 'boolean
1114 :group 'holidays)
1115
1116 ;;; End of user options.
1117
1118 (calendar-recompute-layout-variables)
1119
1120 (defconst calendar-first-date-row 3
1121 "First row in the calendar with actual dates.")
1122
1123 (defconst calendar-buffer "*Calendar*"
1124 "Name of the buffer used for the calendar.")
1125
1126 (defconst holiday-buffer "*Holidays*"
1127 "Name of the buffer used for the displaying the holidays.")
1128
1129 (defconst diary-fancy-buffer "*Fancy Diary Entries*"
1130 "Name of the buffer used for the optional fancy display of the diary.")
1131
1132 (define-obsolete-variable-alias 'fancy-diary-buffer 'diary-fancy-buffer "23.1")
1133
1134 (defconst calendar-other-calendars-buffer "*Other Calendars*"
1135 "Name of the buffer used for the display of date on other calendars.")
1136
1137 (defconst lunar-phases-buffer "*Phases of Moon*"
1138 "Name of the buffer used for the lunar phases.")
1139
1140 (defconst solar-sunrises-buffer "*Sunrise/Sunset Times*"
1141 "Name of buffer used for sunrise/sunset times.")
1142
1143 (defconst calendar-hebrew-yahrzeit-buffer "*Yahrzeits*"
1144 "Name of the buffer used by `list-yahrzeit-dates'.")
1145
1146 (defmacro calendar-increment-month (mon yr n &optional nmonths)
1147 "Increment the variables MON and YR by N months.
1148 Forward if N is positive or backward if N is negative.
1149 A negative YR is interpreted as BC; -1 being 1 BC, and so on.
1150 Optional NMONTHS is the number of months per year (default 12)."
1151 ;; Can view this as a form of base-nmonths arithmetic, in which "a
1152 ;; year" = "ten", and we never bother to use hundreds.
1153 `(let ((nmonths (or ,nmonths 12))
1154 macro-y)
1155 (if (< ,yr 0) (setq ,yr (1+ ,yr))) ; -1 BC -> 0 AD, etc
1156 (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
1157 ,mon (1+ (mod macro-y nmonths))
1158 ,yr (/ macro-y nmonths))
1159 ;; Alternative:
1160 ;;; (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
1161 ;;; ,yr (/ macro-y nmonths)
1162 ;;; ,mon (- macro-y (* ,yr nmonths)))
1163 (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr)))
1164 (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc
1165
1166 (define-obsolete-function-alias 'increment-calendar-month
1167 'calendar-increment-month "23.1")
1168
1169 (defvar displayed-month)
1170 (defvar displayed-year)
1171
1172 (defun calendar-increment-month-cons (n &optional mon yr)
1173 "Return the Nth month after MON/YR.
1174 The return value is a pair (MONTH . YEAR).
1175 MON defaults to `displayed-month'. YR defaults to `displayed-year'."
1176 (unless mon (setq mon displayed-month))
1177 (unless yr (setq yr displayed-year))
1178 (calendar-increment-month mon yr n)
1179 (cons mon yr))
1180
1181 (defmacro calendar-for-loop (var from init to final do &rest body)
1182 "Execute a for loop.
1183 Evaluate BODY with VAR bound to successive integers from INIT to FINAL,
1184 inclusive. The standard macro `dotimes' is preferable in most cases."
1185 (declare (obsolete "use `dotimes' or `while' instead." "23.1")
1186 (debug (symbolp "from" form "to" form "do" body))
1187 (indent defun))
1188 `(let ((,var (1- ,init)))
1189 (while (>= ,final (setq ,var (1+ ,var)))
1190 ,@body)))
1191
1192 (defmacro calendar-sum (index initial condition expression)
1193 "For INDEX = INITIAL, +1, ... (as long as CONDITION holds), sum EXPRESSION."
1194 (declare (debug (symbolp form form form)))
1195 `(let ((,index ,initial)
1196 (sum 0))
1197 (while ,condition
1198 (setq sum (+ sum ,expression)
1199 ,index (1+ ,index)))
1200 sum))
1201
1202 (defmacro calendar-in-read-only-buffer (buffer &rest body)
1203 "Switch to BUFFER and execute the forms in BODY.
1204 First creates or erases BUFFER as needed. Leaves BUFFER read-only,
1205 with disabled undo. Leaves point at point-min, displays BUFFER."
1206 (declare (indent 1) (debug t))
1207 `(progn
1208 (set-buffer (get-buffer-create ,buffer))
1209 (or (derived-mode-p 'special-mode) (special-mode))
1210 (setq buffer-read-only nil
1211 buffer-undo-list t)
1212 (erase-buffer)
1213 ,@body
1214 (goto-char (point-min))
1215 (set-buffer-modified-p nil)
1216 (setq buffer-read-only t)
1217 (display-buffer ,buffer)))
1218
1219 ;; The following are in-line for speed; they can be called thousands of times
1220 ;; when looking up holidays or processing the diary. Here, for example, are
1221 ;; the numbers of calls to calendar/diary/holiday functions in preparing the
1222 ;; fancy diary display, for a moderately complex diary file, with functions
1223 ;; used instead of macros. There were a total of 10000 such calls:
1224 ;;
1225 ;; 1934 calendar-extract-month
1226 ;; 1852 calendar-extract-year
1227 ;; 1819 calendar-extract-day
1228 ;; 845 calendar-leap-year-p
1229 ;; 837 calendar-day-number
1230 ;; 775 calendar-absolute-from-gregorian
1231 ;; 346 calendar-last-day-of-month
1232 ;; 286 calendar-hebrew-last-day-of-month
1233 ;; 188 calendar-hebrew-leap-year-p
1234 ;; 180 calendar-hebrew-elapsed-days
1235 ;; 163 calendar-hebrew-last-month-of-year
1236 ;; 66 calendar-date-compare
1237 ;; 65 calendar-hebrew-days-in-year
1238 ;; 60 calendar-julian-to-absolute
1239 ;; 50 calendar-hebrew-to-absolute
1240 ;; 43 calendar-date-equal
1241 ;; 38 calendar-gregorian-from-absolute
1242 ;; .
1243 ;;
1244 ;; The use of these seven macros eliminates the overhead of 92% of the function
1245 ;; calls; it's faster this way.
1246
1247 (defsubst calendar-extract-month (date)
1248 "Extract the month part of DATE which has the form (month day year)."
1249 (car date))
1250
1251 (define-obsolete-function-alias 'extract-calendar-month
1252 'calendar-extract-month "23.1")
1253
1254 ;; Note gives wrong answer for result of (calendar-read-date 'noday),
1255 ;; but that is only used by `calendar-other-month'.
1256 (defsubst calendar-extract-day (date)
1257 "Extract the day part of DATE which has the form (month day year)."
1258 (cadr date))
1259
1260 (define-obsolete-function-alias 'extract-calendar-day
1261 'calendar-extract-day "23.1")
1262
1263 (defsubst calendar-extract-year (date)
1264 "Extract the year part of DATE which has the form (month day year)."
1265 (nth 2 date))
1266
1267 (define-obsolete-function-alias 'extract-calendar-year
1268 'calendar-extract-year "23.1")
1269
1270 (defsubst calendar-leap-year-p (year)
1271 "Return t if YEAR is a Gregorian leap year.
1272 A negative year is interpreted as BC; -1 being 1 BC, and so on."
1273 ;; 1 BC = 0 AD, 2 BC acts like 1 AD, etc.
1274 (if (< year 0) (setq year (1- (abs year))))
1275 (and (zerop (% year 4))
1276 (or (not (zerop (% year 100)))
1277 (zerop (% year 400)))))
1278
1279 ;; The foregoing is a bit faster, but not as clear as the following:
1280 ;;
1281 ;;(defsubst calendar-leap-year-p (year)
1282 ;; "Return t if YEAR is a Gregorian leap year."
1283 ;; (or
1284 ;; (and (zerop (% year 4))
1285 ;; (not (zerop (% year 100))))
1286 ;; (zerop (% year 400)))
1287
1288 (defsubst calendar-last-day-of-month (month year)
1289 "The last day in MONTH during YEAR."
1290 (if (and (= month 2) (calendar-leap-year-p year))
1291 29
1292 (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
1293
1294 ;; An explanation of the calculation can be found in PascAlgorithms by
1295 ;; Edward and Ruth Reingold, Scott-Foresman/Little, Brown, 1988.
1296
1297 (defsubst calendar-day-number (date)
1298 "Return the day number within the year of the date DATE.
1299 For example, (calendar-day-number '(1 1 1987)) returns the value 1,
1300 while (calendar-day-number '(12 31 1980)) returns 366."
1301 (let* ((month (calendar-extract-month date))
1302 (day (calendar-extract-day date))
1303 (year (calendar-extract-year date))
1304 (day-of-year (+ day (* 31 (1- month)))))
1305 (when (> month 2)
1306 (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
1307 (if (calendar-leap-year-p year)
1308 (setq day-of-year (1+ day-of-year))))
1309 day-of-year))
1310
1311 (defsubst calendar-absolute-from-gregorian (date)
1312 "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
1313 The Gregorian date Sunday, December 31, 1 BC is imaginary.
1314 DATE is a list of the form (month day year). A negative year is
1315 interpreted as BC; -1 being 1 BC, and so on. Dates before 12/31/1 BC
1316 return negative results."
1317 (let ((year (calendar-extract-year date))
1318 offset-years)
1319 (cond ((zerop year)
1320 (error "There was no year zero"))
1321 ((> year 0)
1322 (setq offset-years (1- year))
1323 (+ (calendar-day-number date) ; days this year
1324 (* 365 offset-years) ; + days in prior years
1325 (/ offset-years 4) ; + Julian leap years
1326 (- (/ offset-years 100)) ; - century years
1327 (/ offset-years 400))) ; + Gregorian leap years
1328 (t
1329 ;; Years between date and 1 BC, excluding 1 BC (1 for 2 BC, etc).
1330 (setq offset-years (abs (1+ year)))
1331 (- (calendar-day-number date)
1332 (* 365 offset-years)
1333 (/ offset-years 4)
1334 (- (/ offset-years 100))
1335 (/ offset-years 400)
1336 (calendar-day-number '(12 31 -1))))))) ; days in year 1 BC
1337
1338 ;;;###autoload
1339 (defun calendar (&optional arg)
1340 "Display a three-month Gregorian calendar.
1341 The three months appear side by side, with the current month in
1342 the middle surrounded by the previous and next months. The
1343 cursor is put on today's date. If optional prefix argument ARG
1344 is non-nil, prompts for the central month and year.
1345
1346 Once in the calendar window, future or past months can be moved
1347 into view. Arbitrary months can be displayed, or the calendar
1348 can be scrolled forward or backward. The cursor can be moved
1349 forward or backward by one day, one week, one month, or one year.
1350 All of these commands take prefix arguments which, when negative,
1351 cause movement in the opposite direction. For convenience, the
1352 digit keys and the minus sign are automatically prefixes. Use
1353 \\[describe-mode] for details of the key bindings in the calendar
1354 window.
1355
1356 Displays the calendar in a separate window, or optionally in a
1357 separate frame, depending on the value of `calendar-setup'.
1358
1359 If `calendar-view-diary-initially-flag' is non-nil, also displays the
1360 diary entries for the current date (or however many days
1361 `diary-number-of-entries' specifies). This variable can be
1362 overridden by `calendar-setup'. As well as being displayed,
1363 diary entries can also be marked on the calendar (see
1364 `calendar-mark-diary-entries-flag').
1365
1366 Runs the following hooks:
1367
1368 `calendar-load-hook' - after loading calendar.el
1369 `calendar-today-visible-hook', `calendar-today-invisible-hook' - after
1370 generating a calendar, if today's date is visible or not, respectively
1371 `calendar-initial-window-hook' - after first creating a calendar
1372
1373 This function is suitable for execution in an init file."
1374 (interactive "P")
1375 ;; Avoid loading cal-x unless it will be used.
1376 (if (and (memq calendar-setup '(one-frame two-frames calendar-only))
1377 (display-multi-frame-p))
1378 (calendar-frame-setup calendar-setup arg)
1379 (calendar-basic-setup arg)))
1380
1381 (defun calendar-basic-setup (&optional arg nodisplay)
1382 "Create a three-month calendar.
1383 If optional prefix argument ARG is non-nil, prompts for the month
1384 and year, else uses the current date. If NODISPLAY is non-nil, don't
1385 display the generated calendar."
1386 (interactive "P")
1387 (let ((buff (current-buffer)))
1388 (set-buffer (get-buffer-create calendar-buffer))
1389 (calendar-mode)
1390 (let* ((pop-up-windows t)
1391 ;; Not really needed now, but means we use exactly the same
1392 ;; behavior as before in the non-wide case (see below).
1393 (split-height-threshold 1000)
1394 (split-width-threshold calendar-split-width-threshold)
1395 (date (if arg (calendar-read-date t)
1396 (calendar-current-date)))
1397 (month (calendar-extract-month date))
1398 (year (calendar-extract-year date)))
1399 (calendar-increment-month month year (- calendar-offset))
1400 ;; Display the buffer before calling calendar-generate-window so that it
1401 ;; can get a chance to adjust the window sizes to the frame size.
1402 (unless nodisplay
1403 ;; We want a window configuration that looks something like
1404 ;; X X | Y
1405 ;; - -----
1406 ;; C Z | C
1407 ;; where C is the calendar, and the LHS is the traditional,
1408 ;; non-wide frame, and the RHS is the wide frame case.
1409 ;; We should end up in the same state regardless of whether the
1410 ;; windows were initially split or not.
1411 ;; Previously, we only thought about the non-wide case.
1412 ;; We could just set split-height-threshold to 1000, relying on
1413 ;; the fact that the window splitting treated a single window as
1414 ;; a special case and would always split it (vertically). The
1415 ;; same thing does not work in the wide-frame case, so now we do
1416 ;; the splitting by hand.
1417 ;; See discussion in bug#1806.
1418 ;; Actually, this still does not do quite the right thing in the
1419 ;; wide frame case if started from a configuration like the LHS.
1420 ;; Eg if you start with a non-wide frame, call calendar, then
1421 ;; make the frame wider. This one is problematic because you
1422 ;; might need to split a totally unrelated window. Oh well, it
1423 ;; seems unlikely, and perhaps respecting the original layout is
1424 ;; the right thing in that case.
1425 ;;
1426 ;; Is this a wide frame? If so, split it horizontally.
1427 (if (window-splittable-p t) (split-window-right))
1428 (pop-to-buffer calendar-buffer)
1429 ;; Has the window already been split vertically?
1430 (when (and (not (window-dedicated-p))
1431 (window-full-height-p))
1432 (let ((win (split-window-below)))
1433 ;; In the upper window, show whatever was visible before.
1434 ;; This looks better than using other-buffer.
1435 (switch-to-buffer buff)
1436 ;; Switch to the lower window with the calendar buffer.
1437 (select-window win))))
1438 (calendar-generate-window month year)
1439 (if (and calendar-view-diary-initially-flag
1440 (calendar-date-is-visible-p date))
1441 (diary-view-entries))))
1442 (if calendar-view-holidays-initially-flag
1443 (let* ((diary-buffer (get-file-buffer diary-file))
1444 (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
1445 (split-height-threshold (if diary-window 2 1000)))
1446 ;; FIXME display buffer?
1447 (calendar-list-holidays)))
1448 (run-hooks 'calendar-initial-window-hook))
1449
1450 (defun calendar-generate-window (&optional mon yr)
1451 "Generate the calendar window for the current date.
1452 Optional integers MON and YR are used instead of today's date."
1453 (let* ((inhibit-read-only t)
1454 (today (calendar-current-date))
1455 (month (calendar-extract-month today))
1456 (day (calendar-extract-day today))
1457 (year (calendar-extract-year today))
1458 (today-visible (or (not mon)
1459 (<= (abs (calendar-interval mon yr month year)) 1)))
1460 (in-calendar-window (eq (window-buffer)
1461 (get-buffer calendar-buffer))))
1462 (calendar-generate (or mon month) (or yr year))
1463 (calendar-update-mode-line)
1464 (calendar-cursor-to-visible-date
1465 (if today-visible today (list displayed-month 1 displayed-year)))
1466 (set-buffer-modified-p nil)
1467 ;; Don't do any window-related stuff if we weren't called from a
1468 ;; window displaying the calendar.
1469 (when in-calendar-window
1470 (if (window-combined-p)
1471 ;; Adjust the window to exactly fit the displayed calendar.
1472 (fit-window-to-buffer nil nil calendar-minimum-window-height)
1473 ;; For a full height window or a window that is horizontally
1474 ;; combined don't fit height to that of its buffer.
1475 (set-window-vscroll nil 0))
1476 (sit-for 0))
1477 (and (bound-and-true-p font-lock-mode)
1478 (font-lock-fontify-buffer))
1479 (and calendar-mark-holidays-flag
1480 ;;; (calendar-date-is-valid-p today) ; useful for BC dates
1481 (calendar-mark-holidays)
1482 (and in-calendar-window (sit-for 0)))
1483 (unwind-protect
1484 (if calendar-mark-diary-entries-flag (diary-mark-entries))
1485 (if today-visible
1486 (run-hooks 'calendar-today-visible-hook)
1487 (run-hooks 'calendar-today-invisible-hook)))))
1488
1489 (defun calendar-generate (month year)
1490 "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
1491 ;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on.
1492 ;; Note that while calendars for years BC could be displayed as it
1493 ;; stands, almost all other calendar functions (eg holidays) would
1494 ;; at best have unpredictable results for such dates.
1495 (if (< (+ month (* 12 (1- year))) 2)
1496 (error "Months before January, 1 AD cannot be displayed"))
1497 (setq displayed-month month
1498 displayed-year year)
1499 (erase-buffer)
1500 (calendar-increment-month month year -1)
1501 (dotimes (i 3)
1502 (calendar-generate-month month year
1503 (+ calendar-left-margin
1504 (* calendar-month-width i)))
1505 (calendar-increment-month month year 1)))
1506
1507 (defun calendar-move-to-column (indent)
1508 "Like `move-to-column', but indents if the line is too short."
1509 (if (< (move-to-column indent) indent)
1510 (indent-to indent)))
1511
1512 (defun calendar-ensure-newline ()
1513 "Move to the next line, adding a newline if necessary."
1514 (or (zerop (forward-line 1))
1515 (insert "\n")))
1516
1517 (defun calendar-insert-at-column (indent string truncate)
1518 "Move to column INDENT, adding spaces as needed.
1519 Inserts STRING so that it ends at INDENT. STRING is either a
1520 literal string, or a sexp to evaluate to return such. Truncates
1521 STRING to length TRUNCATE, and ensures a trailing space."
1522 (if (not (ignore-errors (stringp (setq string (eval string)))))
1523 (calendar-move-to-column indent)
1524 (if (> (string-width string) truncate)
1525 (setq string (truncate-string-to-width string truncate)))
1526 (or (string-match " $" string)
1527 (setq string (concat (if (= (string-width string) truncate)
1528 (substring string 0 -1)
1529 string)
1530 ;; Avoid inserting text properties unless
1531 ;; we have to (ie, non-unit-width chars).
1532 ;; This is by no means essential.
1533 (if (= (string-width string) (length string))
1534 " "
1535 ;; Cribbed from buff-menu.el.
1536 (propertize
1537 " " 'display `(space :align-to ,indent))))))
1538 (calendar-move-to-column (- indent (string-width string)))
1539 (insert string)))
1540
1541 (defun calendar-generate-month (month year indent)
1542 "Produce a calendar for MONTH, YEAR on the Gregorian calendar.
1543 The calendar is inserted at the top of the buffer in which point is currently
1544 located, but indented INDENT spaces. The indentation is done from the first
1545 character on the line and does not disturb the first INDENT characters on the
1546 line."
1547 (let ((blank-days ; at start of month
1548 (mod
1549 (- (calendar-day-of-week (list month 1 year))
1550 calendar-week-start-day)
1551 7))
1552 (last (calendar-last-day-of-month month year))
1553 (trunc (min calendar-intermonth-spacing
1554 (1- calendar-left-margin)))
1555 (day 1)
1556 j)
1557 (goto-char (point-min))
1558 (calendar-move-to-column indent)
1559 (insert
1560 (calendar-string-spread (list calendar-month-header)
1561 ?\s calendar-month-digit-width))
1562 (calendar-ensure-newline)
1563 (calendar-insert-at-column indent calendar-intermonth-header trunc)
1564 ;; Use the first N characters of each day to head the columns.
1565 (dotimes (i 7)
1566 (setq j (mod (+ calendar-week-start-day i) 7))
1567 (insert
1568 (truncate-string-to-width
1569 (propertize (calendar-day-name j 'header t)
1570 'font-lock-face (if (memq j '(0 6))
1571 'calendar-weekend-header
1572 'calendar-weekday-header))
1573 calendar-day-header-width nil ?\s)
1574 (make-string (- calendar-column-width calendar-day-header-width) ?\s)))
1575 (calendar-ensure-newline)
1576 (calendar-insert-at-column indent calendar-intermonth-text trunc)
1577 ;; Add blank days before the first of the month.
1578 (insert (make-string (* blank-days calendar-column-width) ?\s))
1579 ;; Put in the days of the month.
1580 (dotimes (i last)
1581 (setq day (1+ i))
1582 ;; TODO should numbers be left-justified, centered...?
1583 (insert (propertize
1584 (format (format "%%%dd" calendar-day-digit-width) day)
1585 'mouse-face 'highlight
1586 'help-echo (eval calendar-date-echo-text)
1587 ;; 'date property prevents intermonth text confusing re-searches.
1588 ;; (Tried intangible, it did not really work.)
1589 'date t)
1590 (make-string
1591 (- calendar-column-width calendar-day-digit-width) ?\s))
1592 (when (and (zerop (mod (+ day blank-days) 7))
1593 (/= day last))
1594 (calendar-ensure-newline)
1595 (setq day (1+ day)) ; first day of next week
1596 (calendar-insert-at-column indent calendar-intermonth-text trunc)))))
1597
1598 (defun calendar-redraw ()
1599 "Redraw the calendar display, if `calendar-buffer' is live."
1600 (interactive)
1601 (when (get-buffer calendar-buffer)
1602 (with-current-buffer calendar-buffer
1603 (let ((cursor-date (calendar-cursor-to-nearest-date)))
1604 (calendar-generate-window displayed-month displayed-year)
1605 (calendar-cursor-to-visible-date cursor-date))
1606 (when (window-live-p (get-buffer-window))
1607 (set-window-point (get-buffer-window) (point))))))
1608
1609 (defvar calendar-mode-map
1610 (let ((map (make-keymap)))
1611 (suppress-keymap map)
1612 (dolist (c '(narrow-to-region mark-word mark-sexp mark-paragraph
1613 mark-defun mark-whole-buffer mark-page
1614 downcase-region upcase-region kill-region
1615 copy-region-as-kill capitalize-region write-region))
1616 (define-key map (vector 'remap c) 'calendar-not-implemented))
1617 (define-key map "<" 'calendar-scroll-right)
1618 (define-key map "\C-x<" 'calendar-scroll-right)
1619 (define-key map [prior] 'calendar-scroll-right-three-months)
1620 (define-key map "\ev" 'calendar-scroll-right-three-months)
1621 (define-key map ">" 'calendar-scroll-left)
1622 (define-key map "\C-x>" 'calendar-scroll-left)
1623 (define-key map [next] 'calendar-scroll-left-three-months)
1624 (define-key map "\C-v" 'calendar-scroll-left-three-months)
1625 (define-key map "\C-b" 'calendar-backward-day)
1626 (define-key map "\C-p" 'calendar-backward-week)
1627 (define-key map "\e{" 'calendar-backward-month)
1628 (define-key map "\C-x[" 'calendar-backward-year)
1629 (define-key map "\C-f" 'calendar-forward-day)
1630 (define-key map "\C-n" 'calendar-forward-week)
1631 (define-key map [left] 'calendar-backward-day)
1632 (define-key map [up] 'calendar-backward-week)
1633 (define-key map [right] 'calendar-forward-day)
1634 (define-key map [down] 'calendar-forward-week)
1635 (define-key map "\e}" 'calendar-forward-month)
1636 (define-key map "\C-x]" 'calendar-forward-year)
1637 (define-key map "\C-a" 'calendar-beginning-of-week)
1638 (define-key map "\C-e" 'calendar-end-of-week)
1639 (define-key map "\ea" 'calendar-beginning-of-month)
1640 (define-key map "\ee" 'calendar-end-of-month)
1641 (define-key map "\e<" 'calendar-beginning-of-year)
1642 (define-key map "\e>" 'calendar-end-of-year)
1643 (define-key map "\C-@" 'calendar-set-mark)
1644 ;; Many people are used to typing C-SPC and getting C-@.
1645 (define-key map [?\C-\s] 'calendar-set-mark)
1646 (define-key map "\C-x\C-x" 'calendar-exchange-point-and-mark)
1647 (define-key map "\e=" 'calendar-count-days-region)
1648 (define-key map "gd" 'calendar-goto-date)
1649 (define-key map "gD" 'calendar-goto-day-of-year)
1650 (define-key map "gj" 'calendar-julian-goto-date)
1651 (define-key map "ga" 'calendar-astro-goto-day-number)
1652 (define-key map "gh" 'calendar-hebrew-goto-date)
1653 (define-key map "gi" 'calendar-islamic-goto-date)
1654 (define-key map "gb" 'calendar-bahai-goto-date)
1655 (define-key map "gC" 'calendar-chinese-goto-date)
1656 (define-key map "gk" 'calendar-coptic-goto-date)
1657 (define-key map "ge" 'calendar-ethiopic-goto-date)
1658 (define-key map "gp" 'calendar-persian-goto-date)
1659 (define-key map "gc" 'calendar-iso-goto-date)
1660 (define-key map "gw" 'calendar-iso-goto-week)
1661 (define-key map "gf" 'calendar-french-goto-date)
1662 (define-key map "gml" 'calendar-mayan-goto-long-count-date)
1663 (define-key map "gmpc" 'calendar-mayan-previous-round-date)
1664 (define-key map "gmnc" 'calendar-mayan-next-round-date)
1665 (define-key map "gmph" 'calendar-mayan-previous-haab-date)
1666 (define-key map "gmnh" 'calendar-mayan-next-haab-date)
1667 (define-key map "gmpt" 'calendar-mayan-previous-tzolkin-date)
1668 (define-key map "gmnt" 'calendar-mayan-next-tzolkin-date)
1669 (define-key map "Aa" 'appt-add)
1670 (define-key map "Ad" 'appt-delete)
1671 (define-key map "S" 'calendar-sunrise-sunset)
1672 (define-key map "M" 'calendar-lunar-phases)
1673 (define-key map " " 'scroll-other-window)
1674 (define-key map [?\S-\ ] 'scroll-other-window-down)
1675 (define-key map "\d" 'scroll-other-window-down)
1676 (define-key map "\C-c\C-l" 'calendar-redraw)
1677 (define-key map "." 'calendar-goto-today)
1678 (define-key map "o" 'calendar-other-month)
1679 (define-key map "q" 'calendar-exit)
1680 (define-key map "a" 'calendar-list-holidays)
1681 (define-key map "h" 'calendar-cursor-holidays)
1682 (define-key map "x" 'calendar-mark-holidays)
1683 (define-key map "u" 'calendar-unmark)
1684 (define-key map "m" 'diary-mark-entries)
1685 (define-key map "d" 'diary-view-entries)
1686 (define-key map "D" 'diary-view-other-diary-entries)
1687 (define-key map "s" 'diary-show-all-entries)
1688 (define-key map "pd" 'calendar-print-day-of-year)
1689 (define-key map "pC" 'calendar-chinese-print-date)
1690 (define-key map "pk" 'calendar-coptic-print-date)
1691 (define-key map "pe" 'calendar-ethiopic-print-date)
1692 (define-key map "pp" 'calendar-persian-print-date)
1693 (define-key map "pc" 'calendar-iso-print-date)
1694 (define-key map "pj" 'calendar-julian-print-date)
1695 (define-key map "pa" 'calendar-astro-print-day-number)
1696 (define-key map "ph" 'calendar-hebrew-print-date)
1697 (define-key map "pi" 'calendar-islamic-print-date)
1698 (define-key map "pb" 'calendar-bahai-print-date)
1699 (define-key map "pf" 'calendar-french-print-date)
1700 (define-key map "pm" 'calendar-mayan-print-date)
1701 (define-key map "po" 'calendar-print-other-dates)
1702 (define-key map "id" 'diary-insert-entry)
1703 (define-key map "iw" 'diary-insert-weekly-entry)
1704 (define-key map "im" 'diary-insert-monthly-entry)
1705 (define-key map "iy" 'diary-insert-yearly-entry)
1706 (define-key map "ia" 'diary-insert-anniversary-entry)
1707 (define-key map "ib" 'diary-insert-block-entry)
1708 (define-key map "ic" 'diary-insert-cyclic-entry)
1709 (define-key map "ihd" 'diary-hebrew-insert-entry)
1710 (define-key map "ihm" 'diary-hebrew-insert-monthly-entry)
1711 (define-key map "ihy" 'diary-hebrew-insert-yearly-entry)
1712 (define-key map "iid" 'diary-islamic-insert-entry)
1713 (define-key map "iim" 'diary-islamic-insert-monthly-entry)
1714 (define-key map "iiy" 'diary-islamic-insert-yearly-entry)
1715 (define-key map "iBd" 'diary-bahai-insert-entry)
1716 (define-key map "iBm" 'diary-bahai-insert-monthly-entry)
1717 (define-key map "iBy" 'diary-bahai-insert-yearly-entry)
1718 (define-key map "iCd" 'diary-chinese-insert-entry)
1719 (define-key map "iCm" 'diary-chinese-insert-monthly-entry)
1720 (define-key map "iCy" 'diary-chinese-insert-yearly-entry)
1721 (define-key map "iCa" 'diary-chinese-insert-anniversary-entry)
1722 (define-key map "?" 'calendar-goto-info-node)
1723 (define-key map "Hm" 'cal-html-cursor-month)
1724 (define-key map "Hy" 'cal-html-cursor-year)
1725 (define-key map "tm" 'cal-tex-cursor-month)
1726 (define-key map "tM" 'cal-tex-cursor-month-landscape)
1727 (define-key map "td" 'cal-tex-cursor-day)
1728 (define-key map "tw1" 'cal-tex-cursor-week)
1729 (define-key map "tw2" 'cal-tex-cursor-week2)
1730 (define-key map "tw3" 'cal-tex-cursor-week-iso) ; FIXME twi ?
1731 (define-key map "tw4" 'cal-tex-cursor-week-monday) ; twm ?
1732 (define-key map "twW" 'cal-tex-cursor-week2-summary)
1733 (define-key map "tfd" 'cal-tex-cursor-filofax-daily)
1734 (define-key map "tfw" 'cal-tex-cursor-filofax-2week)
1735 (define-key map "tfW" 'cal-tex-cursor-filofax-week)
1736 (define-key map "tfy" 'cal-tex-cursor-filofax-year)
1737 (define-key map "ty" 'cal-tex-cursor-year)
1738 (define-key map "tY" 'cal-tex-cursor-year-landscape)
1739
1740 (define-key map [menu-bar edit] 'undefined)
1741 (define-key map [menu-bar search] 'undefined)
1742
1743 (easy-menu-define nil map nil cal-menu-sunmoon-menu)
1744 (easy-menu-define nil map nil cal-menu-diary-menu)
1745 (easy-menu-define nil map nil cal-menu-holidays-menu)
1746 (easy-menu-define nil map nil cal-menu-goto-menu)
1747 (easy-menu-define nil map nil cal-menu-scroll-menu)
1748
1749 ;; These are referenced in the default calendar-date-echo-text.
1750 (define-key map [down-mouse-3]
1751 (easy-menu-binding cal-menu-context-mouse-menu))
1752 (define-key map [down-mouse-2]
1753 (easy-menu-binding cal-menu-global-mouse-menu))
1754
1755 ;; cf scroll-bar.el.
1756 (if (and (boundp 'x-toolkit-scroll-bars) x-toolkit-scroll-bars)
1757 (define-key map [vertical-scroll-bar mouse-1]
1758 'calendar-scroll-toolkit-scroll)
1759 ;; Left-click moves us forward in time, right-click backwards.
1760 (define-key map [vertical-scroll-bar mouse-1] 'calendar-scroll-left)
1761 (define-key map [vertical-scroll-bar drag-mouse-1] 'calendar-scroll-left)
1762 ;; down-mouse-2 stays as scroll-bar-drag.
1763 (define-key map [vertical-scroll-bar mouse-3] 'calendar-scroll-right)
1764 (define-key map [vertical-scroll-bar drag-mouse-3]
1765 'calendar-scroll-right))
1766 map)
1767 "Keymap for `calendar-mode'.")
1768
1769 ;; Calendar mode is suitable only for specially formatted data.
1770 (put 'calendar-mode 'mode-class 'special)
1771
1772 (defun calendar-mode-line-entry (command echo &optional key string)
1773 "Return a propertized string for `calendar-mode-line-format'.
1774 COMMAND is a command to run, ECHO is the help-echo text, KEY
1775 is COMMAND's keybinding, STRING describes the binding."
1776 (propertize (or key
1777 (substitute-command-keys
1778 (format "\\<calendar-mode-map>\\[%s] %s" command string)))
1779 'help-echo (format "mouse-1: %s" echo)
1780 'mouse-face 'mode-line-highlight
1781 'keymap (make-mode-line-mouse-map 'mouse-1 command)))
1782
1783 ;; After calendar-mode-map.
1784 (defcustom calendar-mode-line-format
1785 (list
1786 (calendar-mode-line-entry 'calendar-scroll-right "previous month" "<")
1787 "Calendar"
1788 (concat
1789 (calendar-mode-line-entry 'calendar-goto-info-node "read Info on Calendar"
1790 nil "info")
1791 " / "
1792 (calendar-mode-line-entry 'calendar-other-month "choose another month"
1793 nil "other")
1794 " / "
1795 (calendar-mode-line-entry 'calendar-goto-today "go to today's date"
1796 nil "today"))
1797 '(calendar-date-string (calendar-current-date) t)
1798 (calendar-mode-line-entry 'calendar-scroll-left "next month" ">"))
1799 "The mode line of the calendar buffer.
1800 This is a list of items that evaluate to strings. The elements
1801 are evaluated and concatenated, evenly separated by blanks.
1802 During evaluation, the variable `date' is available as the date
1803 nearest the cursor (or today's date if that fails). To update
1804 the mode-line as the cursor moves, add `calendar-update-mode-line'
1805 to `calendar-move-hook'. Here is an example that has the Hebrew date,
1806 the day number/days remaining in the year, and the ISO week/year numbers:
1807
1808 (list
1809 \"\"
1810 '(calendar-hebrew-date-string date)
1811 '(let* ((year (calendar-extract-year date))
1812 (d (calendar-day-number date))
1813 (days-remaining
1814 (- (calendar-day-number (list 12 31 year)) d)))
1815 (format \"%d/%d\" d days-remaining))
1816 '(let* ((d (calendar-absolute-from-gregorian date))
1817 (iso-date (calendar-iso-from-absolute d)))
1818 (format \"ISO week %d of %d\"
1819 (calendar-extract-month iso-date)
1820 (calendar-extract-year iso-date)))
1821 \"\"))"
1822 :risky t
1823 :type 'sexp
1824 :group 'calendar)
1825
1826 (defun calendar-goto-info-node ()
1827 "Go to the info node for the calendar."
1828 (interactive)
1829 (info "(emacs)Calendar/Diary")
1830 (fit-window-to-buffer))
1831
1832 (defvar calendar-mark-ring nil
1833 "Used by `calendar-set-mark'.")
1834
1835 (define-derived-mode calendar-mode nil "Calendar"
1836 "A major mode for the calendar window.
1837 For a complete description, see the info node `Calendar/Diary'.
1838
1839 \\<calendar-mode-map>\\{calendar-mode-map}"
1840 (setq buffer-read-only t
1841 buffer-undo-list t
1842 indent-tabs-mode nil)
1843 (set (make-local-variable 'scroll-margin) 0) ; bug#10379
1844 (calendar-update-mode-line)
1845 (make-local-variable 'calendar-mark-ring)
1846 (make-local-variable 'displayed-month) ; month in middle of window
1847 (make-local-variable 'displayed-year) ; year in middle of window
1848 ;; Most functions only work if displayed-month and displayed-year are set,
1849 ;; so let's make sure they're always set. Most likely, this will be reset
1850 ;; soon in calendar-generate, but better safe than sorry.
1851 (unless (boundp 'displayed-month) (setq displayed-month 1))
1852 (unless (boundp 'displayed-year) (setq displayed-year 2001))
1853 (if (bound-and-true-p calendar-font-lock-keywords)
1854 (set (make-local-variable 'font-lock-defaults)
1855 '(calendar-font-lock-keywords t))))
1856
1857 (defun calendar-string-spread (strings char length)
1858 "Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH.
1859 The effect is like mapconcat but the separating pieces are as balanced as
1860 possible. Each item of STRINGS is evaluated before concatenation so it can
1861 actually be an expression that evaluates to a string. If LENGTH is too short,
1862 the STRINGS are just concatenated and the result truncated."
1863 ;; The algorithm is based on equation (3.25) on page 85 of Concrete
1864 ;; Mathematics by Ronald L. Graham, Donald E. Knuth, and Oren Patashnik,
1865 ;; Addison-Wesley, Reading, MA, 1989.
1866 (let* ((strings (mapcar 'eval
1867 (if (< (length strings) 2)
1868 (append (list "") strings (list ""))
1869 strings)))
1870 (n (- length (string-width (apply 'concat strings))))
1871 (m (* (1- (length strings)) (char-width char)))
1872 (s (car strings))
1873 (strings (cdr strings))
1874 (i 0))
1875 (dolist (string strings)
1876 (setq s (concat s
1877 (make-string (max 0 (/ (+ n i) m)) char)
1878 string)
1879 i (1+ i)))
1880 (truncate-string-to-width s length)))
1881
1882 (defun calendar-update-mode-line ()
1883 "Update the calendar mode line with the current date and date style."
1884 (if (bufferp (get-buffer calendar-buffer))
1885 (with-current-buffer calendar-buffer
1886 (let ((start (- calendar-left-margin 2))
1887 (date (condition-case nil
1888 (calendar-cursor-to-nearest-date)
1889 (error (calendar-current-date)))))
1890 (setq mode-line-format
1891 (concat (make-string (max 0 (+ start
1892 (- (car (window-inside-edges))
1893 (car (window-edges))))) ?\s)
1894 (calendar-string-spread
1895 (mapcar 'eval calendar-mode-line-format)
1896 ?\s (- calendar-right-margin (1- start))))))
1897 (force-mode-line-update))))
1898
1899 (defun calendar-buffer-list ()
1900 "List of all calendar-related buffers (as buffers, not strings)."
1901 (let (buffs)
1902 (dolist (b (list calendar-hebrew-yahrzeit-buffer lunar-phases-buffer
1903 holiday-buffer diary-fancy-buffer solar-sunrises-buffer
1904 (get-file-buffer diary-file)
1905 calendar-buffer calendar-other-calendars-buffer))
1906 (and b (setq b (get-buffer b))
1907 (push b buffs)))
1908 buffs))
1909
1910 (defun calendar-exit (&optional kill)
1911 "Get out of the calendar window and hide it and related buffers."
1912 (interactive "P")
1913 (let ((diary-buffer (get-file-buffer diary-file))
1914 (calendar-buffers (calendar-buffer-list)))
1915 (when (or (not diary-buffer)
1916 (not (buffer-modified-p diary-buffer))
1917 (yes-or-no-p
1918 "Diary modified; do you really want to exit the calendar? "))
1919 (if (and calendar-setup (display-multi-frame-p))
1920 ;; FIXME: replace this cruft with the `quit-restore' window property
1921 (dolist (w (window-list-1 nil nil t))
1922 (if (and (memq (window-buffer w) calendar-buffers)
1923 (window-dedicated-p w))
1924 (if (eq (window-deletable-p w) 'frame)
1925 (if calendar-remove-frame-by-deleting
1926 (delete-frame (window-frame w))
1927 (iconify-frame (window-frame w)))
1928 (quit-window kill w))))
1929 (dolist (b calendar-buffers)
1930 (quit-windows-on b kill))))))
1931
1932 (define-obsolete-function-alias 'exit-calendar 'calendar-exit "23.1")
1933
1934 (defun calendar-current-date (&optional offset)
1935 "Return the current date in a list (month day year).
1936 Optional integer OFFSET is a number of days from the current date."
1937 (let* ((now (decode-time))
1938 (now (list (nth 4 now) (nth 3 now) (nth 5 now))))
1939 (if (zerop (or offset 0))
1940 now
1941 (calendar-gregorian-from-absolute
1942 (+ offset (calendar-absolute-from-gregorian now))))))
1943
1944 (defun calendar-column-to-segment ()
1945 "Convert current column to calendar month \"segment\".
1946 The left-most month returns 0, the next right 1, and so on."
1947 (let ((col (max 0 (+ (current-column)
1948 (/ calendar-intermonth-spacing 2)
1949 (- calendar-left-margin)))))
1950 (/ col (+ (* 7 calendar-column-width) calendar-intermonth-spacing))))
1951
1952 (defun calendar-cursor-to-date (&optional error event)
1953 "Return a list (month day year) of current cursor position.
1954 If cursor is not on a specific date, signals an error if optional parameter
1955 ERROR is non-nil, otherwise just returns nil.
1956 If EVENT is non-nil, it's an event indicating the buffer position to
1957 use instead of point."
1958 (with-current-buffer
1959 (if event (window-buffer (posn-window (event-start event)))
1960 (current-buffer))
1961 (save-excursion
1962 (and event (setq event (event-start event))
1963 (goto-char (posn-point event)))
1964 (let* ((segment (calendar-column-to-segment))
1965 (month (% (+ displayed-month (1- segment)) 12)))
1966 ;; Call with point on either of the two digits in a 2-digit date,
1967 ;; or on or before the digit of a 1-digit date.
1968 (if (not (and (looking-at "[ 0-9]?[0-9][^0-9]")
1969 (get-text-property (point) 'date)))
1970 (if error (user-error "Not on a date!"))
1971 ;; Convert segment to real month and year.
1972 (if (zerop month) (setq month 12))
1973 ;; Go back to before the first date digit.
1974 (or (looking-at " ")
1975 (re-search-backward "[^0-9]"))
1976 (list month
1977 (string-to-number
1978 (buffer-substring (1+ (point))
1979 (+ 1 calendar-day-digit-width (point))))
1980 (cond
1981 ((and (= 12 month) (zerop segment)) (1- displayed-year))
1982 ((and (= 1 month) (= segment 2)) (1+ displayed-year))
1983 (t displayed-year))))))))
1984
1985 ;; The following version of calendar-gregorian-from-absolute is preferred for
1986 ;; reasons of clarity, BUT it's much slower than the version that follows it.
1987
1988 ;;(defun calendar-gregorian-from-absolute (date)
1989 ;; "Compute the list (month day year) corresponding to the absolute DATE.
1990 ;;The absolute date is the number of days elapsed since the (imaginary)
1991 ;;Gregorian date Sunday, December 31, 1 BC."
1992 ;; (let* ((approx (/ date 366)) ; approximation from below
1993 ;; (year ; search forward from the approximation
1994 ;; (+ approx
1995 ;; (calendar-sum y approx
1996 ;; (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y))))
1997 ;; 1)))
1998 ;; (month ; search forward from January
1999 ;; (1+ (calendar-sum m 1
2000 ;; (> date
2001 ;; (calendar-absolute-from-gregorian
2002 ;; (list m (calendar-last-day-of-month m year) year)))
2003 ;; 1)))
2004 ;; (day ; calculate the day by subtraction
2005 ;; (- date
2006 ;; (1- (calendar-absolute-from-gregorian (list month 1 year))))))
2007 ;; (list month day year)))
2008
2009 (defun calendar-gregorian-from-absolute (date)
2010 "Compute the list (month day year) corresponding to the absolute DATE.
2011 The absolute date is the number of days elapsed since the (imaginary)
2012 Gregorian date Sunday, December 31, 1 BC. This function does not
2013 handle dates in years BC."
2014 ;; See the footnote on page 384 of ``Calendrical Calculations, Part II:
2015 ;; Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
2016 ;; Clamen, Software--Practice and Experience, Volume 23, Number 4
2017 ;; (April, 1993), pages 383-404 for an explanation.
2018 (let* ((d0 (1- date))
2019 (n400 (/ d0 146097))
2020 (d1 (% d0 146097))
2021 (n100 (/ d1 36524))
2022 (d2 (% d1 36524))
2023 (n4 (/ d2 1461))
2024 (d3 (% d2 1461))
2025 (n1 (/ d3 365))
2026 (day (1+ (% d3 365)))
2027 (year (+ (* 400 n400) (* 100 n100) (* n4 4) n1))
2028 (month 1)
2029 mdays)
2030 (if (or (= n100 4) (= n1 4))
2031 (list 12 31 year)
2032 (setq year (1+ year))
2033 (while (< (setq mdays (calendar-last-day-of-month month year)) day)
2034 (setq day (- day mdays)
2035 month (1+ month)))
2036 (list month day year))))
2037
2038 (defun calendar-other-month (month year &optional event)
2039 "Display a three-month calendar centered around MONTH and YEAR.
2040 EVENT is an event like `last-nonmenu-event'."
2041 (interactive (let ((event (list last-nonmenu-event)))
2042 (append (calendar-read-date 'noday) event)))
2043 (save-selected-window
2044 (and event
2045 (setq event (event-start event))
2046 (select-window (posn-window event)))
2047 (unless (and (= month displayed-month)
2048 (= year displayed-year))
2049 (let ((old-date (calendar-cursor-to-date))
2050 (today (calendar-current-date)))
2051 (calendar-generate-window month year)
2052 (calendar-cursor-to-visible-date
2053 (cond
2054 ((calendar-date-is-visible-p old-date) old-date)
2055 ((calendar-date-is-visible-p today) today)
2056 (t (list month 1 year))))))))
2057
2058 (defun calendar-set-mark (arg &optional event)
2059 "Mark the date under the cursor, or jump to marked date.
2060 With no prefix argument, push current date onto marked date ring.
2061 With argument ARG, jump to mark, pop it, and put point at end of ring."
2062 (interactive
2063 (list current-prefix-arg last-nonmenu-event))
2064 (let ((date (calendar-cursor-to-date t event)))
2065 (if arg
2066 (if (null calendar-mark-ring)
2067 (error "No mark set in this buffer")
2068 (calendar-goto-date (car calendar-mark-ring))
2069 (setq calendar-mark-ring
2070 (cdr (nconc calendar-mark-ring (list date)))))
2071 (push date calendar-mark-ring)
2072 ;; Since the top of the mark ring is the marked date in the
2073 ;; calendar, the mark ring in the calendar is one longer than
2074 ;; in other buffers to get the same effect.
2075 (if (> (length calendar-mark-ring) (1+ mark-ring-max))
2076 (setcdr (nthcdr mark-ring-max calendar-mark-ring) nil))
2077 (message "Mark set"))))
2078
2079 (defun calendar-exchange-point-and-mark ()
2080 "Exchange the current cursor position with the marked date."
2081 (interactive)
2082 (let ((mark (car calendar-mark-ring))
2083 (date (calendar-cursor-to-date t)))
2084 (if (null mark)
2085 (error "No mark set in this buffer")
2086 (setq calendar-mark-ring (cons date (cdr calendar-mark-ring)))
2087 (calendar-goto-date mark))))
2088
2089 (defun calendar-count-days-region ()
2090 "Count the number of days (inclusive) between point and the mark."
2091 (interactive)
2092 (let* ((days (- (calendar-absolute-from-gregorian
2093 (calendar-cursor-to-date t))
2094 (calendar-absolute-from-gregorian
2095 (or (car calendar-mark-ring)
2096 (error "No mark set in this buffer")))))
2097 (days (1+ (if (> days 0) days (- days)))))
2098 (message "Region has %d day%s (inclusive)"
2099 days (if (> days 1) "s" ""))))
2100
2101 (defun calendar-not-implemented ()
2102 "Not implemented."
2103 (interactive)
2104 (error "%s not available in the calendar"
2105 (global-key-binding (this-command-keys))))
2106
2107 (defun calendar-read (prompt acceptable &optional initial-contents)
2108 "Return an object read from the minibuffer.
2109 Prompt with the string PROMPT and use the function ACCEPTABLE to decide if
2110 entered item is acceptable. If non-nil, optional third arg INITIAL-CONTENTS
2111 is a string to insert in the minibuffer before reading."
2112 (let ((value (read-minibuffer prompt initial-contents)))
2113 (while (not (funcall acceptable value))
2114 (setq value (read-minibuffer prompt initial-contents)))
2115 value))
2116
2117
2118 (defun calendar-customized-p (symbol)
2119 "Return non-nil if SYMBOL has been customized."
2120 (and (default-boundp symbol)
2121 (let ((standard (get symbol 'standard-value)))
2122 (and standard
2123 (not (equal (eval (car standard)) (default-value symbol)))))))
2124
2125 (defun calendar-abbrev-construct (full &optional maxlen)
2126 "From sequence FULL, return a vector of abbreviations.
2127 Each abbreviation is no longer than MAXLEN (default `calendar-abbrev-length')
2128 characters."
2129 (or maxlen (setq maxlen calendar-abbrev-length))
2130 (apply 'vector (mapcar
2131 (lambda (f)
2132 ;; TODO? truncate-string-to-width?
2133 (substring f 0 (min maxlen (length f))))
2134 full)))
2135
2136 (defcustom calendar-day-name-array
2137 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
2138 "Array of capitalized strings giving, in order from Sunday, the day names.
2139 If you change this without using customize after the calendar has loaded,
2140 then you may also want to change `calendar-day-abbrev-array'
2141 and `calendar-day-header-array'."
2142 :group 'calendar
2143 :initialize 'custom-initialize-default
2144 :set (lambda (symbol value)
2145 (let ((dcustomized (calendar-customized-p 'calendar-day-abbrev-array))
2146 (hcustomized (calendar-customized-p 'cal-html-day-abbrev-array))
2147 (ccustomized (calendar-customized-p 'calendar-day-header-array)))
2148 (set symbol value)
2149 (or dcustomized
2150 (setq calendar-day-abbrev-array
2151 (calendar-abbrev-construct calendar-day-name-array)))
2152 (and (not hcustomized)
2153 (boundp 'cal-html-day-abbrev-array)
2154 (setq cal-html-day-abbrev-array calendar-day-abbrev-array))
2155 (or ccustomized
2156 (equal calendar-day-header-array
2157 (setq calendar-day-header-array
2158 (calendar-day-header-construct)))
2159 (calendar-redraw))))
2160 :type '(vector (string :tag "Sunday")
2161 (string :tag "Monday")
2162 (string :tag "Tuesday")
2163 (string :tag "Wednesday")
2164 (string :tag "Thursday")
2165 (string :tag "Friday")
2166 (string :tag "Saturday")))
2167
2168 (defcustom calendar-abbrev-length 3
2169 "Default length of abbreviations to use for day and month names.
2170 If you change this without using customize after the calendar has loaded,
2171 then you may also want to change `calendar-day-abbrev-array' and
2172 `calendar-month-abbrev-array'."
2173 :group 'calendar
2174 :initialize 'custom-initialize-default
2175 :set (lambda (symbol value)
2176 (let ((dcustomized (calendar-customized-p 'calendar-day-abbrev-array))
2177 (mcustomized (calendar-customized-p
2178 'calendar-month-abbrev-array))
2179 (hcustomized (calendar-customized-p 'cal-html-day-abbrev-array))
2180 (ccustomized (calendar-customized-p 'calendar-day-header-array)))
2181 (set symbol value)
2182 (or dcustomized
2183 (setq calendar-day-abbrev-array
2184 (calendar-abbrev-construct calendar-day-name-array)))
2185 (or mcustomized
2186 (setq calendar-month-abbrev-array
2187 (calendar-abbrev-construct calendar-month-name-array)))
2188 (and (not hcustomized)
2189 (boundp 'cal-html-day-abbrev-array)
2190 (setq cal-html-day-abbrev-array calendar-day-abbrev-array))
2191 (or ccustomized
2192 (equal calendar-day-header-array
2193 (setq calendar-day-header-array
2194 (calendar-day-header-construct)))
2195 (calendar-redraw))))
2196 :type 'integer)
2197
2198 (defcustom calendar-day-abbrev-array
2199 (calendar-abbrev-construct calendar-day-name-array)
2200 "Array of capitalized strings giving the abbreviated day names.
2201 The order should be the same as that of the full names specified
2202 in `calendar-day-name-array'. These abbreviations may be used
2203 instead of the full names in the diary file. Do not include a
2204 trailing `.' in the strings specified in this variable, though
2205 you may use such in the diary file. By default, each string is
2206 the first `calendar-abbrev-length' characters of the corresponding
2207 full name."
2208 :group 'calendar
2209 :initialize 'custom-initialize-default
2210 :set-after '(calendar-abbrev-length calendar-day-name-array)
2211 :set (lambda (symbol value)
2212 (let ((hcustomized (calendar-customized-p 'cal-html-day-abbrev-array))
2213 (ccustomized (calendar-customized-p 'calendar-day-header-array)))
2214 (set symbol value)
2215 (and (not hcustomized)
2216 (boundp 'cal-html-day-abbrev-array)
2217 (setq cal-html-day-abbrev-array calendar-day-abbrev-array))
2218 (or ccustomized
2219 (equal calendar-day-header-array
2220 (setq calendar-day-header-array
2221 (calendar-day-header-construct)))
2222 (calendar-redraw))))
2223 :type '(vector (string :tag "Sun")
2224 (string :tag "Mon")
2225 (string :tag "Tue")
2226 (string :tag "Wed")
2227 (string :tag "Thu")
2228 (string :tag "Fri")
2229 (string :tag "Sat"))
2230 ;; Made defcustom, changed defaults from nil nil...
2231 :version "24.1")
2232
2233 (defcustom calendar-day-header-array (calendar-day-header-construct)
2234 "Array of strings to use for the headers of the calendar's day columns.
2235 The order should be the same as in `calendar-day-name-array'.
2236 In use, the calendar truncates elements to no more than
2237 `calendar-day-header-width' columns wide.
2238 Emacs constructs the default from either `calendar-day-name-array'
2239 \(if `calendar-day-header-width' is more than `calendar-abbrev-length'),
2240 or from `calendar-day-abbrev-array' (assuming that the abbreviated
2241 name are more likely to be unique when truncated)."
2242 :group 'calendar
2243 :initialize 'custom-initialize-default
2244 :set-after '(calendar-day-header-width
2245 calendar-abbrev-length calendar-day-name-array
2246 calendar-day-abbrev-array)
2247 :set (lambda (symbol value)
2248 (or (equal calendar-day-header-array
2249 (set symbol value))
2250 (calendar-redraw)))
2251 :type '(vector (string :tag "Su")
2252 (string :tag "Mo")
2253 (string :tag "Tu")
2254 (string :tag "We")
2255 (string :tag "Th")
2256 (string :tag "Fr")
2257 (string :tag "Sa"))
2258 :version "24.4")
2259
2260 (defcustom calendar-month-name-array
2261 ["January" "February" "March" "April" "May" "June"
2262 "July" "August" "September" "October" "November" "December"]
2263 "Array of capitalized strings giving, in order, the month names.
2264 If you change this without using customize after the calendar has loaded,
2265 then you may also want to change `calendar-month-abbrev-array'."
2266 :group 'calendar
2267 :initialize 'custom-initialize-default
2268 :set (lambda (symbol value)
2269 (let ((mcustomized (calendar-customized-p
2270 'calendar-month-abbrev-array)))
2271 (set symbol value)
2272 (or mcustomized
2273 (setq calendar-month-abbrev-array
2274 (calendar-abbrev-construct calendar-month-name-array)))))
2275 :type '(vector (string :tag "January")
2276 (string :tag "February")
2277 (string :tag "March")
2278 (string :tag "April")
2279 (string :tag "May")
2280 (string :tag "June")
2281 (string :tag "July")
2282 (string :tag "August")
2283 (string :tag "September")
2284 (string :tag "October")
2285 (string :tag "November")
2286 (string :tag "December")))
2287
2288 (defcustom calendar-month-abbrev-array
2289 (calendar-abbrev-construct calendar-month-name-array)
2290 "Array of capitalized strings giving the abbreviated month names.
2291 The order should be the same as that of the full names specified
2292 in `calendar-month-name-array'. These abbreviations are used in
2293 the calendar menu entries, and can also be used in the diary
2294 file. Do not include a trailing `.' in the strings specified in
2295 this variable, though you may use such in the diary file. By
2296 default, each string is the first ``calendar-abbrev-length'
2297 characters of the corresponding full name."
2298 :group 'calendar
2299 :set-after '(calendar-abbrev-length calendar-month-name-array)
2300 :type '(vector (string :tag "Jan")
2301 (string :tag "Feb")
2302 (string :tag "Mar")
2303 (string :tag "Apr")
2304 (string :tag "May")
2305 (string :tag "Jun")
2306 (string :tag "Jul")
2307 (string :tag "Aug")
2308 (string :tag "Sep")
2309 (string :tag "Oct")
2310 (string :tag "Nov")
2311 (string :tag "Dec"))
2312 ;; Made defcustom, changed defaults from nil nil...
2313 :version "24.1")
2314
2315 (defun calendar-make-alist (sequence &optional start-index filter
2316 &rest sequences)
2317 "Return an association list corresponding to SEQUENCE.
2318 Associates each element of SEQUENCE with an incremented integer,
2319 starting from START-INDEX (default 1). Applies the function FILTER,
2320 if provided, to each key in the alist. Repeats the process, with
2321 indices starting from START-INDEX each time, for any remaining
2322 arguments SEQUENCES."
2323 (or start-index (setq start-index 1))
2324 (let (index alist)
2325 (mapc (lambda (seq)
2326 (setq index start-index)
2327 (mapc (lambda (elem)
2328 (setq alist (cons
2329 (cons (if filter (funcall filter elem) elem)
2330 index)
2331 alist)
2332 index (1+ index)))
2333 seq))
2334 (append (list sequence) sequences))
2335 (reverse alist)))
2336
2337 (defun calendar-read-date (&optional noday)
2338 "Prompt for Gregorian date. Return a list (month day year).
2339 If optional NODAY is t, does not ask for day, but just returns
2340 \(month 1 year); if NODAY is any other non-nil value the value returned is
2341 \(month year)"
2342 (let* ((year (calendar-read
2343 "Year (>0): "
2344 (lambda (x) (> x 0))
2345 (number-to-string (calendar-extract-year
2346 (calendar-current-date)))))
2347 (month-array calendar-month-name-array)
2348 (completion-ignore-case t)
2349 (month (cdr (assoc-string
2350 (completing-read
2351 "Month name: "
2352 (mapcar 'list (append month-array nil))
2353 nil t)
2354 (calendar-make-alist month-array 1) t)))
2355 (last (calendar-last-day-of-month month year)))
2356 (if noday
2357 (if (eq noday t)
2358 (list month 1 year)
2359 (list month year))
2360 (list month
2361 (calendar-read (format "Day (1-%d): " last)
2362 (lambda (x) (and (< 0 x) (<= x last))))
2363 year))))
2364
2365 (defun calendar-interval (mon1 yr1 mon2 yr2)
2366 "The number of months difference between MON1, YR1 and MON2, YR2.
2367 The result is positive if the second date is later than the first.
2368 Negative years are interpreted as years BC; -1 being 1 BC, and so on."
2369 (if (< yr1 0) (setq yr1 (1+ yr1))) ; -1 BC -> 0 AD, etc
2370 (if (< yr2 0) (setq yr2 (1+ yr2)))
2371 (+ (* 12 (- yr2 yr1))
2372 (- mon2 mon1)))
2373
2374 (defvar calendar-font-lock-keywords nil
2375 "Default keywords to highlight in Calendar mode.")
2376
2377 (make-obsolete-variable 'calendar-font-lock-keywords
2378 "set font-lock keywords in `calendar-mode-hook', \
2379 or customize calendar faces." "24.4")
2380
2381 (defun calendar-day-name (date &optional abbrev absolute)
2382 "Return a string with the name of the day of the week of DATE.
2383 DATE should be a list in the format (MONTH DAY YEAR), unless the
2384 optional argument ABSOLUTE is non-nil, in which case DATE should
2385 be an integer in the range 0 to 6 corresponding to the day of the
2386 week. Day names are taken from the variable `calendar-day-name-array',
2387 unless the optional argument ABBREV is non-nil:
2388 `header' means to use `calendar-day-header-array';
2389 t to use `calendar-day-abbrev-array'."
2390 (aref (cond ((eq abbrev 'header) calendar-day-header-array)
2391 (abbrev calendar-day-abbrev-array)
2392 (t calendar-day-name-array))
2393 (if absolute date (calendar-day-of-week date))))
2394
2395 (defun calendar-month-name (month &optional abbrev)
2396 "Return a string with the name of month number MONTH.
2397 Months are numbered from one. Month names are taken from the
2398 variable `calendar-month-name-array', unless the optional
2399 argument ABBREV is non-nil, in which case
2400 `calendar-month-abbrev-array' is used."
2401 (aref (if abbrev calendar-month-abbrev-array calendar-month-name-array)
2402 (1- month)))
2403
2404 (defun calendar-day-of-week (date)
2405 "Return the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc.
2406 DATE is a list of the form (month day year). A negative year is
2407 interpreted as BC; -1 being 1 BC, and so on."
2408 (mod (calendar-absolute-from-gregorian date) 7))
2409
2410 (defun calendar-week-end-day ()
2411 "Return the index (0 for Sunday, etc.) of the last day of the week."
2412 (mod (+ calendar-week-start-day 6) 7))
2413
2414 (defun calendar-unmark ()
2415 "Delete all diary/holiday marks/highlighting from the calendar."
2416 (interactive)
2417 (setq calendar-mark-holidays-flag nil
2418 calendar-mark-diary-entries-flag nil)
2419 (with-current-buffer calendar-buffer
2420 (mapc 'delete-overlay (overlays-in (point-min) (point-max)))))
2421
2422 (defun calendar-date-is-visible-p (date)
2423 "Return non-nil if DATE is valid and is visible in the calendar window."
2424 (and (calendar-date-is-valid-p date)
2425 (< (abs (calendar-interval
2426 displayed-month displayed-year
2427 (calendar-extract-month date) (calendar-extract-year date)))
2428 2)))
2429
2430 ;; FIXME can this be generalized for holiday-chinese?
2431 (defun calendar-nongregorian-visible-p (month day toabs fromabs switch)
2432 "Return non-nil if MONTH, DAY is visible in the calendar window.
2433 MONTH and DAY are in some non-Gregorian calendar system. The
2434 functions TOABS and FROMABS convert that system to and from
2435 absolute, respectively. SWITCH is a function that takes a single
2436 argument (a local month number). It applies when the local year
2437 changes across the calendar window, and returns non-nil if the
2438 specified month should be associated with the higher year.
2439 Returns the corresponding Gregorian date."
2440 ;; We need to choose the local year associated with month and day
2441 ;; that might make them visible.
2442 (let* ((m1 displayed-month)
2443 (y1 displayed-year)
2444 (m2 displayed-month)
2445 (y2 displayed-year)
2446 ;; Absolute date of first/last dates in calendar window.
2447 (start-date (progn
2448 (calendar-increment-month m1 y1 -1)
2449 (calendar-absolute-from-gregorian (list m1 1 y1))))
2450 (end-date (progn
2451 (calendar-increment-month m2 y2 1)
2452 (calendar-absolute-from-gregorian
2453 (list m2 (calendar-last-day-of-month m2 y2) y2))))
2454 ;; Local date of first/last date in calendar window.
2455 (local-start (funcall fromabs start-date))
2456 (local-end (funcall fromabs end-date))
2457 ;; Local year of first/last dates.
2458 ;; Can only differ if displayed-month = 12, 1, 2.
2459 (local-y1 (calendar-extract-year local-start))
2460 (local-y2 (calendar-extract-year local-end))
2461 ;; Choose which year might be visible in the window.
2462 ;; Obviously it only matters when y1 and y2 differ, ie
2463 ;; when the _local_ new year is visible.
2464 (year (if (funcall switch month) local-y2 local-y1))
2465 (date (calendar-gregorian-from-absolute
2466 (funcall toabs (list month day year)))))
2467 (if (calendar-date-is-visible-p date)
2468 date)))
2469
2470 (defun calendar-date-is-valid-p (date)
2471 "Return t if DATE is a valid date."
2472 (let ((month (calendar-extract-month date))
2473 (day (calendar-extract-day date))
2474 (year (calendar-extract-year date)))
2475 (and (<= 1 month) (<= month 12)
2476 ;; (calendar-read-date t) used to return a date with day = nil.
2477 ;; Should not be valid (?), since many funcs prob assume integer.
2478 ;; (calendar-read-date 'noday) returns (month year), which
2479 ;; currently results in calendar-extract-year returning nil.
2480 day year (<= 1 day) (<= day (calendar-last-day-of-month month year))
2481 ;; BC dates left as non-valid, to suppress errors from
2482 ;; complex holiday algorithms not suitable for years BC.
2483 ;; Note there are side effects on calendar navigation.
2484 (<= 1 year))))
2485
2486 (define-obsolete-function-alias 'calendar-date-is-legal-p
2487 'calendar-date-is-valid-p "23.1")
2488
2489 (defun calendar-date-equal (date1 date2)
2490 "Return t if the DATE1 and DATE2 are the same."
2491 (and
2492 (= (calendar-extract-month date1) (calendar-extract-month date2))
2493 (= (calendar-extract-day date1) (calendar-extract-day date2))
2494 (= (calendar-extract-year date1) (calendar-extract-year date2))))
2495
2496 (defun calendar-make-temp-face (attrlist)
2497 "Return a temporary face based on the attributes in ATTRLIST.
2498 ATTRLIST is a list with elements of the form :face face :foreground color."
2499 (let ((attrs attrlist)
2500 faceinfo face temp-face)
2501 ;; Separate :face from the other attributes. Use the last :face
2502 ;; if there are more than one. FIXME is merging meaningful?
2503 (while attrs
2504 (if (eq (car attrs) :face)
2505 (setq face (intern-soft (cadr attrs))
2506 attrs (cddr attrs))
2507 (push (car attrs) faceinfo)
2508 (setq attrs (cdr attrs))))
2509 (or (facep face) (setq face 'default))
2510 (if (not faceinfo)
2511 ;; No attributes to apply, so just use an existing-face.
2512 face
2513 ;; FIXME should we be using numbered temp-faces, re-using where poss?
2514 (setq temp-face
2515 (make-symbol
2516 (concat ":caltemp"
2517 (mapconcat (lambda (sym)
2518 (cond
2519 ((symbolp sym) (symbol-name sym))
2520 ((numberp sym) (number-to-string sym))
2521 (t sym)))
2522 attrlist ""))))
2523 (make-face temp-face)
2524 (copy-face face temp-face)
2525 ;; Apply the font aspects.
2526 (apply 'set-face-attribute temp-face nil (nreverse faceinfo))
2527 temp-face)))
2528
2529 (defun calendar-mark-visible-date (date &optional mark)
2530 "Mark DATE in the calendar window with MARK.
2531 MARK is a single-character string, a list of face attributes/values, or a face.
2532 MARK defaults to `diary-entry-marker'."
2533 (if (calendar-date-is-valid-p date)
2534 (with-current-buffer calendar-buffer
2535 (save-excursion
2536 (calendar-cursor-to-visible-date date)
2537 (setq mark
2538 (or (and (stringp mark) (= (length mark) 1) mark) ; single-char
2539 ;; The next two use to also check font-lock-mode.
2540 ;; See comments above diary-entry-marker for why
2541 ;; this was dropped.
2542 ;;; (and font-lock-mode
2543 ;;; (or
2544 (and (listp mark) (> (length mark) 0) mark) ; attrs
2545 (and (facep mark) mark) ; )) face-name
2546 diary-entry-marker))
2547 (cond
2548 ;; Face or an attr-list that contained a face.
2549 ((facep mark)
2550 (overlay-put
2551 (make-overlay (1- (point)) (1+ (point))) 'face mark))
2552 ;; Single-character mark, goes after the date.
2553 ((and (stringp mark) (= (length mark) 1))
2554 (overlay-put
2555 (make-overlay (1+ (point)) (+ 2 (point))) 'display mark))
2556 (t ; attr list
2557 (overlay-put
2558 (make-overlay (1- (point)) (1+ (point))) 'face
2559 (calendar-make-temp-face mark))))))))
2560
2561 (define-obsolete-function-alias 'mark-visible-calendar-date
2562 'calendar-mark-visible-date "23.1")
2563
2564 (defun calendar-star-date ()
2565 "Replace the date under the cursor in the calendar window with asterisks.
2566 You might want to add this function to `calendar-today-visible-hook'."
2567 (unless (catch 'found
2568 (dolist (ol (overlays-at (point)))
2569 (and (overlay-get ol 'calendar-star)
2570 (throw 'found t))))
2571 (let ((ol (make-overlay (1- (point)) (point))))
2572 (overlay-put ol 'display "*")
2573 (overlay-put ol 'calendar-star t)
2574 ;; Use copy-sequence to avoid merging of identical 'display props.
2575 ;; Use two overlays so as not to mess up
2576 ;; calendar-cursor-to-nearest-date (and calendar-forward-day).
2577 (overlay-put (setq ol (make-overlay (point) (1+ (point))))
2578 'display (copy-sequence "*"))
2579 (overlay-put ol 'calendar-star t))))
2580
2581 (defun calendar-mark-today ()
2582 "Mark the date under the cursor in the calendar window.
2583 The date is marked with `calendar-today-marker'. You might want to add
2584 this function to `calendar-today-visible-hook'."
2585 (calendar-mark-visible-date (calendar-cursor-to-date) calendar-today-marker))
2586
2587 ;; FIXME why the car? Almost every usage calls list on the args.
2588 (defun calendar-date-compare (date1 date2)
2589 "Return t if DATE1 is before DATE2, nil otherwise.
2590 The actual dates are in the car of DATE1 and DATE2."
2591 (< (calendar-absolute-from-gregorian (car date1))
2592 (calendar-absolute-from-gregorian (car date2))))
2593
2594 (defun calendar-date-string (date &optional abbreviate nodayname)
2595 "A string form of DATE, driven by the variable `calendar-date-display-form'.
2596 An optional parameter ABBREVIATE, when non-nil, causes the month
2597 and day names to be abbreviated as specified by
2598 `calendar-month-abbrev-array' and `calendar-day-abbrev-array',
2599 respectively. An optional parameter NODAYNAME, when t, omits the
2600 name of the day of the week."
2601 (let* ((dayname (unless nodayname (calendar-day-name date abbreviate)))
2602 (month (calendar-extract-month date))
2603 (monthname (calendar-month-name month abbreviate))
2604 (day (number-to-string (calendar-extract-day date)))
2605 (month (number-to-string month))
2606 (year (number-to-string (calendar-extract-year date))))
2607 (mapconcat 'eval calendar-date-display-form "")))
2608
2609 (defun calendar-dayname-on-or-before (dayname date)
2610 "Return the absolute date of the DAYNAME on or before absolute DATE.
2611 DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
2612
2613 Note: Applying this function to d+6 gives us the DAYNAME on or after an
2614 absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
2615 absolute date d, applying it to d-1 gives the DAYNAME previous to absolute
2616 date d, and applying it to d+7 gives the DAYNAME following absolute date d."
2617 (- date (% (- date dayname) 7)))
2618
2619 (defun calendar-nth-named-absday (n dayname month year &optional day)
2620 "Absolute date of the Nth DAYNAME after/before MONTH YEAR DAY.
2621 A DAYNAME of 0 means Sunday, 1 means Monday, and so on.
2622 If N>0, return the Nth DAYNAME after MONTH DAY, YEAR (inclusive).
2623 If N<0, return the Nth DAYNAME before MONTH DAY, YEAR (inclusive).
2624 DAY defaults to 1 if N>0, and MONTH's last day otherwise."
2625 (if (> n 0)
2626 (+ (* 7 (1- n))
2627 (calendar-dayname-on-or-before
2628 dayname
2629 (+ 6 (calendar-absolute-from-gregorian
2630 (list month (or day 1) year)))))
2631 (+ (* 7 (1+ n))
2632 (calendar-dayname-on-or-before
2633 dayname
2634 (calendar-absolute-from-gregorian
2635 (list month
2636 (or day (calendar-last-day-of-month month year))
2637 year))))))
2638
2639 (defun calendar-nth-named-day (n dayname month year &optional day)
2640 "Date of the Nth DAYNAME after/before MONTH YEAR DAY.
2641 Like `calendar-nth-named-absday', but returns a Gregorian date."
2642 (calendar-gregorian-from-absolute
2643 (calendar-nth-named-absday n dayname month year day)))
2644
2645 (defun calendar-day-of-year-string (&optional date)
2646 "String of day number of year of Gregorian DATE.
2647 Defaults to today's date if DATE is not given."
2648 (let* ((d (or date (calendar-current-date)))
2649 (year (calendar-extract-year d))
2650 (day (calendar-day-number d))
2651 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
2652 (format "Day %d of %d; %d day%s remaining in the year"
2653 day year days-remaining (if (= days-remaining 1) "" "s"))))
2654
2655 (defun calendar-other-dates (date)
2656 "Return a list of strings giving Gregorian DATE in other calendars.
2657 DATE is (month day year). Calendars that do not apply are omitted."
2658 (let (odate)
2659 (delq nil
2660 (list
2661 (calendar-day-of-year-string date)
2662 (format "ISO date: %s" (calendar-iso-date-string date))
2663 (format "Julian date: %s"
2664 (calendar-julian-date-string date))
2665 (format "Astronomical (Julian) day number (at noon UTC): %s.0"
2666 (calendar-astro-date-string date))
2667 (format "Fixed (RD) date: %s"
2668 (calendar-absolute-from-gregorian date))
2669 (format "Hebrew date (before sunset): %s"
2670 (calendar-hebrew-date-string date))
2671 (format "Persian date: %s"
2672 (calendar-persian-date-string date))
2673 (unless (string-equal
2674 (setq odate (calendar-islamic-date-string date))
2675 "")
2676 (format "Islamic date (before sunset): %s" odate))
2677 (unless (string-equal
2678 (setq odate (calendar-bahai-date-string date))
2679 "")
2680 (format "Bahá'í date: %s" odate))
2681 (format "Chinese date: %s"
2682 (calendar-chinese-date-string date))
2683 (unless (string-equal
2684 (setq odate (calendar-coptic-date-string date))
2685 "")
2686 (format "Coptic date: %s" odate))
2687 (unless (string-equal
2688 (setq odate (calendar-ethiopic-date-string date))
2689 "")
2690 (format "Ethiopic date: %s" odate))
2691 (unless (string-equal
2692 (setq odate (calendar-french-date-string date))
2693 "")
2694 (format "French Revolutionary date: %s" odate))
2695 (format "Mayan date: %s"
2696 (calendar-mayan-date-string date))))))
2697
2698 (declare-function x-popup-menu "menu.c" (position menu))
2699
2700 (defun calendar-print-other-dates (&optional event)
2701 "Show dates on other calendars for date under the cursor.
2702 If called by a mouse-event, pops up a menu with the result."
2703 (interactive (list last-nonmenu-event))
2704 (let* ((date (calendar-cursor-to-date t event))
2705 (title (format "%s (Gregorian)" (calendar-date-string date)))
2706 (others (calendar-other-dates date))
2707 selection)
2708 (if (mouse-event-p event)
2709 (and (setq selection (cal-menu-x-popup-menu event title
2710 (mapcar 'list others)))
2711 (call-interactively selection))
2712 (calendar-in-read-only-buffer calendar-other-calendars-buffer
2713 (calendar-set-mode-line title)
2714 (insert (mapconcat 'identity others "\n"))))))
2715
2716 (defun calendar-print-day-of-year ()
2717 "Show day number in year/days remaining in year for date under the cursor."
2718 (interactive)
2719 (message "%s" (calendar-day-of-year-string (calendar-cursor-to-date t))))
2720
2721 (defun calendar-set-mode-line (str)
2722 "Set mode line to STR, centered, surrounded by dashes."
2723 (let* ((edges (window-edges))
2724 ;; As per doc of window-width, total visible mode-line length.
2725 (width (- (nth 2 edges) (car edges))))
2726 ;; Hack for --daemon. See bug #2199.
2727 ;; If no frame exists yet, we have no idea what width to use.
2728 (and (= width 10)
2729 (not window-system)
2730 (setq width (string-to-number (or (getenv "COLUMNS") "80"))))
2731 (setq mode-line-format
2732 (if buffer-file-name
2733 `("-" mode-line-modified
2734 ,(calendar-string-spread (list str) ?- (- width 6))
2735 "---")
2736 (calendar-string-spread (list str) ?- width)))))
2737
2738 (define-obsolete-function-alias 'calendar-version 'emacs-version "23.1")
2739
2740 (run-hooks 'calendar-load-hook)
2741
2742 (provide 'calendar)
2743
2744 ;; Local variables:
2745 ;; byte-compile-dynamic: t
2746 ;; coding: utf-8
2747 ;; End:
2748
2749 ;;; calendar.el ends here