PageRenderTime 71ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/lisp/calendar/calendar.el

https://bitbucket.org/hgiddens/emacs
Emacs Lisp | 2738 lines | 2135 code | 276 blank | 327 comment | 79 complexity | 00ddaaf7a9a4a06e073280f841242ec9 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-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. (defface calendar-weekday-header '((t :inherit font-lock-constant-face))
  221. "Face used for weekday column headers in the calendar.
  222. See also the face `calendar-weekend-header'."
  223. :version "24.4"
  224. :group 'calendar-faces)
  225. (defface calendar-weekend-header '((t :inherit font-lock-comment-face))
  226. "Face used for weekend column headers in the calendar.
  227. See also the face `calendar-weekday-header'."
  228. :version "24.4"
  229. :group 'calendar-faces)
  230. (defface calendar-month-header '((t :inherit font-lock-function-name-face))
  231. "Face used for month headers in the calendar."
  232. :version "24.4"
  233. :group 'calendar-faces)
  234. ;; These briefly checked font-lock-mode, but that is broken, since it
  235. ;; is a buffer-local variable, and which buffer happens to be current
  236. ;; when this file is loaded shouldn't make a difference. One could
  237. ;; perhaps check global-font-lock-mode, or font-lock-global-modes; but
  238. ;; this feature doesn't use font-lock, so there's no real reason it
  239. ;; should respect those either. See bug#2199.
  240. ;; They also used to check display-color-p, but that is a problem if
  241. ;; loaded from --daemon. Since BW displays are rare now, this was
  242. ;; also taken out. The way to keep it would be to have nil mean do a
  243. ;; runtime check whenever this variable is used.
  244. (defcustom diary-entry-marker 'diary
  245. "How to mark dates that have diary entries.
  246. The value can be either a single-character string (e.g. \"+\") or a face."
  247. :type '(choice (string :tag "Single character string") face)
  248. :group 'diary
  249. :version "23.1")
  250. (defcustom calendar-today-marker 'calendar-today
  251. "How to mark today's date in the calendar.
  252. The value can be either a single-character string (e.g. \"=\") or a face.
  253. Used by `calendar-mark-today'."
  254. :type '(choice (string :tag "Single character string") face)
  255. :group 'calendar
  256. :version "23.1")
  257. (defcustom calendar-holiday-marker 'holiday
  258. "How to mark notable dates in the calendar.
  259. The value can be either a single-character string (e.g. \"*\") or a face."
  260. :type '(choice (string :tag "Single character string") face)
  261. :group 'holidays
  262. :version "23.1")
  263. (define-obsolete-variable-alias 'view-calendar-holidays-initially
  264. 'calendar-view-holidays-initially-flag "23.1")
  265. (defcustom calendar-view-holidays-initially-flag nil
  266. "Non-nil means display holidays for current three month period on entry.
  267. The holidays are displayed in another window when the calendar is first
  268. displayed."
  269. :type 'boolean
  270. :group 'holidays)
  271. (define-obsolete-variable-alias 'mark-holidays-in-calendar
  272. 'calendar-mark-holidays-flag "23.1")
  273. ;; FIXME :set
  274. (defcustom calendar-mark-holidays-flag nil
  275. "Non-nil means mark dates of holidays in the calendar window.
  276. The marking symbol is specified by the variable `calendar-holiday-marker'."
  277. :type 'boolean
  278. :group 'holidays)
  279. (defcustom calendar-mode-hook nil
  280. "Hook run when entering `calendar-mode'."
  281. :type 'hook
  282. :group 'calendar-hooks)
  283. (defcustom calendar-load-hook nil
  284. "List of functions to be called after the calendar is first loaded.
  285. This is the place to add key bindings to `calendar-mode-map'."
  286. :type 'hook
  287. :group 'calendar-hooks)
  288. (define-obsolete-variable-alias 'initial-calendar-window-hook
  289. 'calendar-initial-window-hook "23.1")
  290. (defcustom calendar-initial-window-hook nil
  291. "List of functions to be called when the calendar window is created.
  292. Quitting the calendar and re-entering it will cause these functions
  293. to be called again."
  294. :type 'hook
  295. :group 'calendar-hooks)
  296. (define-obsolete-variable-alias 'today-visible-calendar-hook
  297. 'calendar-today-visible-hook "23.1")
  298. (defcustom calendar-today-visible-hook nil
  299. "List of functions called whenever the current date is visible.
  300. To mark today's date, add the function `calendar-mark-today'.
  301. To replace the date with asterisks, add the function `calendar-star-date'.
  302. See also `calendar-today-invisible-hook'.
  303. In general, be careful about changing characters in the calendar buffer,
  304. since it may cause the movement commands to fail."
  305. :type 'hook
  306. :options '(calendar-mark-today calendar-star-date)
  307. :group 'calendar-hooks)
  308. (define-obsolete-variable-alias 'today-invisible-calendar-hook
  309. 'calendar-today-invisible-hook "23.1")
  310. (defcustom calendar-today-invisible-hook nil
  311. "List of functions called whenever the current date is not visible.
  312. See also `calendar-today-visible-hook'."
  313. :type 'hook
  314. :group 'calendar-hooks)
  315. (defcustom calendar-move-hook nil
  316. "List of functions called whenever the cursor moves in the calendar.
  317. For example,
  318. (add-hook 'calendar-move-hook (lambda () (diary-view-entries 1)))
  319. redisplays the diary for whatever date the cursor is moved to."
  320. :type 'hook
  321. :options '(calendar-update-mode-line)
  322. :group 'calendar-hooks)
  323. (defcustom calendar-date-echo-text
  324. "mouse-2: general menu\nmouse-3: menu for this date"
  325. "String displayed when the cursor is over a date in the calendar.
  326. Can be either a fixed string, or a lisp expression that returns one.
  327. When this expression is evaluated, DAY, MONTH, and YEAR are
  328. integers appropriate to the relevant date. For example, to
  329. display the ISO date:
  330. (setq calendar-date-echo-text '(format \"ISO date: %s\"
  331. (calendar-iso-date-string
  332. (list month day year))))
  333. Changing this variable without using customize has no effect on
  334. pre-existing calendar windows."
  335. :group 'calendar
  336. :initialize 'custom-initialize-default
  337. :risky t
  338. :set (lambda (sym val)
  339. (set sym val)
  340. (calendar-redraw))
  341. :type '(choice (string :tag "Fixed string")
  342. (sexp :value
  343. (format "ISO date: %s"
  344. (calendar-iso-date-string
  345. (list month day year)))))
  346. :version "23.1")
  347. (defvar calendar-month-digit-width nil
  348. "Width of the region with numbers in each month in the calendar.")
  349. (defvar calendar-month-width nil
  350. "Full width of each month in the calendar.")
  351. (defvar calendar-right-margin nil
  352. "Right margin of the calendar.")
  353. (defvar calendar-month-edges nil
  354. "Alist of month edge columns.
  355. Each element has the form (N LEFT FIRST LAST RIGHT), where
  356. LEFT is the leftmost column associated with month segment N,
  357. FIRST and LAST are the first and last columns with day digits in,
  358. and LAST is the rightmost column.")
  359. (defun calendar-month-edges (segment)
  360. "Compute the month edge columns for month SEGMENT.
  361. Returns a list (LEFT FIRST LAST RIGHT), where LEFT is the
  362. leftmost column associated with a month, FIRST and LAST are the
  363. first and last columns with day digits in, and LAST is the
  364. rightmost column."
  365. ;; The leftmost column with a digit in it in this month segment.
  366. (let* ((first (+ calendar-left-margin
  367. (* segment calendar-month-width)))
  368. ;; The rightmost column with a digit in it in this month segment.
  369. (last (+ first (1- calendar-month-digit-width)))
  370. (left (if (eq segment 0)
  371. 0
  372. (+ calendar-left-margin
  373. (* segment calendar-month-width)
  374. (- (/ calendar-intermonth-spacing 2)))))
  375. ;; The rightmost edge of this month segment, dividing the
  376. ;; space between months in two.
  377. (right (+ calendar-left-margin
  378. (* (1+ segment) calendar-month-width)
  379. (- (/ calendar-intermonth-spacing 2)))))
  380. (list left first last right)))
  381. (defun calendar-recompute-layout-variables ()
  382. "Recompute some layout-related calendar \"constants\"."
  383. (setq calendar-month-digit-width (+ (* 6 calendar-column-width)
  384. calendar-day-digit-width)
  385. calendar-month-width (+ (* 7 calendar-column-width)
  386. calendar-intermonth-spacing)
  387. calendar-right-margin (+ calendar-left-margin
  388. (* 3 (* 7 calendar-column-width))
  389. (* 2 calendar-intermonth-spacing))
  390. calendar-month-edges nil)
  391. (dotimes (i 3)
  392. (push (cons i (calendar-month-edges i)) calendar-month-edges))
  393. (setq calendar-month-edges (reverse calendar-month-edges)))
  394. (defun calendar-set-layout-variable (symbol value &optional minmax)
  395. "Set SYMBOL's value to VALUE, an integer.
  396. A positive/negative MINMAX enforces a minimum/maximum value.
  397. Then redraw the calendar, if necessary."
  398. (let ((oldvalue (symbol-value symbol)))
  399. (custom-set-default symbol (if minmax
  400. (if (< minmax 0)
  401. (min value (- minmax))
  402. (max value minmax))
  403. value))
  404. (unless (equal value oldvalue)
  405. (calendar-recompute-layout-variables)
  406. (calendar-redraw))))
  407. (defcustom calendar-left-margin 5
  408. "Empty space to the left of the first month in the calendar."
  409. :group 'calendar
  410. :initialize 'custom-initialize-default
  411. :set 'calendar-set-layout-variable
  412. :type 'integer
  413. :version "23.1")
  414. ;; Or you can view it as columns of width 2, with 1 space, no space
  415. ;; after the last column, and a 5 space gap between month.
  416. ;; FIXME check things work if this is odd.
  417. (defcustom calendar-intermonth-spacing 4
  418. "Space between months in the calendar. Minimum value is 1."
  419. :group 'calendar
  420. :initialize 'custom-initialize-default
  421. :set (lambda (sym val)
  422. (calendar-set-layout-variable sym val 1))
  423. :type 'integer
  424. :version "23.1")
  425. ;; FIXME calendar-month-column-width?
  426. (defcustom calendar-column-width 3
  427. "Width of each day column in the calendar. Minimum value is 3."
  428. :initialize 'custom-initialize-default
  429. :set (lambda (sym val)
  430. (calendar-set-layout-variable sym val 3))
  431. :type 'integer
  432. :version "23.1")
  433. (defun calendar-day-header-construct (&optional width)
  434. "Return the default value for `calendar-day-header-array'.
  435. WIDTH defaults to `calendar-day-header-width'."
  436. (or width (setq width calendar-day-header-width))
  437. (calendar-abbrev-construct (if (<= width calendar-abbrev-length)
  438. calendar-day-abbrev-array
  439. calendar-day-name-array)
  440. width))
  441. ;; FIXME better to use a format spec?
  442. (defcustom calendar-day-header-width 2
  443. "Width of the day column headers in the calendar.
  444. Must be at least one less than `calendar-column-width'."
  445. :group 'calendar
  446. :initialize 'custom-initialize-default
  447. :set (lambda (sym val)
  448. (or (calendar-customized-p 'calendar-day-header-array)
  449. (setq calendar-day-header-array
  450. (calendar-day-header-construct val)))
  451. (calendar-set-layout-variable sym val (- 1 calendar-column-width)))
  452. :type 'integer
  453. :version "23.1")
  454. ;; FIXME a format specifier instead?
  455. (defcustom calendar-day-digit-width 2
  456. "Width of the day digits in the calendar. Minimum value is 2."
  457. :group 'calendar
  458. :initialize 'custom-initialize-default
  459. :set (lambda (sym val)
  460. (calendar-set-layout-variable sym val 2))
  461. :type 'integer
  462. :version "23.1")
  463. (defcustom calendar-intermonth-header nil
  464. "Header text to display in the space to the left of each calendar month.
  465. See `calendar-intermonth-text'."
  466. :group 'calendar
  467. :initialize 'custom-initialize-default
  468. :risky t
  469. :set (lambda (sym val)
  470. (set sym val)
  471. (calendar-redraw))
  472. :type '(choice (const nil :tag "Nothing")
  473. (string :tag "Fixed string")
  474. (sexp :value
  475. (propertize "WK" 'font-lock-face
  476. 'font-lock-function-name-face)))
  477. :version "23.1")
  478. (defcustom calendar-intermonth-text nil
  479. "Text to display in the space to the left of each calendar month.
  480. Can be nil, a fixed string, or a lisp expression that returns a string.
  481. When the expression is evaluated, the variables DAY, MONTH and YEAR
  482. are integers appropriate for the first day in each week.
  483. Will be truncated to the smaller of `calendar-left-margin' and
  484. `calendar-intermonth-spacing'. The last character is forced to be a space.
  485. For example, to display the ISO week numbers:
  486. (setq calendar-week-start-day 1
  487. calendar-intermonth-text
  488. '(propertize
  489. (format \"%2d\"
  490. (car
  491. (calendar-iso-from-absolute
  492. (calendar-absolute-from-gregorian (list month day year)))))
  493. 'font-lock-face 'font-lock-function-name-face))
  494. See also `calendar-intermonth-header'."
  495. :group 'calendar
  496. :initialize 'custom-initialize-default
  497. :risky t
  498. :set (lambda (sym val)
  499. (set sym val)
  500. (calendar-redraw))
  501. :type '(choice (const nil :tag "Nothing")
  502. (string :tag "Fixed string")
  503. (sexp :value
  504. (propertize
  505. (format "%2d"
  506. (car
  507. (calendar-iso-from-absolute
  508. (calendar-absolute-from-gregorian
  509. (list month day year)))))
  510. 'font-lock-face 'font-lock-function-name-face)))
  511. :version "23.1")
  512. (defcustom diary-file "~/diary"
  513. "Name of the file in which one's personal diary of dates is kept.
  514. The file's entries are lines beginning with any of the forms
  515. specified by the variable `diary-date-forms', which by default
  516. uses the forms of `diary-american-date-forms':
  517. MONTH/DAY
  518. MONTH/DAY/YEAR
  519. MONTHNAME DAY
  520. MONTHNAME DAY, YEAR
  521. DAYNAME
  522. with the remainder of the line being the diary entry string for
  523. that date. MONTH and DAY are one or two digit numbers, YEAR is a
  524. number and may be written in full or abbreviated to the final two
  525. digits (if `diary-abbreviated-year-flag' is non-nil). MONTHNAME
  526. and DAYNAME can be spelled in full (as specified by the variables
  527. `calendar-month-name-array' and `calendar-day-name-array'), or
  528. abbreviated (as specified by `calendar-month-abbrev-array' and
  529. `calendar-day-abbrev-array') with or without a period. Case is
  530. ignored. Any of DAY, MONTH, or MONTHNAME, YEAR can be `*' which
  531. matches any day, month, or year, respectively. If the date does
  532. not contain a year, it is generic and applies to any year. A
  533. DAYNAME entry applies to the appropriate day of the week in every week.
  534. You can customize `diary-date-forms' to your preferred format.
  535. Three default styles are provided: `diary-american-date-forms',
  536. `diary-european-date-forms', and `diary-iso-date-forms'.
  537. You can choose between these by setting `calendar-date-style' in your
  538. init file, or by using `calendar-set-date-style' when in the calendar.
  539. A diary entry can be preceded by the character `diary-nonmarking-symbol'
  540. \(ordinarily `&') to make that entry nonmarking--that is, it will not be
  541. marked on dates in the calendar window but will appear in a diary window.
  542. Multiline diary entries are made by indenting lines after the first with
  543. either a TAB or one or more spaces.
  544. Lines not in one the above formats are ignored. Here are some sample diary
  545. entries (in the default American style):
  546. 12/22/1988 Twentieth wedding anniversary!!
  547. &1/1. Happy New Year!
  548. 10/22 Ruth's birthday.
  549. 21: Payday
  550. Tuesday--weekly meeting with grad students at 10am
  551. Supowit, Shen, Bitner, and Kapoor to attend.
  552. 1/13/89 Friday the thirteenth!!
  553. &thu 4pm squash game with Lloyd.
  554. mar 16 Dad's birthday
  555. April 15, 1989 Income tax due.
  556. &* 15 time cards due.
  557. If the first line of a diary entry consists only of the date or day name with
  558. no trailing blanks or punctuation, then that line is not displayed in the
  559. diary window; only the continuation lines is shown. For example, the
  560. single diary entry
  561. 02/11/1989
  562. Bill Blattner visits Princeton today
  563. 2pm Cognitive Studies Committee meeting
  564. 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
  565. 4:00pm Jamie Tappenden
  566. 7:30pm Dinner at George and Ed's for Alan Ryan
  567. 7:30-10:00pm dance at Stewart Country Day School
  568. will appear in the diary window without the date line at the beginning. This
  569. facility allows the diary window to look neater, but can cause confusion if
  570. used with more than one day's entries displayed.
  571. Diary entries can be based on Lisp sexps. For example, the diary entry
  572. %%(diary-block 11 1 1990 11 10 1990) Vacation
  573. causes the diary entry \"Vacation\" to appear from November 1 through
  574. November 10, 1990. See the documentation for the function
  575. `diary-list-sexp-entries' for more details.
  576. Diary entries based on the Hebrew, the Islamic and/or the Bahá
  577. calendar are also possible, but because these are somewhat slow, they
  578. are ignored unless you set the `diary-nongregorian-listing-hook' and
  579. the `diary-nongregorian-marking-hook' appropriately. See the
  580. documentation of these hooks for details.
  581. Diary files can contain directives to include the contents of other files; for
  582. details, see the documentation for the variable `diary-list-entries-hook'."
  583. :type 'file
  584. :group 'diary)
  585. ;; FIXME do these have to be single characters?
  586. (defcustom diary-nonmarking-symbol "&"
  587. "Symbol indicating that a diary entry is not to be marked in the calendar."
  588. :type 'string
  589. :group 'diary)
  590. (define-obsolete-variable-alias 'hebrew-diary-entry-symbol
  591. 'diary-hebrew-entry-symbol "23.1")
  592. (defcustom diary-hebrew-entry-symbol "H"
  593. "Symbol indicating a diary entry according to the Hebrew calendar."
  594. :type 'string
  595. :group 'diary)
  596. (define-obsolete-variable-alias 'islamic-diary-entry-symbol
  597. 'diary-islamic-entry-symbol "23.1")
  598. (defcustom diary-islamic-entry-symbol "I"
  599. "Symbol indicating a diary entry according to the Islamic calendar."
  600. :type 'string
  601. :group 'diary)
  602. (define-obsolete-variable-alias 'bahai-diary-entry-symbol
  603. 'diary-bahai-entry-symbol "23.1")
  604. (defcustom diary-bahai-entry-symbol "B"
  605. "Symbol indicating a diary entry according to the Bahá'í calendar."
  606. :type 'string
  607. :group 'diary)
  608. (defcustom european-calendar-style nil
  609. "Non-nil means use the European style of dates in the diary and display.
  610. In this case, a date like 1/2/1990 would be interpreted as
  611. February 1, 1990. See `diary-european-date-forms' for the
  612. default European diary date styles.
  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. :type 'boolean
  617. ;; Without :initialize (require 'calendar) throws an error because
  618. ;; calendar-set-date-style is undefined at this point.
  619. :initialize 'custom-initialize-default
  620. :set (lambda (symbol value)
  621. (if value
  622. (calendar-set-date-style 'european)
  623. (calendar-set-date-style 'american)))
  624. :group 'calendar)
  625. (make-obsolete-variable 'european-calendar-style 'calendar-date-style "23.1")
  626. ;; If this is autoloaded, c-d-s gets set before any customization of e-c-s.
  627. (defcustom calendar-date-style (if european-calendar-style 'european
  628. 'american)
  629. "Your preferred style for writing dates.
  630. The options are:
  631. `american' - month/day/year
  632. `european' - day/month/year
  633. `iso' - year/month/day
  634. This affects how dates written in your diary are interpreted.
  635. It also affects date display, as well as those calendar and diary
  636. functions that take a date as an argument, e.g. `diary-date', by
  637. changing the order in which the arguments are interpreted.
  638. Setting this variable directly does not take effect (if the
  639. calendar package is already loaded). Rather, use either
  640. \\[customize] or the function `calendar-set-date-style'."
  641. :version "23.1"
  642. :type '(choice (const american :tag "Month/Day/Year")
  643. (const european :tag "Day/Month/Year")
  644. (const iso :tag "Year/Month/Day"))
  645. :initialize 'custom-initialize-default
  646. :set (lambda (symbol value)
  647. (calendar-set-date-style value))
  648. :group 'calendar)
  649. ;; Next three are provided to aid in setting diary-date-forms.
  650. ;; FIXME move to diary-lib?
  651. (defcustom diary-iso-date-forms
  652. '((month "[-/]" day "[^-/0-9]")
  653. (year "[-/]" month "[-/]" day "[^0-9]")
  654. ;; Cannot allow [-/] as separators here, since it would also match
  655. ;; the first element (bug#7377).
  656. (monthname " *" day "[^-0-9]")
  657. (year " *" monthname " *" day "[^0-9]")
  658. (dayname "\\W"))
  659. "List of pseudo-patterns describing the ISO style of dates.
  660. The defaults are: MONTH[-/]DAY; YEAR[-/]MONTH[-/]DAY; MONTHNAME DAY;
  661. YEAR MONTHNAME DAY; DAYNAME. Normally you should not customize this,
  662. but `diary-date-forms' (which see)."
  663. :version "23.3" ; bug#7377
  664. :type '(repeat (choice (cons :tag "Backup"
  665. :value (backup . nil)
  666. (const backup)
  667. (repeat (list :inline t :format "%v"
  668. (symbol :tag "Keyword")
  669. (choice symbol regexp))))
  670. (repeat (list :inline t :format "%v"
  671. (symbol :tag "Keyword")
  672. (choice symbol regexp)))))
  673. :group 'diary)
  674. (define-obsolete-variable-alias 'american-date-diary-pattern
  675. 'diary-american-date-forms "23.1")
  676. (defcustom diary-american-date-forms
  677. '((month "/" day "[^/0-9]")
  678. (month "/" day "/" year "[^0-9]")
  679. (monthname " *" day "[^,0-9]")
  680. (monthname " *" day ", *" year "[^0-9]")
  681. (dayname "\\W"))
  682. "List of pseudo-patterns describing the American style of dates.
  683. The defaults are: MONTH/DAY; MONTH/DAY/YEAR; MONTHNAME DAY;
  684. MONTHNAME DAY, YEAR; DAYNAME. Normally you should not customize this,
  685. but `diary-date-forms' (which see)."
  686. :type '(repeat (choice (cons :tag "Backup"
  687. :value (backup . nil)
  688. (const backup)
  689. (repeat (list :inline t :format "%v"
  690. (symbol :tag "Keyword")
  691. (choice symbol regexp))))
  692. (repeat (list :inline t :format "%v"
  693. (symbol :tag "Keyword")
  694. (choice symbol regexp)))))
  695. :group 'diary)
  696. (define-obsolete-variable-alias 'european-date-diary-pattern
  697. 'diary-european-date-forms "23.1")
  698. (defcustom diary-european-date-forms
  699. '((day "/" month "[^/0-9]")
  700. (day "/" month "/" year "[^0-9]")
  701. (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
  702. (day " *" monthname " *" year "[^0-9]")
  703. (dayname "\\W"))
  704. "List of pseudo-patterns describing the European style of dates.
  705. The defaults are: DAY/MONTH; DAY/MONTH/YEAR; DAY MONTHNAME;
  706. DAY MONTHNAME YEAR; DAYNAME. Normally you should not customize this, but
  707. `diary-date-forms' (which see)."
  708. :type '(repeat (choice (cons :tag "Backup"
  709. :value (backup . nil)
  710. (const backup)
  711. (repeat (list :inline t :format "%v"
  712. (symbol :tag "Keyword")
  713. (choice symbol regexp))))
  714. (repeat (list :inline t :format "%v"
  715. (symbol :tag "Keyword")
  716. (choice symbol regexp)))))
  717. :group 'diary)
  718. (defvar diary-font-lock-keywords)
  719. (defcustom diary-date-forms (cond ((eq calendar-date-style 'iso)
  720. diary-iso-date-forms)
  721. ((eq calendar-date-style 'european)
  722. diary-european-date-forms)
  723. (t diary-american-date-forms))
  724. "List of pseudo-patterns describing the forms of date used in the diary.
  725. The patterns on the list must be MUTUALLY EXCLUSIVE and should not match
  726. any portion of the diary entry itself, just the date component.
  727. A pseudo-pattern is a list of regular expressions and the keywords `month',
  728. `day', `year', `monthname', and `dayname'. The keyword `monthname' will
  729. match the name of the month (see `calendar-month-name-array'), capitalized
  730. or not, or its user-specified abbreviation (see `calendar-month-abbrev-array'),
  731. followed by a period or not; it will also match `*'. Similarly, `dayname'
  732. will match the name of the day (see `calendar-day-name-array'), capitalized or
  733. not, or its user-specified abbreviation (see `calendar-day-abbrev-array'),
  734. followed by a period or not. The keywords `month', `day', and `year' will
  735. match those numerical values, preceded by arbitrarily many zeros; they will
  736. also match `*'.
  737. The matching of the diary entries with the date forms is done with the
  738. standard syntax table from Fundamental mode, but with the `*' changed so
  739. that it is a word constituent.
  740. If, to be mutually exclusive, a pseudo-pattern must match a portion of the
  741. diary entry itself, the first element of the pattern MUST be `backup'. This
  742. directive causes the date recognizer to back up to the beginning of the
  743. current word of the diary entry, so in no case can the pattern match more than
  744. a portion of the first word of the diary entry.
  745. For examples of three common styles, see `diary-american-date-forms',
  746. `diary-european-date-forms', and `diary-iso-date-forms'."
  747. :type '(repeat (choice (cons :tag "Backup"
  748. :value (backup . nil)
  749. (const backup)
  750. (repeat (list :inline t :format "%v"
  751. (symbol :tag "Keyword")
  752. (choice symbol regexp))))
  753. (repeat (list :inline t :format "%v"
  754. (symbol :tag "Keyword")
  755. (choice symbol regexp)))))
  756. :set-after '(calendar-date-style diary-iso-date-forms
  757. diary-european-date-forms
  758. diary-american-date-forms)
  759. :initialize 'custom-initialize-default
  760. :set (lambda (symbol value)
  761. (unless (equal value (eval symbol))
  762. (custom-set-default symbol value)
  763. (setq diary-font-lock-keywords (diary-font-lock-keywords))
  764. ;; Need to redraw not just to get new font-locking, but also
  765. ;; to pick up any newly recognized entries.
  766. (and (diary-live-p)
  767. (diary))))
  768. :group 'diary)
  769. ;; Next three are provided to aid in setting calendar-date-display-form.
  770. (defcustom calendar-iso-date-display-form '((format "%s-%.2d-%.2d" year
  771. (string-to-number month)
  772. (string-to-number day)))
  773. "Pseudo-pattern governing the way a date appears in the ISO style.
  774. Normally you should not customize this, but `calendar-date-display-form'
  775. \(which see)."
  776. :type 'sexp
  777. :version "23.1"
  778. :group 'calendar)
  779. (define-obsolete-variable-alias 'european-calendar-display-form
  780. 'calendar-european-date-display-form "23.1")
  781. (defcustom calendar-european-date-display-form
  782. '((if dayname (concat dayname ", ")) day " " monthname " " year)
  783. "Pseudo-pattern governing the way a date appears in the European style.
  784. Normally you should not customize this, but `calendar-date-display-form'
  785. \(which see)."
  786. :type 'sexp
  787. :group 'calendar)
  788. (define-obsolete-variable-alias 'american-calendar-display-form
  789. 'calendar-american-date-display-form "23.1")
  790. (defcustom calendar-american-date-display-form
  791. '((if dayname (concat dayname ", ")) monthname " " day ", " year)
  792. "Pseudo-pattern governing the way a date appears in the American style.
  793. Normally you should not customize this, but `calendar-date-display-form'
  794. \(which see)."
  795. :type 'sexp
  796. :group 'calendar)
  797. (defcustom calendar-date-display-form
  798. (cond ((eq calendar-date-style 'iso)
  799. calendar-iso-date-display-form)
  800. ((eq calendar-date-style 'european)
  801. calendar-european-date-display-form)
  802. (t calendar-american-date-display-form))
  803. "Pseudo-pattern governing the way a calendar date appears.
  804. Used by the function `calendar-date-string' (which see), a pseudo-pattern
  805. is a list of expressions that can involve the keywords `month', `day',
  806. and `year' (all numbers in string form), and `monthname' and `dayname'
  807. \(both alphabetic strings). For example, a typical American form would be
  808. '(month \"/\" day \"/\" (substring year -2))
  809. whereas
  810. '((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
  811. would give the usual American style in fixed-length fields. The variables
  812. `calendar-iso-date-display-form', `calendar-european-date-display-form', and
  813. `calendar-american-date-display-form' provide some defaults for three common
  814. styles."
  815. :type 'sexp
  816. :set-after '(calendar-date-style calendar-iso-date-display-form
  817. calendar-european-date-display-form
  818. calendar-american-date-display-form)
  819. :group 'calendar)
  820. (defcustom calendar-american-month-header
  821. '(propertize (format "%s %d" (calendar-month-name month) year)
  822. 'font-lock-face 'calendar-month-header)
  823. "Default format for calendar month headings with the American date style.
  824. Normally you should not customize this, but `calender-month-header'."
  825. :group 'calendar
  826. :risky t
  827. :type 'sexp
  828. :version "24.4") ; font-lock-function-name-face -> calendar-month-header
  829. (defcustom calendar-european-month-header
  830. '(propertize (format "%s %d" (calendar-month-name month) year)
  831. 'font-lock-face 'calendar-month-header)
  832. "Default format for calendar month headings with the European date style.
  833. Normally you should not customize this, but `calender-month-header'."
  834. :group 'calendar
  835. :risky t
  836. :type 'sexp
  837. :version "24.4") ; font-lock-function-name-face -> calendar-month-header
  838. (defcustom calendar-iso-month-header
  839. '(propertize (format "%d %s" year (calendar-month-name month))
  840. 'font-lock-face 'calendar-month-header)
  841. "Default format for calendar month headings with the ISO date style.
  842. Normally you should not customize this, but `calender-month-header'."
  843. :group 'calendar
  844. :risky t
  845. :type 'sexp
  846. :version "24.4") ; font-lock-function-name-face -> calendar-month-header
  847. (defcustom calendar-month-header
  848. (cond ((eq calendar-date-style 'iso)
  849. calendar-iso-month-header)
  850. ((eq calendar-date-style 'european)
  851. calendar-european-month-header)
  852. (t calendar-american-month-header))
  853. "Expression to evaluate to return the calendar month headings.
  854. When this expression is evaluated, the variables MONTH and YEAR are
  855. integers appropriate to the relevant month. The result is padded
  856. to the width of `calendar-month-digit-width'.
  857. For examples of three common styles, see `calendar-american-month-header',
  858. `calendar-european-month-header', and `calendar-iso-month-header'.
  859. Changing this variable without using customize has no effect on
  860. pre-existing calendar windows."
  861. :group 'calendar
  862. :initialize 'custom-initialize-default
  863. :risky t
  864. :set (lambda (sym val)
  865. (set sym val)
  866. (calendar-redraw))
  867. :set-after '(calendar-date-style calendar-american-month-header
  868. calendar-european-month-header
  869. calendar-iso-month-header)
  870. :type 'sexp
  871. :version "24.3")
  872. (defun calendar-set-date-style (style)
  873. "Set the style of calendar and diary dates to STYLE (a symbol).
  874. The valid styles are described in the documentation of `calendar-date-style'."
  875. (interactive (list (intern
  876. (completing-read "Date style: "
  877. '("american" "european" "iso") nil t
  878. nil nil "american"))))
  879. (or (memq style '(american european iso))
  880. (setq style 'american))
  881. (setq calendar-date-style style
  882. calendar-date-display-form
  883. (symbol-value (intern-soft
  884. (format "calendar-%s-date-display-form" style)))
  885. calendar-month-header
  886. (symbol-value (intern-soft (format "calendar-%s-month-header" style)))
  887. diary-date-forms
  888. (symbol-value (intern-soft (format "diary-%s-date-forms" style))))
  889. (calendar-redraw)
  890. (calendar-update-mode-line))
  891. (defun european-calendar ()
  892. "Set the interpretation and display of dates to the European style."
  893. (declare (obsolete calendar-set-date-style "23.1"))
  894. (interactive)
  895. (calendar-set-date-style 'european))
  896. (defun american-calendar ()
  897. "Set the interpretation and display of dates to the American style."
  898. (declare (obsolete calendar-set-date-style "23.1"))
  899. (interactive)
  900. (calendar-set-date-style 'american))
  901. (define-obsolete-variable-alias 'holidays-in-diary-buffer
  902. 'diary-show-holidays-flag "23.1")
  903. (defcustom diary-show-holidays-flag t
  904. "Non-nil means include holidays in the diary display.
  905. The holidays appear in the mode line of the diary buffer, or in the
  906. fancy diary buffer next to the date. This slows down the diary functions
  907. somewhat; setting it to nil makes the diary display faster."
  908. :type 'boolean
  909. :group 'holidays)
  910. (defcustom calendar-debug-sexp nil
  911. "Turn debugging on when evaluating a sexp in the diary or holiday list."
  912. :type 'boolean
  913. :group 'calendar)
  914. (define-obsolete-variable-alias 'all-hebrew-calendar-holidays
  915. 'calendar-hebrew-all-holidays-flag "23.1")
  916. (defcustom calendar-hebrew-all-holidays-flag nil
  917. "If nil, show only major holidays from the Hebrew calendar.
  918. This means only those Jewish holidays that appear on secular calendars.
  919. Otherwise, show all the holidays that would appear in a complete Hebrew
  920. calendar."
  921. :type 'boolean
  922. :group 'holidays)
  923. (define-obsolete-variable-alias 'all-christian-calendar-holidays
  924. 'calendar-christian-all-holidays-flag "23.1")
  925. (defcustom calendar-christian-all-holidays-flag nil
  926. "If nil, show only major holidays from the Christian calendar.
  927. This means only those Christian holidays that appear on secular calendars.
  928. Otherwise, show all the holidays that would appear in a complete Christian
  929. calendar."
  930. :type 'boolean
  931. :group 'holidays)
  932. (define-obsolete-variable-alias 'all-islamic-calendar-holidays
  933. 'calendar-islamic-all-holidays-flag "23.1")
  934. (defcustom calendar-islamic-all-holidays-flag nil
  935. "If nil, show only major holidays from the Islamic calendar.
  936. This means only those Islamic holidays that appear on secular calendars.
  937. Otherwise, show all the holidays that would appear in a complete Islamic
  938. calendar."
  939. :type 'boolean
  940. :group 'holidays)
  941. (define-obsolete-variable-alias 'all-bahai-calendar-holidays
  942. 'calendar-bahai-all-holidays-flag "23.1")
  943. (defcustom calendar-bahai-all-holidays-flag nil
  944. "If nil, show only major holidays from the Bahá'í calendar.
  945. These are the days on which work and school must be suspended.
  946. Otherwise, show all the holidays that would appear in a complete Bahá'í
  947. calendar."
  948. :type 'boolean
  949. :group 'holidays)
  950. (defcustom calendar-chinese-all-holidays-flag nil
  951. "If nil, show only the major holidays from the Chinese calendar."
  952. :version "23.1"
  953. :type 'boolean
  954. :group 'holidays)
  955. ;;; End of user options.
  956. (calendar-recompute-layout-variables)
  957. (defconst calendar-first-date-row 3
  958. "First row in the calendar with actual dates.")
  959. (defconst calendar-buffer "*Calendar*"
  960. "Name of the buffer used for the calendar.")
  961. (defconst holiday-buffer "*Holidays*"
  962. "Name of the buffer used for the displaying the holidays.")
  963. (defconst diary-fancy-buffer "*Fancy Diary Entries*"
  964. "Name of the buffer used for the optional fancy display of the diary.")
  965. (define-obsolete-variable-alias 'fancy-diary-buffer 'diary-fancy-buffer "23.1")
  966. (defconst calendar-other-calendars-buffer "*Other Calendars*"
  967. "Name of the buffer used for the display of date on other calendars.")
  968. (defconst lunar-phases-buffer "*Phases of Moon*"
  969. "Name of the buffer used for the lunar phases.")
  970. (defconst solar-sunrises-buffer "*Sunrise/Sunset Times*"
  971. "Name of buffer used for sunrise/sunset times.")
  972. (defconst calendar-hebrew-yahrzeit-buffer "*Yahrzeits*"
  973. "Name of the buffer used by `list-yahrzeit-dates'.")
  974. (defmacro calendar-increment-month (mon yr n &optional nmonths)
  975. "Increment the variables MON and YR by N months.
  976. Forward if N is positive or backward if N is negative.
  977. A negative YR is interpreted as BC; -1 being 1 BC, and so on.
  978. Optional NMONTHS is the number of months per year (default 12)."
  979. ;; Can view this as a form of base-nmonths arithmetic, in which "a
  980. ;; year" = "ten", and we never bother to use hundreds.
  981. `(let ((nmonths (or ,nmonths 12))
  982. macro-y)
  983. (if (< ,yr 0) (setq ,yr (1+ ,yr))) ; -1 BC -> 0 AD, etc
  984. (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
  985. ,mon (1+ (mod macro-y nmonths))
  986. ,yr (/ macro-y nmonths))
  987. ;; Alternative:
  988. ;;; (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
  989. ;;; ,yr (/ macro-y nmonths)
  990. ;;; ,mon (- macro-y (* ,yr nmonths)))
  991. (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr)))
  992. (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc
  993. (define-obsolete-function-alias 'increment-calendar-month
  994. 'calendar-increment-month "23.1")
  995. (defvar displayed-month)
  996. (defvar displayed-year)
  997. (defun calendar-increment-month-cons (n &optional mon yr)
  998. "Return the Nth month after MON/YR.
  999. The return value is a pair (MONTH . YEAR).
  1000. MON defaults to `displayed-month'. YR defaults to `displayed-year'."
  1001. (unless mon (setq mon displayed-month))
  1002. (unless yr (setq yr displayed-year))
  1003. (calendar-increment-month mon yr n)
  1004. (cons mon yr))
  1005. (defmacro calendar-for-loop (var from init to final do &rest body)
  1006. "Execute a for loop.
  1007. Evaluate BODY with VAR bound to successive integers from INIT to FINAL,
  1008. inclusive. The standard macro `dotimes' is preferable in most cases."
  1009. (declare (obsolete "use `dotimes' or `while' instead." "23.1")
  1010. (debug (symbolp "from" form "to" form "do" body))
  1011. (indent defun))
  1012. `(let ((,var (1- ,init)))
  1013. (while (>= ,final (setq ,var (1+ ,var)))
  1014. ,@body)))
  1015. (defmacro calendar-sum (index initial condition expression)
  1016. "For INDEX = INITIAL, +1, ... (as long as CONDITION holds), sum EXPRESSION."
  1017. (declare (debug (symbolp form form form)))
  1018. `(let ((,index ,initial)
  1019. (sum 0))
  1020. (while ,condition
  1021. (setq sum (+ sum ,expression)
  1022. ,index (1+ ,index)))
  1023. sum))
  1024. (defmacro calendar-in-read-only-buffer (buffer &rest body)
  1025. "Switch to BUFFER and execute the forms in BODY.
  1026. First creates or erases BUFFER as needed. Leaves BUFFER read-only,
  1027. with disabled undo. Leaves point at point-min, displays BUFFER."
  1028. (declare (indent 1) (debug t))
  1029. `(progn
  1030. (set-buffer (get-buffer-create ,buffer))
  1031. (or (derived-mode-p 'special-mode) (special-mode))
  1032. (setq buffer-read-only nil
  1033. buffer-undo-list t)
  1034. (erase-buffer)
  1035. ,@body
  1036. (goto-char (point-min))
  1037. (set-buffer-modified-p nil)
  1038. (setq buffer-read-only t)
  1039. (display-buffer ,buffer)))
  1040. ;; The following are in-line for speed; they can be called thousands of times
  1041. ;; when looking up holidays or processing the diary. Here, for example, are
  1042. ;; the numbers of calls to calendar/diary/holiday functions in preparing the
  1043. ;; fancy diary display, for a moderately complex diary file, with functions
  1044. ;;…

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