PageRenderTime 77ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/xemacs-packages-extra-20110502/xemacs-packages/calendar/calendar.el

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