PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/calendar/calendar.el

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

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