PageRenderTime 68ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/calendar/calendar.el

https://bitbucket.org/rev22/progressive-gc-emacsen
Emacs Lisp | 2629 lines | 2030 code | 272 blank | 327 comment | 72 complexity | dcbf89ea6a571fa753f9c7fe49af42e8 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. ;;; calendar.el --- calendar functions
  2. ;; Copyright (C) 1988-1995, 1997, 2000-2012 Free Software Foundation, Inc.
  3. ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
  4. ;; Maintainer: Glenn Morris <rgm@gnu.org>
  5. ;; Keywords: calendar
  6. ;; Human-Keywords: calendar, Gregorian calendar, diary, holidays
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This collection of functions implements a calendar window. It
  20. ;; generates a calendar for the current month, together with the
  21. ;; previous and coming months, or for any other three-month period.
  22. ;; The calendar can be scrolled forward and backward in the window to
  23. ;; show months in the past or future; the cursor can move forward and
  24. ;; backward by days, weeks, or months, making it possible, for
  25. ;; instance, to jump to the date a specified number of days, weeks, or
  26. ;; months from the date under the cursor. The user can display a list
  27. ;; of holidays and other notable days for the period shown; the
  28. ;; notable days can be marked on the calendar, if desired. The user
  29. ;; can also specify that dates having corresponding diary entries (in
  30. ;; a file that the user specifies) be marked; the diary entries for
  31. ;; any date can be viewed in a separate window. The diary and the
  32. ;; notable days can be viewed independently of the calendar. Dates
  33. ;; can be translated from the (usual) Gregorian calendar to the day of
  34. ;; the year/days remaining in year, to the ISO commercial calendar, to
  35. ;; the Julian (old style) calendar, to the Hebrew calendar, to the
  36. ;; Islamic calendar, to the Baha'i calendar, to the French
  37. ;; Revolutionary calendar, to the Mayan calendar, to the Chinese
  38. ;; calendar, to the Coptic calendar, to the Ethiopic calendar, and to
  39. ;; the astronomical (Julian) day number. Times of sunrise/sunset can
  40. ;; be displayed, as can the phases of the moon. Appointment
  41. ;; notification for diary entries is available. Calendar printing via
  42. ;; LaTeX is available.
  43. ;; The following files are part of the calendar/diary code:
  44. ;; appt.el Appointment notification
  45. ;; cal-bahai.el Baha'i calendar
  46. ;; cal-china.el Chinese calendar
  47. ;; cal-coptic.el Coptic/Ethiopic calendars
  48. ;; cal-dst.el Daylight saving time rules
  49. ;; cal-french.el French revolutionary calendar
  50. ;; cal-hebrew.el Hebrew calendar
  51. ;; cal-html.el Calendars in HTML
  52. ;; cal-islam.el Islamic calendar
  53. ;; cal-iso.el ISO calendar
  54. ;; cal-julian.el Julian/astronomical calendars
  55. ;; cal-mayan.el Mayan calendars
  56. ;; cal-menu.el Menu support
  57. ;; cal-move.el Movement in the calendar
  58. ;; cal-persia.el Persian calendar
  59. ;; cal-tex.el Calendars in LaTeX
  60. ;; cal-x.el Dedicated frame functions
  61. ;; calendar.el This file
  62. ;; diary-lib.el Diary functions
  63. ;; holidays.el Holiday functions
  64. ;; lunar.el Phases of the moon
  65. ;; solar.el Sunrise/sunset, equinoxes/solstices
  66. ;; Technical details of all the calendrical calculations can be found in
  67. ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
  68. ;; and Nachum Dershowitz, Cambridge University Press (2001).
  69. ;; An earlier version of the technical details appeared in
  70. ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
  71. ;; Software--Practice and Experience, Volume 20, Number 9 (September, 1990),
  72. ;; pages 899-928, and in ``Calendrical Calculations, Part II: Three Historical
  73. ;; Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. Clamen,
  74. ;; Software--Practice and Experience, Volume 23, Number 4 (April, 1993),
  75. ;; pages 383-404.
  76. ;; Hard copies of these two papers can be obtained by sending email to
  77. ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and
  78. ;; the message BODY containing your mailing address (snail).
  79. ;; A note on free variables:
  80. ;; The calendar passes around a few dynamically bound variables, which
  81. ;; unfortunately have rather common names. They are meant to be
  82. ;; available for external functions, so the names can't be changed.
  83. ;; displayed-month, displayed-year: bound in calendar-generate, the
  84. ;; central month of the 3 month calendar window
  85. ;; original-date, number: bound in diary-list-entries, the arguments
  86. ;; with which that function was called.
  87. ;; date, entry: bound in diary-list-sexp-entries (qv)
  88. ;; Bound in diary-list-entries:
  89. ;; diary-entries-list: use in d-l, appt.el, and by diary-add-to-list
  90. ;; diary-saved-point: only used in diary-lib.el, passed to the display func
  91. ;; date-string: only used in diary-lib.el
  92. ;; list-only: don't modify the diary-buffer, just return a list of entries
  93. ;; file-glob-attrs: yuck
  94. ;;; Code:
  95. (load "cal-loaddefs" nil t)
  96. ;; Avoid recursive load of calendar when loading cal-menu. Yuck.
  97. (provide 'calendar)
  98. (require 'cal-menu)
  99. (defgroup calendar nil
  100. "Calendar and time management support."
  101. :prefix "calendar-"
  102. :group 'applications)
  103. (defgroup calendar-hooks nil
  104. "Calendar hooks."
  105. :prefix "calendar-"
  106. :group 'calendar)
  107. (defgroup calendar-faces nil
  108. "Calendar faces."
  109. :prefix "calendar-"
  110. :group 'calendar)
  111. (defcustom calendar-offset 0
  112. "The offset of the principal month from the center of the calendar window.
  113. 0 means the principal month is in the center (default), -1 means on the left,
  114. +1 means on the right. Larger (or smaller) values push the principal month off
  115. the screen."
  116. :type 'integer
  117. :group 'calendar)
  118. (defcustom calendar-setup nil
  119. "The frame setup of the calendar.
  120. The choices are: `one-frame' (calendar and diary together in one separate,
  121. dedicated frame); `two-frames' (calendar and diary in separate, dedicated
  122. frames); `calendar-only' (calendar in a separate, dedicated frame); with
  123. any other value the current frame is used. Using any of the first
  124. three options overrides the value of `calendar-view-diary-initially-flag'."
  125. :type '(choice
  126. (const :tag "calendar and diary in separate frame" one-frame)
  127. (const :tag "calendar and diary each in own frame" two-frames)
  128. (const :tag "calendar in separate frame" calendar-only)
  129. (const :tag "use current frame" nil))
  130. :group 'calendar)
  131. (defcustom calendar-minimum-window-height 8
  132. "Minimum height `calendar-generate-window' should use for calendar window."
  133. :type 'integer
  134. :version "22.1"
  135. :group 'calendar)
  136. ;; See discussion in bug#1806.
  137. (defcustom calendar-split-width-threshold nil
  138. "Value to use for `split-width-threshold' when creating a calendar.
  139. This only affects frames wider than the default value of
  140. `split-width-threshold'."
  141. :type '(choice (const nil)
  142. (integer))
  143. :version "23.2"
  144. :group 'calendar)
  145. (defcustom calendar-week-start-day 0
  146. "The day of the week on which a week in the calendar begins.
  147. 0 means Sunday (default), 1 means Monday, and so on.
  148. If you change this variable directly (without using customize)
  149. after starting `calendar', you should call `calendar-redraw' to
  150. update the calendar display to reflect the change, otherwise
  151. movement commands will not work correctly."
  152. :type 'integer
  153. ;; Change the initialize so that if you reload calendar.el, it will not
  154. ;; cause a redraw (which may fail, e.g. with "invalid byte-code in
  155. ;; calendar.elc" because of the "byte-compile-dynamic").
  156. :initialize 'custom-initialize-default
  157. :set (lambda (sym val)
  158. (set sym val)
  159. (calendar-redraw))
  160. :group 'calendar)
  161. (define-obsolete-variable-alias 'view-diary-entries-initially
  162. 'calendar-view-diary-initially-flag "23.1")
  163. (defcustom calendar-view-diary-initially-flag nil
  164. "Non-nil means display current date's diary entries on entry to calendar.
  165. The diary is displayed in another window when the calendar is first displayed,
  166. if the current date is visible. The number of days of diary entries displayed
  167. is governed by the variable `diary-number-of-entries'. This variable can
  168. be overridden by the value of `calendar-setup'."
  169. :type 'boolean
  170. :group 'diary)
  171. (define-obsolete-variable-alias 'mark-diary-entries-in-calendar
  172. 'calendar-mark-diary-entries-flag "23.1")
  173. ;; FIXME :set
  174. (defcustom calendar-mark-diary-entries-flag nil
  175. "Non-nil means mark dates with diary entries, in the calendar window.
  176. The marking symbol is specified by the variable `diary-entry-marker'."
  177. :type 'boolean
  178. :group 'diary)
  179. (defcustom calendar-remove-frame-by-deleting t
  180. "Determine how the calendar mode removes a frame no longer needed.
  181. If nil, make an icon of the frame. If non-nil, delete the frame."
  182. :type 'boolean
  183. :version "23.1" ; changed from nil to t
  184. :group 'view
  185. :group 'calendar)
  186. (defface calendar-today
  187. '((t (:underline t)))
  188. "Face for indicating today's date in the calendar.
  189. See the variable `calendar-today-marker'."
  190. :group 'calendar-faces)
  191. (define-obsolete-face-alias 'calendar-today-face 'calendar-today "22.1")
  192. (defface diary
  193. '((((min-colors 88) (class color) (background light))
  194. :foreground "red1")
  195. (((class color) (background light))
  196. :foreground "red")
  197. (((min-colors 88) (class color) (background dark))
  198. :foreground "yellow1")
  199. (((class color) (background dark))
  200. :foreground "yellow")
  201. (t
  202. :weight bold))
  203. "Face for highlighting diary entries.
  204. Used to mark diary entries in the calendar (see `diary-entry-marker'),
  205. and to highlight the date header in the fancy diary."
  206. :group 'calendar-faces)
  207. (define-obsolete-face-alias 'diary-face 'diary "22.1")
  208. (defface holiday
  209. '((((class color) (background light))
  210. :background "pink")
  211. (((class color) (background dark))
  212. :background "chocolate4")
  213. (t
  214. :inverse-video t))
  215. "Face for indicating in the calendar dates that have holidays.
  216. See `calendar-holiday-marker'."
  217. :group 'calendar-faces)
  218. (define-obsolete-face-alias 'holiday-face 'holiday "22.1")
  219. ;; These briefly checked font-lock-mode, but that is broken, since it
  220. ;; is a buffer-local variable, and which buffer happens to be current
  221. ;; when this file is loaded shouldn't make a difference. One could
  222. ;; perhaps check global-font-lock-mode, or font-lock-global-modes; but
  223. ;; this feature doesn't use font-lock, so there's no real reason it
  224. ;; should respect those either. See bug#2199.
  225. ;; They also used to check display-color-p, but that is a problem if
  226. ;; loaded from --daemon. Since BW displays are rare now, this was
  227. ;; also taken out. The way to keep it would be to have nil mean do a
  228. ;; runtime check whenever this variable is used.
  229. (defcustom diary-entry-marker 'diary
  230. "How to mark dates that have diary entries.
  231. The value can be either a single-character string (e.g. \"+\") or a face."
  232. :type '(choice (string :tag "Single character string") face)
  233. :group 'diary
  234. :version "23.1")
  235. (defcustom calendar-today-marker 'calendar-today
  236. "How to mark today's date in the calendar.
  237. The value can be either a single-character string (e.g. \"=\") or a face.
  238. Used by `calendar-mark-today'."
  239. :type '(choice (string :tag "Single character string") face)
  240. :group 'calendar
  241. :version "23.1")
  242. (defcustom calendar-holiday-marker 'holiday
  243. "How to mark notable dates in the calendar.
  244. The value can be either a single-character string (e.g. \"*\") or a face."
  245. :type '(choice (string :tag "Single character string") face)
  246. :group 'holidays
  247. :version "23.1")
  248. (define-obsolete-variable-alias 'view-calendar-holidays-initially
  249. 'calendar-view-holidays-initially-flag "23.1")
  250. (defcustom calendar-view-holidays-initially-flag nil
  251. "Non-nil means display holidays for current three month period on entry.
  252. The holidays are displayed in another window when the calendar is first
  253. displayed."
  254. :type 'boolean
  255. :group 'holidays)
  256. (define-obsolete-variable-alias 'mark-holidays-in-calendar
  257. 'calendar-mark-holidays-flag "23.1")
  258. ;; FIXME :set
  259. (defcustom calendar-mark-holidays-flag nil
  260. "Non-nil means mark dates of holidays in the calendar window.
  261. The marking symbol is specified by the variable `calendar-holiday-marker'."
  262. :type 'boolean
  263. :group 'holidays)
  264. (defcustom calendar-mode-hook nil
  265. "Hook run when entering `calendar-mode'."
  266. :type 'hook
  267. :group 'calendar-hooks)
  268. (defcustom calendar-load-hook nil
  269. "List of functions to be called after the calendar is first loaded.
  270. This is the place to add key bindings to `calendar-mode-map'."
  271. :type 'hook
  272. :group 'calendar-hooks)
  273. (define-obsolete-variable-alias 'initial-calendar-window-hook
  274. 'calendar-initial-window-hook "23.1")
  275. (defcustom calendar-initial-window-hook nil
  276. "List of functions to be called when the calendar window is created.
  277. Quitting the calendar and re-entering it will cause these functions
  278. to be called again."
  279. :type 'hook
  280. :group 'calendar-hooks)
  281. (define-obsolete-variable-alias 'today-visible-calendar-hook
  282. 'calendar-today-visible-hook "23.1")
  283. (defcustom calendar-today-visible-hook nil
  284. "List of functions called whenever the current date is visible.
  285. To mark today's date, add the function `calendar-mark-today'.
  286. To replace the date with asterisks, add the function `calendar-star-date'.
  287. See also `calendar-today-invisible-hook'.
  288. In general, be careful about changing characters in the calendar buffer,
  289. since it may cause the movement commands to fail."
  290. :type 'hook
  291. :options '(calendar-mark-today calendar-star-date)
  292. :group 'calendar-hooks)
  293. (define-obsolete-variable-alias 'today-invisible-calendar-hook
  294. 'calendar-today-invisible-hook "23.1")
  295. (defcustom calendar-today-invisible-hook nil
  296. "List of functions called whenever the current date is not visible.
  297. See also `calendar-today-visible-hook'."
  298. :type 'hook
  299. :group 'calendar-hooks)
  300. (defcustom calendar-move-hook nil
  301. "List of functions called whenever the cursor moves in the calendar.
  302. For example,
  303. (add-hook 'calendar-move-hook (lambda () (diary-view-entries 1)))
  304. redisplays the diary for whatever date the cursor is moved to."
  305. :type 'hook
  306. :options '(calendar-update-mode-line)
  307. :group 'calendar-hooks)
  308. (defcustom calendar-date-echo-text
  309. "mouse-2: general menu\nmouse-3: menu for this date"
  310. "String displayed when the cursor is over a date in the calendar.
  311. Can be either a fixed string, or a lisp expression that returns one.
  312. When this expression is evaluated, DAY, MONTH, and YEAR are
  313. integers appropriate to the relevant date. For example, to
  314. display the ISO date:
  315. (setq calendar-date-echo-text '(format \"ISO date: %s\"
  316. (calendar-iso-date-string
  317. (list month day year))))
  318. Changing this variable without using customize has no effect on
  319. pre-existing calendar windows."
  320. :group 'calendar
  321. :initialize 'custom-initialize-default
  322. :risky t
  323. :set (lambda (sym val)
  324. (set sym val)
  325. (calendar-redraw))
  326. :type '(choice (string :tag "Fixed string")
  327. (sexp :value
  328. (format "ISO date: %s"
  329. (calendar-iso-date-string
  330. (list month day year)))))
  331. :version "23.1")
  332. (defvar calendar-month-digit-width nil
  333. "Width of the region with numbers in each month in the calendar.")
  334. (defvar calendar-month-width nil
  335. "Full width of each month in the calendar.")
  336. (defvar calendar-right-margin nil
  337. "Right margin of the calendar.")
  338. (defvar calendar-month-edges nil
  339. "Alist of month edge columns.
  340. Each element has the form (N LEFT FIRST LAST RIGHT), where
  341. LEFT is the leftmost column associated with month segment N,
  342. FIRST and LAST are the first and last columns with day digits in,
  343. and LAST is the rightmost column.")
  344. (defun calendar-month-edges (segment)
  345. "Compute the month edge columns for month SEGMENT.
  346. Returns a list (LEFT FIRST LAST RIGHT), where LEFT is the
  347. leftmost column associated with a month, FIRST and LAST are the
  348. first and last columns with day digits in, and LAST is the
  349. rightmost column."
  350. ;; The leftmost column with a digit in it in this month segment.
  351. (let* ((first (+ calendar-left-margin
  352. (* segment calendar-month-width)))
  353. ;; The rightmost column with a digit in it in this month segment.
  354. (last (+ first (1- calendar-month-digit-width)))
  355. (left (if (eq segment 0)
  356. 0
  357. (+ calendar-left-margin
  358. (* segment calendar-month-width)
  359. (- (/ calendar-intermonth-spacing 2)))))
  360. ;; The rightmost edge of this month segment, dividing the
  361. ;; space between months in two.
  362. (right (+ calendar-left-margin
  363. (* (1+ segment) calendar-month-width)
  364. (- (/ calendar-intermonth-spacing 2)))))
  365. (list left first last right)))
  366. (defun calendar-recompute-layout-variables ()
  367. "Recompute some layout-related calendar \"constants\"."
  368. (setq calendar-month-digit-width (+ (* 6 calendar-column-width)
  369. calendar-day-digit-width)
  370. calendar-month-width (+ (* 7 calendar-column-width)
  371. calendar-intermonth-spacing)
  372. calendar-right-margin (+ calendar-left-margin
  373. (* 3 (* 7 calendar-column-width))
  374. (* 2 calendar-intermonth-spacing))
  375. calendar-month-edges nil)
  376. (dotimes (i 3)
  377. (push (cons i (calendar-month-edges i)) calendar-month-edges))
  378. (setq calendar-month-edges (reverse calendar-month-edges)))
  379. ;; FIXME add font-lock-keywords.
  380. (defun calendar-set-layout-variable (symbol value &optional minmax)
  381. "Set SYMBOL's value to VALUE, an integer.
  382. A positive/negative MINMAX enforces a minimum/maximum value.
  383. Then redraw the calendar, if necessary."
  384. (let ((oldvalue (symbol-value symbol)))
  385. (custom-set-default symbol (if minmax
  386. (if (< minmax 0)
  387. (min value (- minmax))
  388. (max value minmax))
  389. value))
  390. (unless (equal value oldvalue)
  391. (calendar-recompute-layout-variables)
  392. (calendar-redraw))))
  393. (defcustom calendar-left-margin 5
  394. "Empty space to the left of the first month in the calendar."
  395. :group 'calendar
  396. :initialize 'custom-initialize-default
  397. :set 'calendar-set-layout-variable
  398. :type 'integer
  399. :version "23.1")
  400. ;; Or you can view it as columns of width 2, with 1 space, no space
  401. ;; after the last column, and a 5 space gap between month.
  402. ;; FIXME check things work if this is odd.
  403. (defcustom calendar-intermonth-spacing 4
  404. "Space between months in the calendar. Minimum value is 1."
  405. :group 'calendar
  406. :initialize 'custom-initialize-default
  407. :set (lambda (sym val)
  408. (calendar-set-layout-variable sym val 1))
  409. :type 'integer
  410. :version "23.1")
  411. ;; FIXME calendar-month-column-width?
  412. (defcustom calendar-column-width 3
  413. "Width of each day column in the calendar. Minimum value is 3."
  414. :initialize 'custom-initialize-default
  415. :set (lambda (sym val)
  416. (calendar-set-layout-variable sym val 3))
  417. :type 'integer
  418. :version "23.1")
  419. (defcustom calendar-day-header-width 2
  420. "Width of the day column headers in the calendar.
  421. Must be at least one less than `calendar-column-width'."
  422. :group 'calendar
  423. :initialize 'custom-initialize-default
  424. :set (lambda (sym val)
  425. (calendar-set-layout-variable sym val (- 1 calendar-column-width)))
  426. :type 'integer
  427. :version "23.1")
  428. ;; FIXME a format specifier instead?
  429. (defcustom calendar-day-digit-width 2
  430. "Width of the day digits in the calendar. Minimum value is 2."
  431. :group 'calendar
  432. :initialize 'custom-initialize-default
  433. :set (lambda (sym val)
  434. (calendar-set-layout-variable sym val 2))
  435. :type 'integer
  436. :version "23.1")
  437. (defcustom calendar-intermonth-header nil
  438. "Header text display in the space to the left of each calendar month.
  439. See `calendar-intermonth-text'."
  440. :group 'calendar
  441. :initialize 'custom-initialize-default
  442. :risky t
  443. :set (lambda (sym val)
  444. (set sym val)
  445. (calendar-redraw))
  446. :type '(choice (const nil :tag "Nothing")
  447. (string :tag "Fixed string")
  448. (sexp :value
  449. (propertize "WK" 'font-lock-face
  450. 'font-lock-function-name-face)))
  451. :version "23.1")
  452. (defcustom calendar-intermonth-text nil
  453. "Text to display in the space to the left of each calendar month.
  454. Can be nil, a fixed string, or a lisp expression that returns a string.
  455. When the expression is evaluated, the variables DAY, MONTH and YEAR
  456. are integers appropriate for the first day in each week.
  457. Will be truncated to the smaller of `calendar-left-margin' and
  458. `calendar-intermonth-spacing'. The last character is forced to be a space.
  459. For example, to display the ISO week numbers:
  460. (setq calendar-week-start-day 1
  461. calendar-intermonth-text
  462. '(propertize
  463. (format \"%2d\"
  464. (car
  465. (calendar-iso-from-absolute
  466. (calendar-absolute-from-gregorian (list month day year)))))
  467. 'font-lock-face 'font-lock-function-name-face))
  468. See also `calendar-intermonth-header'."
  469. :group 'calendar
  470. :initialize 'custom-initialize-default
  471. :risky t
  472. :set (lambda (sym val)
  473. (set sym val)
  474. (calendar-redraw))
  475. :type '(choice (const nil :tag "Nothing")
  476. (string :tag "Fixed string")
  477. (sexp :value
  478. (propertize
  479. (format "%2d"
  480. (car
  481. (calendar-iso-from-absolute
  482. (calendar-absolute-from-gregorian
  483. (list month day year)))))
  484. 'font-lock-face 'font-lock-function-name-face)))
  485. :version "23.1")
  486. (defcustom diary-file "~/diary"
  487. "Name of the file in which one's personal diary of dates is kept.
  488. The file's entries are lines beginning with any of the forms
  489. specified by the variable `diary-date-forms', which by default
  490. uses the forms of `diary-american-date-forms':
  491. MONTH/DAY
  492. MONTH/DAY/YEAR
  493. MONTHNAME DAY
  494. MONTHNAME DAY, YEAR
  495. DAYNAME
  496. with the remainder of the line being the diary entry string for
  497. that date. MONTH and DAY are one or two digit numbers, YEAR is a
  498. number and may be written in full or abbreviated to the final two
  499. digits (if `diary-abbreviated-year-flag' is non-nil). MONTHNAME
  500. and DAYNAME can be spelled in full (as specified by the variables
  501. `calendar-month-name-array' and `calendar-day-name-array'), or
  502. abbreviated (as specified by `calendar-month-abbrev-array' and
  503. `calendar-day-abbrev-array') with or without a period. Case is
  504. ignored. Any of DAY, MONTH, or MONTHNAME, YEAR can be `*' which
  505. matches any day, month, or year, respectively. If the date does
  506. not contain a year, it is generic and applies to any year. A
  507. DAYNAME entry applies to the appropriate day of the week in every week.
  508. You can customize `diary-date-forms' to your preferred format.
  509. Three default styles are provided: `diary-american-date-forms',
  510. `diary-european-date-forms', and `diary-iso-date-forms'.
  511. You can choose between these by setting `calendar-date-style' in your
  512. .emacs file, or by using `calendar-set-date-style' when in the calendar.
  513. A diary entry can be preceded by the character `diary-nonmarking-symbol'
  514. \(ordinarily `&') to make that entry nonmarking--that is, it will not be
  515. marked on dates in the calendar window but will appear in a diary window.
  516. Multiline diary entries are made by indenting lines after the first with
  517. either a TAB or one or more spaces.
  518. Lines not in one the above formats are ignored. Here are some sample diary
  519. entries (in the default American style):
  520. 12/22/1988 Twentieth wedding anniversary!!
  521. &1/1. Happy New Year!
  522. 10/22 Ruth's birthday.
  523. 21: Payday
  524. Tuesday--weekly meeting with grad students at 10am
  525. Supowit, Shen, Bitner, and Kapoor to attend.
  526. 1/13/89 Friday the thirteenth!!
  527. &thu 4pm squash game with Lloyd.
  528. mar 16 Dad's birthday
  529. April 15, 1989 Income tax due.
  530. &* 15 time cards due.
  531. If the first line of a diary entry consists only of the date or day name with
  532. no trailing blanks or punctuation, then that line is not displayed in the
  533. diary window; only the continuation lines is shown. For example, the
  534. single diary entry
  535. 02/11/1989
  536. Bill Blattner visits Princeton today
  537. 2pm Cognitive Studies Committee meeting
  538. 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
  539. 4:00pm Jamie Tappenden
  540. 7:30pm Dinner at George and Ed's for Alan Ryan
  541. 7:30-10:00pm dance at Stewart Country Day School
  542. will appear in the diary window without the date line at the beginning. This
  543. facility allows the diary window to look neater, but can cause confusion if
  544. used with more than one day's entries displayed.
  545. Diary entries can be based on Lisp sexps. For example, the diary entry
  546. %%(diary-block 11 1 1990 11 10 1990) Vacation
  547. causes the diary entry \"Vacation\" to appear from November 1 through
  548. November 10, 1990. See the documentation for the function
  549. `diary-list-sexp-entries' for more details.
  550. Diary entries based on the Hebrew, the Islamic and/or the Baha'i
  551. calendar are also possible, but because these are somewhat slow, they
  552. are ignored unless you set the `diary-nongregorian-listing-hook' and
  553. the `diary-nongregorian-marking-hook' appropriately. See the
  554. documentation of these hooks for details.
  555. Diary files can contain directives to include the contents of other files; for
  556. details, see the documentation for the variable `diary-list-entries-hook'."
  557. :type 'file
  558. :group 'diary)
  559. ;; FIXME do these have to be single characters?
  560. (defcustom diary-nonmarking-symbol "&"
  561. "Symbol indicating that a diary entry is not to be marked in the calendar."
  562. :type 'string
  563. :group 'diary)
  564. (define-obsolete-variable-alias 'hebrew-diary-entry-symbol
  565. 'diary-hebrew-entry-symbol "23.1")
  566. (defcustom diary-hebrew-entry-symbol "H"
  567. "Symbol indicating a diary entry according to the Hebrew calendar."
  568. :type 'string
  569. :group 'diary)
  570. (define-obsolete-variable-alias 'islamic-diary-entry-symbol
  571. 'diary-islamic-entry-symbol "23.1")
  572. (defcustom diary-islamic-entry-symbol "I"
  573. "Symbol indicating a diary entry according to the Islamic calendar."
  574. :type 'string
  575. :group 'diary)
  576. (define-obsolete-variable-alias 'bahai-diary-entry-symbol
  577. 'diary-bahai-entry-symbol "23.1")
  578. (defcustom diary-bahai-entry-symbol "B"
  579. "Symbol indicating a diary entry according to the Baha'i calendar."
  580. :type 'string
  581. :group 'diary)
  582. (defcustom european-calendar-style nil
  583. "Non-nil means use the European style of dates in the diary and display.
  584. In this case, a date like 1/2/1990 would be interpreted as
  585. February 1, 1990. See `diary-european-date-forms' for the
  586. default European diary date styles.
  587. Setting this variable directly does not take effect (if the
  588. calendar package is already loaded). Rather, use either
  589. \\[customize] or the function `calendar-set-date-style'."
  590. :type 'boolean
  591. ;; Without :initialize (require 'calendar) throws an error because
  592. ;; calendar-set-date-style is undefined at this point.
  593. :initialize 'custom-initialize-default
  594. :set (lambda (symbol value)
  595. (if value
  596. (calendar-set-date-style 'european)
  597. (calendar-set-date-style 'american)))
  598. :group 'calendar)
  599. (make-obsolete-variable 'european-calendar-style 'calendar-date-style "23.1")
  600. ;; If this is autoloaded, c-d-s gets set before any customization of e-c-s.
  601. (defcustom calendar-date-style (if european-calendar-style 'european
  602. 'american)
  603. "Your preferred style for writing dates.
  604. The options are:
  605. `american' - month/day/year
  606. `european' - day/month/year
  607. `iso' - year/month/day
  608. This affects how dates written in your diary are interpreted.
  609. It also affects date display, as well as those calendar and diary
  610. functions that take a date as an argument, e.g. `diary-date', by
  611. changing the order in which the arguments are interpreted.
  612. Setting this variable directly does not take effect (if the
  613. calendar package is already loaded). Rather, use either
  614. \\[customize] or the function `calendar-set-date-style'."
  615. :version "23.1"
  616. :type '(choice (const american :tag "Month/Day/Year")
  617. (const european :tag "Day/Month/Year")
  618. (const iso :tag "Year/Month/Day"))
  619. :initialize 'custom-initialize-default
  620. :set (lambda (symbol value)
  621. (calendar-set-date-style value))
  622. :group 'calendar)
  623. ;; Next three are provided to aid in setting diary-date-forms.
  624. ;; FIXME move to diary-lib?
  625. (defcustom diary-iso-date-forms
  626. '((month "[-/]" day "[^-/0-9]")
  627. (year "[-/]" month "[-/]" day "[^0-9]")
  628. ;; Cannot allow [-/] as separators here, since it would also match
  629. ;; the first element (bug#7377).
  630. (monthname " *" day "[^-0-9]")
  631. (year " *" monthname " *" day "[^0-9]")
  632. (dayname "\\W"))
  633. "List of pseudo-patterns describing the ISO style of dates.
  634. The defaults are: MONTH[-/]DAY; YEAR[-/]MONTH[-/]DAY; MONTHNAME DAY;
  635. YEAR MONTHNAME DAY; DAYNAME. Normally you should not customize this,
  636. but `diary-date-forms' (which see)."
  637. :version "23.3" ; bug#7377
  638. :type '(repeat (choice (cons :tag "Backup"
  639. :value (backup . nil)
  640. (const backup)
  641. (repeat (list :inline t :format "%v"
  642. (symbol :tag "Keyword")
  643. (choice symbol regexp))))
  644. (repeat (list :inline t :format "%v"
  645. (symbol :tag "Keyword")
  646. (choice symbol regexp)))))
  647. :group 'diary)
  648. (define-obsolete-variable-alias 'american-date-diary-pattern
  649. 'diary-american-date-forms "23.1")
  650. (defcustom diary-american-date-forms
  651. '((month "/" day "[^/0-9]")
  652. (month "/" day "/" year "[^0-9]")
  653. (monthname " *" day "[^,0-9]")
  654. (monthname " *" day ", *" year "[^0-9]")
  655. (dayname "\\W"))
  656. "List of pseudo-patterns describing the American style of dates.
  657. The defaults are: MONTH/DAY; MONTH/DAY/YEAR; MONTHNAME DAY;
  658. MONTHNAME DAY, YEAR; DAYNAME. Normally you should not customize this,
  659. but `diary-date-forms' (which see)."
  660. :type '(repeat (choice (cons :tag "Backup"
  661. :value (backup . nil)
  662. (const backup)
  663. (repeat (list :inline t :format "%v"
  664. (symbol :tag "Keyword")
  665. (choice symbol regexp))))
  666. (repeat (list :inline t :format "%v"
  667. (symbol :tag "Keyword")
  668. (choice symbol regexp)))))
  669. :group 'diary)
  670. (define-obsolete-variable-alias 'european-date-diary-pattern
  671. 'diary-european-date-forms "23.1")
  672. (defcustom diary-european-date-forms
  673. '((day "/" month "[^/0-9]")
  674. (day "/" month "/" year "[^0-9]")
  675. (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
  676. (day " *" monthname " *" year "[^0-9]")
  677. (dayname "\\W"))
  678. "List of pseudo-patterns describing the European style of dates.
  679. The defaults are: DAY/MONTH; DAY/MONTH/YEAR; DAY MONTHNAME;
  680. DAY MONTHNAME YEAR; DAYNAME. Normally you should not customize this, but
  681. `diary-date-forms' (which see)."
  682. :type '(repeat (choice (cons :tag "Backup"
  683. :value (backup . nil)
  684. (const backup)
  685. (repeat (list :inline t :format "%v"
  686. (symbol :tag "Keyword")
  687. (choice symbol regexp))))
  688. (repeat (list :inline t :format "%v"
  689. (symbol :tag "Keyword")
  690. (choice symbol regexp)))))
  691. :group 'diary)
  692. (defvar diary-font-lock-keywords)
  693. (defcustom diary-date-forms (cond ((eq calendar-date-style 'iso)
  694. diary-iso-date-forms)
  695. ((eq calendar-date-style 'european)
  696. diary-european-date-forms)
  697. (t diary-american-date-forms))
  698. "List of pseudo-patterns describing the forms of date used in the diary.
  699. The patterns on the list must be MUTUALLY EXCLUSIVE and should not match
  700. any portion of the diary entry itself, just the date component.
  701. A pseudo-pattern is a list of regular expressions and the keywords `month',
  702. `day', `year', `monthname', and `dayname'. The keyword `monthname' will
  703. match the name of the month (see `calendar-month-name-array'), capitalized
  704. or not, or its user-specified abbreviation (see `calendar-month-abbrev-array'),
  705. followed by a period or not; it will also match `*'. Similarly, `dayname'
  706. will match the name of the day (see `calendar-day-name-array'), capitalized or
  707. not, or its user-specified abbreviation (see `calendar-day-abbrev-array'),
  708. followed by a period or not. The keywords `month', `day', and `year' will
  709. match those numerical values, preceded by arbitrarily many zeros; they will
  710. also match `*'.
  711. The matching of the diary entries with the date forms is done with the
  712. standard syntax table from Fundamental mode, but with the `*' changed so
  713. that it is a word constituent.
  714. If, to be mutually exclusive, a pseudo-pattern must match a portion of the
  715. diary entry itself, the first element of the pattern MUST be `backup'. This
  716. directive causes the date recognizer to back up to the beginning of the
  717. current word of the diary entry, so in no case can the pattern match more than
  718. a portion of the first word of the diary entry.
  719. For examples of three common styles, see `diary-american-date-forms',
  720. `diary-european-date-forms', and `diary-iso-date-forms'."
  721. :type '(repeat (choice (cons :tag "Backup"
  722. :value (backup . nil)
  723. (const backup)
  724. (repeat (list :inline t :format "%v"
  725. (symbol :tag "Keyword")
  726. (choice symbol regexp))))
  727. (repeat (list :inline t :format "%v"
  728. (symbol :tag "Keyword")
  729. (choice symbol regexp)))))
  730. :set-after '(calendar-date-style diary-iso-date-forms
  731. diary-european-date-forms
  732. diary-american-date-forms)
  733. :initialize 'custom-initialize-default
  734. :set (lambda (symbol value)
  735. (unless (equal value (eval symbol))
  736. (custom-set-default symbol value)
  737. (setq diary-font-lock-keywords (diary-font-lock-keywords))
  738. ;; Need to redraw not just to get new font-locking, but also
  739. ;; to pick up any newly recognized entries.
  740. (and (diary-live-p)
  741. (diary))))
  742. :group 'diary)
  743. ;; Next three are provided to aid in setting calendar-date-display-form.
  744. (defcustom calendar-iso-date-display-form '((format "%s-%.2d-%.2d" year
  745. (string-to-number month)
  746. (string-to-number day)))
  747. "Pseudo-pattern governing the way a date appears in the ISO style.
  748. Normally you should not customize this, but `calendar-date-display-form'
  749. \(which see)."
  750. :type 'sexp
  751. :version "23.1"
  752. :group 'calendar)
  753. (define-obsolete-variable-alias 'european-calendar-display-form
  754. 'calendar-european-date-display-form "23.1")
  755. (defcustom calendar-european-date-display-form
  756. '((if dayname (concat dayname ", ")) day " " monthname " " year)
  757. "Pseudo-pattern governing the way a date appears in the European style.
  758. Normally you should not customize this, but `calendar-date-display-form'
  759. \(which see)."
  760. :type 'sexp
  761. :group 'calendar)
  762. (define-obsolete-variable-alias 'american-calendar-display-form
  763. 'calendar-american-date-display-form "23.1")
  764. (defcustom calendar-american-date-display-form
  765. '((if dayname (concat dayname ", ")) monthname " " day ", " year)
  766. "Pseudo-pattern governing the way a date appears in the American style.
  767. Normally you should not customize this, but `calendar-date-display-form'
  768. \(which see)."
  769. :type 'sexp
  770. :group 'calendar)
  771. (defcustom calendar-date-display-form
  772. (cond ((eq calendar-date-style 'iso)
  773. calendar-iso-date-display-form)
  774. ((eq calendar-date-style 'european)
  775. calendar-european-date-display-form)
  776. (t calendar-american-date-display-form))
  777. "Pseudo-pattern governing the way a calendar date appears.
  778. Used by the function `calendar-date-string' (which see), a pseudo-pattern
  779. is a list of expressions that can involve the keywords `month', `day',
  780. and `year' (all numbers in string form), and `monthname' and `dayname'
  781. \(both alphabetic strings). For example, a typical American form would be
  782. '(month \"/\" day \"/\" (substring year -2))
  783. whereas
  784. '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
  785. would give the usual American style in fixed-length fields. The variables
  786. `calendar-iso-date-display-form', `calendar-european-date-display-form', and
  787. `calendar-american-date-display-form' provide some defaults for three common
  788. styles."
  789. :type 'sexp
  790. :set-after '(calendar-date-style calendar-iso-date-display-form
  791. calendar-european-date-display-form
  792. calendar-american-date-display-form)
  793. :group 'calendar)
  794. (defun calendar-set-date-style (style)
  795. "Set the style of calendar and diary dates to STYLE (a symbol).
  796. The valid styles are described in the documentation of `calendar-date-style'."
  797. (interactive (list (intern
  798. (completing-read "Date style: "
  799. '("american" "european" "iso") nil t
  800. nil nil "american"))))
  801. (or (memq style '(american european iso))
  802. (setq style 'american))
  803. (setq calendar-date-style style
  804. calendar-date-display-form
  805. (symbol-value (intern-soft
  806. (format "calendar-%s-date-display-form" style)))
  807. diary-date-forms
  808. (symbol-value (intern-soft (format "diary-%s-date-forms" style))))
  809. (calendar-update-mode-line))
  810. (defun european-calendar ()
  811. "Set the interpretation and display of dates to the European style."
  812. (interactive)
  813. (calendar-set-date-style 'european))
  814. (make-obsolete 'european-calendar 'calendar-set-date-style "23.1")
  815. (defun american-calendar ()
  816. "Set the interpretation and display of dates to the American style."
  817. (interactive)
  818. (calendar-set-date-style 'american))
  819. (make-obsolete 'american-calendar 'calendar-set-date-style "23.1")
  820. (define-obsolete-variable-alias 'holidays-in-diary-buffer
  821. 'diary-show-holidays-flag "23.1")
  822. (defcustom diary-show-holidays-flag t
  823. "Non-nil means include holidays in the diary display.
  824. The holidays appear in the mode line of the diary buffer, or in the
  825. fancy diary buffer next to the date. This slows down the diary functions
  826. somewhat; setting it to nil makes the diary display faster."
  827. :type 'boolean
  828. :group 'holidays)
  829. (defcustom calendar-debug-sexp nil
  830. "Turn debugging on when evaluating a sexp in the diary or holiday list."
  831. :type 'boolean
  832. :group 'calendar)
  833. (define-obsolete-variable-alias 'all-hebrew-calendar-holidays
  834. 'calendar-hebrew-all-holidays-flag "23.1")
  835. (defcustom calendar-hebrew-all-holidays-flag nil
  836. "If nil, show only major holidays from the Hebrew calendar.
  837. This means only those Jewish holidays that appear on secular calendars.
  838. Otherwise, show all the holidays that would appear in a complete Hebrew
  839. calendar."
  840. :type 'boolean
  841. :group 'holidays)
  842. (define-obsolete-variable-alias 'all-christian-calendar-holidays
  843. 'calendar-christian-all-holidays-flag "23.1")
  844. (defcustom calendar-christian-all-holidays-flag nil
  845. "If nil, show only major holidays from the Christian calendar.
  846. This means only those Christian holidays that appear on secular calendars.
  847. Otherwise, show all the holidays that would appear in a complete Christian
  848. calendar."
  849. :type 'boolean
  850. :group 'holidays)
  851. (define-obsolete-variable-alias 'all-islamic-calendar-holidays
  852. 'calendar-islamic-all-holidays-flag "23.1")
  853. (defcustom calendar-islamic-all-holidays-flag nil
  854. "If nil, show only major holidays from the Islamic calendar.
  855. This means only those Islamic holidays that appear on secular calendars.
  856. Otherwise, show all the holidays that would appear in a complete Islamic
  857. calendar."
  858. :type 'boolean
  859. :group 'holidays)
  860. (define-obsolete-variable-alias 'all-bahai-calendar-holidays
  861. 'calendar-bahai-all-holidays-flag "23.1")
  862. (defcustom calendar-bahai-all-holidays-flag nil
  863. "If nil, show only major holidays from the Baha'i calendar.
  864. These are the days on which work and school must be suspended.
  865. Otherwise, show all the holidays that would appear in a complete Baha'i
  866. calendar."
  867. :type 'boolean
  868. :group 'holidays)
  869. (defcustom calendar-chinese-all-holidays-flag nil
  870. "If nil, show only the major holidays from the Chinese calendar."
  871. :version "23.1"
  872. :type 'boolean
  873. :group 'holidays)
  874. ;;; End of user options.
  875. (calendar-recompute-layout-variables)
  876. (defconst calendar-first-date-row 3
  877. "First row in the calendar with actual dates.")
  878. (defconst calendar-buffer "*Calendar*"
  879. "Name of the buffer used for the calendar.")
  880. (defconst holiday-buffer "*Holidays*"
  881. "Name of the buffer used for the displaying the holidays.")
  882. (defconst diary-fancy-buffer "*Fancy Diary Entries*"
  883. "Name of the buffer used for the optional fancy display of the diary.")
  884. (define-obsolete-variable-alias 'fancy-diary-buffer 'diary-fancy-buffer "23.1")
  885. (defconst calendar-other-calendars-buffer "*Other Calendars*"
  886. "Name of the buffer used for the display of date on other calendars.")
  887. (defconst lunar-phases-buffer "*Phases of Moon*"
  888. "Name of the buffer used for the lunar phases.")
  889. (defconst solar-sunrises-buffer "*Sunrise/Sunset Times*"
  890. "Name of buffer used for sunrise/sunset times.")
  891. (defconst calendar-hebrew-yahrzeit-buffer "*Yahrzeits*"
  892. "Name of the buffer used by `list-yahrzeit-dates'.")
  893. (defmacro calendar-increment-month (mon yr n &optional nmonths)
  894. "Increment the variables MON and YR by N months.
  895. Forward if N is positive or backward if N is negative.
  896. A negative YR is interpreted as BC; -1 being 1 BC, and so on.
  897. Optional NMONTHS is the number of months per year (default 12)."
  898. ;; Can view this as a form of base-nmonths arithmetic, in which "a
  899. ;; year" = "ten", and we never bother to use hundreds.
  900. `(let ((nmonths (or ,nmonths 12))
  901. macro-y)
  902. (if (< ,yr 0) (setq ,yr (1+ ,yr))) ; -1 BC -> 0 AD, etc
  903. (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
  904. ,mon (1+ (mod macro-y nmonths))
  905. ,yr (/ macro-y nmonths))
  906. ;; Alternative:
  907. ;;; (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
  908. ;;; ,yr (/ macro-y nmonths)
  909. ;;; ,mon (- macro-y (* ,yr nmonths)))
  910. (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr)))
  911. (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc
  912. (define-obsolete-function-alias 'increment-calendar-month
  913. 'calendar-increment-month "23.1")
  914. (defvar displayed-month)
  915. (defvar displayed-year)
  916. (defun calendar-increment-month-cons (n &optional mon yr)
  917. "Return the Nth month after MON/YR.
  918. The return value is a pair (MONTH . YEAR).
  919. MON defaults to `displayed-month'. YR defaults to `displayed-year'."
  920. (unless mon (setq mon displayed-month))
  921. (unless yr (setq yr displayed-year))
  922. (calendar-increment-month mon yr n)
  923. (cons mon yr))
  924. (defmacro calendar-for-loop (var from init to final do &rest body)
  925. "Execute a for loop.
  926. Evaluate BODY with VAR bound to successive integers from INIT to FINAL,
  927. inclusive. The standard macro `dotimes' is preferable in most cases."
  928. (declare (debug (symbolp "from" form "to" form "do" body))
  929. (indent defun))
  930. `(let ((,var (1- ,init)))
  931. (while (>= ,final (setq ,var (1+ ,var)))
  932. ,@body)))
  933. (make-obsolete 'calendar-for-loop "use `dotimes' or `while' instead." "23.1")
  934. (defmacro calendar-sum (index initial condition expression)
  935. "For INDEX = INITIAL, +1, ... (as long as CONDITION holds), sum EXPRESSION."
  936. (declare (debug (symbolp form form form)))
  937. `(let ((,index ,initial)
  938. (sum 0))
  939. (while ,condition
  940. (setq sum (+ sum ,expression)
  941. ,index (1+ ,index)))
  942. sum))
  943. ;; FIXME bind q to bury-buffer?
  944. (defmacro calendar-in-read-only-buffer (buffer &rest body)
  945. "Switch to BUFFER and executes the forms in BODY.
  946. First creates or erases BUFFER as needed. Leaves BUFFER read-only,
  947. with disabled undo. Leaves point at point-min, displays BUFFER."
  948. (declare (indent 1) (debug t))
  949. `(progn
  950. (set-buffer (get-buffer-create ,buffer))
  951. (setq buffer-read-only nil
  952. buffer-undo-list t)
  953. (erase-buffer)
  954. ,@body
  955. (goto-char (point-min))
  956. (set-buffer-modified-p nil)
  957. (setq buffer-read-only t)
  958. (display-buffer ,buffer)))
  959. ;; The following are in-line for speed; they can be called thousands of times
  960. ;; when looking up holidays or processing the diary. Here, for example, are
  961. ;; the numbers of calls to calendar/diary/holiday functions in preparing the
  962. ;; fancy diary display, for a moderately complex diary file, with functions
  963. ;; used instead of macros. There were a total of 10000 such calls:
  964. ;;
  965. ;; 1934 calendar-extract-month
  966. ;; 1852 calendar-extract-year
  967. ;; 1819 calendar-extract-day
  968. ;; 845 calendar-leap-year-p
  969. ;; 837 calendar-day-number
  970. ;; 775 calendar-absolute-from-gregorian
  971. ;; 346 calendar-last-day-of-month
  972. ;; 286 calendar-hebrew-last-day-of-month
  973. ;; 188 calendar-hebrew-leap-year-p
  974. ;; 180 calendar-hebrew-elapsed-days
  975. ;; 163 calendar-hebrew-last-month-of-year
  976. ;; 66 calendar-date-compare
  977. ;; 65 calendar-hebrew-days-in-year
  978. ;; 60 calendar-julian-to-absolute
  979. ;; 50 calendar-hebrew-to-absolute
  980. ;; 43 calendar-date-equal
  981. ;; 38 calendar-gregorian-from-absolute
  982. ;; .
  983. ;;
  984. ;; The use of these seven macros eliminates the overhead of 92% of the function
  985. ;; calls; it's faster this way.
  986. (defsubst calendar-extract-month (date)
  987. "Extract the month part of DATE which has the form (month day year)."
  988. (car date))
  989. (define-obsolete-function-alias 'extract-calendar-month
  990. 'calendar-extract-month "23.1")
  991. ;; Note gives wrong answer for result of (calendar-read-date 'noday),
  992. ;; but that is only used by `calendar-other-month'.
  993. (defsubst calendar-extract-day (date)
  994. "Extract the day part of DATE which has the form (month day year)."
  995. (cadr date))
  996. (define-obsolete-function-alias 'extract-calendar-day
  997. 'calendar-extract-day "23.1")
  998. (defsubst calendar-extract-year (date)
  999. "Extract the year part of DATE which has the form (month day year)."
  1000. (nth 2 date))
  1001. (define-obsolete-function-alias 'extract-calendar-year
  1002. 'calendar-extract-year "23.1")
  1003. (defsubst calendar-leap-year-p (year)
  1004. "Return t if YEAR is a Gregorian leap year.
  1005. A negative year is interpreted as BC; -1 being 1 BC, and so on."
  1006. ;; 1 BC = 0 AD, 2 BC acts like 1 AD, etc.
  1007. (if (< year 0) (setq year (1- (abs year))))
  1008. (and (zerop (% year 4))
  1009. (or (not (zerop (% year 100)))
  1010. (zerop (% year 400)))))
  1011. ;; The foregoing is a bit faster, but not as clear as the following:
  1012. ;;
  1013. ;;(defsubst calendar-leap-year-p (year)
  1014. ;; "Return t if YEAR is a Gregorian leap year."
  1015. ;; (or
  1016. ;; (and (zerop (% year 4))
  1017. ;; (not (zerop (% year 100))))
  1018. ;; (zerop (% year 400)))
  1019. (defsubst calendar-last-day-of-month (month year)
  1020. "The last day in MONTH during YEAR."
  1021. (if (and (= month 2) (calendar-leap-year-p year))
  1022. 29
  1023. (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
  1024. ;; An explanation of the calculation can be found in PascAlgorithms by
  1025. ;; Edward and Ruth Reingold, Scott-Foresman/Little, Brown, 1988.
  1026. (defsubst calendar-day-number (date)
  1027. "Return the day number within the year of the date DATE.
  1028. For example, (calendar-day-number '(1 1 1987)) returns the value 1,
  1029. while (calendar-day-number '(12 31 1980)) returns 366."
  1030. (let* ((month (calendar-extract-month date))
  1031. (day (calendar-extract-day date))
  1032. (year (calendar-extract-year date))
  1033. (day-of-year (+ day (* 31 (1- month)))))
  1034. (when (> month 2)
  1035. (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
  1036. (if (calendar-leap-year-p year)
  1037. (setq day-of-year (1+ day-of-year))))
  1038. day-of-year))
  1039. (defsubst calendar-absolute-from-gregorian (date)
  1040. "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
  1041. The Gregorian date Sunday, December 31, 1 BC is imaginary.
  1042. DATE is a list of the form (month day year). A negative year is
  1043. interpreted as BC; -1 being 1 BC, and so on. Dates before 12/31/1 BC
  1044. return negative results."
  1045. (let ((year (calendar-extract-year date))
  1046. offset-years)
  1047. (cond ((zerop year)
  1048. (error "There was no year zero"))
  1049. ((> year 0)
  1050. (setq offset-years (1- year))

Large files files are truncated, but you can click here to view the full file