]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/calendar.el
(calc-embedded-close-formula, calc-embedded-open-formula,
[gnu-emacs] / lisp / calendar / calendar.el
index 99e6757c03ae24a564c5d30f1c239521a4ef5666..3e075b9d6bd564fa4e763d2576a11a087d61e0d5 100644 (file)
@@ -1,9 +1,10 @@
 ;;; calendar.el --- calendar functions
 
 ;; Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1997,
-;;     2000, 2001 Free Software Foundation, Inc.
+;;     2000, 2001, 2003, 2004, 2005  Free Software Foundation, Inc.
 
 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
+;; Maintainer: Glenn Morris <gmorris@ast.cam.ac.uk>
 ;; Keywords: calendar
 ;; Human-Keywords: calendar, Gregorian calendar, diary, holidays
 
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
-;; 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 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
+;; 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
 ;; available.  Calendar printing via LaTeX is available.
 
 ;; The following files are part of the calendar/diary code:
@@ -56,6 +60,7 @@
 ;;       cal-dst.el                    Daylight savings time rules
 ;;       cal-hebrew.el                 Hebrew calendar
 ;;       cal-islam.el                  Islamic calendar
+;;       cal-bahai.el                  Baha'i calendar
 ;;       cal-iso.el                    ISO calendar
 ;;       cal-julian.el                 Julian/astronomical calendars
 ;;       cal-mayan.el                  Mayan calendars
 ;;       solar.el                      Sunrise/sunset, equinoxes/solstices
 
 ;; Technical details of all the calendrical calculations can be found in
-;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
-;; Cambridge University Press (1997).
+;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
+;; and Nachum Dershowitz, Cambridge University Press (2001).
 
 ;; An earlier version of the technical details appeared in
 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
 ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
-;; pages 899-928 ``Calendrical Calculations, Part II: Three Historical
+;; pages 899-928, and in ``Calendrical Calculations, Part II: Three Historical
 ;; Calendars'' by E. M. Reingold,  N. Dershowitz, and S. M. Clamen,
 ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
 ;; pages 383-404.
   :group 'calendar)
 
 
-;;;###autoload
-(defcustom calendar-week-start-day 0
-  "*The day of the week on which a week in the calendar begins.
-0 means Sunday (default), 1 means Monday, and so on."
-  :type 'integer
-  :group 'calendar)
+(defconst calendar-buffer "*Calendar*"
+  "Name of the buffer used for the calendar.")
 
 ;;;###autoload
 (defcustom calendar-offset 0
@@ -154,10 +155,11 @@ the screen."
 
 ;;;###autoload
 (defcustom view-diary-entries-initially nil
-  "*Non-nil means display current date's diary entries on entry.
+  "*Non-nil means display current date's diary entries on entry to calendar.
 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
-is governed by the variable `number-of-diary-entries'."
+is governed by the variable `number-of-diary-entries'.  This variable can
+be overridden by the value of `calendar-setup'."
   :type 'boolean
   :group 'diary)
 
@@ -204,25 +206,32 @@ If nil, make an icon of the frame.  If non-nil, delete the frame."
   :type 'boolean
   :group 'view)
 
-(add-to-list 'facemenu-unlisted-faces 'diary-face)
-(defface diary-face
-  '((((class color) (background light))
+(defvar diary-face 'diary
+  "Face name to use for diary entries.")
+(defface diary
+  '((((min-colors 88) (class color) (background light))
+     :foreground "red1")
+    (((class color) (background light))
      :foreground "red")
+    (((min-colors 88) (class color) (background dark))
+     :foreground "yellow1")
     (((class color) (background dark))
      :foreground "yellow")
     (t
      :weight bold))
   "Face for highlighting diary entries."
   :group 'diary)
+;; backward-compatibility alias
+(put 'diary-face 'face-alias 'diary)
 
-(add-to-list 'facemenu-unlisted-faces 'calendar-today-face)
-(defface calendar-today-face
+(defface calendar-today
   '((t (:underline t)))
   "Face for indicating today's date."
   :group 'diary)
+;; backward-compatibility alias
+(put 'calendar-today-face 'face-alias 'calendar-today)
 
-(add-to-list 'facemenu-unlisted-faces 'holiday-face)
-(defface holiday-face
+(defface holiday
   '((((class color) (background light))
      :background "pink")
     (((class color) (background dark))
@@ -231,11 +240,19 @@ If nil, make an icon of the frame.  If non-nil, delete the frame."
      :inverse-video t))
   "Face for indicating dates that have holidays."
   :group 'diary)
+;; backward-compatibility alias
+(put 'holiday-face 'face-alias 'holiday)
+
+(eval-after-load "facemenu"
+  '(progn
+     (add-to-list 'facemenu-unlisted-faces 'diary)
+     (add-to-list 'facemenu-unlisted-faces 'calendar-today)
+     (add-to-list 'facemenu-unlisted-faces 'holiday)))
 
 (defcustom diary-entry-marker
   (if (not (display-color-p))
       "+"
-    'diary-face)
+    'diary)
   "*How to mark dates that have diary entries.
 The value can be either a single-character string or a face."
   :type '(choice string face)
@@ -244,7 +261,7 @@ The value can be either a single-character string or a face."
 (defcustom calendar-today-marker
   (if (not (display-color-p))
       "="
-    'calendar-today-face)
+    'calendar-today)
   "*How to mark today's date in the calendar.
 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'
@@ -255,7 +272,7 @@ to request that."
 (defcustom calendar-holiday-marker
   (if (not (display-color-p))
       "*"
-    'holiday-face)
+    'holiday)
   "*How to mark notable dates in the calendar.
 The value can be either a single-character string or a face."
   :type '(choice string face)
@@ -305,6 +322,21 @@ calendar."
   :type 'boolean
   :group 'holidays)
 
+(defcustom diary-file-name-prefix-function (function (lambda (str) str))
+  "*The function that will take a diary file name and return the desired prefix."
+  :type 'function
+  :group 'diary)
+
+;;;###autoload
+(defcustom all-bahai-calendar-holidays nil
+  "*If nil, show only major holidays from the Baha'i calendar.
+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)
+
 ;;;###autoload
 (defcustom calendar-load-hook nil
   "*List of functions to be called after the calendar is first loaded.
@@ -371,7 +403,8 @@ redisplays the diary for whatever date the cursor is moved to."
 (defcustom diary-file "~/diary"
   "*Name of the file in which one's personal diary of dates is kept.
 
-The file's entries are lines in any of the forms
+The file's entries are lines beginning with any of the forms
+specified by the variable `american-date-diary-pattern', by default:
 
             MONTH/DAY
             MONTH/DAY/YEAR
@@ -379,19 +412,24 @@ The file's entries are lines in any of the forms
             MONTHNAME DAY, YEAR
             DAYNAME
 
-at the beginning of the line; the remainder of the line is 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 the date does not contain a year, it is generic and applies to any year.
-DAYNAME entries apply to any date on which is on that day of the week.
-MONTHNAME and DAYNAME can be spelled in full, abbreviated to three
-characters (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.
-
-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 are
+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
 
             DAY/MONTH
             DAY/MONTH/YEAR
@@ -446,21 +484,23 @@ Diary entries can be based on Lisp sexps.  For example, the diary entry
 
       %%(diary-block 11 1 1990 11 10 1990) Vacation
 
-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-mayan-date',
+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',
 `diary-chinese-date', `diary-coptic-date', `diary-ethiopic-date',
 `diary-persian-date', `diary-yahrzeit', `diary-sunrise-sunset',
-`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.
+`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.
 
-Diary entries based on the Hebrew and/or the Islamic 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.
+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.
 
 Diary files can contain directives to include the contents of other files; for
 details, see the documentation for the variable `list-diary-entries-hook'."
@@ -485,6 +525,12 @@ details, see the documentation for the variable `list-diary-entries-hook'."
   :type 'string
   :group 'diary)
 
+;;;###autoload
+(defcustom bahai-diary-entry-symbol "B"
+  "*Symbol indicating a diary entry according to the Baha'i calendar."
+  :type 'string
+  :group 'diary)
+
 ;;;###autoload
 (defcustom diary-include-string "#include"
   "*The string indicating inclusion of another file of diary entries.
@@ -492,6 +538,41 @@ See the documentation for the function `include-other-diary-files'."
   :type 'string
   :group 'diary)
 
+(defcustom diary-glob-file-regexp-prefix "^\\#"
+  "*The regular expression that gets pre-pended to each of the attribute-regexp's for file-wide specifiers."
+  :type 'regexp
+  :group 'diary)
+
+(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)
+    )
+  "*A list of (regexp regnum attr attrtype) lists where the
+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."
+  :type 'sexp
+  :group 'diary)
+
+(defcustom diary-file-name-prefix nil
+  "If non-nil each diary entry is prefixed with the name of the file where it is defined."
+  :type 'boolean
+  :group 'diary)
+
 ;;;###autoload
 (defcustom sexp-diary-entry-symbol "%%"
   "*The string used to indicate a sexp diary entry in `diary-file'.
@@ -502,8 +583,9 @@ See the documentation for the function `list-sexp-diary-entries'."
 ;;;###autoload
 (defcustom abbreviated-calendar-year t
   "*Interpret a two-digit year DD in a diary entry as either 19DD or 20DD.
-For the Gregorian calendar; similarly for the Hebrew and Islamic calendars.
-If this variable is nil, years must be written in full."
+For the Gregorian calendar; similarly for the Hebrew, Islamic and
+Baha'i calendars.  If this variable is nil, years must be written in
+full."
   :type 'boolean
   :group 'diary)
 
@@ -511,7 +593,8 @@ If this variable is nil, years must be written in full."
 (defcustom european-calendar-style nil
   "*Use the European style of dates in the diary and in any displays.
 If this variable is t, a date 1/2/1990 would be interpreted as February 1,
-1990.  The accepted European date styles are
+1990.  The default European date styles (see `european-date-diary-pattern')
+are
 
             DAY/MONTH
             DAY/MONTH/YEAR
@@ -519,8 +602,12 @@ If this variable is t, a date 1/2/1990 would be interpreted as February 1,
             DAY MONTHNAME YEAR
             DAYNAME
 
-Names can be capitalized or not, written in full, or abbreviated to three
-characters with or without a period."
+Names can be capitalized or not, written in full (as specified by the
+variable `calendar-day-name-array'), or abbreviated (as specified by
+`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."
   :type 'boolean
   :group 'diary)
 
@@ -569,17 +656,19 @@ See the documentation of `diary-date-forms' for an explanation."
       european-date-diary-pattern
     american-date-diary-pattern)
   "*List of pseudo-patterns describing the forms of date used in the diary.
-The patterns on the list must be MUTUALLY EXCLUSIVE and must not match
+The patterns on the list must be MUTUALLY EXCLUSIVE and should not match
 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
-match the name of the month, capitalized or not, or its three-letter
-abbreviation, followed by a period or not; it will also match `*'.
-Similarly, `dayname' will match the name of the day, capitalized or not, or
-its three-letter abbreviation, 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 `*'.
+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 `*'.
 
 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
@@ -605,7 +694,7 @@ a portion of the first word of the diary entry."
 (defcustom european-calendar-display-form
   '((if dayname (concat dayname ", ")) day " " monthname " " year)
   "*Pseudo-pattern governing the way a date appears in the European style.
-See the documentation of calendar-date-display-form for an explanation."
+See the documentation of `calendar-date-display-form' for an explanation."
   :type 'sexp
   :group 'calendar)
 
@@ -698,6 +787,7 @@ in your `.emacs' file to cause the fancy diary buffer to be displayed with
 diary entries from various included files, each day's entries sorted into
 lexicographic order."
   :type 'hook
+  :options '(include-other-diary-files sort-diary-entries)
   :group 'diary)
 
 ;;;###autoload
@@ -730,16 +820,21 @@ 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
 diary buffer, set the variable `diary-list-include-blanks' to t."
   :type 'hook
+  :options '(fancy-diary-display)
   :group 'diary)
 
 ;;;###autoload
 (defcustom nongregorian-diary-listing-hook nil
   "*List of functions called for listing diary file and included files.
-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'
-and `list-islamic-diary-entries'.  The documentation for these functions
+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
 describes the style of such diary entries."
   :type 'hook
+  :options '(list-hebrew-diary-entries
+            list-islamic-diary-entries
+            list-bahai-diary-entries)
   :group 'diary)
 
 ;;;###autoload
@@ -757,16 +852,21 @@ 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
 function `include-other-diary-files' as part of `list-diary-entries-hook'."
   :type 'hook
+  :options '(mark-included-diary-files)
   :group 'diary)
 
 ;;;###autoload
 (defcustom nongregorian-diary-marking-hook nil
   "*List of functions called for marking diary file and included files.
-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'
-and `mark-islamic-diary-entries'.  The documentation for these functions
+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
 describes the style of such diary entries."
   :type 'hook
+  :options '(mark-hebrew-diary-entries
+            mark-islamic-diary-entries
+            mark-bahai-diary-entries)
   :group 'diary)
 
 ;;;###autoload
@@ -953,13 +1053,43 @@ See the documentation for `calendar-holidays' for details."
 (defcustom christian-holidays
   '((if all-christian-calendar-holidays
         (holiday-fixed 1 6 "Epiphany"))
-    (holiday-easter-etc)
+    (holiday-easter-etc 0 "Easter Sunday")
+    (holiday-easter-etc -2 "Good Friday")
+    (holiday-easter-etc -46 "Ash Wednesday")
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -63 "Septuagesima Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -56 "Sexagesima Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -49 "Shrove Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -48 "Shrove Monday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -47 "Shrove Tuesday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -14 "Passion Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -7 "Palm Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc -3 "Maundy Thursday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc 35 "Rogation Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc 39 "Ascension Day"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc 49 "Pentecost (Whitsunday)"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc 50 "Whitmonday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc 56 "Trinity Sunday"))
+    (if all-christian-calendar-holidays
+        (holiday-easter-etc 60 "Corpus Christi"))
     (if all-christian-calendar-holidays
         (holiday-greek-orthodox-easter))
     (if all-christian-calendar-holidays
         (holiday-fixed 8 15 "Assumption"))
     (if all-christian-calendar-holidays
-        (holiday-advent))
+        (holiday-advent 0 "Advent"))
     (holiday-fixed 12 25 "Christmas")
     (if all-christian-calendar-holidays
         (holiday-julian 12 25 "Eastern Orthodox Christmas")))
@@ -1003,6 +1133,48 @@ See the documentation for `calendar-holidays' for details."
   :type 'sexp
   :group 'holidays)
 
+;;;###autoload
+(put 'bahai-holidays 'risky-local-variable t)
+;;;###autoload
+(defcustom bahai-holidays
+  '((holiday-fixed
+     3 21
+     (format "Baha'i New Year (Naw-Ruz) %d" (- displayed-year (1- 1844))))
+    (holiday-fixed  4 21 "First Day of Ridvan")
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 22 "Second Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 23 "Third Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 24 "Fourth Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 25 "Fifth Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 26 "Sixth Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 27 "Seventh Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 28 "Eighth Day of Ridvan"))
+    (holiday-fixed  4 29 "Ninth Day of Ridvan")
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  4 30 "Tenth Day of Ridvan"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed  5  1 "Eleventh Day of Ridvan"))
+    (holiday-fixed  5  2 "Twelfth Day of Ridvan")
+    (holiday-fixed  5 23 "Declaration of the Bab")
+    (holiday-fixed  5 29 "Ascension of Baha'u'llah")
+    (holiday-fixed  7  9 "Martyrdom of the Bab")
+    (holiday-fixed 10 20 "Birth of the Bab")
+    (holiday-fixed 11 12 "Birth of Baha'u'llah")
+    (if all-bahai-calendar-holidays
+       (holiday-fixed 11 26 "Day of the Covenant"))
+    (if all-bahai-calendar-holidays
+       (holiday-fixed 11 28 "Ascension of `Abdu'l-Baha")))
+  "*Baha'i holidays.
+See the documentation for `calendar-holidays' for details."
+  :type 'sexp
+  :group 'holidays)
+
 ;;;###autoload
 (put 'solar-holidays 'risky-local-variable t)
 ;;;###autoload
@@ -1040,15 +1212,16 @@ See the documentation for `calendar-holidays' for details."
 (defcustom calendar-holidays
   (append general-holidays local-holidays other-holidays
           christian-holidays hebrew-holidays islamic-holidays
-          oriental-holidays solar-holidays)
+          bahai-holidays oriental-holidays solar-holidays)
   "*List of notable days for the command \\[holidays].
 
-Additional holidays are easy to add to the list, just put them in the list
-`other-holidays' in your .emacs file.  Similarly, by setting any of
-`general-holidays', `local-holidays' `christian-holidays', `hebrew-holidays',
-`islamic-holidays', `oriental-holidays', or `solar-holidays' to nil in your
-.emacs file, you can eliminate unwanted categories of holidays.  The intention
-is that (in the US) `local-holidays' be set in site-init.el and
+Additional holidays are easy to add to the list, just put them in the
+list `other-holidays' in your .emacs file.  Similarly, by setting any
+of `general-holidays', `local-holidays' `christian-holidays',
+`hebrew-holidays', `islamic-holidays', `bahai-holidays',
+`oriental-holidays', or `solar-holidays' to nil in your .emacs file,
+you can eliminate unwanted categories of holidays.  The intention is
+that (in the US) `local-holidays' be set in site-init.el and
 `other-holidays' be set by the user.
 
 Entries on the list are expressions that return (possibly empty) lists of
@@ -1064,6 +1237,7 @@ Several basic functions are provided for this purpose:
                                DAYNAME after/before MONTH DAY.
     (holiday-hebrew MONTH DAY STRING)  a fixed date on the Hebrew calendar
     (holiday-islamic MONTH DAY STRING) a fixed date on the Islamic calendar
+    (holiday-bahai MONTH DAY STRING)   a fixed date on the Baha'i calendar
     (holiday-julian MONTH DAY STRING)  a fixed date on the Julian calendar
     (holiday-sexp SEXP STRING) SEXP is a Gregorian-date-valued expression
                                in the variable `year'; if it evaluates to
@@ -1091,6 +1265,11 @@ add the Islamic feast celebrating Mohammed's birthday use
      (holiday-islamic 3 12 \"Mohammed's Birthday\")
 
 since the Islamic months are numbered from 1 starting with Muharram.  To
+add an entry for the Baha'i festival of Ridvan, use
+
+     (holiday-bahai 2 13 \"Festival of Ridvan\")
+
+since the Baha'i months are numbered from 1 starting with Baha.  To
 add Thomas Jefferson's birthday, April 2, 1743 (Julian), use
 
      (holiday-julian 4 2 \"Jefferson's Birthday\")
@@ -1100,7 +1279,7 @@ example, to include American presidential elections, which occur on the first
 Tuesday after the first Monday in November of years divisible by 4, add
 
      (holiday-sexp
-       (if (zerop (% year 4))
+       '(if (zerop (% year 4))
            (calendar-gregorian-from-absolute
              (1+ (calendar-dayname-on-or-before
                    1 (+ 6 (calendar-absolute-from-gregorian
@@ -1130,9 +1309,6 @@ with descriptive strings such as
   :type 'sexp
   :group 'holidays)
 
-(defconst calendar-buffer "*Calendar*"
-  "Name of the buffer used for the calendar.")
-
 (defconst holiday-buffer "*Holidays*"
   "Name of the buffer used for the displaying the holidays.")
 
@@ -1146,11 +1322,16 @@ with descriptive strings such as
   "Name of the buffer used for the lunar phases.")
 
 (defmacro increment-calendar-month (mon yr n)
-  "Move the variables MON and YR to the month and year by N months.
-Forward if N is positive or backward if N is negative."
-  `(let ((macro-y (+ (* ,yr 12) ,mon -1 ,n)))
-    (setq ,mon (1+ (% macro-y 12)))
-    (setq ,yr (/ macro-y 12))))
+  "Increment the variables MON and YR by N months.
+Forward if N is positive or backward if N is negative.
+A negative YR is interpreted as BC; -1 being 1 BC, and so on."
+  `(let (macro-y)
+     (if (< ,yr 0) (setq ,yr (1+ ,yr))) ; -1 BC -> 0 AD, etc
+     (setq macro-y (+ (* ,yr 12) ,mon -1 ,n)
+           ,mon (1+ (mod macro-y 12))
+           ,yr (/ macro-y 12))
+     (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr)))
+     (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc
 
 (defmacro calendar-for-loop (var from init to final do &rest body)
   "Execute a for loop."
@@ -1210,7 +1391,10 @@ Forward if N is positive or backward if N is negative."
   (car (cdr (cdr date))))
 
 (defsubst calendar-leap-year-p (year)
-  "Return t if YEAR is a Gregorian leap year."
+  "Return t if YEAR is a Gregorian leap year.
+A negative year is interpreted as BC; -1 being 1 BC, and so on."
+  ;; 1 BC = 0 AD, 2 BC acts like 1 AD, etc.
+  (if (< year 0) (setq year (1- (abs year))))
   (and (zerop (% year 4))
        (or (not (zerop (% year 100)))
            (zerop (% year 400)))))
@@ -1250,13 +1434,30 @@ while (calendar-day-number '(12 31 1980)) returns 366."
 
 (defsubst calendar-absolute-from-gregorian (date)
   "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
-The Gregorian date Sunday, December 31, 1 BC is imaginary."
-  (let ((prior-years (1- (extract-calendar-year date))))
-    (+ (calendar-day-number date);; Days this year
-       (* 365 prior-years);;        + Days in prior years
-       (/ prior-years 4);;          + Julian leap years
-       (- (/ prior-years 100));;    - century years
-       (/ prior-years 400))));;     + Gregorian leap years
+The Gregorian date Sunday, December 31, 1 BC is imaginary.
+DATE is a list of the form (month day year).  A negative year is
+interpreted as BC; -1 being 1 BC, and so on.  Dates before 12/31/1 BC
+return negative results."
+  (let ((year (extract-calendar-year date))
+        offset-years)
+    (cond ((= year 0)
+           (error "There was no year zero"))
+          ((> year 0)
+           (setq offset-years (1- year))
+           (+ (calendar-day-number date) ; Days this year
+              (* 365 offset-years)       ; + Days in prior years
+              (/ offset-years 4)         ; + Julian leap years
+              (- (/ offset-years 100))   ; - century years
+              (/ offset-years 400)))     ; + Gregorian leap years
+          (t
+           ;; Years between date and 1 BC, excluding 1 BC (1 for 2 BC, etc).
+           (setq offset-years (abs (1+ year)))
+           (- (calendar-day-number date)
+              (* 365 offset-years)
+              (/ offset-years 4)
+              (- (/ offset-years 100))
+              (/ offset-years 400)
+              (calendar-day-number '(12 31 -1))))))) ; days in year 1 BC
 
 (autoload 'calendar-goto-today "cal-move"
   "Reposition the calendar window so the current date is visible."
@@ -1346,6 +1547,13 @@ The Gregorian date Sunday, December 31, 1 BC is imaginary."
   "Move cursor to DATE."
   t)
 
+(autoload 'calendar-goto-day-of-year "cal-move"
+  "Move cursor to day of year."
+  t)
+
+(autoload 'calendar-only-one-frame-setup "cal-x"
+ "Start calendar and display it in a dedicated frame.")
+
 (autoload 'calendar-one-frame-setup "cal-x"
   "Start calendar and display it in a dedicated frame together with the diary.")
 
@@ -1353,12 +1561,25 @@ The Gregorian date Sunday, December 31, 1 BC is imaginary."
   "Start calendar and diary in separate, dedicated frames.")
 
 ;;;###autoload
-(defvar calendar-setup nil
-  "The frame set up of the calendar.
-The choices are `one-frame' (calendar and diary together in one separate,
-dedicated frame), `two-frames' (calendar and diary in separate, dedicated
-frames), `calendar-only' (calendar in a separate, dedicated frame); with
-any other value the current frame is used.")
+(defcustom calendar-setup nil
+  "The frame setup of the calendar.
+The choices are: `one-frame' (calendar and diary together in one separate,
+dedicated frame); `two-frames' (calendar and diary in separate, dedicated
+frames); `calendar-only' (calendar in a separate, dedicated frame); with
+any other value the current frame is used.  Using any of the first
+three options overrides the value of `view-diary-entries-initially'."
+  :type '(choice
+          (const :tag "calendar and diary in separate frame" one-frame)
+          (const :tag "calendar and diary each in own frame" two-frames)
+          (const :tag "calendar in separate frame" calendar-only)
+          (const :tag "use current frame" nil))
+  :group 'calendar)
+
+(defcustom calendar-minimum-window-height 8
+  "Minimum height `generate-calendar-window' should use for calendar window."
+  :type 'integer
+  :version "22.1"
+  :group 'calendar)
 
 ;;;###autoload
 (defun calendar (&optional arg)
@@ -1448,6 +1669,13 @@ the date indicated by the cursor position in the displayed three-month
 calendar."
   t)
 
+(autoload 'view-other-diary-entries "diary-lib"
+  "Prepare and display buffer of diary entries from an alternative diary file.
+Searches for entries that match ARG days, starting with the date indicated
+by the cursor position in the displayed three-month calendar.
+D-FILE specifies the file to use as the diary file."
+  t)
+
 (autoload 'calendar-sunrise-sunset "solar"
   "Local time of sunrise and sunset for date under cursor."
   t)
@@ -1557,6 +1785,10 @@ Driven by the variable `calendar-date-display-form'.")
   "Move cursor to ISO date."
   t)
 
+(autoload 'calendar-goto-iso-week "cal-iso"
+  "Move cursor to start of ISO week."
+  t)
+
 (autoload 'calendar-print-iso-date "cal-iso"
   "Show the ISO date equivalents of date."
   t)
@@ -1577,8 +1809,16 @@ Driven by the variable `calendar-date-display-form'.")
   "String of Islamic date of Gregorian date."
   t)
 
+(autoload 'calendar-print-bahai-date "cal-bahai"
+  "Show the Baha'i date equivalents of date."
+  t)
+
+(autoload 'calendar-bahai-date-string "cal-bahai"
+  "String of Baha'i date of Gregorian date."
+  t)
+
 (autoload 'calendar-goto-hebrew-date "cal-hebrew"
-  "Move cursor to Hebrew date date."
+  "Move cursor to Hebrew date."
   t)
 
 (autoload 'calendar-print-hebrew-date "cal-hebrew"
@@ -1590,7 +1830,7 @@ Driven by the variable `calendar-date-display-form'.")
   t)
 
 (autoload 'calendar-goto-coptic-date "cal-coptic"
-   "Move cursor to Coptic date date."
+   "Move cursor to Coptic date."
    t)
 
 (autoload 'calendar-print-coptic-date "cal-coptic"
@@ -1602,7 +1842,7 @@ Driven by the variable `calendar-date-display-form'.")
   t)
 
 (autoload 'calendar-goto-ethiopic-date "cal-coptic"
-   "Move cursor to Ethiopic date date."
+   "Move cursor to Ethiopic date."
    t)
 
 (autoload 'calendar-print-ethiopic-date "cal-coptic"
@@ -1614,7 +1854,7 @@ Driven by the variable `calendar-date-display-form'.")
   t)
 
 (autoload 'calendar-goto-persian-date "cal-persia"
-   "Move cursor to Persian date date."
+   "Move cursor to Persian date."
    t)
 
 (autoload 'calendar-print-persian-date "cal-persia"
@@ -1700,6 +1940,21 @@ to the date indicated by point."
 to the date indicated by point."
   t)
 
+(autoload 'insert-bahai-diary-entry "cal-bahai"
+  "Insert a diary entry for the Baha'i date corresponding to the date
+indicated by point."
+  t)
+
+(autoload 'insert-monthly-bahai-diary-entry "cal-bahai"
+  "Insert a monthly diary entry for the day of the Baha'i month corresponding
+to the date indicated by point."
+  t)
+
+(autoload 'insert-yearly-bahai-diary-entry "cal-bahai"
+  "Insert an annual diary entry for the day of the Baha'i year corresponding
+to the date indicated by point."
+  t)
+
 (autoload 'list-calendar-holidays "holidays"
   "Create a buffer containing the holidays for the current calendar window.
 The holidays are those in the list `calendar-notable-days'.  Returns t if any
@@ -1793,24 +2048,33 @@ Or, for optional MON, YR."
           (or (not mon)
               (let ((offset (calendar-interval mon yr month year)))
                 (and (<= offset 1) (>= offset -1)))))
-         (day-in-week (calendar-day-of-week today)))
+         (day-in-week (calendar-day-of-week today))
+         (in-calendar-window (eq (window-buffer (selected-window))
+                                 (get-buffer calendar-buffer))))
     (update-calendar-mode-line)
     (if mon
         (generate-calendar mon yr)
-        (generate-calendar month year))
+      (generate-calendar month year))
     (calendar-cursor-to-visible-date
      (if today-visible today (list displayed-month 1 displayed-year)))
     (set-buffer-modified-p nil)
-    (if (or (one-window-p t) (/= (frame-width) (window-width)))
-       ;; Don't mess with the window size, but ensure that the first
-       ;; line is fully visible
-       (set-window-vscroll nil 0)
-      ;; Adjust the window to exactly fit the displayed calendar
-      (fit-window-to-buffer))
-    (sit-for 0)
+    ;; Don't do any window-related stuff if we weren't called from a
+    ;; window displaying the calendar
+    (when in-calendar-window
+      (if (or (one-window-p t) (/= (frame-width) (window-width)))
+          ;; Don't mess with the window size, but ensure that the first
+          ;; line is fully visible
+          (set-window-vscroll nil 0)
+        ;; Adjust the window to exactly fit the displayed calendar
+        (fit-window-to-buffer nil nil calendar-minimum-window-height))
+      (sit-for 0))
+    (if (and (boundp 'font-lock-mode)
+            font-lock-mode)
+       (font-lock-fontify-buffer))
     (and mark-holidays-in-calendar
+;;;         (calendar-date-is-legal-p today) ; useful for BC dates
          (mark-calendar-holidays)
-         (sit-for 0))
+         (and in-calendar-window (sit-for 0)))
     (unwind-protect
         (if mark-diary-entries-in-calendar (mark-diary-entries))
       (if today-visible
@@ -1819,10 +2083,14 @@ Or, for optional MON, YR."
 
 (defun generate-calendar (month year)
   "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
+;;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on.
+;;; Note that while calendars for years BC could be displayed as it
+;;; stands, almost all other calendar functions (eg holidays) would
+;;; at best have unpredictable results for such dates.
   (if (< (+ month (* 12 (1- year))) 2)
-      (error "Months before February, 1 AD are not available"))
-  (setq displayed-month month)
-  (setq displayed-year year)
+      (error "Months before January, 1 AD cannot be displayed"))
+  (setq displayed-month month
+        displayed-year year)
   (erase-buffer)
   (increment-calendar-month month year -1)
   (calendar-for-loop i from 0 to 2 do
@@ -1847,10 +2115,15 @@ line."
      (list (format "%s %d" (calendar-month-name month) year)) ?  20)
     indent t)
    (calendar-insert-indented "" indent);; Go to proper spot
+   ;; Use the first two characters of each day to head the columns.
    (calendar-for-loop i from 0 to 6 do
-      (insert (calendar-day-name (mod (+ calendar-week-start-day i) 7)
-                                2 t))
-      (insert " "))
+      (insert
+       (let ((string
+              (calendar-day-name (mod (+ calendar-week-start-day i) 7) nil t)))
+         (if enable-multibyte-characters
+             (truncate-string-to-width string 2)
+           (substring string 0 2)))
+       " "))
    (calendar-insert-indented "" 0 t);; Force onto following line
    (calendar-insert-indented "" indent);; Go to proper spot
    ;; Add blank days before the first of the month
@@ -1888,11 +2161,28 @@ the inserted text.  Value is always t."
   t)
 
 (defun redraw-calendar ()
-  "Redraw the calendar display."
+  "Redraw the calendar display, if `calendar-buffer' is live."
   (interactive)
-  (let ((cursor-date (calendar-cursor-to-nearest-date)))
-    (generate-calendar-window displayed-month displayed-year)
-    (calendar-cursor-to-visible-date cursor-date)))
+  (if (get-buffer calendar-buffer)
+      (with-current-buffer calendar-buffer
+        (let ((cursor-date (calendar-cursor-to-nearest-date)))
+          (generate-calendar-window displayed-month displayed-year)
+          (calendar-cursor-to-visible-date cursor-date)))))
+
+;;;###autoload
+(defcustom calendar-week-start-day 0
+  "*The day of the week on which a week in the calendar begins.
+0 means Sunday (default), 1 means Monday, and so on.
+
+If you change this variable directly (without using customize)
+after starting `calendar', you should call `redraw-calendar' to
+update the calendar display to reflect the change, otherwise
+movement commands will not work correctly."
+  :type 'integer
+  :set (lambda (sym val)
+         (set sym val)
+         (redraw-calendar))
+  :group 'calendar)
 
 (defcustom calendar-debug-sexp nil
   "*Turn debugging on when evaluating a sexp in the diary or holiday list."
@@ -1915,9 +2205,11 @@ the inserted text.  Value is always t."
                                 calendar-mode-map global-map)
       (setq l (cdr l))))
   (define-key calendar-mode-map "-"     'negative-argument)
+  (define-key calendar-mode-map ">"     'scroll-calendar-right)
   (define-key calendar-mode-map "\C-x>" 'scroll-calendar-right)
   (define-key calendar-mode-map [prior] 'scroll-calendar-right-three-months)
   (define-key calendar-mode-map "\ev"   'scroll-calendar-right-three-months)
+  (define-key calendar-mode-map "<"     'scroll-calendar-left)
   (define-key calendar-mode-map "\C-x<" 'scroll-calendar-left)
   (define-key calendar-mode-map [next]  'scroll-calendar-left-three-months)
   (define-key calendar-mode-map "\C-v"  'scroll-calendar-left-three-months)
@@ -1945,15 +2237,18 @@ the inserted text.  Value is always t."
   (define-key calendar-mode-map "\C-x\C-x" 'calendar-exchange-point-and-mark)
   (define-key calendar-mode-map "\e=" 'calendar-count-days-region)
   (define-key calendar-mode-map "gd"  'calendar-goto-date)
+  (define-key calendar-mode-map "gD"  'calendar-goto-day-of-year)
   (define-key calendar-mode-map "gj"  'calendar-goto-julian-date)
   (define-key calendar-mode-map "ga"  'calendar-goto-astro-day-number)
   (define-key calendar-mode-map "gh"  'calendar-goto-hebrew-date)
   (define-key calendar-mode-map "gi"  'calendar-goto-islamic-date)
+  (define-key calendar-mode-map "gb"  'calendar-goto-bahai-date)
   (define-key calendar-mode-map "gC"  'calendar-goto-chinese-date)
   (define-key calendar-mode-map "gk"  'calendar-goto-coptic-date)
   (define-key calendar-mode-map "ge"  'calendar-goto-ethiopic-date)
   (define-key calendar-mode-map "gp"  'calendar-goto-persian-date)
   (define-key calendar-mode-map "gc"  'calendar-goto-iso-date)
+  (define-key calendar-mode-map "gw"  'calendar-goto-iso-week)
   (define-key calendar-mode-map "gf"  'calendar-goto-french-date)
   (define-key calendar-mode-map "gml"  'calendar-goto-mayan-long-count-date)
   (define-key calendar-mode-map "gmpc" 'calendar-previous-calendar-round-date)
@@ -1967,6 +2262,7 @@ the inserted text.  Value is always t."
   (define-key calendar-mode-map "S"   'calendar-sunrise-sunset)
   (define-key calendar-mode-map "M"   'calendar-phases-of-moon)
   (define-key calendar-mode-map " "   'scroll-other-window)
+  (define-key calendar-mode-map (kbd "DEL") 'scroll-other-window-down)
   (define-key calendar-mode-map "\C-c\C-l" 'redraw-calendar)
   (define-key calendar-mode-map "."   'calendar-goto-today)
   (define-key calendar-mode-map "o"   'calendar-other-month)
@@ -1989,6 +2285,7 @@ the inserted text.  Value is always t."
   (define-key calendar-mode-map "pa"  'calendar-print-astro-day-number)
   (define-key calendar-mode-map "ph"  'calendar-print-hebrew-date)
   (define-key calendar-mode-map "pi"  'calendar-print-islamic-date)
+  (define-key calendar-mode-map "pb"  'calendar-print-bahai-date)
   (define-key calendar-mode-map "pf"  'calendar-print-french-date)
   (define-key calendar-mode-map "pm"  'calendar-print-mayan-date)
   (define-key calendar-mode-map "po"  'calendar-print-other-dates)
@@ -2005,6 +2302,9 @@ the inserted text.  Value is always t."
   (define-key calendar-mode-map "iid" 'insert-islamic-diary-entry)
   (define-key calendar-mode-map "iim" 'insert-monthly-islamic-diary-entry)
   (define-key calendar-mode-map "iiy" 'insert-yearly-islamic-diary-entry)
+  (define-key calendar-mode-map "iBd" 'insert-bahai-diary-entry)
+  (define-key calendar-mode-map "iBm" 'insert-monthly-bahai-diary-entry)
+  (define-key calendar-mode-map "iBy" 'insert-yearly-bahai-diary-entry)
   (define-key calendar-mode-map "?"   'calendar-goto-info-node)
   (define-key calendar-mode-map "tm" 'cal-tex-cursor-month)
   (define-key calendar-mode-map "tM" 'cal-tex-cursor-month-landscape)
@@ -2021,7 +2321,7 @@ the inserted text.  Value is always t."
   (define-key calendar-mode-map "tY" 'cal-tex-cursor-year-landscape))
 
 (defun describe-calendar-mode ()
-  "Create a help buffer with a brief description of the calendar-mode."
+  "Create a help buffer with a brief description of the `calendar-mode'."
   (interactive)
   (with-output-to-temp-buffer "*Help*"
     (princ
@@ -2043,39 +2343,90 @@ the inserted text.  Value is always t."
    (propertize (substitute-command-keys
                "\\<calendar-mode-map>\\[scroll-calendar-left]")
               'help-echo "mouse-2: scroll left"
+              'mouse-face 'mode-line-highlight
               'keymap (make-mode-line-mouse-map 'mouse-2
-                                                #'scroll-calendar-left))
+                                                'mouse-scroll-calendar-left))
    "Calendar"
    (concat
     (propertize
      (substitute-command-keys
       "\\<calendar-mode-map>\\[calendar-goto-info-node] info")
      'help-echo "mouse-2: read Info on Calendar"
+     'mouse-face 'mode-line-highlight
      'keymap (make-mode-line-mouse-map 'mouse-2 'calendar-goto-info-node))
     "/"
     (propertize
      (substitute-command-keys
      "\\<calendar-mode-map>\\[calendar-other-month] other")
      'help-echo "mouse-2: choose another month"
+     'mouse-face 'mode-line-highlight
      'keymap (make-mode-line-mouse-map
-             'mouse-2
-             (lambda ()
-               (interactive)
-               (call-interactively
-                'calendar-other-month))))
+             'mouse-2 'mouse-calendar-other-month))
     "/"
     (propertize
      (substitute-command-keys
      "\\<calendar-mode-map>\\[calendar-goto-today] today")
      'help-echo "mouse-2: go to today's date"
+     'mouse-face 'mode-line-highlight
      'keymap (make-mode-line-mouse-map 'mouse-2 #'calendar-goto-today)))
    '(calendar-date-string (calendar-current-date) t)
    (propertize (substitute-command-keys
                "\\<calendar-mode-map>\\[scroll-calendar-right]")
               'help-echo "mouse-2: scroll right"
+              'mouse-face 'mode-line-highlight
               'keymap (make-mode-line-mouse-map
-                       'mouse-2 #'scroll-calendar-right)))
-  "The mode line of the calendar buffer.")
+                       'mouse-2 'mouse-scroll-calendar-right)))
+  "The mode line of the calendar buffer.
+
+This must be a list of items that evaluate to strings--those strings are
+evaluated and concatenated together, evenly separated by blanks.  The variable
+`date' is available for use as the date under (or near) the cursor; `date'
+defaults to the current date if it is otherwise undefined.  Here is an example
+value that has the Hebrew date, the day number/days remaining in the year,
+and the ISO week/year numbers in the mode.  When calendar-move-hook is set to
+'update-calendar-mode-line, these mode line shows these values for the date
+under the cursor:
+
+      (list
+       \"\"
+       '(calendar-hebrew-date-string date)
+       '(let* ((year (extract-calendar-year date))
+               (d (calendar-day-number date))
+               (days-remaining
+                (- (calendar-day-number (list 12 31 year)) d)))
+          (format \"%d/%d\" d days-remaining))
+       '(let* ((d (calendar-absolute-from-gregorian date))
+               (iso-date (calendar-iso-from-absolute d)))
+          (format \"ISO week %d of %d\"
+            (extract-calendar-month iso-date)
+            (extract-calendar-year iso-date)))
+       \"\"))
+")
+
+(defun mouse-scroll-calendar-left (event)
+  "Scroll the displayed calendar left by one month.
+Maintains the relative position of the cursor
+with respect to the calendar as well as possible."
+  (interactive "e")
+  (save-selected-window
+    (select-window (posn-window (event-start event)))
+    (scroll-calendar-left 1)))
+
+(defun mouse-scroll-calendar-right (event)
+  "Scroll the displayed calendar right by one month.
+Maintains the relative position of the cursor
+with respect to the calendar as well as possible."
+  (interactive "e")
+  (save-selected-window
+    (select-window (posn-window (event-start event)))
+    (scroll-calendar-right 1)))
+
+(defun mouse-calendar-other-month (event)
+  "Display a three-month calendar centered around a specified month and year."
+  (interactive "e")
+  (save-selected-window
+    (select-window (posn-window (event-start event)))
+    (call-interactively 'calendar-other-month)))
 
 (defun calendar-goto-info-node ()
   "Go to the info node for the calendar."
@@ -2089,6 +2440,8 @@ the inserted text.  Value is always t."
        (info))
       (Info-find-node (car (car where)) (car (cdr (car where)))))))
 
+
+
 (defun calendar-mode ()
   "A major mode for the calendar window.
 
@@ -2096,7 +2449,6 @@ For a complete description, type \
 \\<calendar-mode-map>\\[calendar-goto-info-node] from within the calendar.
 
 \\<calendar-mode-map>\\{calendar-mode-map}"
-
   (kill-all-local-variables)
   (setq major-mode 'calendar-mode)
   (setq mode-name "Calendar")
@@ -2107,7 +2459,10 @@ For a complete description, type \
   (add-hook 'activate-menubar-hook 'cal-menu-update nil t)
   (make-local-variable 'calendar-mark-ring)
   (make-local-variable 'displayed-month);;  Month in middle of window.
-  (make-local-variable 'displayed-year));;  Year in middle of window.
+  (make-local-variable 'displayed-year)        ;;  Year in middle of window.
+  (set (make-local-variable 'font-lock-defaults)
+       '(calendar-font-lock-keywords t))
+  (run-mode-hooks 'calendar-mode-hook))
 
 (defun calendar-string-spread (strings char length)
   "Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH.
@@ -2142,7 +2497,12 @@ the STRINGS are just concatenated and the result truncated."
         (set-buffer calendar-buffer)
         (setq mode-line-format
               (calendar-string-spread
-               calendar-mode-line-format ?  (frame-width))))))
+               (let ((date (condition-case nil
+                               (calendar-cursor-to-nearest-date)
+                             (error (calendar-current-date)))))
+                 (mapcar 'eval  calendar-mode-line-format))
+               ?  (frame-width)))
+        (force-mode-line-update))))
 
 (defun calendar-window-list ()
   "List of all calendar-related windows."
@@ -2227,7 +2587,7 @@ ERROR is t, otherwise just returns nil."
           (if (not (looking-at " "))
                    (re-search-backward "[^0-9]"))
           (list month
-                (string-to-int (buffer-substring (1+ (point)) (+ 4 (point))))
+                (string-to-number (buffer-substring (1+ (point)) (+ 4 (point))))
                 year))
       (if (looking-at "\\*")
           (save-excursion
@@ -2264,7 +2624,8 @@ ERROR is t, otherwise just returns nil."
 (defun calendar-gregorian-from-absolute (date)
   "Compute the list (month day year) corresponding to the absolute DATE.
 The absolute date is the number of days elapsed since the (imaginary)
-Gregorian date Sunday, December 31, 1 BC."
+Gregorian date Sunday, December 31, 1 BC.  This function does not
+handle dates in years BC."
 ;; See the footnote on page 384 of ``Calendrical Calculations, Part II:
 ;; Three Historical Calendars'' by E. M. Reingold,  N. Dershowitz, and S. M.
 ;; Clamen, Software--Practice and Experience, Volume 23, Number 4
@@ -2375,12 +2736,12 @@ If optional NODAY is t, does not ask for day, but just returns
                                 (calendar-current-date)))))
          (month-array calendar-month-name-array)
          (completion-ignore-case t)
-         (month (cdr (assoc-ignore-case
+         (month (cdr (assoc-string
                        (completing-read
                         "Month name: "
                         (mapcar 'list (append month-array nil))
                         nil t)
-                      (calendar-make-alist month-array 1))))
+                      (calendar-make-alist month-array 1) t)))
          (last (calendar-last-day-of-month month year)))
     (if noday
         (if (eq noday t)
@@ -2392,59 +2753,145 @@ If optional NODAY is t, does not ask for day, but just returns
             year))))
 
 (defun calendar-interval (mon1 yr1 mon2 yr2)
-  "The number of months difference between MON1, YR1 and MON2, YR2."
+  "The number of months difference between MON1, YR1 and MON2, YR2.
+The result is positive if the second date is later than the first.
+Negative years are interpreted as years BC; -1 being 1 BC, and so on."
+  (if (< yr1 0) (setq yr1 (1+ yr1)))      ; -1 BC -> 0 AD, etc
+  (if (< yr2 0) (setq yr2 (1+ yr2)))
   (+ (* 12 (- yr2 yr1))
      (- mon2 mon1)))
 
-(defun calendar-day-name (date &optional width absolute)
-  "Return a string with the name of the day of the week of DATE.
-If WIDTH is non-nil, return just the first WIDTH characters of the name.
-If ABSOLUTE is non-nil, then DATE is actually the day-of-the-week
-rather than a date."
-  (let ((string (aref calendar-day-name-array
-                     (if absolute date (calendar-day-of-week date)))))
-    (cond ((null width) string)
-         (enable-multibyte-characters (truncate-string-to-width string width))
-         (t (substring string 0 width)))))
+(defvar calendar-abbrev-length 3
+  "*Length of abbreviations to be used for day and month names.
+See also `calendar-day-abbrev-array' and `calendar-month-abbrev-array'.")
 
 (defvar calendar-day-name-array
   ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
-  "Array of capitalized strings giving, in order, the day names.")
+  "*Array of capitalized strings giving, in order, the day names.
+The first two characters of each string will be used to head the
+day columns in the calendar.  See also the variable
+`calendar-day-abbrev-array'.")
+
+(defvar calendar-day-abbrev-array
+  [nil nil nil nil nil nil nil]
+  "*Array of capitalized strings giving the abbreviated day names.
+The order should be the same as that of the full names specified
+in `calendar-day-name-array'.  These abbreviations may be used
+instead of the full names in the diary file.  Do not include a
+trailing `.' in the strings specified in this variable, though
+you may use such in the diary file.  If any element of this array
+is nil, then the abbreviation will be constructed as the first
+`calendar-abbrev-length' characters of the corresponding full name.")
 
 (defvar calendar-month-name-array
   ["January" "February" "March"     "April"   "May"      "June"
    "July"    "August"   "September" "October" "November" "December"]
-  "Array of capitalized strings giving, in order, the month names.")
-
-(defun calendar-make-alist (sequence &optional start-index filter)
+  "*Array of capitalized strings giving, in order, the month names.
+See also the variable `calendar-month-abbrev-array'.")
+
+(defvar calendar-month-abbrev-array
+  [nil nil nil nil nil nil nil nil nil nil nil nil]
+ "*Array of capitalized strings giving the abbreviated month names.
+The order should be the same as that of the full names specified
+in `calendar-month-name-array'.  These abbreviations are used in
+the calendar menu entries, and can also be used in the diary
+file.  Do not include a trailing `.' in the strings specified in
+this variable, though you may use such in the diary file.  If any
+element of this array is nil, then the abbreviation will be
+constructed as the first `calendar-abbrev-length' characters of the
+corresponding full name.")
+
+(defun calendar-abbrev-construct (abbrev full &optional period)
+  "Internal calendar function to return a complete abbreviation array.
+ABBREV is an array of abbreviations, FULL the corresponding array
+of full names.  The return value is the ABBREV array, with any nil
+elements replaced by the first three characters taken from the
+corresponding element of FULL.  If optional argument PERIOD is non-nil,
+each element returned has a final `.' character."
+  (let (elem array name)
+    (dotimes (i (length full))
+      (setq name (aref full i)
+            elem (or (aref abbrev i)
+                     (substring name 0
+                                (min calendar-abbrev-length (length name))))
+            elem (format "%s%s" elem (if period "." ""))
+            array (append array (list elem))))
+    (vconcat array)))
+
+(defvar calendar-font-lock-keywords
+  `((,(concat (regexp-opt (mapcar 'identity calendar-month-name-array) t)
+             " -?[0-9]+")
+     . font-lock-function-name-face) ; month and year
+    (,(regexp-opt
+       (list (substring (aref calendar-day-name-array 6) 0 2)
+            (substring (aref calendar-day-name-array 0) 0 2)))
+     ;; Saturdays and Sundays are hilited differently.
+     . font-lock-comment-face)
+    ;; First two chars of each day are used in the calendar.
+    (,(regexp-opt (mapcar (lambda (x) (substring x 0 2)) calendar-day-name-array))
+     . font-lock-reference-face))
+  "Default keywords to highlight in Calendar mode.")
+
+(defun calendar-day-name (date &optional abbrev absolute)
+  "Return a string with the name of the day of the week of DATE.
+DATE should be a list in the format (MONTH DAY YEAR), unless the
+optional argument ABSOLUTE is non-nil, in which case DATE should
+be an integer in the range 0 to 6 corresponding to the day of the
+week.  Day names are taken from the variable `calendar-day-name-array',
+unless the optional argument ABBREV is non-nil, in which case
+the variable `calendar-day-abbrev-array' is used."
+  (aref (if abbrev
+            (calendar-abbrev-construct calendar-day-abbrev-array
+                                       calendar-day-name-array)
+          calendar-day-name-array)
+        (if absolute date (calendar-day-of-week date))))
+
+(defun calendar-make-alist (sequence &optional start-index filter abbrevs)
   "Make an assoc list corresponding to SEQUENCE.
-Start at index 1, unless optional START-INDEX is provided.
-If FILTER is provided, apply it to each item in the list."
-  (let ((index (if start-index (1- start-index) 0)))
-    (mapcar
-     (lambda (x)
-        (setq index (1+ index))
-        (cons (if filter (funcall filter x) x)
-              index))
-     (append sequence nil))))
-
-(defun calendar-month-name (month &optional width)
-  "The name of MONTH.
-If WIDTH is non-nil, return just the first WIDTH characters of the name."
-  (let ((string (aref calendar-month-name-array (1- month))))
-    (if width
-       (let ((i 0) (result "") (pos 0))
-         (while (< i width)
-           (let ((chartext (char-to-string (aref string pos))))
-             (setq pos (+ pos (length chartext)))
-             (setq result (concat result chartext)))
-           (setq i (1+ i)))
-         result)
-      string)))
+Each element of sequence will be associated with an integer, starting
+from 1, or from START-INDEX if that is non-nil.  If a sequence ABBREVS
+is supplied, the function `calendar-abbrev-construct' is used to
+construct abbreviations corresponding to the elements in SEQUENCE.
+Each abbreviation is entered into the alist with the same
+association index as the full name it represents.
+If FILTER is provided, apply it to each key in the alist."
+  (let ((index 0)
+        (offset (or start-index 1))
+        (aseq (if abbrevs (calendar-abbrev-construct abbrevs sequence)))
+        (aseqp (if abbrevs (calendar-abbrev-construct abbrevs sequence
+                                                      'period)))
+        alist elem)
+    (dotimes (i (length sequence) (reverse alist))
+      (setq index (+ i offset)
+            elem (elt sequence i)
+            alist
+            (cons (cons (if filter (funcall filter elem) elem) index) alist))
+      (if aseq
+          (setq elem (elt aseq i)
+                alist (cons (cons (if filter (funcall filter elem) elem)
+                                  index) alist)))
+      (if aseqp
+          (setq elem (elt aseqp i)
+                alist (cons (cons (if filter (funcall filter elem) elem)
+                                  index) alist))))))
+
+(defun calendar-month-name (month &optional abbrev)
+  "Return a string with the name of month number MONTH.
+Months are numbered from one.  Month names are taken from the
+variable `calendar-month-name-array', unless the optional
+argument ABBREV is non-nil, in which case
+`calendar-month-abbrev-array' is used."
+  (aref (if abbrev
+            (calendar-abbrev-construct calendar-month-abbrev-array
+                                       calendar-month-name-array)
+          calendar-month-name-array)
+        (1- month)))
 
 (defun calendar-day-of-week (date)
-  "Return the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc."
-  (% (calendar-absolute-from-gregorian date) 7))
+  "Return the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc.
+DATE is a list of the form (month day year).  A negative year is
+interpreted as BC; -1 being 1 BC, and so on."
+  (mod (calendar-absolute-from-gregorian date) 7))
 
 (defun calendar-unmark ()
   "Delete all diary/holiday marks/highlighting from the calendar."
@@ -2454,19 +2901,22 @@ If WIDTH is non-nil, return just the first WIDTH characters of the name."
   (redraw-calendar))
 
 (defun calendar-date-is-visible-p (date)
-  "Return t if DATE is legal and is visible in the calendar window."
+  "Return t if DATE is valid and is visible in the calendar window."
   (let ((gap (calendar-interval
               displayed-month displayed-year
               (extract-calendar-month date) (extract-calendar-year date))))
     (and (calendar-date-is-legal-p date) (> 2 gap) (< -2 gap))))
 
 (defun calendar-date-is-legal-p (date)
-  "Return t if DATE is a legal date."
+  "Return t if DATE is a valid date."
   (let ((month (extract-calendar-month date))
         (day (extract-calendar-day date))
         (year (extract-calendar-year date)))
     (and (<= 1 month) (<= month 12)
          (<= 1 day) (<= day (calendar-last-day-of-month month year))
+         ;; BC dates left as non-valid, to suppress errors from
+         ;; complex holiday algorithms not suitable for years BC.
+         ;; Note there are side effects on calendar navigation.
          (<= 1 year))))
 
 (defun calendar-date-equal (date1 date2)
@@ -2478,21 +2928,46 @@ If WIDTH is non-nil, return just the first WIDTH characters of the name."
 
 (defun mark-visible-calendar-date (date &optional mark)
   "Mark DATE in the calendar window with MARK.
-MARK is either a single-character string or a face.
-MARK defaults to diary-entry-marker."
+MARK is a single-character string, a list of face attributes/values, or a face.
+MARK defaults to `diary-entry-marker'."
   (if (calendar-date-is-legal-p date)
       (save-excursion
         (set-buffer calendar-buffer)
         (calendar-cursor-to-visible-date date)
-        (let ((mark (or mark diary-entry-marker)))
-          (if (stringp mark)
-              (let ((buffer-read-only nil))
-                (forward-char 1)
-                (delete-char 1)
-                (insert mark)
-                (forward-char -2))
-           (overlay-put
-             (make-overlay (1- (point)) (1+ (point))) 'face mark))))))
+        (let ((mark (or (and (stringp mark) (= (length mark) 1) mark) ; single-char
+                        (and (listp mark) (> (length mark) 0) mark) ; attr list
+                        (and (facep mark) mark) ; face-name
+                        diary-entry-marker)))
+          (if (facep mark)
+              (progn      ; face or an attr-list that contained a face
+                (overlay-put
+                 (make-overlay (1- (point)) (1+ (point))) 'face mark))
+            (if (and (stringp mark)
+                     (= (length mark) 1)) ; single-char
+                (let ((buffer-read-only nil))
+                  (forward-char 1)
+                  (delete-char 1)
+                  (insert mark)
+                  (forward-char -2))
+              (let                      ; attr list
+                  ((temp-face
+                    (make-symbol (apply 'concat "temp-"
+                                        (mapcar '(lambda (sym)
+                                                   (cond ((symbolp sym) (symbol-name sym))
+                                                         ((numberp sym) (int-to-string sym))
+                                                         (t sym))) mark))))
+                   (faceinfo mark))
+                (make-face temp-face)
+                ;; Remove :face info from the mark, copy the face info into temp-face
+                (while (setq faceinfo (memq :face faceinfo))
+                  (copy-face (read (nth 1 faceinfo)) temp-face)
+                  (setcar faceinfo nil)
+                  (setcar (cdr faceinfo) nil))
+                (setq mark (delq nil mark))
+                ;; Apply the font aspects
+                (apply 'set-face-attribute temp-face nil mark)
+                (overlay-put
+                 (make-overlay (1- (point)) (1+ (point))) 'face temp-face))))))))
 
 (defun calendar-star-date ()
   "Replace the date under the cursor in the calendar window with asterisks.
@@ -2502,7 +2977,7 @@ calendar window has been prepared."
     (make-local-variable 'calendar-starred-day)
     (forward-char 1)
     (setq calendar-starred-day
-          (string-to-int
+          (string-to-number
            (buffer-substring (point) (- (point) 2))))
     (delete-char -2)
     (insert "**")
@@ -2511,7 +2986,7 @@ calendar window has been prepared."
 
 (defun calendar-mark-today ()
   "Mark the date under the cursor in the calendar window.
-The date is marked with calendar-today-marker.  This function can be used with
+The date is marked with `calendar-today-marker'.  This function can be used with
 the `today-visible-calendar-hook' run after the calendar window has been
 prepared."
   (mark-visible-calendar-date
@@ -2526,20 +3001,16 @@ The actual dates are in the car of DATE1 and DATE2."
 
 (defun calendar-date-string (date &optional abbreviate nodayname)
   "A string form of DATE, driven by the variable `calendar-date-display-form'.
-An optional parameter ABBREVIATE, when t, causes the month and day names to be
-abbreviated to three characters.  An optional parameter NODAYNAME, when t,
-omits the name of the day of the week."
+An optional parameter ABBREVIATE, when non-nil, causes the month
+and day names to be abbreviated as specified by
+`calendar-month-abbrev-array' and `calendar-day-abbrev-array',
+respectively.  An optional parameter NODAYNAME, when t, omits the
+name of the day of the week."
   (let* ((dayname
-          (if nodayname
-              nil
-            (if abbreviate
-                (calendar-day-name date 3)
-              (calendar-day-name date))))
+          (unless nodayname
+            (calendar-day-name date abbreviate)))
          (month (extract-calendar-month date))
-         (monthname
-          (if abbreviate
-              (calendar-month-name month 3)
-            (calendar-month-name month)))
+         (monthname (calendar-month-name month abbreviate))
          (day (int-to-string (extract-calendar-day date)))
          (month (int-to-string month))
          (year (int-to-string (extract-calendar-year date))))
@@ -2624,6 +3095,9 @@ Defaults to today's date if DATE is not given."
                         (let ((i (calendar-islamic-date-string date)))
                           (if (not (string-equal i ""))
                               (format "Islamic date (before sunset): %s" i)))
+                       (let ((b (calendar-bahai-date-string date)))
+                         (if (not (string-equal b ""))
+                             (format "Baha'i date (before sunset): %s" b)))
                         (format "Chinese date: %s"
                                 (calendar-chinese-date-string date))
                         (let ((c (calendar-coptic-date-string date)))
@@ -2651,7 +3125,10 @@ Defaults to today's date if DATE is not given."
 (defun calendar-set-mode-line (str)
   "Set mode line to STR, centered, surrounded by dashes."
   (setq mode-line-format
-        (calendar-string-spread (list str) ?- (frame-width))))
+        (calendar-string-spread
+         (list str) ?-
+         ;; As per doc of window-width, total visible mode-line length.
+         (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))))))
 
 (defun calendar-mod (m n)
   "Non-negative remainder of M/N with N instead of 0."
@@ -2665,4 +3142,5 @@ Defaults to today's date if DATE is not given."
 ;;; byte-compile-dynamic: t
 ;;; End:
 
+;;; arch-tag: 19c61596-c8fb-4c69-bcf1-7dd739919cd8
 ;;; calendar.el ends here