calendar.el 121 KB
Newer Older
1
;;; calendar.el --- calendar functions
Eric S. Raymond's avatar
Eric S. Raymond committed
2

3
;; Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1997,
4
;;   2000, 2001, 2002, 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
Eric S. Raymond's avatar
Eric S. Raymond committed
5

Eric S. Raymond's avatar
Eric S. Raymond committed
6
;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7
;; Maintainer: Glenn Morris <rgm@gnu.org>
Eric S. Raymond's avatar
Eric S. Raymond committed
8
;; Keywords: calendar
9
;; Human-Keywords: calendar, Gregorian calendar, diary, holidays
Eric S. Raymond's avatar
Eric S. Raymond committed
10

Richard M. Stallman's avatar
Richard M. Stallman committed
11 12
;; This file is part of GNU Emacs.

Richard M. Stallman's avatar
Richard M. Stallman committed
13 14 15 16 17
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

Richard M. Stallman's avatar
Richard M. Stallman committed
18
;; GNU Emacs is distributed in the hope that it will be useful,
Richard M. Stallman's avatar
Richard M. Stallman committed
19 20 21 22 23
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
Erik Naggum's avatar
Erik Naggum committed
24
;; along with GNU Emacs; see the file COPYING.  If not, write to the
Lute Kamstra's avatar
Lute Kamstra committed
25 26
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
Richard M. Stallman's avatar
Richard M. Stallman committed
27

Eric S. Raymond's avatar
Eric S. Raymond committed
28 29
;;; Commentary:

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
;; This collection of functions implements a calendar window.  It
;; generates a calendar for the current month, together with the
;; previous and coming months, or for any other three-month period.
;; The calendar can be scrolled forward and backward in the window to
;; show months in the past or future; the cursor can move forward and
;; backward by days, weeks, or months, making it possible, for
;; instance, to jump to the date a specified number of days, weeks, or
;; months from the date under the cursor.  The user can display a list
;; of holidays and other notable days for the period shown; the
;; notable days can be marked on the calendar, if desired.  The user
;; can also specify that dates having corresponding diary entries (in
;; a file that the user specifies) be marked; the diary entries for
;; any date can be viewed in a separate window.  The diary and the
;; notable days can be viewed independently of the calendar.  Dates
;; can be translated from the (usual) Gregorian calendar to the day of
;; the year/days remaining in year, to the ISO commercial calendar, to
;; the Julian (old style) calendar, to the Hebrew calendar, to the
;; Islamic calendar, to the Baha'i calendar, to the French
;; Revolutionary calendar, to the Mayan calendar, to the Chinese
;; calendar, to the Coptic calendar, to the Ethiopic calendar, and to
;; the astronomical (Julian) day number.  When floating point is
;; available, times of sunrise/sunset can be displayed, as can the
;; phases of the moon.  Appointment notification for diary entries is
53
;; available.  Calendar printing via LaTeX is available.
Jim Blandy's avatar
Jim Blandy committed
54 55 56

;; The following files are part of the calendar/diary code:

57
;;       appt.el                       Appointment notification
58
;;       cal-china.el                  Chinese calendar
59 60 61
;;       cal-coptic.el                 Coptic/Ethiopic calendars
;;       cal-dst.el                    Daylight savings time rules
;;       cal-hebrew.el                 Hebrew calendar
62
;;       cal-islam.el                  Islamic calendar
63
;;       cal-bahai.el                  Baha'i calendar
64 65 66
;;       cal-iso.el                    ISO calendar
;;       cal-julian.el                 Julian/astronomical calendars
;;       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                      X-windows dedicated frame functions
Richard M. Stallman's avatar
Richard M. Stallman committed
72
;;       diary-lib.el                  Diary functions
Jim Blandy's avatar
Jim Blandy committed
73 74
;;       holidays.el                   Holiday functions
;;       lunar.el                      Phases of the moon
75
;;       solar.el                      Sunrise/sunset, equinoxes/solstices
Richard M. Stallman's avatar
Richard M. Stallman committed
76 77

;; Technical details of all the calendrical calculations can be found in
78 79
;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
;; and Nachum Dershowitz, Cambridge University Press (2001).
Jim Blandy's avatar
Jim Blandy committed
80

81
;; An earlier version of the technical details appeared in
Richard M. Stallman's avatar
Richard M. Stallman committed
82 83
;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
84
;; pages 899-928, and in ``Calendrical Calculations, Part II: Three Historical
Jim Blandy's avatar
Jim Blandy committed
85
;; Calendars'' by E. M. Reingold,  N. Dershowitz, and S. M. Clamen,
86 87
;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
;; pages 383-404.
Jim Blandy's avatar
Jim Blandy committed
88 89 90 91

;; Hard copies of these two papers can be obtained by sending email to
;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
;; the message BODY containing your mailing address (snail).
Richard M. Stallman's avatar
Richard M. Stallman committed
92

93 94 95 96 97 98
;; Comments, corrections, and improvements should be sent to
;;  Edward M. Reingold               Department of Computer Science
;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
;;                                   Urbana, Illinois 61801

Eric S. Raymond's avatar
Eric S. Raymond committed
99
;;; Code:
Richard M. Stallman's avatar
Richard M. Stallman committed
100

101 102 103 104
(defvar displayed-month)
(defvar displayed-year)
(defvar calendar-month-name-array)
(defvar calendar-starred-day)
105

Richard M. Stallman's avatar
Richard M. Stallman committed
106 107
(defun calendar-version ()
  (interactive)
108
  (message "Version 6, October 12, 1995"))
Richard M. Stallman's avatar
Richard M. Stallman committed
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
(defgroup calendar nil
  "Calendar and time management support."
  :group 'applications)

(defgroup diary nil
  "Emacs diary."
  :group 'calendar)

(defgroup appt nil
  "Appointment notification."
  :group 'calendar)

(defgroup holidays nil
  "Holidays support in calendar."
  :group 'calendar
  :prefix "calendar-"
  :group 'local)

(defgroup chinese-calendar nil
  "Chinese calendar support."
  :group 'calendar)

(defgroup calendar-tex nil
  "Options for printing calendar with LaTeX."
  :prefix "cal-tex-"
  :group 'calendar)

(defgroup calendar-hooks nil
  "Calendar hooks."
  :prefix "calendar-"
  :group 'calendar)


143 144 145
(defconst calendar-buffer "*Calendar*"
  "Name of the buffer used for the calendar.")

146
;;;###autoload
147
(defcustom calendar-offset 0
148
  "The offset of the principal month from the center of the calendar window.
149 150
0 means the principal month is in the center (default), -1 means on the left,
+1 means on the right.  Larger (or smaller) values push the principal month off
151 152 153
the screen."
  :type 'integer
  :group 'calendar)
154

Jim Blandy's avatar
Jim Blandy committed
155
;;;###autoload
156
(defcustom view-diary-entries-initially nil
157
  "Non-nil means display current date's diary entries on entry to calendar.
Richard M. Stallman's avatar
Richard M. Stallman committed
158 159
The diary is displayed in another window when the calendar is first displayed,
if the current date is visible.  The number of days of diary entries displayed
Glenn Morris's avatar
Glenn Morris committed
160 161
is governed by the variable `number-of-diary-entries'.  This variable can
be overridden by the value of `calendar-setup'."
162 163
  :type 'boolean
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
164

Jim Blandy's avatar
Jim Blandy committed
165
;;;###autoload
166
(defcustom mark-diary-entries-in-calendar nil
167
  "Non-nil means mark dates with diary entries, in the calendar window.
168 169 170
The marking symbol is specified by the variable `diary-entry-marker'."
  :type 'boolean
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
171

172 173
;;;###autoload
(defcustom calendar-remove-frame-by-deleting nil
174
  "Determine how the calendar mode removes a frame no longer needed.
175 176 177 178
If nil, make an icon of the frame.  If non-nil, delete the frame."
  :type 'boolean
  :group 'view)

179
(defvar diary-face 'diary
180
  "Face name to use for diary entries.")
181
(defface diary
182 183 184
  '((((min-colors 88) (class color) (background light))
     :foreground "red1")
    (((class color) (background light))
ShengHuo ZHU's avatar
ShengHuo ZHU committed
185
     :foreground "red")
186 187
    (((min-colors 88) (class color) (background dark))
     :foreground "yellow1")
188
    (((class color) (background dark))
ShengHuo ZHU's avatar
ShengHuo ZHU committed
189
     :foreground "yellow")
190
    (t
191
     :weight bold))
192 193
  "Face for highlighting diary entries."
  :group 'diary)
194 195
;; backward-compatibility alias
(put 'diary-face 'face-alias 'diary)
196

197
(defface calendar-today
198 199 200
  '((t (:underline t)))
  "Face for indicating today's date."
  :group 'diary)
201 202
;; backward-compatibility alias
(put 'calendar-today-face 'face-alias 'calendar-today)
203

204
(defface holiday
205
  '((((class color) (background light))
ShengHuo ZHU's avatar
ShengHuo ZHU committed
206
     :background "pink")
207
    (((class color) (background dark))
ShengHuo ZHU's avatar
ShengHuo ZHU committed
208
     :background "chocolate4")
209
    (t
ShengHuo ZHU's avatar
ShengHuo ZHU committed
210
     :inverse-video t))
211 212
  "Face for indicating dates that have holidays."
  :group 'diary)
213 214
;; backward-compatibility alias
(put 'holiday-face 'face-alias 'holiday)
215

216 217
(eval-after-load "facemenu"
  '(progn
218 219 220
     (add-to-list 'facemenu-unlisted-faces 'diary)
     (add-to-list 'facemenu-unlisted-faces 'calendar-today)
     (add-to-list 'facemenu-unlisted-faces 'holiday)))
221

222
(defcustom diary-entry-marker
223
  (if (not (display-color-p))
224
      "+"
225
    'diary)
226
  "How to mark dates that have diary entries.
227
The value can be either a single-character string or a face."
228 229
  :type '(choice string face)
  :group 'diary)
230

231
(defcustom calendar-today-marker
232
  (if (not (display-color-p))
233
      "="
234
    'calendar-today)
235
  "How to mark today's date in the calendar.
236 237 238
The value can be either a single-character string or a face.
Marking today's date is done only if you set up `today-visible-calendar-hook'
to request that."
239 240
  :type '(choice string face)
  :group 'calendar)
241

242
(defcustom calendar-holiday-marker
243
  (if (not (display-color-p))
244
      "*"
245
    'holiday)
246
  "How to mark notable dates in the calendar.
247
The value can be either a single-character string or a face."
248 249
  :type '(choice string face)
  :group 'calendar)
Richard M. Stallman's avatar
Richard M. Stallman committed
250

Jim Blandy's avatar
Jim Blandy committed
251
;;;###autoload
252
(defcustom view-calendar-holidays-initially nil
253
  "Non-nil means display holidays for current three month period on entry.
254
The holidays are displayed in another window when the calendar is first
255 256 257
displayed."
  :type 'boolean
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
258

Jim Blandy's avatar
Jim Blandy committed
259
;;;###autoload
260
(defcustom mark-holidays-in-calendar nil
261
  "Non-nil means mark dates of holidays in the calendar window.
262 263 264
The marking symbol is specified by the variable `calendar-holiday-marker'."
  :type 'boolean
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
265

Jim Blandy's avatar
Jim Blandy committed
266
;;;###autoload
267
(defcustom all-hebrew-calendar-holidays nil
268
  "If nil, show only major holidays from the Hebrew calendar.
Richard M. Stallman's avatar
Richard M. Stallman committed
269
This means only those Jewish holidays that appear on secular calendars.
270

271 272 273
If t, show all the holidays that would appear in a complete Hebrew calendar."
  :type 'boolean
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
274

Jim Blandy's avatar
Jim Blandy committed
275
;;;###autoload
276
(defcustom all-christian-calendar-holidays nil
277
  "If nil, show only major holidays from the Christian calendar.
Richard M. Stallman's avatar
Richard M. Stallman committed
278
This means only those Christian holidays that appear on secular calendars.
279

Richard M. Stallman's avatar
Richard M. Stallman committed
280
If t, show all the holidays that would appear in a complete Christian
281 282 283
calendar."
  :type 'boolean
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
284

Jim Blandy's avatar
Jim Blandy committed
285
;;;###autoload
286
(defcustom all-islamic-calendar-holidays nil
287
  "If nil, show only major holidays from the Islamic calendar.
Richard M. Stallman's avatar
Richard M. Stallman committed
288
This means only those Islamic holidays that appear on secular calendars.
289

Richard M. Stallman's avatar
Richard M. Stallman committed
290
If t, show all the holidays that would appear in a complete Islamic
291 292 293
calendar."
  :type 'boolean
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
294

295
(defcustom diary-file-name-prefix-function (function (lambda (str) str))
296
  "The function that will take a diary file name and return the desired prefix."
297
  :type 'function
298 299
  :group 'diary)

300 301
;;;###autoload
(defcustom all-bahai-calendar-holidays nil
302
  "If nil, show only major holidays from the Baha'i calendar.
303 304 305 306 307 308 309
These are the days on which work and school must be suspended.

If t, show all the holidays that would appear in a complete Baha'i
calendar."
  :type 'boolean
  :group 'holidays)

Jim Blandy's avatar
Jim Blandy committed
310
;;;###autoload
311
(defcustom calendar-load-hook nil
312
  "List of functions to be called after the calendar is first loaded.
313 314 315
This is the place to add key bindings to `calendar-mode-map'."
  :type 'hook
  :group 'calendar-hooks)
Jim Blandy's avatar
Jim Blandy committed
316 317

;;;###autoload
318
(defcustom initial-calendar-window-hook nil
319
  "List of functions to be called when the calendar window is first opened.
Richard M. Stallman's avatar
Richard M. Stallman committed
320 321
The functions invoked are called after the calendar window is opened, but
once opened is never called again.  Leaving the calendar with the `q' command
322 323 324
and reentering it will cause these functions to be called again."
  :type 'hook
  :group 'calendar-hooks)
Richard M. Stallman's avatar
Richard M. Stallman committed
325

Jim Blandy's avatar
Jim Blandy committed
326
;;;###autoload
327
(defcustom today-visible-calendar-hook nil
328
  "List of functions called whenever the current date is visible.
Richard M. Stallman's avatar
Richard M. Stallman committed
329 330 331
This can be used, for example, to replace today's date with asterisks; a
function `calendar-star-date' is included for this purpose:
    (setq today-visible-calendar-hook 'calendar-star-date)
Richard M. Stallman's avatar
Richard M. Stallman committed
332
It can also be used to mark the current date with `calendar-today-marker';
333
a function is also provided for this:
Richard M. Stallman's avatar
Richard M. Stallman committed
334 335 336 337 338 339 340 341
    (setq today-visible-calendar-hook 'calendar-mark-today)

The corresponding variable `today-invisible-calendar-hook' is the list of
functions called when the calendar function was called when the current
date is not visible in the window.

Other than the use of the provided functions, the changing of any
characters in the calendar buffer by the hooks may cause the failure of the
342 343 344
functions that move by days and weeks."
  :type 'hook
  :group 'calendar-hooks)
Richard M. Stallman's avatar
Richard M. Stallman committed
345

Jim Blandy's avatar
Jim Blandy committed
346
;;;###autoload
347
(defcustom today-invisible-calendar-hook nil
348
  "List of functions called whenever the current date is not visible.
Richard M. Stallman's avatar
Richard M. Stallman committed
349 350 351 352 353 354 355

The corresponding variable `today-visible-calendar-hook' is the list of
functions called when the calendar function was called when the current
date is visible in the window.

Other than the use of the provided functions, the changing of any
characters in the calendar buffer by the hooks may cause the failure of the
356 357 358
functions that move by days and weeks."
  :type 'hook
  :group 'calendar-hooks)
Richard M. Stallman's avatar
Richard M. Stallman committed
359

360 361
;;;###autoload
(defcustom calendar-move-hook nil
362
  "List of functions called whenever the cursor moves in the calendar.
363

364
For example,
365

366
  (add-hook 'calendar-move-hook (lambda () (diary-view-entries 1)))
367 368 369 370 371

redisplays the diary for whatever date the cursor is moved to."
  :type 'hook
  :group 'calendar-hooks)

Jim Blandy's avatar
Jim Blandy committed
372
;;;###autoload
373
(defcustom diary-file "~/diary"
374
  "Name of the file in which one's personal diary of dates is kept.
Richard M. Stallman's avatar
Richard M. Stallman committed
375

376 377
The file's entries are lines beginning with any of the forms
specified by the variable `american-date-diary-pattern', by default:
Richard M. Stallman's avatar
Richard M. Stallman committed
378 379 380 381 382 383 384

            MONTH/DAY
            MONTH/DAY/YEAR
            MONTHNAME DAY
            MONTHNAME DAY, YEAR
            DAYNAME

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
with the remainder of the line being the diary entry string for
that date.  MONTH and DAY are one or two digit numbers, YEAR is a
number and may be written in full or abbreviated to the final two
digits (if `abbreviated-calendar-year' is non-nil).  MONTHNAME
and DAYNAME can be spelled in full (as specified by the variables
`calendar-month-name-array' and `calendar-day-name-array'),
abbreviated (as specified by `calendar-month-abbrev-array' and
`calendar-day-abbrev-array') with or without a period,
capitalized or not.  Any of DAY, MONTH, or MONTHNAME, YEAR can be
`*' which matches any day, month, or year, respectively. If the
date does not contain a year, it is generic and applies to any
year.  A DAYNAME entry applies to the appropriate day of the week
in every week.

The European style (in which the day precedes the month) can be
used instead, if you execute `european-calendar' when in the
calendar, or set `european-calendar-style' to t in your .emacs
file.  The European forms (see `european-date-diary-pattern') are
Richard M. Stallman's avatar
Richard M. Stallman committed
403 404 405 406 407 408 409 410 411 412

            DAY/MONTH
            DAY/MONTH/YEAR
            DAY MONTHNAME
            DAY MONTHNAME YEAR
            DAYNAME

To revert to the default American style from the European style, execute
`american-calendar' in the calendar.

Richard M. Stallman's avatar
Richard M. Stallman committed
413 414 415 416
A diary entry can be preceded by the character
`diary-nonmarking-symbol' (ordinarily `&') to make that entry
nonmarking--that is, it will not be marked on dates in the calendar
window but will appear in a diary window.
Richard M. Stallman's avatar
Richard M. Stallman committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436

Multiline diary entries are made by indenting lines after the first with
either a TAB or one or more spaces.

Lines not in one the above formats are ignored.  Here are some sample diary
entries (in the default American style):

     12/22/1988 Twentieth wedding anniversary!!
     &1/1. Happy New Year!
     10/22 Ruth's birthday.
     21: Payday
     Tuesday--weekly meeting with grad students at 10am
              Supowit, Shen, Bitner, and Kapoor to attend.
     1/13/89 Friday the thirteenth!!
     &thu 4pm squash game with Lloyd.
     mar 16 Dad's birthday
     April 15, 1989 Income tax due.
     &* 15 time cards due.

If the first line of a diary entry consists only of the date or day name with
Richard M. Stallman's avatar
Richard M. Stallman committed
437 438
no trailing blanks or punctuation, then that line is not displayed in the
diary window; only the continuation lines is shown.  For example, the
Richard M. Stallman's avatar
Richard M. Stallman committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
single diary entry

     02/11/1989
      Bill Blattner visits Princeton today
      2pm Cognitive Studies Committee meeting
      2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
      4:00pm Jamie Tappenden
      7:30pm Dinner at George and Ed's for Alan Ryan
      7:30-10:00pm dance at Stewart Country Day School

will appear in the diary window without the date line at the beginning.  This
facility allows the diary window to look neater, but can cause confusion if
used with more than one day's entries displayed.

Diary entries can be based on Lisp sexps.  For example, the diary entry

      %%(diary-block 11 1 1990 11 10 1990) Vacation

457 458 459 460 461
causes the diary entry \"Vacation\" to appear from November 1 through
November 10, 1990.  Other functions available are `diary-float',
`diary-anniversary', `diary-cyclic', `diary-day-of-year',
`diary-iso-date', `diary-french-date', `diary-hebrew-date',
`diary-islamic-date', `diary-bahai-date', `diary-mayan-date',
462
`diary-chinese-date', `diary-coptic-date', `diary-ethiopic-date',
463
`diary-persian-date', `diary-yahrzeit', `diary-sunrise-sunset',
464 465 466 467
`diary-phases-of-moon', `diary-parasha', `diary-omer',
`diary-rosh-hodesh', and `diary-sabbath-candles'.  See the
documentation for the function `list-sexp-diary-entries' for more
details.
Richard M. Stallman's avatar
Richard M. Stallman committed
468

469 470 471 472 473
Diary entries based on the Hebrew, the Islamic and/or the Baha'i
calendar are also possible, but because these are somewhat slow, they
are ignored unless you set the `nongregorian-diary-listing-hook' and
the `nongregorian-diary-marking-hook' appropriately.  See the
documentation for these functions for details.
Richard M. Stallman's avatar
Richard M. Stallman committed
474 475

Diary files can contain directives to include the contents of other files; for
476 477 478
details, see the documentation for the variable `list-diary-entries-hook'."
  :type 'file
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
479

Jim Blandy's avatar
Jim Blandy committed
480
;;;###autoload
481
(defcustom diary-nonmarking-symbol "&"
482
  "Symbol indicating that a diary entry is not to be marked in the calendar."
483 484
  :type 'string
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
485

Jim Blandy's avatar
Jim Blandy committed
486
;;;###autoload
487
(defcustom hebrew-diary-entry-symbol "H"
488
  "Symbol indicating a diary entry according to the Hebrew calendar."
489 490
  :type 'string
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
491

Jim Blandy's avatar
Jim Blandy committed
492
;;;###autoload
493
(defcustom islamic-diary-entry-symbol "I"
494
  "Symbol indicating a diary entry according to the Islamic calendar."
495 496
  :type 'string
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
497

498 499
;;;###autoload
(defcustom bahai-diary-entry-symbol "B"
500
  "Symbol indicating a diary entry according to the Baha'i calendar."
501 502 503
  :type 'string
  :group 'diary)

Jim Blandy's avatar
Jim Blandy committed
504
;;;###autoload
505
(defcustom diary-include-string "#include"
506
  "The string indicating inclusion of another file of diary entries.
507 508 509
See the documentation for the function `include-other-diary-files'."
  :type 'string
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
510

511
(defcustom diary-glob-file-regexp-prefix "^\\#"
512
  "The regular expression that gets pre-pended to each of the attribute-regexp's for file-wide specifiers."
513 514 515
  :type 'regexp
  :group 'diary)

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
(defcustom diary-face-attrs
  '((" *\\[foreground:\\([-a-z]+\\)\\]$" 1 :foreground string)
    (" *\\[background:\\([-a-z]+\\)\\]$" 1 :background string)
    (" *\\[width:\\([-a-z]+\\)\\]$" 1 :width symbol)
    (" *\\[height:\\([-0-9a-z]+\\)\\]$" 1 :height int)
    (" *\\[weight:\\([-a-z]+\\)\\]$" 1 :weight symbol)
    (" *\\[slant:\\([-a-z]+\\)\\]$" 1 :slant symbol)
    (" *\\[underline:\\([-a-z]+\\)\\]$" 1 :underline stringtnil)
    (" *\\[overline:\\([-a-z]+\\)\\]$" 1 :overline stringtnil)
    (" *\\[strike-through:\\([-a-z]+\\)\\]$" 1 :strike-through stringtnil)
    (" *\\[inverse-video:\\([-a-z]+\\)\\]$" 1 :inverse-video tnil)
    (" *\\[face:\\([-0-9a-z]+\\)\\]$" 1 :face string)
    (" *\\[font:\\([-a-z0-9]+\\)\\]$" 1 :font string)
    ;; Unsupported.
;;;    (" *\\[box:\\([-a-z]+\\)\\]$" 1 :box)
;;;    (" *\\[stipple:\\([-a-z]+\\)\\]$" 1 :stipple)
    )
533
  "A list of (regexp regnum attr attrtype) lists where the
534 535 536 537
regexp says how to find the tag, the regnum says which
parenthetical sub-regexp this regexp looks for, and the attr says
which attribute of the face (or that this _is_ a face) is being
modified."
538 539 540 541
  :type 'sexp
  :group 'diary)

(defcustom diary-file-name-prefix nil
542
  "If non-nil each diary entry is prefixed with the name of the file where it is defined."
543 544 545
  :type 'boolean
  :group 'diary)

Jim Blandy's avatar
Jim Blandy committed
546
;;;###autoload
547
(defcustom sexp-diary-entry-symbol "%%"
548
  "The string used to indicate a sexp diary entry in `diary-file'.
549 550 551
See the documentation for the function `list-sexp-diary-entries'."
  :type 'string
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
552

Jim Blandy's avatar
Jim Blandy committed
553
;;;###autoload
554
(defcustom abbreviated-calendar-year t
555
  "Interpret a two-digit year DD in a diary entry as either 19DD or 20DD.
556 557 558
For the Gregorian calendar; similarly for the Hebrew, Islamic and
Baha'i calendars.  If this variable is nil, years must be written in
full."
559 560
  :type 'boolean
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
561

Jim Blandy's avatar
Jim Blandy committed
562
;;;###autoload
563
(defcustom european-calendar-style nil
564
  "Use the European style of dates in the diary and in any displays.
565
If this variable is t, a date 1/2/1990 would be interpreted as February 1,
566 567
1990.  The default European date styles (see `european-date-diary-pattern')
are
Richard M. Stallman's avatar
Richard M. Stallman committed
568 569 570 571 572 573 574

            DAY/MONTH
            DAY/MONTH/YEAR
            DAY MONTHNAME
            DAY MONTHNAME YEAR
            DAYNAME

575 576
Names can be capitalized or not, written in full (as specified by the
variable `calendar-day-name-array'), or abbreviated (as specified by
Glenn Morris's avatar
Glenn Morris committed
577 578 579 580
`calendar-day-abbrev-array') with or without a period.  To take effect,
this variable should be set before the calendar package and its associates
are loaded.  Otherwise, use one of the functions `european-calendar' or
`american-calendar' to force the appropriate update."
581 582
  :type 'boolean
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
583

Jim Blandy's avatar
Jim Blandy committed
584
;;;###autoload
585
(defcustom american-date-diary-pattern
Richard M. Stallman's avatar
Richard M. Stallman committed
586 587 588 589 590
  '((month "/" day "[^/0-9]")
    (month "/" day "/" year "[^0-9]")
    (monthname " *" day "[^,0-9]")
    (monthname " *" day ", *" year "[^0-9]")
    (dayname "\\W"))
591
  "List of pseudo-patterns describing the American patterns of date used.
592 593 594 595 596 597 598 599 600 601 602
See the documentation of `diary-date-forms' for an explanation."
  :type '(repeat (choice (cons :tag "Backup"
			       :value (backup . nil)
			       (const backup)
			       (repeat (list :inline t :format "%v"
					     (symbol :tag "Keyword")
					     (choice symbol regexp))))
			 (repeat (list :inline t :format "%v"
				       (symbol :tag "Keyword")
				       (choice symbol regexp)))))
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
603

Jim Blandy's avatar
Jim Blandy committed
604
;;;###autoload
605
(defcustom european-date-diary-pattern
Richard M. Stallman's avatar
Richard M. Stallman committed
606 607
  '((day "/" month "[^/0-9]")
    (day "/" month "/" year "[^0-9]")
608
    (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
Richard M. Stallman's avatar
Richard M. Stallman committed
609 610
    (day " *" monthname " *" year "[^0-9]")
    (dayname "\\W"))
611
  "List of pseudo-patterns describing the European patterns of date used.
612 613 614 615 616 617 618 619 620 621 622 623 624
See the documentation of `diary-date-forms' for an explanation."
  :type '(repeat (choice (cons :tag "Backup"
			       :value (backup . nil)
			       (const backup)
			       (repeat (list :inline t :format "%v"
					     (symbol :tag "Keyword")
					     (choice symbol regexp))))
			 (repeat (list :inline t :format "%v"
				       (symbol :tag "Keyword")
				       (choice symbol regexp)))))
  :group 'diary)

(defcustom diary-date-forms
Richard M. Stallman's avatar
Richard M. Stallman committed
625 626 627
  (if european-calendar-style
      european-date-diary-pattern
    american-date-diary-pattern)
628
  "List of pseudo-patterns describing the forms of date used in the diary.
Juanma Barranquero's avatar
Juanma Barranquero committed
629
The patterns on the list must be MUTUALLY EXCLUSIVE and should not match
Richard M. Stallman's avatar
Richard M. Stallman committed
630 631 632 633
any portion of the diary entry itself, just the date component.

A pseudo-pattern is a list of regular expressions and the keywords `month',
`day', `year', `monthname', and `dayname'.  The keyword `monthname' will
634 635 636 637 638 639 640 641
match the name of the month (see `calendar-month-name-array'), capitalized
or not, or its user-specified abbreviation (see `calendar-month-abbrev-array'),
followed by a period or not; it will also match `*'.  Similarly, `dayname'
will match the name of the day (see `calendar-day-name-array'), capitalized or
not, or its user-specified abbreviation (see `calendar-day-abbrev-array'),
followed by a period or not.  The keywords `month', `day', and `year' will
match those numerical values, preceded by arbitrarily many zeros; they will
also match `*'.
Richard M. Stallman's avatar
Richard M. Stallman committed
642 643 644 645 646 647 648

The matching of the diary entries with the date forms is done with the
standard syntax table from Fundamental mode, but with the `*' changed so
that it is a word constituent.

If, to be mutually exclusive, a pseudo-pattern must match a portion of the
diary entry itself, the first element of the pattern MUST be `backup'.  This
Jim Blandy's avatar
Jim Blandy committed
649 650
directive causes the date recognizer to back up to the beginning of the
current word of the diary entry, so in no case can the pattern match more than
651 652 653 654 655 656 657 658 659 660 661
a portion of the first word of the diary entry."
  :type '(repeat (choice (cons :tag "Backup"
			       :value (backup . nil)
			       (const backup)
			       (repeat (list :inline t :format "%v"
					     (symbol :tag "Keyword")
					     (choice symbol regexp))))
			 (repeat (list :inline t :format "%v"
				       (symbol :tag "Keyword")
				       (choice symbol regexp)))))
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
662

Jim Blandy's avatar
Jim Blandy committed
663
;;;###autoload
664
(defcustom european-calendar-display-form
Jim Blandy's avatar
Jim Blandy committed
665
  '((if dayname (concat dayname ", ")) day " " monthname " " year)
666
  "Pseudo-pattern governing the way a date appears in the European style.
667
See the documentation of `calendar-date-display-form' for an explanation."
668 669
  :type 'sexp
  :group 'calendar)
Richard M. Stallman's avatar
Richard M. Stallman committed
670

Jim Blandy's avatar
Jim Blandy committed
671
;;;###autoload
672
(defcustom american-calendar-display-form
Jim Blandy's avatar
Jim Blandy committed
673
  '((if dayname (concat dayname ", ")) monthname " " day ", " year)
674
  "Pseudo-pattern governing the way a date appears in the American style.
675 676 677
See the documentation of `calendar-date-display-form' for an explanation."
  :type 'sexp
  :group 'calendar)
Richard M. Stallman's avatar
Richard M. Stallman committed
678

679
(defcustom calendar-date-display-form
Richard M. Stallman's avatar
Richard M. Stallman committed
680 681 682
  (if european-calendar-style
      european-calendar-display-form
    american-calendar-display-form)
683
  "Pseudo-pattern governing the way a date appears.
684 685 686 687 688

Used by the function `calendar-date-string', a pseudo-pattern is a list of
expressions that can involve the keywords `month', `day', and `year', all
numbers in string form, and `monthname' and `dayname', both alphabetic
strings.  For example, the ISO standard would use the pseudo- pattern
Richard M. Stallman's avatar
Richard M. Stallman committed
689 690 691 692 693 694 695 696 697 698 699 700 701

       '(year \"-\" month \"-\" day)

while a typical American form would be

       '(month \"/\" day \"/\" (substring year -2))

and

       '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))

would give the usual American style in fixed-length fields.

702 703 704
See the documentation of the function `calendar-date-string'."
  :type 'sexp
  :group 'calendar)
Richard M. Stallman's avatar
Richard M. Stallman committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721

(defun european-calendar ()
  "Set the interpretation and display of dates to the European style."
  (interactive)
  (setq european-calendar-style t)
  (setq calendar-date-display-form european-calendar-display-form)
  (setq diary-date-forms european-date-diary-pattern)
  (update-calendar-mode-line))

(defun american-calendar ()
  "Set the interpretation and display of dates to the American style."
  (interactive)
  (setq european-calendar-style nil)
  (setq calendar-date-display-form american-calendar-display-form)
  (setq diary-date-forms american-date-diary-pattern)
  (update-calendar-mode-line))

Jim Blandy's avatar
Jim Blandy committed
722
;;;###autoload
723
(defcustom print-diary-entries-hook 'lpr-buffer
724
  "List of functions called after a temporary diary buffer is prepared.
725 726 727
The buffer shows only the diary entries currently visible in the diary
buffer.  The default just does the printing.  Other uses might include, for
example, rearranging the lines into order by day and time, saving the buffer
728 729 730
instead of deleting it, or changing the function used to do the printing."
  :type 'hook
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
731

Jim Blandy's avatar
Jim Blandy committed
732
;;;###autoload
733
(defcustom list-diary-entries-hook nil
734
  "List of functions called after diary file is culled for relevant entries.
735
It is to be used for diary entries that are not found in the diary file.
Richard M. Stallman's avatar
Richard M. Stallman committed
736 737 738

A function `include-other-diary-files' is provided for use as the value of
this hook.  This function enables you to use shared diary files together
Richard M. Stallman's avatar
Richard M. Stallman committed
739
with your own.  The files included are specified in the diary file by lines
Richard M. Stallman's avatar
Richard M. Stallman committed
740 741 742 743 744 745 746 747
of the form

        #include \"filename\"

This is recursive; that is, #include directives in files thus included are
obeyed.  You can change the \"#include\" to some other string by changing
the variable `diary-include-string'.  When you use `include-other-diary-files'
as part of the list-diary-entries-hook, you will probably also want to use the
Richard M. Stallman's avatar
Richard M. Stallman committed
748
function `mark-included-diary-files' as part of `mark-diary-entries-hook'.
Richard M. Stallman's avatar
Richard M. Stallman committed
749 750 751 752

For example, you could use

     (setq list-diary-entries-hook
Jim Blandy's avatar
Jim Blandy committed
753
       '(include-other-diary-files sort-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
754 755
     (setq diary-display-hook 'fancy-diary-display)

Richard M. Stallman's avatar
Richard M. Stallman committed
756
in your `.emacs' file to cause the fancy diary buffer to be displayed with
Richard M. Stallman's avatar
Richard M. Stallman committed
757
diary entries from various included files, each day's entries sorted into
758 759
lexicographic order."
  :type 'hook
760
  :options '(include-other-diary-files sort-diary-entries)
761
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
762

Jim Blandy's avatar
Jim Blandy committed
763
;;;###autoload
764
(defcustom diary-hook nil
765
  "List of functions called after the display of the diary.
766 767 768
Can be used for appointment notification."
  :type 'hook
  :group 'diary)
769 770

;;;###autoload
771
(defcustom diary-display-hook nil
772
  "List of functions that handle the display of the diary.
Richard M. Stallman's avatar
Richard M. Stallman committed
773
If nil (the default), `simple-diary-display' is used.  Use `ignore' for no
774
diary display.
Richard M. Stallman's avatar
Richard M. Stallman committed
775 776 777 778 779 780

Ordinarily, this just displays the diary buffer (with holidays indicated in
the mode line), if there are any relevant entries.  At the time these
functions are called, the variable `diary-entries-list' is a list, in order
by date, of all relevant diary entries in the form of ((MONTH DAY YEAR)
STRING), where string is the diary entry for the given date.  This can be
781 782
used, for example, a different buffer for display (perhaps combined with
holidays), or produce hard copy output.
Richard M. Stallman's avatar
Richard M. Stallman committed
783 784 785 786 787 788 789 790

A function `fancy-diary-display' is provided as an alternative
choice for this hook; this function prepares a special noneditable diary
buffer with the relevant diary entries that has neat day-by-day arrangement
with headings.  The fancy diary buffer will show the holidays unless the
variable `holidays-in-diary-buffer' is set to nil.  Ordinarily, the fancy
diary buffer will not show days for which there are no diary entries, even
if that day is a holiday; if you want such days to be shown in the fancy
791 792
diary buffer, set the variable `diary-list-include-blanks' to t."
  :type 'hook
793
  :options '(fancy-diary-display)
794
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
795

Jim Blandy's avatar
Jim Blandy committed
796
;;;###autoload
797
(defcustom nongregorian-diary-listing-hook nil
798
  "List of functions called for listing diary file and included files.
799 800 801 802
As the files are processed for diary entries, these functions are used
to cull relevant entries.  You can use either or both of
`list-hebrew-diary-entries', `list-islamic-diary-entries' and
`list-bahai-diary-entries'.  The documentation for these functions
803 804
describes the style of such diary entries."
  :type 'hook
805 806 807
  :options '(list-hebrew-diary-entries
	     list-islamic-diary-entries
	     list-bahai-diary-entries)
808
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
809

Jim Blandy's avatar
Jim Blandy committed
810
;;;###autoload
811
(defcustom mark-diary-entries-hook nil
812
  "List of functions called after marking diary entries in the calendar.
Richard M. Stallman's avatar
Richard M. Stallman committed
813 814

A function `mark-included-diary-files' is also provided for use as the
Stefan Monnier's avatar
Stefan Monnier committed
815
`mark-diary-entries-hook'; it enables you to use shared diary files together
Richard M. Stallman's avatar
Richard M. Stallman committed
816
with your own.  The files included are specified in the diary file by lines
Richard M. Stallman's avatar
Richard M. Stallman committed
817 818 819 820 821 822
of the form
        #include \"filename\"
This is recursive; that is, #include directives in files thus included are
obeyed.  You can change the \"#include\" to some other string by changing the
variable `diary-include-string'.  When you use `mark-included-diary-files' as
part of the mark-diary-entries-hook, you will probably also want to use the
823 824
function `include-other-diary-files' as part of `list-diary-entries-hook'."
  :type 'hook
825
  :options '(mark-included-diary-files)
826
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
827

Jim Blandy's avatar
Jim Blandy committed
828
;;;###autoload
829
(defcustom nongregorian-diary-marking-hook nil
830
  "List of functions called for marking diary file and included files.
831 832 833 834
As the files are processed for diary entries, these functions are used
to cull relevant entries.  You can use either or both of
`mark-hebrew-diary-entries', `mark-islamic-diary-entries' and
`mark-bahai-diary-entries'.  The documentation for these functions
835 836
describes the style of such diary entries."
  :type 'hook
837 838 839
  :options '(mark-hebrew-diary-entries
	     mark-islamic-diary-entries
	     mark-bahai-diary-entries)
840
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
841

Jim Blandy's avatar
Jim Blandy committed
842
;;;###autoload
843
(defcustom diary-list-include-blanks nil
844
  "If nil, do not include days with no diary entry in the list of diary entries.
845
Such days will then not be shown in the fancy diary buffer, even if they
846 847 848
are holidays."
  :type 'boolean
  :group 'diary)
Richard M. Stallman's avatar
Richard M. Stallman committed
849

Jim Blandy's avatar
Jim Blandy committed
850
;;;###autoload
851
(defcustom holidays-in-diary-buffer t
852
  "Non-nil means include holidays in the diary display.
Richard M. Stallman's avatar
Richard M. Stallman committed
853
The holidays appear in the mode line of the diary buffer, or in the
854
fancy diary buffer next to the date.  This slows down the diary functions
855 856 857
somewhat; setting it to nil makes the diary display faster."
  :type 'boolean
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
858

859 860
(defvar calendar-mark-ring nil)

Richard M. Stallman's avatar
Richard M. Stallman committed
861 862
;;;###autoload
(put 'general-holidays 'risky-local-variable t)
Jim Blandy's avatar
Jim Blandy committed
863
;;;###autoload
864
(defcustom general-holidays
865 866
  '((holiday-fixed 1 1 "New Year's Day")
    (holiday-float 1 1 3 "Martin Luther King Day")
Edward M. Reingold's avatar
Edward M. Reingold committed
867
    (holiday-fixed 2 2 "Groundhog Day")
868 869 870
    (holiday-fixed 2 14 "Valentine's Day")
    (holiday-float 2 1 3 "President's Day")
    (holiday-fixed 3 17 "St. Patrick's Day")
Edward M. Reingold's avatar
Edward M. Reingold committed
871
    (holiday-fixed 4 1 "April Fools' Day")
872 873 874 875 876 877 878 879 880 881
    (holiday-float 5 0 2 "Mother's Day")
    (holiday-float 5 1 -1 "Memorial Day")
    (holiday-fixed 6 14 "Flag Day")
    (holiday-float 6 0 3 "Father's Day")
    (holiday-fixed 7 4 "Independence Day")
    (holiday-float 9 1 1 "Labor Day")
    (holiday-float 10 1 2 "Columbus Day")
    (holiday-fixed 10 31 "Halloween")
    (holiday-fixed 11 11 "Veteran's Day")
    (holiday-float 11 4 4 "Thanksgiving"))
882
  "General holidays.  Default value is for the United States.
883 884 885
See the documentation for `calendar-holidays' for details."
  :type 'sexp
  :group 'holidays)
Richard M. Stallman's avatar
Richard M. Stallman committed
886