PageRenderTime 37ms CodeModel.GetById 43ms RepoModel.GetById 0ms app.codeStats 2ms

/lisp/calendar/calendar.el

http://github.com/davidswelt/aquamacs-emacs
Emacs Lisp | 2644 lines | 2070 code | 245 blank | 329 comment | 77 complexity | 349736d40172406872d0885f4066383b MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, GPL-2.0, AGPL-3.0
  1. ;;; calendar.el --- calendar functions
  2. ;; Copyright (C) 1988-1995, 1997, 2000-2016 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. (defcustom calendar-weekend-days '(0 6)
  163. "Days of the week considered weekend days.
  164. 0 means Sunday, 1 means Monday, and so on.
  165. Determines which day headers are fontified with
  166. `calendar-weekend-header'."
  167. :type '(repeat integer)
  168. :version "25.1"
  169. :group 'calendar)
  170. (defcustom calendar-view-diary-initially-flag nil
  171. "Non-nil means display current date's diary entries on entry to calendar.
  172. The diary is displayed in another window when the calendar is first displayed,
  173. if the current date is visible. The number of days of diary entries displayed
  174. is governed by the variable `diary-number-of-entries'. This variable can
  175. be overridden by the value of `calendar-setup'."
  176. :type 'boolean
  177. :group 'diary)
  178. ;; FIXME :set
  179. (defcustom calendar-mark-diary-entries-flag nil
  180. "Non-nil means mark dates with diary entries, in the calendar window.
  181. The marking symbol is specified by the variable `diary-entry-marker'."
  182. :type 'boolean
  183. :group 'diary)
  184. (defcustom calendar-remove-frame-by-deleting t
  185. "Determine how the calendar mode removes a frame no longer needed.
  186. If nil, make an icon of the frame. If non-nil, delete the frame."
  187. :type 'boolean
  188. :version "23.1" ; changed from nil to t
  189. :group 'view
  190. :group 'calendar)
  191. (defface calendar-today
  192. '((t (:underline t)))
  193. "Face for indicating today's date in the calendar.
  194. See the variable `calendar-today-marker'."
  195. :group 'calendar-faces)
  196. (defface diary
  197. '((((min-colors 88) (class color) (background light))
  198. :foreground "red1")
  199. (((class color) (background light))
  200. :foreground "red")
  201. (((min-colors 88) (class color) (background dark))
  202. :foreground "yellow1")
  203. (((class color) (background dark))
  204. :foreground "yellow")
  205. (t
  206. :weight bold))
  207. "Face for highlighting diary entries.
  208. Used to mark diary entries in the calendar (see `diary-entry-marker'),
  209. and to highlight the date header in the fancy diary."
  210. :group 'calendar-faces)
  211. (defface holiday
  212. '((((class color) (background light))
  213. :background "pink")
  214. (((class color) (background dark))
  215. :background "chocolate4")
  216. (t
  217. :inverse-video t))
  218. "Face for indicating in the calendar dates that have holidays.
  219. See `calendar-holiday-marker'."
  220. :group 'calendar-faces)
  221. (defface calendar-weekday-header '((t :inherit font-lock-constant-face))
  222. "Face used for weekday column headers in the calendar.
  223. See also the face `calendar-weekend-header'."
  224. :version "24.4"
  225. :group 'calendar-faces)
  226. (defface calendar-weekend-header '((t :inherit font-lock-comment-face))
  227. "Face used for weekend column headers in the calendar.
  228. See also the face `calendar-weekday-header'."
  229. :version "24.4"
  230. :group 'calendar-faces)
  231. (defface calendar-month-header '((t :inherit font-lock-function-name-face))
  232. "Face used for month headers in the calendar."
  233. :version "24.4"
  234. :group 'calendar-faces)
  235. ;; These briefly checked font-lock-mode, but that is broken, since it
  236. ;; is a buffer-local variable, and which buffer happens to be current
  237. ;; when this file is loaded shouldn't make a difference. One could
  238. ;; perhaps check global-font-lock-mode, or font-lock-global-modes; but
  239. ;; this feature doesn't use font-lock, so there's no real reason it
  240. ;; should respect those either. See bug#2199.
  241. ;; They also used to check display-color-p, but that is a problem if
  242. ;; loaded from --daemon. Since BW displays are rare now, this was
  243. ;; also taken out. The way to keep it would be to have nil mean do a
  244. ;; runtime check whenever this variable is used.
  245. (defcustom diary-entry-marker 'diary
  246. "How to mark dates that have diary entries.
  247. The value can be either a single-character string (e.g. \"+\") or a face."
  248. :type '(choice (string :tag "Single character string") face)
  249. :group 'diary
  250. :version "23.1")
  251. (defcustom calendar-today-marker 'calendar-today
  252. "How to mark today's date in the calendar.
  253. The value can be either a single-character string (e.g. \"=\") or a face.
  254. Used by `calendar-mark-today'."
  255. :type '(choice (string :tag "Single character string") face)
  256. :group 'calendar
  257. :version "23.1")
  258. (defcustom calendar-holiday-marker 'holiday
  259. "How to mark notable dates in the calendar.
  260. The value can be either a single-character string (e.g. \"*\") or a face."
  261. :type '(choice (string :tag "Single character string") face)
  262. :group 'holidays
  263. :version "23.1")
  264. (defcustom calendar-view-holidays-initially-flag nil
  265. "Non-nil means display holidays for current three month period on entry.
  266. The holidays are displayed in another window when the calendar is first
  267. displayed."
  268. :type 'boolean
  269. :group 'holidays)
  270. ;; FIXME :set
  271. (defcustom calendar-mark-holidays-flag nil
  272. "Non-nil means mark dates of holidays in the calendar window.
  273. The marking symbol is specified by the variable `calendar-holiday-marker'."
  274. :type 'boolean
  275. :group 'holidays)
  276. (defcustom calendar-mode-hook nil
  277. "Hook run when entering `calendar-mode'."
  278. :type 'hook
  279. :group 'calendar-hooks)
  280. (defcustom calendar-load-hook nil
  281. "List of functions to be called after the calendar is first loaded.
  282. This is the place to add key bindings to `calendar-mode-map'."
  283. :type 'hook
  284. :group 'calendar-hooks)
  285. (defcustom calendar-initial-window-hook nil
  286. "List of functions to be called when the calendar window is created.
  287. Quitting the calendar and re-entering it will cause these functions
  288. to be called again."
  289. :type 'hook
  290. :group 'calendar-hooks)
  291. (defcustom calendar-today-visible-hook nil
  292. "List of functions called whenever the current date is visible.
  293. To mark today's date, add the function `calendar-mark-today'.
  294. To replace the date with asterisks, add the function `calendar-star-date'.
  295. See also `calendar-today-invisible-hook'.
  296. In general, be careful about changing characters in the calendar buffer,
  297. since it may cause the movement commands to fail."
  298. :type 'hook
  299. :options '(calendar-mark-today calendar-star-date)
  300. :group 'calendar-hooks)
  301. (defcustom calendar-today-invisible-hook nil
  302. "List of functions called whenever the current date is not visible.
  303. See also `calendar-today-visible-hook'."
  304. :type 'hook
  305. :group 'calendar-hooks)
  306. (defcustom calendar-move-hook nil
  307. "List of functions called whenever the cursor moves in the calendar.
  308. For example,
  309. (add-hook \\='calendar-move-hook (lambda () (diary-view-entries 1)))
  310. redisplays the diary for whatever date the cursor is moved to."
  311. :type 'hook
  312. :options '(calendar-update-mode-line)
  313. :group 'calendar-hooks)
  314. (defcustom calendar-date-echo-text
  315. "mouse-2: general menu\nmouse-3: menu for this date"
  316. "String displayed when the cursor is over a date in the calendar.
  317. Can be either a fixed string, or a lisp expression that returns one.
  318. When this expression is evaluated, DAY, MONTH, and YEAR are
  319. integers appropriate to the relevant date. For example, to
  320. display the ISO date:
  321. (setq calendar-date-echo-text \\='(format \"ISO date: %s\"
  322. (calendar-iso-date-string
  323. (list month day year))))
  324. Changing this variable without using customize has no effect on
  325. pre-existing calendar windows."
  326. :group 'calendar
  327. :initialize 'custom-initialize-default
  328. :risky t
  329. :set (lambda (sym val)
  330. (set sym val)
  331. (calendar-redraw))
  332. :type '(choice (string :tag "Fixed string")
  333. (sexp :value
  334. (format "ISO date: %s"
  335. (calendar-iso-date-string
  336. (list month day year)))))
  337. :version "23.1")
  338. (defvar calendar-month-digit-width nil
  339. "Width of the region with numbers in each month in the calendar.")
  340. (defvar calendar-month-width nil
  341. "Full width of each month in the calendar.")
  342. (defvar calendar-right-margin nil
  343. "Right margin of the calendar.")
  344. (defvar calendar-month-edges nil
  345. "Alist of month edge columns.
  346. Each element has the form (N LEFT FIRST LAST RIGHT), where
  347. LEFT is the leftmost column associated with month segment N,
  348. FIRST and LAST are the first and last columns with day digits in,
  349. and LAST is the rightmost column.")
  350. (defun calendar-month-edges (segment)
  351. "Compute the month edge columns for month SEGMENT.
  352. Returns a list (LEFT FIRST LAST RIGHT), where LEFT is the
  353. leftmost column associated with a month, FIRST and LAST are the
  354. first and last columns with day digits in, and LAST is the
  355. rightmost column."
  356. ;; The leftmost column with a digit in it in this month segment.
  357. (let* ((first (+ calendar-left-margin
  358. (* segment calendar-month-width)))
  359. ;; The rightmost column with a digit in it in this month segment.
  360. (last (+ first (1- calendar-month-digit-width)))
  361. (left (if (eq segment 0)
  362. 0
  363. (+ calendar-left-margin
  364. (* segment calendar-month-width)
  365. (- (/ calendar-intermonth-spacing 2)))))
  366. ;; The rightmost edge of this month segment, dividing the
  367. ;; space between months in two.
  368. (right (+ calendar-left-margin
  369. (* (1+ segment) calendar-month-width)
  370. (- (/ calendar-intermonth-spacing 2)))))
  371. (list left first last right)))
  372. (defun calendar-recompute-layout-variables ()
  373. "Recompute some layout-related calendar \"constants\"."
  374. (setq calendar-month-digit-width (+ (* 6 calendar-column-width)
  375. calendar-day-digit-width)
  376. calendar-month-width (+ (* 7 calendar-column-width)
  377. calendar-intermonth-spacing)
  378. calendar-right-margin (+ calendar-left-margin
  379. (* 3 (* 7 calendar-column-width))
  380. (* 2 calendar-intermonth-spacing))
  381. calendar-month-edges nil)
  382. (dotimes (i 3)
  383. (push (cons i (calendar-month-edges i)) calendar-month-edges))
  384. (setq calendar-month-edges (reverse calendar-month-edges)))
  385. (defun calendar-set-layout-variable (symbol value &optional minmax)
  386. "Set SYMBOL's value to VALUE, an integer.
  387. A positive/negative MINMAX enforces a minimum/maximum value.
  388. Then redraw the calendar, if necessary."
  389. (let ((oldvalue (symbol-value symbol)))
  390. (custom-set-default symbol (if minmax
  391. (if (< minmax 0)
  392. (min value (- minmax))
  393. (max value minmax))
  394. value))
  395. (unless (equal value oldvalue)
  396. (calendar-recompute-layout-variables)
  397. (calendar-redraw))))
  398. (defcustom calendar-left-margin 5
  399. "Empty space to the left of the first month in the calendar."
  400. :group 'calendar
  401. :initialize 'custom-initialize-default
  402. :set 'calendar-set-layout-variable
  403. :type 'integer
  404. :version "23.1")
  405. ;; Or you can view it as columns of width 2, with 1 space, no space
  406. ;; after the last column, and a 5 space gap between month.
  407. ;; FIXME check things work if this is odd.
  408. (defcustom calendar-intermonth-spacing 4
  409. "Space between months in the calendar. Minimum value is 1."
  410. :group 'calendar
  411. :initialize 'custom-initialize-default
  412. :set (lambda (sym val)
  413. (calendar-set-layout-variable sym val 1))
  414. :type 'integer
  415. :version "23.1")
  416. ;; FIXME calendar-month-column-width?
  417. (defcustom calendar-column-width 3
  418. "Width of each day column in the calendar. Minimum value is 3."
  419. :initialize 'custom-initialize-default
  420. :set (lambda (sym val)
  421. (calendar-set-layout-variable sym val 3))
  422. :type 'integer
  423. :version "23.1")
  424. (defun calendar-day-header-construct (&optional width)
  425. "Return the default value for `calendar-day-header-array'.
  426. WIDTH defaults to `calendar-day-header-width'."
  427. (or width (setq width calendar-day-header-width))
  428. (calendar-abbrev-construct (if (<= width calendar-abbrev-length)
  429. calendar-day-abbrev-array
  430. calendar-day-name-array)
  431. width))
  432. ;; FIXME better to use a format spec?
  433. (defcustom calendar-day-header-width 2
  434. "Width of the day column headers in the calendar.
  435. Must be at least one less than `calendar-column-width'."
  436. :group 'calendar
  437. :initialize 'custom-initialize-default
  438. :set (lambda (sym val)
  439. (or (calendar-customized-p 'calendar-day-header-array)
  440. (setq calendar-day-header-array
  441. (calendar-day-header-construct val)))
  442. (calendar-set-layout-variable sym val (- 1 calendar-column-width)))
  443. :type 'integer
  444. :version "23.1")
  445. ;; FIXME a format specifier instead?
  446. (defcustom calendar-day-digit-width 2
  447. "Width of the day digits in the calendar. Minimum value is 2."
  448. :group 'calendar
  449. :initialize 'custom-initialize-default
  450. :set (lambda (sym val)
  451. (calendar-set-layout-variable sym val 2))
  452. :type 'integer
  453. :version "23.1")
  454. (defcustom calendar-intermonth-header nil
  455. "Header text to display in the space to the left of each calendar month.
  456. See `calendar-intermonth-text'."
  457. :group 'calendar
  458. :initialize 'custom-initialize-default
  459. :risky t
  460. :set (lambda (sym val)
  461. (set sym val)
  462. (calendar-redraw))
  463. :type '(choice (const nil :tag "Nothing")
  464. (string :tag "Fixed string")
  465. (sexp :value
  466. (propertize "WK" 'font-lock-face
  467. 'font-lock-function-name-face)))
  468. :version "23.1")
  469. (defcustom calendar-intermonth-text nil
  470. "Text to display in the space to the left of each calendar month.
  471. Can be nil, a fixed string, or a lisp expression that returns a string.
  472. When the expression is evaluated, the variables DAY, MONTH and YEAR
  473. are integers appropriate for the first day in each week.
  474. Will be truncated to the smaller of `calendar-left-margin' and
  475. `calendar-intermonth-spacing'. The last character is forced to be a space.
  476. For example, to display the ISO week numbers:
  477. (setq calendar-week-start-day 1
  478. calendar-intermonth-text
  479. \\='(propertize
  480. (format \"%2d\"
  481. (car
  482. (calendar-iso-from-absolute
  483. (calendar-absolute-from-gregorian (list month day year)))))
  484. \\='font-lock-face \\='font-lock-function-name-face))
  485. See also `calendar-intermonth-header'."
  486. :group 'calendar
  487. :initialize 'custom-initialize-default
  488. :risky t
  489. :set (lambda (sym val)
  490. (set sym val)
  491. (calendar-redraw))
  492. :type '(choice (const nil :tag "Nothing")
  493. (string :tag "Fixed string")
  494. (sexp :value
  495. (propertize
  496. (format "%2d"
  497. (car
  498. (calendar-iso-from-absolute
  499. (calendar-absolute-from-gregorian
  500. (list month day year)))))
  501. 'font-lock-face 'font-lock-function-name-face)))
  502. :version "23.1")
  503. (defcustom diary-file (locate-user-emacs-file "diary" "diary")
  504. "Name of the file in which one's personal diary of dates is kept.
  505. The file's entries are lines beginning with any of the forms
  506. specified by the variable `diary-date-forms', which by default
  507. uses the forms of `diary-american-date-forms':
  508. MONTH/DAY
  509. MONTH/DAY/YEAR
  510. MONTHNAME DAY
  511. MONTHNAME DAY, YEAR
  512. DAYNAME
  513. with the remainder of the line being the diary entry string for
  514. that date. MONTH and DAY are one or two digit numbers, YEAR is a
  515. number and may be written in full or abbreviated to the final two
  516. digits (if `diary-abbreviated-year-flag' is non-nil). MONTHNAME
  517. and DAYNAME can be spelled in full (as specified by the variables
  518. `calendar-month-name-array' and `calendar-day-name-array'), or
  519. abbreviated (as specified by `calendar-month-abbrev-array' and
  520. `calendar-day-abbrev-array') with or without a period. Case is
  521. ignored. Any of DAY, MONTH, or MONTHNAME, YEAR can be `*' which
  522. matches any day, month, or year, respectively. If the date does
  523. not contain a year, it is generic and applies to any year. A
  524. DAYNAME entry applies to the appropriate day of the week in every week.
  525. You can customize `diary-date-forms' to your preferred format.
  526. Three default styles are provided: `diary-american-date-forms',
  527. `diary-european-date-forms', and `diary-iso-date-forms'.
  528. You can choose between these by setting `calendar-date-style' in your
  529. init file, or by using `calendar-set-date-style' when in the calendar.
  530. A diary entry can be preceded by the character `diary-nonmarking-symbol'
  531. \(ordinarily `&') to make that entry nonmarking--that is, it will not be
  532. marked on dates in the calendar window but will appear in a diary window.
  533. Multiline diary entries are made by indenting lines after the first with
  534. either a TAB or one or more spaces.
  535. Lines not in one the above formats are ignored. Here are some sample diary
  536. entries (in the default American style):
  537. 12/22/1988 Twentieth wedding anniversary!!
  538. &1/1. Happy New Year!
  539. 10/22 Ruth's birthday.
  540. 21: Payday
  541. Tuesday--weekly meeting with grad students at 10am
  542. Supowit, Shen, Bitner, and Kapoor to attend.
  543. 1/13/89 Friday the thirteenth!!
  544. &thu 4pm squash game with Lloyd.
  545. mar 16 Dad's birthday
  546. April 15, 1989 Income tax due.
  547. &* 15 time cards due.
  548. If the first line of a diary entry consists only of the date or day name with
  549. no trailing blanks or punctuation, then that line is not displayed in the
  550. diary window; only the continuation lines is shown. For example, the
  551. single diary entry
  552. 02/11/1989
  553. Bill Blattner visits Princeton today
  554. 2pm Cognitive Studies Committee meeting
  555. 2:30-5:30 Lizzie at Lawrenceville for `Group Initiative'
  556. 4:00pm Jamie Tappenden
  557. 7:30pm Dinner at George and Ed's for Alan Ryan
  558. 7:30-10:00pm dance at Stewart Country Day School
  559. will appear in the diary window without the date line at the beginning. This
  560. facility allows the diary window to look neater, but can cause confusion if
  561. used with more than one day's entries displayed.
  562. Diary entries can be based on Lisp sexps. For example, the diary entry
  563. %%(diary-block 11 1 1990 11 10 1990) Vacation
  564. causes the diary entry \"Vacation\" to appear from November 1 through
  565. November 10, 1990. See the documentation for the function
  566. `diary-list-sexp-entries' for more details.
  567. Diary entries based on the Hebrew, the Islamic and/or the Baháí
  568. calendar are also possible, but because these are somewhat slow, they
  569. are ignored unless you set the `diary-nongregorian-listing-hook' and
  570. the `diary-nongregorian-marking-hook' appropriately. See the
  571. documentation of these hooks for details.
  572. Diary files can contain directives to include the contents of other files; for
  573. details, see the documentation for the variable `diary-list-entries-hook'."
  574. :version "25.1" ; ~/diary -> locate-user-emacs-file
  575. :type 'file
  576. :group 'diary)
  577. ;; FIXME do these have to be single characters?
  578. (defcustom diary-nonmarking-symbol "&"
  579. "Symbol indicating that a diary entry is not to be marked in the calendar."
  580. :type 'string
  581. :group 'diary)
  582. (defcustom diary-chinese-entry-symbol "C"
  583. "Symbol indicating a diary entry according to the Chinese calendar."
  584. :type 'string
  585. :group 'diary
  586. :version "25.1")
  587. (defcustom diary-hebrew-entry-symbol "H"
  588. "Symbol indicating a diary entry according to the Hebrew calendar."
  589. :type 'string
  590. :group 'diary)
  591. (defcustom diary-islamic-entry-symbol "I"
  592. "Symbol indicating a diary entry according to the Islamic calendar."
  593. :type 'string
  594. :group 'diary)
  595. (defcustom diary-bahai-entry-symbol "B"
  596. "Symbol indicating a diary entry according to the Bahá’í calendar."
  597. :type 'string
  598. :group 'diary)
  599. (defcustom calendar-date-style 'american
  600. "Your preferred style for writing dates.
  601. The options are:
  602. `american' - month/day/year
  603. `european' - day/month/year
  604. `iso' - year/month/day
  605. This affects how dates written in your diary are interpreted.
  606. It also affects date display, as well as those calendar and diary
  607. functions that take a date as an argument, e.g. `diary-date', by
  608. changing the order in which the arguments are interpreted.
  609. Setting this variable directly does not take effect (if the
  610. calendar package is already loaded). Rather, use either
  611. \\[customize] or the function `calendar-set-date-style'."
  612. :version "23.1"
  613. :type '(choice (const american :tag "Month/Day/Year")
  614. (const european :tag "Day/Month/Year")
  615. (const iso :tag "Year/Month/Day"))
  616. :initialize 'custom-initialize-default
  617. :set (lambda (symbol value)
  618. (calendar-set-date-style value))
  619. :group 'calendar)
  620. ;; Next three are provided to aid in setting diary-date-forms.
  621. ;; FIXME move to diary-lib?
  622. (defcustom diary-iso-date-forms
  623. '((month "[-/]" day "[^-/0-9]")
  624. (year "[-/]" month "[-/]" day "[^0-9]")
  625. ;; Cannot allow [-/] as separators here, since it would also match
  626. ;; the first element (bug#7377).
  627. (monthname " *" day "[^-0-9]")
  628. (year " *" monthname " *" day "[^0-9]")
  629. (dayname "\\W"))
  630. "List of pseudo-patterns describing the ISO style of dates.
  631. The defaults are: MONTH[-/]DAY; YEAR[-/]MONTH[-/]DAY; MONTHNAME DAY;
  632. YEAR MONTHNAME DAY; DAYNAME. Normally you should not customize this,
  633. but `diary-date-forms' (which see)."
  634. :version "23.3" ; bug#7377
  635. :type '(repeat (choice (cons :tag "Backup"
  636. :value (backup . nil)
  637. (const backup)
  638. (repeat (list :inline t :format "%v"
  639. (symbol :tag "Keyword")
  640. (choice symbol regexp))))
  641. (repeat (list :inline t :format "%v"
  642. (symbol :tag "Keyword")
  643. (choice symbol regexp)))))
  644. :group 'diary)
  645. (defcustom diary-american-date-forms
  646. '((month "/" day "[^/0-9]")
  647. (month "/" day "/" year "[^0-9]")
  648. (monthname " *" day "[^,0-9]")
  649. (monthname " *" day ", *" year "[^0-9]")
  650. (dayname "\\W"))
  651. "List of pseudo-patterns describing the American style of dates.
  652. The defaults are: MONTH/DAY; MONTH/DAY/YEAR; MONTHNAME DAY;
  653. MONTHNAME DAY, YEAR; DAYNAME. Normally you should not customize this,
  654. but `diary-date-forms' (which see)."
  655. :type '(repeat (choice (cons :tag "Backup"
  656. :value (backup . nil)
  657. (const backup)
  658. (repeat (list :inline t :format "%v"
  659. (symbol :tag "Keyword")
  660. (choice symbol regexp))))
  661. (repeat (list :inline t :format "%v"
  662. (symbol :tag "Keyword")
  663. (choice symbol regexp)))))
  664. :group 'diary)
  665. (defcustom diary-european-date-forms
  666. '((day "/" month "[^/0-9]")
  667. (day "/" month "/" year "[^0-9]")
  668. (backup day " *" monthname "\\W+\\<\\([^*0-9]\\|\\([0-9]+[:aApP]\\)\\)")
  669. (day " *" monthname " *" year "[^0-9]")
  670. (dayname "\\W"))
  671. "List of pseudo-patterns describing the European style of dates.
  672. The defaults are: DAY/MONTH; DAY/MONTH/YEAR; DAY MONTHNAME;
  673. DAY MONTHNAME YEAR; DAYNAME. Normally you should not customize this, but
  674. `diary-date-forms' (which see)."
  675. :type '(repeat (choice (cons :tag "Backup"
  676. :value (backup . nil)
  677. (const backup)
  678. (repeat (list :inline t :format "%v"
  679. (symbol :tag "Keyword")
  680. (choice symbol regexp))))
  681. (repeat (list :inline t :format "%v"
  682. (symbol :tag "Keyword")
  683. (choice symbol regexp)))))
  684. :group 'diary)
  685. (defvar diary-font-lock-keywords)
  686. (defcustom diary-date-forms (cond ((eq calendar-date-style 'iso)
  687. diary-iso-date-forms)
  688. ((eq calendar-date-style 'european)
  689. diary-european-date-forms)
  690. (t diary-american-date-forms))
  691. "List of pseudo-patterns describing the forms of date used in the diary.
  692. The patterns on the list must be MUTUALLY EXCLUSIVE and should not match
  693. any portion of the diary entry itself, just the date component.
  694. A pseudo-pattern is a list of regular expressions and the keywords `month',
  695. `day', `year', `monthname', and `dayname'. The keyword `monthname' will
  696. match the name of the month (see `calendar-month-name-array'), capitalized
  697. or not, or its user-specified abbreviation (see `calendar-month-abbrev-array'),
  698. followed by a period or not; it will also match `*'. Similarly, `dayname'
  699. will match the name of the day (see `calendar-day-name-array'), capitalized or
  700. not, or its user-specified abbreviation (see `calendar-day-abbrev-array'),
  701. followed by a period or not. The keywords `month', `day', and `year' will
  702. match those numerical values, preceded by arbitrarily many zeros; they will
  703. also match `*'.
  704. The matching of the diary entries with the date forms is done with the
  705. standard syntax table from Fundamental mode, but with the `*' changed so
  706. that it is a word constituent.
  707. If, to be mutually exclusive, a pseudo-pattern must match a portion of the
  708. diary entry itself, the first element of the pattern MUST be `backup'. This
  709. directive causes the date recognizer to back up to the beginning of the
  710. current word of the diary entry, so in no case can the pattern match more than
  711. a portion of the first word of the diary entry.
  712. For examples of three common styles, see `diary-american-date-forms',
  713. `diary-european-date-forms', and `diary-iso-date-forms'."
  714. :type '(repeat (choice (cons :tag "Backup"
  715. :value (backup . nil)
  716. (const backup)
  717. (repeat (list :inline t :format "%v"
  718. (symbol :tag "Keyword")
  719. (choice symbol regexp))))
  720. (repeat (list :inline t :format "%v"
  721. (symbol :tag "Keyword")
  722. (choice symbol regexp)))))
  723. :set-after '(calendar-date-style diary-iso-date-forms
  724. diary-european-date-forms
  725. diary-american-date-forms)
  726. :initialize 'custom-initialize-default
  727. :set (lambda (symbol value)
  728. (unless (equal value (eval symbol))
  729. (custom-set-default symbol value)
  730. (setq diary-font-lock-keywords (diary-font-lock-keywords))
  731. ;; Need to redraw not just to get new font-locking, but also
  732. ;; to pick up any newly recognized entries.
  733. (and (diary-live-p)
  734. (diary))))
  735. :group 'diary)
  736. ;; Next three are provided to aid in setting calendar-date-display-form.
  737. (defcustom calendar-iso-date-display-form '((format "%s-%.2d-%.2d" year
  738. (string-to-number month)
  739. (string-to-number day)))
  740. "Pseudo-pattern governing the way a date appears in the ISO style.
  741. Normally you should not customize this, but `calendar-date-display-form'
  742. \(which see)."
  743. :type 'sexp
  744. :risky t
  745. :version "23.1"
  746. :group 'calendar)
  747. (defcustom calendar-european-date-display-form
  748. '((if dayname (concat dayname ", ")) day " " monthname " " year)
  749. "Pseudo-pattern governing the way a date appears in the European style.
  750. Normally you should not customize this, but `calendar-date-display-form'
  751. \(which see)."
  752. :type 'sexp
  753. :risky t
  754. :group 'calendar)
  755. (defcustom calendar-american-date-display-form
  756. '((if dayname (concat dayname ", ")) monthname " " day ", " year)
  757. "Pseudo-pattern governing the way a date appears in the American style.
  758. Normally you should not customize this, but `calendar-date-display-form'
  759. \(which see)."
  760. :type 'sexp
  761. :risky t
  762. :group 'calendar)
  763. (defcustom calendar-date-display-form
  764. (cond ((eq calendar-date-style 'iso)
  765. calendar-iso-date-display-form)
  766. ((eq calendar-date-style 'european)
  767. calendar-european-date-display-form)
  768. (t calendar-american-date-display-form))
  769. "Pseudo-pattern governing the way a calendar date appears.
  770. Used by the function `calendar-date-string' (which see), a pseudo-pattern
  771. is a list of expressions that can involve the keywords `month', `day',
  772. and `year' (all numbers in string form), and `monthname' and `dayname'
  773. \(both alphabetic strings). For example, a typical American form would be
  774. (month \"/\" day \"/\" (substring year -2))
  775. whereas
  776. ((format \"%9s, %9s %2s, %4s\" dayname monthname day year))
  777. would give the usual American style in fixed-length fields. The variables
  778. `calendar-iso-date-display-form', `calendar-european-date-display-form', and
  779. `calendar-american-date-display-form' provide some defaults for three common
  780. styles."
  781. :type 'sexp
  782. :risky t
  783. :set-after '(calendar-date-style calendar-iso-date-display-form
  784. calendar-european-date-display-form
  785. calendar-american-date-display-form)
  786. :group 'calendar)
  787. (defcustom calendar-american-month-header
  788. '(propertize (format "%s %d" (calendar-month-name month) year)
  789. 'font-lock-face 'calendar-month-header)
  790. "Default format for calendar month headings with the American date style.
  791. Normally you should not customize this, but `calender-month-header'."
  792. :group 'calendar
  793. :risky t
  794. :type 'sexp
  795. :version "24.4") ; font-lock-function-name-face -> calendar-month-header
  796. (defcustom calendar-european-month-header
  797. '(propertize (format "%s %d" (calendar-month-name month) year)
  798. 'font-lock-face 'calendar-month-header)
  799. "Default format for calendar month headings with the European date style.
  800. Normally you should not customize this, but `calender-month-header'."
  801. :group 'calendar
  802. :risky t
  803. :type 'sexp
  804. :version "24.4") ; font-lock-function-name-face -> calendar-month-header
  805. (defcustom calendar-iso-month-header
  806. '(propertize (format "%d %s" year (calendar-month-name month))
  807. 'font-lock-face 'calendar-month-header)
  808. "Default format for calendar month headings with the ISO date style.
  809. Normally you should not customize this, but `calender-month-header'."
  810. :group 'calendar
  811. :risky t
  812. :type 'sexp
  813. :version "24.4") ; font-lock-function-name-face -> calendar-month-header
  814. (defcustom calendar-month-header
  815. (cond ((eq calendar-date-style 'iso)
  816. calendar-iso-month-header)
  817. ((eq calendar-date-style 'european)
  818. calendar-european-month-header)
  819. (t calendar-american-month-header))
  820. "Expression to evaluate to return the calendar month headings.
  821. When this expression is evaluated, the variables MONTH and YEAR are
  822. integers appropriate to the relevant month. The result is padded
  823. to the width of `calendar-month-digit-width'.
  824. For examples of three common styles, see `calendar-american-month-header',
  825. `calendar-european-month-header', and `calendar-iso-month-header'.
  826. Changing this variable without using customize has no effect on
  827. pre-existing calendar windows."
  828. :group 'calendar
  829. :initialize 'custom-initialize-default
  830. :risky t
  831. :set (lambda (sym val)
  832. (set sym val)
  833. (calendar-redraw))
  834. :set-after '(calendar-date-style calendar-american-month-header
  835. calendar-european-month-header
  836. calendar-iso-month-header)
  837. :type 'sexp
  838. :version "24.3")
  839. (defun calendar-set-date-style (style)
  840. "Set the style of calendar and diary dates to STYLE (a symbol).
  841. The valid styles are described in the documentation of `calendar-date-style'."
  842. (interactive (list (intern
  843. (completing-read "Date style: "
  844. '("american" "european" "iso") nil t
  845. nil nil "american"))))
  846. (or (memq style '(american european iso))
  847. (setq style 'american))
  848. (setq calendar-date-style style
  849. calendar-date-display-form
  850. (symbol-value (intern-soft
  851. (format "calendar-%s-date-display-form" style)))
  852. calendar-month-header
  853. (symbol-value (intern-soft (format "calendar-%s-month-header" style)))
  854. diary-date-forms
  855. (symbol-value (intern-soft (format "diary-%s-date-forms" style))))
  856. (calendar-redraw)
  857. (calendar-update-mode-line))
  858. (defcustom diary-show-holidays-flag t
  859. "Non-nil means include holidays in the diary display.
  860. The holidays appear in the mode line of the diary buffer, or in the
  861. fancy diary buffer next to the date. This slows down the diary functions
  862. somewhat; setting it to nil makes the diary display faster."
  863. :type 'boolean
  864. :group 'holidays)
  865. (defcustom calendar-debug-sexp nil
  866. "Turn debugging on when evaluating a sexp in the diary or holiday list."
  867. :type 'boolean
  868. :group 'calendar)
  869. (defcustom calendar-hebrew-all-holidays-flag nil
  870. "If nil, show only major holidays from the Hebrew calendar.
  871. This means only those Jewish holidays that appear on secular calendars.
  872. Otherwise, show all the holidays that would appear in a complete Hebrew
  873. calendar."
  874. :type 'boolean
  875. :group 'holidays)
  876. (defcustom calendar-christian-all-holidays-flag nil
  877. "If nil, show only major holidays from the Christian calendar.
  878. This means only those Christian holidays that appear on secular calendars.
  879. Otherwise, show all the holidays that would appear in a complete Christian
  880. calendar."
  881. :type 'boolean
  882. :group 'holidays)
  883. (defcustom calendar-islamic-all-holidays-flag nil
  884. "If nil, show only major holidays from the Islamic calendar.
  885. This means only those Islamic holidays that appear on secular calendars.
  886. Otherwise, show all the holidays that would appear in a complete Islamic
  887. calendar."
  888. :type 'boolean
  889. :group 'holidays)
  890. (defcustom calendar-bahai-all-holidays-flag nil
  891. "If nil, show only major holidays from the Bahá’í calendar.
  892. These are the days on which work and school must be suspended.
  893. Otherwise, show all the holidays that would appear in a complete Bahá’í
  894. calendar."
  895. :type 'boolean
  896. :group 'holidays)
  897. (defcustom calendar-chinese-all-holidays-flag nil
  898. "If nil, show only the major holidays from the Chinese calendar."
  899. :version "23.1"
  900. :type 'boolean
  901. :group 'holidays)
  902. ;;; End of user options.
  903. (calendar-recompute-layout-variables)
  904. (defconst calendar-first-date-row 3
  905. "First row in the calendar with actual dates.")
  906. (defconst calendar-buffer "*Calendar*"
  907. "Name of the buffer used for the calendar.")
  908. (defconst holiday-buffer "*Holidays*"
  909. "Name of the buffer used for the displaying the holidays.")
  910. (defconst diary-fancy-buffer "*Fancy Diary Entries*"
  911. "Name of the buffer used for the optional fancy display of the diary.")
  912. (defconst calendar-other-calendars-buffer "*Other Calendars*"
  913. "Name of the buffer used for the display of date on other calendars.")
  914. (defconst lunar-phases-buffer "*Phases of Moon*"
  915. "Name of the buffer used for the lunar phases.")
  916. (defconst solar-sunrises-buffer "*Sunrise/Sunset Times*"
  917. "Name of buffer used for sunrise/sunset times.")
  918. (defconst calendar-hebrew-yahrzeit-buffer "*Yahrzeits*"
  919. "Name of the buffer used by `list-yahrzeit-dates'.")
  920. (defmacro calendar-increment-month (mon yr n &optional nmonths)
  921. "Increment the variables MON and YR by N months.
  922. Forward if N is positive or backward if N is negative.
  923. A negative YR is interpreted as BC; -1 being 1 BC, and so on.
  924. Optional NMONTHS is the number of months per year (default 12)."
  925. ;; Can view this as a form of base-nmonths arithmetic, in which "a
  926. ;; year" = "ten", and we never bother to use hundreds.
  927. `(let ((nmonths (or ,nmonths 12))
  928. macro-y)
  929. (if (< ,yr 0) (setq ,yr (1+ ,yr))) ; -1 BC -> 0 AD, etc
  930. (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
  931. ,mon (1+ (mod macro-y nmonths))
  932. ,yr (/ macro-y nmonths))
  933. ;; Alternative:
  934. ;;; (setq macro-y (+ (* ,yr nmonths) ,mon -1 ,n)
  935. ;;; ,yr (/ macro-y nmonths)
  936. ;;; ,mon (- macro-y (* ,yr nmonths)))
  937. (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr)))
  938. (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc
  939. (defvar displayed-month)
  940. (defvar displayed-year)
  941. (defun calendar-increment-month-cons (n &optional mon yr)
  942. "Return the Nth month after MON/YR.
  943. The return value is a pair (MONTH . YEAR).
  944. MON defaults to `displayed-month'. YR defaults to `displayed-year'."
  945. (unless mon (setq mon displayed-month))
  946. (unless yr (setq yr displayed-year))
  947. (calendar-increment-month mon yr n)
  948. (cons mon yr))
  949. (defmacro calendar-sum (index initial condition expression)
  950. "For INDEX = INITIAL, +1, ... (as long as CONDITION holds), sum EXPRESSION."
  951. (declare (debug (symbolp form form form)))
  952. `(let ((,index ,initial)
  953. (sum 0))
  954. (while ,condition
  955. (setq sum (+ sum ,expression)
  956. ,index (1+ ,index)))
  957. sum))
  958. (defmacro calendar-in-read-only-buffer (buffer &rest body)
  959. "Switch to BUFFER and execute the forms in BODY.
  960. First creates or erases BUFFER as needed. Leaves BUFFER read-only,
  961. with disabled undo. Leaves point at point-min, displays BUFFER."
  962. (declare (indent 1) (debug t))
  963. `(progn
  964. (set-buffer (get-buffer-create ,buffer))
  965. (or (derived-mode-p 'special-mode) (special-mode))
  966. (setq buffer-read-only nil
  967. buffer-undo-list t)
  968. (erase-buffer)
  969. (display-buffer ,buffer)
  970. ,@body
  971. (goto-char (point-min))
  972. (set-buffer-modified-p nil)
  973. (setq buffer-read-only t)))
  974. ;; The following are in-line for speed; they can be called thousands of times
  975. ;; when looking up holidays or processing the diary. Here, for example, are
  976. ;; the numbers of calls to calendar/diary/holiday functions in preparing the
  977. ;; fancy diary display, for a moderately complex diary file, with functions
  978. ;; used instead of macros. There were a total of 10000 such calls:
  979. ;;
  980. ;; 1934 calendar-extract-month
  981. ;; 1852 calendar-extract-year
  982. ;; 1819 calendar-extract-day
  983. ;; 845 calendar-leap-year-p
  984. ;; 837 calendar-day-number
  985. ;; 775 calendar-absolute-from-gregorian
  986. ;; 346 calendar-last-day-of-month
  987. ;; 286 calendar-hebrew-last-day-of-month
  988. ;; 188 calendar-hebrew-leap-year-p
  989. ;; 180 calendar-hebrew-elapsed-days
  990. ;; 163 calendar-hebrew-last-month-of-year
  991. ;; 66 calendar-date-compare
  992. ;; 65 calendar-hebrew-days-in-year
  993. ;; 60 calendar-julian-to-absolute
  994. ;; 50 calendar-hebrew-to-absolute
  995. ;; 43 calendar-date-equal
  996. ;; 38 calendar-gregorian-from-absolute
  997. ;; .
  998. ;;
  999. ;; The use of these seven macros eliminates the overhead of 92% of the function
  1000. ;; calls; it's faster this way.
  1001. (defsubst calendar-extract-month (date)
  1002. "Extract the month part of DATE which has the form (month day year)."
  1003. (car date))
  1004. ;; Note gives wrong answer for result of (calendar-read-date 'noday),
  1005. ;; but that is only used by `calendar-other-month'.
  1006. (defsubst calendar-extract-day (date)
  1007. "Extract the day part of DATE which has the form (month day year)."
  1008. (cadr date))
  1009. (defsubst calendar-extract-year (date)
  1010. "Extract the year part of DATE which has the form (month day year)."
  1011. (nth 2 date))
  1012. (defsubst calendar-leap-year-p (year)
  1013. "Return t if YEAR is a Gregorian leap year.
  1014. A negative year is interpreted as BC; -1 being 1 BC, and so on."
  1015. ;; 1 BC = 0 AD, 2 BC acts like 1 AD, etc.
  1016. (if (< year 0) (setq year (1- (abs year))))
  1017. (and (zerop (% year 4))
  1018. (or (not (zerop (% year 100)))
  1019. (zerop (% year 400)))))
  1020. ;; The foregoing is a bit faster, but not as clear as the following:
  1021. ;;
  1022. ;;(defsubst calendar-leap-year-p (year)
  1023. ;; "Return t if YEAR is a Gregorian leap year."
  1024. ;; (or
  1025. ;; (and (zerop (% year 4))
  1026. ;; (not (zerop (% year 100))))
  1027. ;; (zerop (% year 400)))
  1028. (defsubst calendar-last-day-of-month (month year)
  1029. "The last day in MONTH during YEAR."
  1030. (if (and (= month 2) (calendar-leap-year-p year))
  1031. 29
  1032. (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
  1033. ;; An explanation of the calculation can be found in PascAlgorithms by
  1034. ;; Edward and Ruth Reingold, Scott-Foresman/Little, Brown, 1988.
  1035. (defsubst calendar-day-number (date)
  1036. "Return the day number within the year of the date DATE.
  1037. For example, (calendar-day-number \\='(1 1 1987)) returns the value 1,
  1038. while (calendar-day-number \\='(12 31 1980)) returns 366."
  1039. (let* ((month (calendar-extract-month date))
  1040. (day (calendar-extract-day date))
  1041. (year (calendar-extract-year date))
  1042. (day-of-year (+ day (* 31 (1- month)))))
  1043. (when (> month 2)
  1044. (setq day-of-year (- day-of-year (/ (+ 23 (* 4 month)) 10)))
  1045. (if (calendar-leap-year-p year)
  1046. (setq day-of-year (1+ day-of-year))))
  1047. day-of-year))
  1048. (defsubst calendar-absolute-from-gregorian (date)
  1049. "The number of days elapsed between the Gregorian date 12/31/1 BC and DATE.
  1050. The Gregorian date Sunday, December 31, 1 BC is imaginary.
  1051. DATE is a list of the form (month day year). A negative year is
  1052. interpreted as BC; -1 being 1 BC, and so on. Dates before 12/31/1 BC
  1053. return negative results."
  1054. (let ((year (calendar-extract-year date))
  1055. offset-years)
  1056. (cond ((zerop year)
  1057. (user-error "There was no year zero"))
  1058. ((> year 0)
  1059. (setq offset-years (1- year))
  1060. (+ (calendar-day-number date) ; days this year
  1061. (* 365 offset-years) ; + days in prior years
  1062. (/ offset-years 4) ; + Julian leap years
  1063. (- (/ offset-years 100)) ; - century years
  1064. (/ offset-years 400))) ; + Gregorian leap years
  1065. (t
  1066. ;; Years between date and 1 BC, excluding 1 BC (1 for 2 BC, etc).
  1067. (setq offset-years (abs (1+ year)))
  1068. (- (calendar-day-number date)
  1069. (* 365 offset-years)
  1070. (/ offset-years 4)
  1071. (- (/ offset-years 100))
  1072. (/ offset-years 400)
  1073. (calendar-day-number '(12 31 -1))))))) ; days in year 1 BC
  1074. ;;;###autoload
  1075. (defun calendar (&optional arg)
  1076. "Display a three-month Gregorian calendar.
  1077. The three months appear side by side, with the current month in
  1078. the middle surrounded by the previous and next months. The
  1079. cursor is put on today's date. If optional prefix argument ARG
  1080. is non-nil, prompts for the central month and year.
  1081. Once in the calendar window, future or past months can be moved
  1082. into view. Arbitrary months can be displayed, or the calendar
  1083. can be scrolled forward or backward. The cursor can be moved
  1084. forward or backward by one day, one week, one month, or one year.
  1085. All of these commands take prefix arguments which, when negative,
  1086. cause movement in the opposite direction. For convenience, the
  1087. digit keys and the minus sign are automatically prefixes. Use
  1088. \\[describe-mode] for details of the key bindings in the calendar
  1089. window.
  1090. Displays the calendar in a separate window, or optionally in a
  1091. separate frame, depending on the value of `calendar-setup'.
  1092. If `calendar-view-diary-initially-flag' is non-nil, also displays the
  1093. diary entries for the current date (or however many days
  1094. `diary-number-of-entries' specifies). This variable can be
  1095. overridden by `calendar-setup'. As well as being displayed,
  1096. diary entries can also be marked on the calendar (see
  1097. `calendar-mark-diary-entries-flag').
  1098. Runs the following hooks:
  1099. `calendar-load-hook' - after loading calendar.el
  1100. `calendar-today-visible-hook', `calendar-today-invisible-hook' - after
  1101. generating a calendar, if today's date is visible or not, respectively
  1102. `calendar-initial-window-hook' - after first creating a calendar
  1103. This function is suitable for execution in an init file."
  1104. (interactive "P")
  1105. ;; Avoid loading cal-x unless it will be used.
  1106. (if (and (memq calendar-setup '(one-frame two-frames calendar-only))
  1107. (display-multi-frame-p))
  1108. (calendar-frame-setup calendar-setup arg)
  1109. (calendar-basic-setup arg)))
  1110. (defun calendar-basic-setup (&optional arg nodisplay)
  1111. "Create a three-month calendar.
  1112. If optional prefix argument ARG is non-nil, prompts for the month
  1113. and year, else uses the current date. If NODISPLAY is non-nil, don't
  1114. display the generated calendar."
  1115. (interactive "P")
  1116. (let ((buff (current-buffer)))
  1117. (set-buffer (get-buffer-create calendar-buffer))
  1118. (calendar-mode)
  1119. (let* ((pop-up-windows t)
  1120. ;; Not really needed now, but means we use exactly the same
  1121. ;; behavior as before in the non-wide case (see below).
  1122. (split-height-threshold 1000)
  1123. (split-width-threshold calendar-split-width-threshold)
  1124. (date (if arg (calendar-read-date t)
  1125. (calendar-current-date)))
  1126. (month (calendar-extract-month date))
  1127. (year (calendar-extract-year date)))
  1128. (calendar-increment-month month year (- calendar-offset))
  1129. ;; Display the buffer before calling calendar-generate-window so that it
  1130. ;; can get a chance to adjust the window sizes to the frame size.
  1131. (unless nodisplay
  1132. ;; We want a window configuration that looks something like
  1133. ;; X X | Y
  1134. ;; - -----
  1135. ;; C Z | C
  1136. ;; where C is the calendar, and the LHS is the traditional,
  1137. ;; non-wide frame, and the RHS is the wide frame case.
  1138. ;; We should end up in the same state regardless of whether the
  1139. ;; windows were initially split or not.
  1140. ;; Previously, we only thought about the non-wide case.
  1141. ;; We could just set split-height-threshold to 1000, relying on
  1142. ;; the fact that the window splitting treated a single window as
  1143. ;; a special case and would always split it (vertically). The
  1144. ;; same thing does not work in the wide-frame case, so now we do
  1145. ;; the splitting by hand.
  1146. ;; See discussion in bug#1806.
  1147. ;; Actually, this still does not do quite the right thing in the
  1148. ;; wide frame case if started from a configuration like the LHS.
  1149. ;; Eg if you start with a non-wide frame, call calendar, then
  1150. ;; make the frame wider. This one is problematic because you
  1151. ;; might need to split a totally unrelated window. Oh well, it
  1152. ;; seems unlikely, and perhaps respecting the original layout is
  1153. ;; the right thing in that case.
  1154. ;;
  1155. ;; Is this a wide frame? If so, split it horizontally.
  1156. ;; The following doesn't sound useful: If we split horizontally
  1157. ;; here, the subsequent `pop-to-buffer' will likely split again
  1158. ;; horizontally and we end up with three side-by-side windows.
  1159. (when (window-splittable-p (selected-window) t)
  1160. (split-window-right))
  1161. (pop-to-buffer calendar-buffer)
  1162. ;; Has the window already been split vertically?
  1163. (when (and (not (window-dedicated-p))
  1164. (window-splittable-p (selected-window))
  1165. (window-full-height-p))
  1166. (let ((win (split-window-below)))
  1167. ;; In the upper window, show whatever was visible before.
  1168. ;; This looks better than using other-buffer.
  1169. (switch-to-buffer buff)
  1170. ;; Switch to the lower window with the calendar buffer.
  1171. (select-window win))))
  1172. (calendar-generate-window month year)
  1173. (if (and calendar-view-diary-initially-flag
  1174. (calendar-date-is-visible-p date))
  1175. ;; Do not clobber the calendar with the diary, if the diary
  1176. ;; has previously been shown in the window that now shows the
  1177. ;; calendar (bug#18381).
  1178. (let ((display-buffer-overriding-action
  1179. '(nil . ((inhibit-same-window . t)))))
  1180. (diary-view-entries)))))
  1181. (if calendar-view-holidays-initially-flag
  1182. (let* ((diary-buffer (diary-live-p))
  1183. (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
  1184. (split-height-threshold (if diary-window 2 1000)))
  1185. ;; FIXME display buffer?
  1186. (calendar-list-holidays)))
  1187. (run-hooks 'calendar-initial-window-hook))
  1188. (defun calendar-generate-window (&optional mon yr)
  1189. "Generate the calendar window for the current date.
  1190. Optional integers MON and YR are used instead of today's date."
  1191. (let* ((inhibit-read-only t)
  1192. (today (calendar-current-date))
  1193. (month (calendar-extract-month today))
  1194. (day (calendar-extract-day today))
  1195. (year (calendar-extract-year today))
  1196. (today-visible (or (not mon)
  1197. (<= (abs (calendar-interval mon yr month year)) 1)))
  1198. (in-calendar-window (eq (window-buffer)
  1199. (get-buffer calendar-buffer))))
  1200. (calendar-generate (or mon month) (or yr year))
  1201. (calendar-update-mode-line)
  1202. (calendar-cursor-to-visible-date
  1203. (if today-visible today (list displayed-month 1 displayed-year)))
  1204. (set-buffer-modified-p nil)
  1205. ;; Don't do any window-related stuff if we weren't called from a
  1206. ;; window displaying the calendar.
  1207. (when in-calendar-window
  1208. (if (window-combined-p)
  1209. ;; Adjust the window to exactly fit the displayed calendar.
  1210. (fit-window-to-buffer nil nil calendar-minimum-window-height)
  1211. ;; For a full height window or a window that is horizontally
  1212. ;; combined don't fit height to that of its buffer.
  1213. (set-window-vscroll nil 0))
  1214. (sit-for 0))
  1215. (and calendar-mark-holidays-flag
  1216. ;; (calendar-date-is-valid-p today) ; useful for BC dates
  1217. (calendar-mark-holidays)
  1218. (and in-calendar-window (sit-for 0)))
  1219. (unwind-protect
  1220. (if calendar-mark-diary-entries-flag (diary-mark-entries))
  1221. (run-hooks (if today-visible
  1222. 'calendar-today-visible-hook
  1223. 'calendar-today-invisible-hook)))))
  1224. (defun calendar-generate (month year)
  1225. "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
  1226. ;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on.
  1227. ;; Note that while calendars for years BC could be displayed as it
  1228. ;; stands, almost all other calendar functions (eg holidays) would
  1229. ;; at best have unpredictable results for such dates.
  1230. (if (< (+ month (* 12 (1- year))) 2)
  1231. (user-error "Months before January, 1 AD cannot be displayed"))
  1232. (setq displayed-month month
  1233. displayed-year year)
  1234. (erase-buffer)
  1235. (calendar-increment-month month year -1)
  1236. (dotimes (i 3)
  1237. (calendar-generate-month month year
  1238. (+ calendar-left-margin
  1239. (* calendar-month-width i)))
  1240. (calendar-increment-month month year 1)))
  1241. (defun calendar-move-to-column (indent)
  1242. "Like `move-to-column', but indents if the line is too short."
  1243. (if (< (move-to-column indent) indent)
  1244. (indent-to indent)))
  1245. (defun calendar-ensure-newline ()
  1246. "Move to the next line, adding a newline if necessary."
  1247. (or (zerop (forward-line 1))
  1248. (insert "\n")))
  1249. (defun calendar-insert-at-column (indent string truncate)
  1250. "Move to column INDENT, adding spaces as needed.
  1251. Inserts STRING so that it ends at INDENT. STRING is either a
  1252. literal string, or a sexp to evaluate to return such. Truncates
  1253. STRING to length TRUNCATE, and ensures a trailing space."
  1254. (if (not (ignore-errors (stringp (setq string (eval string)))))
  1255. (calendar-move-to-column indent)
  1256. (if (> (string-width string) truncate)
  1257. (setq string (truncate-string-to-width string truncate)))
  1258. (or (string-match " $" string)
  1259. (setq string (concat (if (= (string-width string) truncate)
  1260. (substring string 0 -1)
  1261. string)
  1262. ;; Avoid inserting text properties unless
  1263. ;; we have to (ie, non-unit-width chars).
  1264. ;; This is by no means essential.
  1265. (if (= (string-width string) (length string))
  1266. " "
  1267. ;; Cribbed from buff-menu.el.
  1268. (propertize
  1269. " " 'display `(space :align-to ,indent))))))
  1270. (calendar-move-to-column (- indent (string-width string)))
  1271. (insert string)))
  1272. (defun calendar-generate-month (month year indent)
  1273. "Produce a calendar for MONTH, YEAR on the Gregorian calendar.
  1274. The calendar is inserted at the top of the buffer in which point is currently
  1275. located, but indented INDENT spaces. The indentation is done from the first
  1276. character on the line and does not disturb the first INDENT characters on the
  1277. line."
  1278. (let ((blank-days ; at start of month
  1279. (mod
  1280. (- (calendar-day-of-week (list month 1 year))
  1281. calendar-week-start-day)
  1282. 7))
  1283. (last (calendar-last-day-of-month month year))
  1284. (trunc (min calendar-intermonth-spacing
  1285. (1- calendar-left-margin)))
  1286. (day 1)
  1287. j)
  1288. (goto-char (point-min))
  1289. (calendar-move-to-column indent)
  1290. (insert
  1291. (calendar-string-spread (list calendar-month-header)
  1292. ?\s calendar-month-digit-width))
  1293. (calendar-ensure-newline)
  1294. (calendar-insert-at-column indent calendar-intermonth-header trunc)
  1295. ;; Use the first N characters of each day to head the columns.
  1296. (dotimes (i 7)
  1297. (setq j (mod (+ calendar-week-start-day i) 7))
  1298. (insert
  1299. (truncate-string-to-width
  1300. (propertize (calendar-day-name j 'header t)
  1301. 'font-lock-face (if (memq j calendar-weekend-days)
  1302. 'calendar-weekend-header
  1303. 'calendar-weekday-header))
  1304. calendar-day-header-width nil ?\s)
  1305. (make-string (- calendar-column-width calendar-day-header-width) ?\s)))
  1306. (calendar-ensure-newline)
  1307. (calendar-insert-at-column indent calendar-intermonth-text trunc)
  1308. ;; Add blank days before the first of the month.
  1309. (insert (make-string (* blank-days calendar-column-width) ?\s))
  1310. ;; Put in the days of the month.
  1311. (dotimes (i last)
  1312. (setq day (1+ i))
  1313. ;; TODO should numbers be left-justified, centered...?
  1314. (insert (propertize
  1315. (format (format "%%%dd" calendar-day-digit-width) day)
  1316. 'mouse-face 'highlight
  1317. 'help-echo (eval calendar-date-echo-text)
  1318. ;; 'date property prevents intermonth text confusing re-searches.
  1319. ;; (Tried intangible, it did not really work.)
  1320. 'date t)
  1321. (make-string
  1322. (- calendar-column-width calendar-day-digit-width) ?\s))
  1323. (when (and (zerop (mod (+ day blank-days) 7))
  1324. (/= day last))
  1325. (calendar-ensure-newline)
  1326. (setq day (1+ day)) ; first day of next week
  1327. (calendar-insert-at-column indent calendar-intermonth-text trunc)))))
  1328. (defun calendar-redraw ()
  1329. "Redraw the calendar display, if `calendar-buffer' is live."
  1330. (interactive)
  1331. (when (get-buffer calendar-buffer)
  1332. (with-current-buffer calendar-buffer
  1333. (let ((cursor-date (calendar-cursor-to-nearest-date)))
  1334. (calendar-generate-window displayed-month displayed-year)
  1335. (calendar-cursor-to-visible-date cursor-date))
  1336. (when (window-live-p (get-buffer-window))
  1337. (set-window-point (get-buffer-window) (point))))))
  1338. (defvar calendar-mode-map
  1339. (let ((map (make-keymap)))
  1340. (suppress-keymap map)
  1341. (dolist (c '(narrow-to-region mark-word mark-sexp mark-paragraph
  1342. mark-defun mark-whole-buffer mark-page
  1343. downcase-region upcase-region kill-region
  1344. copy-region-as-kill capitalize-region write-region))
  1345. (define-key map (vector 'remap c) 'calendar-not-implemented))
  1346. (define-key map "<" 'calendar-scroll-right)
  1347. (define-key map "\C-x<" 'calendar-scroll-right)
  1348. (define-key map [prior] 'calendar-scroll-right-three-months)
  1349. (define-key map "\ev" 'calendar-scroll-right-three-months)
  1350. (define-key map ">" 'calendar-scroll-left)
  1351. (define-key map "\C-x>" 'calendar-scroll-left)
  1352. (define-key map [next] 'calendar-scroll-left-three-months)
  1353. (define-key map "\C-v" 'calendar-scroll-left-three-months)
  1354. (define-key map "\C-b" 'calendar-backward-day)
  1355. (define-key map "\C-p" 'calendar-backward-week)
  1356. (define-key map "\e{" 'calendar-backward-month)
  1357. (define-key map "\C-x[" 'calendar-backward-year)
  1358. (define-key map "\C-f" 'calendar-forward-day)
  1359. (define-key map "\C-n" 'calendar-forward-week)
  1360. (define-key map [left] 'calendar-backward-day)
  1361. (define-key map [up] 'calendar-backward-week)
  1362. (define-key map [right] 'calendar-forward-day)
  1363. (define-key map [down] 'calendar-forward-week)
  1364. (define-key map "\e}" 'calendar-forward-month)
  1365. (define-key map "\C-x]" 'calendar-forward-year)
  1366. (define-key map "\C-a" 'calendar-beginning-of-week)
  1367. (define-key map "\C-e" 'calendar-end-of-week)
  1368. (define-key map "\ea" 'calendar-beginning-of-month)
  1369. (define-key map "\ee" 'calendar-end-of-month)
  1370. (define-key map "\e<" 'calendar-beginning-of-year)
  1371. (define-key map "\e>" 'calendar-end-of-year)
  1372. (define-key map "\C-@" 'calendar-set-mark)
  1373. ;; Many people are used to typing C-SPC and getting C-@.
  1374. (define-key map [?\C-\s] 'calendar-set-mark)
  1375. (define-key map "\C-x\C-x" 'calendar-exchange-point-and-mark)
  1376. (define-key map "\e=" 'calendar-count-days-region)
  1377. (define-key map "gd" 'calendar-goto-date)
  1378. (define-key map "gD" 'calendar-goto-day-of-year)
  1379. (define-key map "gj" 'calendar-julian-goto-date)
  1380. (define-key map "ga" 'calendar-astro-goto-day-number)
  1381. (define-key map "gh" 'calendar-hebrew-goto-date)
  1382. (define-key map "gi" 'calendar-islamic-goto-date)
  1383. (define-key map "gb" 'calendar-bahai-goto-date)
  1384. (define-key map "gC" 'calendar-chinese-goto-date)
  1385. (define-key map "gk" 'calendar-coptic-goto-date)
  1386. (define-key map "ge" 'calendar-ethiopic-goto-date)
  1387. (define-key map "gp" 'calendar-persian-goto-date)
  1388. (define-key map "gc" 'calendar-iso-goto-date)
  1389. (define-key map "gw" 'calendar-iso-goto-week)
  1390. (define-key map "gf" 'calendar-french-goto-date)
  1391. (define-key map "gml" 'calendar-mayan-goto-long-count-date)
  1392. (define-key map "gmpc" 'calendar-mayan-previous-round-date)
  1393. (define-key map "gmnc" 'calendar-mayan-next-round-date)
  1394. (define-key map "gmph" 'calendar-mayan-previous-haab-date)
  1395. (define-key map "gmnh" 'calendar-mayan-next-haab-date)
  1396. (define-key map "gmpt" 'calendar-mayan-previous-tzolkin-date)
  1397. (define-key map "gmnt" 'calendar-mayan-next-tzolkin-date)
  1398. (define-key map "Aa" 'appt-add)
  1399. (define-key map "Ad" 'appt-delete)
  1400. (define-key map "S" 'calendar-sunrise-sunset)
  1401. (define-key map "M" 'calendar-lunar-phases)
  1402. (define-key map " " 'scroll-other-window)
  1403. (define-key map [?\S-\ ] 'scroll-other-window-down)
  1404. (define-key map "\d" 'scroll-other-window-down)
  1405. (define-key map "\C-c\C-l" 'calendar-redraw)
  1406. (define-key map "." 'calendar-goto-today)
  1407. (define-key map "o" 'calendar-other-month)
  1408. (define-key map "q" 'calendar-exit)
  1409. (define-key map "a" 'calendar-list-holidays)
  1410. (define-key map "h" 'calendar-cursor-holidays)
  1411. (define-key map "x" 'calendar-mark-holidays)
  1412. (define-key map "u" 'calendar-unmark)
  1413. (define-key map "m" 'diary-mark-entries)
  1414. (define-key map "d" 'diary-view-entries)
  1415. (define-key map "D" 'diary-view-other-diary-entries)
  1416. (define-key map "s" 'diary-show-all-entries)
  1417. (define-key map "pd" 'calendar-print-day-of-year)
  1418. (define-key map "pC" 'calendar-chinese-print-date)
  1419. (define-key map "pk" 'calendar-coptic-print-date)
  1420. (define-key map "pe" 'calendar-ethiopic-print-date)
  1421. (define-key map "pp" 'calendar-persian-print-date)
  1422. (define-key map "pc" 'calendar-iso-print-date)
  1423. (define-key map "pj" 'calendar-julian-print-date)
  1424. (define-key map "pa" 'calendar-astro-print-day-number)
  1425. (define-key map "ph" 'calendar-hebrew-print-date)
  1426. (define-key map "pi" 'calendar-islamic-print-date)
  1427. (define-key map "pb" 'calendar-bahai-print-date)
  1428. (define-key map "pf" 'calendar-french-print-date)
  1429. (define-key map "pm" 'calendar-mayan-print-date)
  1430. (define-key map "po" 'calendar-print-other-dates)
  1431. (define-key map "id" 'diary-insert-entry)
  1432. (define-key map "iw" 'diary-insert-weekly-entry)
  1433. (define-key map "im" 'diary-insert-monthly-entry)
  1434. (define-key map "iy" 'diary-insert-yearly-entry)
  1435. (define-key map "ia" 'diary-insert-anniversary-entry)
  1436. (define-key map "ib" 'diary-insert-block-entry)
  1437. (define-key map "ic" 'diary-insert-cyclic-entry)
  1438. (define-key map "ihd" 'diary-hebrew-insert-entry)
  1439. (define-key map "ihm" 'diary-hebrew-insert-monthly-entry)
  1440. (define-key map "ihy" 'diary-hebrew-insert-yearly-entry)
  1441. (define-key map "iid" 'diary-islamic-insert-entry)
  1442. (define-key map "iim" 'diary-islamic-insert-monthly-entry)
  1443. (define-key map "iiy" 'diary-islamic-insert-yearly-entry)
  1444. (define-key map "iBd" 'diary-bahai-insert-entry)
  1445. (define-key map "iBm" 'diary-bahai-insert-monthly-entry)
  1446. (define-key map "iBy" 'diary-bahai-insert-yearly-entry)
  1447. (define-key map "iCd" 'diary-chinese-insert-entry)
  1448. (define-key map "iCm" 'diary-chinese-insert-monthly-entry)
  1449. (define-key map "iCy" 'diary-chinese-insert-yearly-entry)
  1450. (define-key map "iCa" 'diary-chinese-insert-anniversary-entry)
  1451. (define-key map "?" 'calendar-goto-info-node)
  1452. (define-key map "Hm" 'cal-html-cursor-month)
  1453. (define-key map "Hy" 'cal-html-cursor-year)
  1454. (define-key map "tm" 'cal-tex-cursor-month)
  1455. (define-key map "tM" 'cal-tex-cursor-month-landscape)
  1456. (define-key map "td" 'cal-tex-cursor-day)
  1457. (define-key map "tw1" 'cal-tex-cursor-week)
  1458. (define-key map "tw2" 'cal-tex-cursor-week2)
  1459. (define-key map "tw3" 'cal-tex-cursor-week-iso) ; FIXME twi ?
  1460. (define-key map "tw4" 'cal-tex-cursor-week-monday) ; twm ?
  1461. (define-key map "twW" 'cal-tex-cursor-week2-summary)
  1462. (define-key map "tfd" 'cal-tex-cursor-filofax-daily)
  1463. (define-key map "tfw" 'cal-tex-cursor-filofax-2week)
  1464. (define-key map "tfW" 'cal-tex-cursor-filofax-week)
  1465. (define-key map "tfy" 'cal-tex-cursor-filofax-year)
  1466. (define-key map "ty" 'cal-tex-cursor-year)
  1467. (define-key map "tY" 'cal-tex-cursor-year-landscape)
  1468. (define-key map [menu-bar edit] 'undefined)
  1469. (define-key map [menu-bar search] 'undefined)
  1470. (easy-menu-define nil map nil cal-menu-sunmoon-menu)
  1471. (easy-menu-define nil map nil cal-menu-diary-menu)
  1472. (easy-menu-define nil map nil cal-menu-holidays-menu)
  1473. (easy-menu-define nil map nil cal-menu-goto-menu)
  1474. (easy-menu-define nil map nil cal-menu-scroll-menu)
  1475. ;; These are referenced in the default calendar-date-echo-text.
  1476. (define-key map [down-mouse-3]
  1477. (easy-menu-binding cal-menu-context-mouse-menu))
  1478. (define-key map [down-mouse-2]
  1479. (easy-menu-binding cal-menu-global-mouse-menu))
  1480. ;; cf scroll-bar.el.
  1481. (if (and (boundp 'x-toolkit-scroll-bars) x-toolkit-scroll-bars)
  1482. (define-key map [vertical-scroll-bar mouse-1]
  1483. 'calendar-scroll-toolkit-scroll)
  1484. ;; Left-click moves us forward in time, right-click backwards.
  1485. (define-key map [vertical-scroll-bar mouse-1] 'calendar-scroll-left)
  1486. (define-key map [vertical-scroll-bar drag-mouse-1] 'calendar-scroll-left)
  1487. ;; down-mouse-2 stays as scroll-bar-drag.
  1488. (define-key map [vertical-scroll-bar mouse-3] 'calendar-scroll-right)
  1489. (define-key map [vertical-scroll-bar drag-mouse-3]
  1490. 'calendar-scroll-right))
  1491. map)
  1492. "Keymap for `calendar-mode'.")
  1493. ;; Calendar mode is suitable only for specially formatted data.
  1494. (put 'calendar-mode 'mode-class 'special)
  1495. (defun calendar-mode-line-entry (command echo &optional key string)
  1496. "Return a propertized string for `calendar-mode-line-format'.
  1497. COMMAND is a command to run, ECHO is the help-echo text, KEY
  1498. is COMMAND's keybinding, STRING describes the binding."
  1499. (propertize (or key
  1500. (substitute-command-keys
  1501. (format "\\<calendar-mode-map>\\[%s] %s" command string)))
  1502. 'help-echo (format "mouse-1: %s" echo)
  1503. 'mouse-face 'mode-line-highlight
  1504. 'keymap (make-mode-line-mouse-map 'mouse-1 command)))
  1505. ;; After calendar-mode-map.
  1506. (defcustom calendar-mode-line-format
  1507. (list
  1508. (calendar-mode-line-entry 'calendar-scroll-right "previous month" "<")
  1509. "Calendar"
  1510. (concat
  1511. (calendar-mode-line-entry 'calendar-goto-info-node "read Info on Calendar"
  1512. nil "info")
  1513. " / "
  1514. (calendar-mode-line-entry 'calendar-other-month "choose another month"
  1515. nil "other")
  1516. " / "
  1517. (calendar-mode-line-entry 'calendar-goto-today "go to today's date"
  1518. nil "today"))
  1519. '(calendar-date-string (calendar-current-date) t)
  1520. (calendar-mode-line-entry 'calendar-scroll-left "next month" ">"))
  1521. "If non-nil, the mode line of the calendar buffer.
  1522. This is a list of items that evaluate to strings. The elements
  1523. are evaluated and concatenated, evenly separated by blanks.
  1524. During evaluation, the variable `date' is available as the date
  1525. nearest the cursor (or today's date if that fails). To update
  1526. the mode-line as the cursor moves, add
  1527. `calendar-update-mode-line' to `calendar-move-hook'.
  1528. If nil, do not modify the mode line at all.
  1529. Here is an example that has the Hebrew date, the day number/days
  1530. remaining in the year, and the ISO week/year numbers:
  1531. (list
  1532. \"\"
  1533. \\='(calendar-hebrew-date-string date)
  1534. \\='(let* ((year (calendar-extract-year date))
  1535. (d (calendar-day-number date))
  1536. (days-remaining
  1537. (- (calendar-day-number (list 12 31 year)) d)))
  1538. (format \"%d/%d\" d days-remaining))
  1539. \\='(let* ((d (calendar-absolute-from-gregorian date))
  1540. (iso-date (calendar-iso-from-absolute d)))
  1541. (format \"ISO week %d of %d\"
  1542. (calendar-extract-month iso-date)
  1543. (calendar-extract-year iso-date)))
  1544. \"\"))"
  1545. :risky t
  1546. :type 'sexp
  1547. :group 'calendar)
  1548. (defun calendar-goto-info-node ()
  1549. "Go to the info node for the calendar."
  1550. (interactive)
  1551. (info "(emacs)Calendar/Diary")
  1552. (fit-window-to-buffer))
  1553. (defvar calendar-mark-ring nil
  1554. "Used by `calendar-set-mark'.")
  1555. (define-derived-mode calendar-mode nil "Calendar"
  1556. "A major mode for the calendar window.
  1557. For a complete description, see the info node `Calendar/Diary'.
  1558. \\<calendar-mode-map>\\{calendar-mode-map}"
  1559. (setq buffer-read-only t
  1560. buffer-undo-list t
  1561. indent-tabs-mode nil)
  1562. (set (make-local-variable 'scroll-margin) 0) ; bug#10379
  1563. (calendar-update-mode-line)
  1564. (make-local-variable 'calendar-mark-ring)
  1565. (make-local-variable 'displayed-month) ; month in middle of window
  1566. (make-local-variable 'displayed-year) ; year in middle of window
  1567. ;; Most functions only work if displayed-month and displayed-year are set,
  1568. ;; so let's make sure they're always set. Most likely, this will be reset
  1569. ;; soon in calendar-generate, but better safe than sorry.
  1570. (unless (boundp 'displayed-month) (setq displayed-month 1))
  1571. (unless (boundp 'displayed-year) (setq displayed-year 2001))
  1572. (if (bound-and-true-p calendar-font-lock-keywords)
  1573. (set (make-local-variable 'font-lock-defaults)
  1574. '(calendar-font-lock-keywords t))))
  1575. (defun calendar-string-spread (strings char length)
  1576. "Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH.
  1577. The effect is like mapconcat but the separating pieces are as balanced as
  1578. possible. Each item of STRINGS is evaluated before concatenation so it can
  1579. actually be an expression that evaluates to a string. If LENGTH is too short,
  1580. the STRINGS are just concatenated and the result truncated."
  1581. ;; The algorithm is based on equation (3.25) on page 85 of Concrete
  1582. ;; Mathematics by Ronald L. Graham, Donald E. Knuth, and Oren Patashnik,
  1583. ;; Addison-Wesley, Reading, MA, 1989.
  1584. (let* ((strings (mapcar 'eval
  1585. (if (< (length strings) 2)
  1586. (append (list "") strings (list ""))
  1587. strings)))
  1588. (n (- length (string-width (apply 'concat strings))))
  1589. (m (* (1- (length strings)) (char-width char)))
  1590. (s (car strings))
  1591. (strings (cdr strings))
  1592. (i 0))
  1593. (dolist (string strings)
  1594. (setq s (concat s
  1595. (make-string (max 0 (/ (+ n i) m)) char)
  1596. string)
  1597. i (1+ i)))
  1598. (truncate-string-to-width s length)))
  1599. (defun calendar-update-mode-line ()
  1600. "Update the calendar mode line with the current date and date style."
  1601. (if (and calendar-mode-line-format
  1602. (bufferp (get-buffer calendar-buffer)))
  1603. (with-current-buffer calendar-buffer
  1604. (let ((start (- calendar-left-margin 2))
  1605. (date (condition-case nil
  1606. (calendar-cursor-to-nearest-date)
  1607. (error (calendar-current-date)))))
  1608. (setq mode-line-format
  1609. (concat (make-string (max 0 (+ start
  1610. (- (car (window-inside-edges))
  1611. (car (window-edges))))) ?\s)
  1612. (calendar-string-spread
  1613. (mapcar 'eval calendar-mode-line-format)
  1614. ?\s (- calendar-right-margin (1- start))))))
  1615. (force-mode-line-update))))
  1616. (defun calendar-buffer-list ()
  1617. "List of all calendar-related buffers (as buffers, not strings)."
  1618. (let (buffs)
  1619. (dolist (b (list calendar-hebrew-yahrzeit-buffer lunar-phases-buffer
  1620. holiday-buffer diary-fancy-buffer solar-sunrises-buffer
  1621. (get-file-buffer diary-file)
  1622. calendar-buffer calendar-other-calendars-buffer))
  1623. (and b (setq b (get-buffer b))
  1624. (push b buffs)))
  1625. buffs))
  1626. (defun calendar-exit (&optional kill)
  1627. "Get out of the calendar window and hide it and related buffers."
  1628. (interactive "P")
  1629. (let ((diary-buffer (get-file-buffer diary-file))
  1630. (calendar-buffers (calendar-buffer-list)))
  1631. (when (or (not diary-buffer)
  1632. (not (buffer-modified-p diary-buffer))
  1633. (yes-or-no-p
  1634. "Diary modified; do you really want to exit the calendar? "))
  1635. (if (and calendar-setup (display-multi-frame-p))
  1636. ;; FIXME: replace this cruft with the `quit-restore' window property
  1637. (dolist (w (window-list-1 nil nil t))
  1638. (if (and (memq (window-buffer w) calendar-buffers)
  1639. (window-dedicated-p w))
  1640. (if (eq (window-deletable-p w) 'frame)
  1641. (if calendar-remove-frame-by-deleting
  1642. (delete-frame (window-frame w))
  1643. (iconify-frame (window-frame w)))
  1644. (quit-window kill w))))
  1645. (dolist (b calendar-buffers)
  1646. (quit-windows-on b kill))))))
  1647. (defun calendar-current-date (&optional offset)
  1648. "Return the current date in a list (month day year).
  1649. Optional integer OFFSET is a number of days from the current date."
  1650. (let* ((now (decode-time))
  1651. (now (list (nth 4 now) (nth 3 now) (nth 5 now))))
  1652. (if (zerop (or offset 0))
  1653. now
  1654. (calendar-gregorian-from-absolute
  1655. (+ offset (calendar-absolute-from-gregorian now))))))
  1656. (defun calendar-column-to-segment ()
  1657. "Convert current column to calendar month \"segment\".
  1658. The left-most month returns 0, the next right 1, and so on."
  1659. (let ((col (max 0 (+ (current-column)
  1660. (/ calendar-intermonth-spacing 2)
  1661. (- calendar-left-margin)))))
  1662. (/ col (+ (* 7 calendar-column-width) calendar-intermonth-spacing))))
  1663. (defun calendar-cursor-to-date (&optional error event)
  1664. "Return a list (month day year) of current cursor position.
  1665. If cursor is not on a specific date, signals an error if optional parameter
  1666. ERROR is non-nil, otherwise just returns nil.
  1667. If EVENT is non-nil, it's an event indicating the buffer position to
  1668. use instead of point."
  1669. (with-current-buffer
  1670. (if event (window-buffer (posn-window (event-start event)))
  1671. (current-buffer))
  1672. (save-excursion
  1673. (and event (setq event (event-start event))
  1674. (goto-char (posn-point event)))
  1675. (let* ((segment (calendar-column-to-segment))
  1676. (month (% (+ displayed-month (1- segment)) 12)))
  1677. ;; Call with point on either of the two digits in a 2-digit date,
  1678. ;; or on or before the digit of a 1-digit date.
  1679. (if (not (and (looking-at "[ 0-9]?[0-9][^0-9]")
  1680. (get-text-property (point) 'date)))
  1681. (if error (user-error "Not on a date!"))
  1682. ;; Convert segment to real month and year.
  1683. (if (zerop month) (setq month 12))
  1684. ;; Go back to before the first date digit.
  1685. (or (looking-at " ")
  1686. (re-search-backward "[^0-9]"))
  1687. (list month
  1688. (string-to-number
  1689. (buffer-substring (1+ (point))
  1690. (+ 1 calendar-day-digit-width (point))))
  1691. (cond
  1692. ((and (= 12 month) (zerop segment)) (1- displayed-year))
  1693. ((and (= 1 month) (= segment 2)) (1+ displayed-year))
  1694. (t displayed-year))))))))
  1695. ;; The following version of calendar-gregorian-from-absolute is preferred for
  1696. ;; reasons of clarity, BUT it's much slower than the version that follows it.
  1697. ;;(defun calendar-gregorian-from-absolute (date)
  1698. ;; "Compute the list (month day year) corresponding to the absolute DATE.
  1699. ;;The absolute date is the number of days elapsed since the (imaginary)
  1700. ;;Gregorian date Sunday, December 31, 1 BC."
  1701. ;; (let* ((approx (/ date 366)) ; approximation from below
  1702. ;; (year ; search forward from the approximation
  1703. ;; (+ approx
  1704. ;; (calendar-sum y approx
  1705. ;; (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y))))
  1706. ;; 1)))
  1707. ;; (month ; search forward from January
  1708. ;; (1+ (calendar-sum m 1
  1709. ;; (> date
  1710. ;; (calendar-absolute-from-gregorian
  1711. ;; (list m (calendar-last-day-of-month m year) year)))
  1712. ;; 1)))
  1713. ;; (day ; calculate the day by subtraction
  1714. ;; (- date
  1715. ;; (1- (calendar-absolute-from-gregorian (list month 1 year))))))
  1716. ;; (list month day year)))
  1717. (defun calendar-gregorian-from-absolute (date)
  1718. "Compute the list (month day year) corresponding to the absolute DATE.
  1719. The absolute date is the number of days elapsed since the (imaginary)
  1720. Gregorian date Sunday, December 31, 1 BC. This function does not
  1721. handle dates in years BC."
  1722. ;; See the footnote on page 384 of ``Calendrical Calculations, Part II:
  1723. ;; Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
  1724. ;; Clamen, Software--Practice and Experience, Volume 23, Number 4
  1725. ;; (April, 1993), pages 383-404 for an explanation.
  1726. (let* ((d0 (1- date))
  1727. (n400 (/ d0 146097))
  1728. (d1 (% d0 146097))
  1729. (n100 (/ d1 36524))
  1730. (d2 (% d1 36524))
  1731. (n4 (/ d2 1461))
  1732. (d3 (% d2 1461))
  1733. (n1 (/ d3 365))
  1734. (day (1+ (% d3 365)))
  1735. (year (+ (* 400 n400) (* 100 n100) (* n4 4) n1))
  1736. (month 1)
  1737. mdays)
  1738. (if (or (= n100 4) (= n1 4))
  1739. (list 12 31 year)
  1740. (setq year (1+ year))
  1741. (while (< (setq mdays (calendar-last-day-of-month month year)) day)
  1742. (setq day (- day mdays)
  1743. month (1+ month)))
  1744. (list month day year))))
  1745. (defun calendar-other-month (month year &optional event)
  1746. "Display a three-month calendar centered around MONTH and YEAR.
  1747. EVENT is an event like `last-nonmenu-event'."
  1748. (interactive (let ((event (list last-nonmenu-event)))
  1749. (append (calendar-read-date 'noday) event)))
  1750. (save-selected-window
  1751. (and event
  1752. (setq event (event-start event))
  1753. (select-window (posn-window event)))
  1754. (unless (and (= month displayed-month)
  1755. (= year displayed-year))
  1756. (let ((old-date (calendar-cursor-to-date))
  1757. (today (calendar-current-date)))
  1758. (calendar-generate-window month year)
  1759. (calendar-cursor-to-visible-date
  1760. (cond
  1761. ((calendar-date-is-visible-p old-date) old-date)
  1762. ((calendar-date-is-visible-p today) today)
  1763. (t (list month 1 year))))))))
  1764. (defun calendar-set-mark (arg &optional event)
  1765. "Mark the date under the cursor, or jump to marked date.
  1766. With no prefix argument, push current date onto marked date ring.
  1767. With argument ARG, jump to mark, pop it, and put point at end of ring."
  1768. (interactive
  1769. (list current-prefix-arg last-nonmenu-event))
  1770. (let ((date (calendar-cursor-to-date t event)))
  1771. (if arg
  1772. (if (null calendar-mark-ring)
  1773. (error "No mark set in this buffer")
  1774. (calendar-goto-date (car calendar-mark-ring))
  1775. (setq calendar-mark-ring
  1776. (cdr (nconc calendar-mark-ring (list date)))))
  1777. (push date calendar-mark-ring)
  1778. ;; Since the top of the mark ring is the marked date in the
  1779. ;; calendar, the mark ring in the calendar is one longer than
  1780. ;; in other buffers to get the same effect.
  1781. (if (> (length calendar-mark-ring) (1+ mark-ring-max))
  1782. (setcdr (nthcdr mark-ring-max calendar-mark-ring) nil))
  1783. (message "Mark set"))))
  1784. (defun calendar-exchange-point-and-mark ()
  1785. "Exchange the current cursor position with the marked date."
  1786. (interactive)
  1787. (let ((mark (car calendar-mark-ring))
  1788. (date (calendar-cursor-to-date t)))
  1789. (if (null mark)
  1790. (error "No mark set in this buffer")
  1791. (setq calendar-mark-ring (cons date (cdr calendar-mark-ring)))
  1792. (calendar-goto-date mark))))
  1793. (defun calendar-count-days-region ()
  1794. "Count the number of days (inclusive) between point and the mark."
  1795. (interactive)
  1796. (let* ((days (- (calendar-absolute-from-gregorian
  1797. (calendar-cursor-to-date t))
  1798. (calendar-absolute-from-gregorian
  1799. (or (car calendar-mark-ring)
  1800. (error "No mark set in this buffer")))))
  1801. (days (1+ (if (> days 0) days (- days)))))
  1802. (message "Region has %d day%s (inclusive)"
  1803. days (if (> days 1) "s" ""))))
  1804. (defun calendar-not-implemented ()
  1805. "Not implemented."
  1806. (interactive)
  1807. (error "%s not available in the calendar"
  1808. (global-key-binding (this-command-keys))))
  1809. (defun calendar-read (prompt acceptable &optional initial-contents)
  1810. "Return an object read from the minibuffer.
  1811. Prompt with the string PROMPT and use the function ACCEPTABLE to decide if
  1812. entered item is acceptable. If non-nil, optional third arg INITIAL-CONTENTS
  1813. is a string to insert in the minibuffer before reading."
  1814. (let ((value (read-minibuffer prompt initial-contents)))
  1815. (while (not (funcall acceptable value))
  1816. (setq value (read-minibuffer prompt initial-contents)))
  1817. value))
  1818. (defun calendar-customized-p (symbol)
  1819. "Return non-nil if SYMBOL has been customized."
  1820. (and (default-boundp symbol)
  1821. (let ((standard (get symbol 'standard-value)))
  1822. (and standard
  1823. (not (equal (eval (car standard)) (default-value symbol)))))))
  1824. (defun calendar-abbrev-construct (full &optional maxlen)
  1825. "From sequence FULL, return a vector of abbreviations.
  1826. Each abbreviation is no longer than MAXLEN (default `calendar-abbrev-length')
  1827. characters."
  1828. (or maxlen (setq maxlen calendar-abbrev-length))
  1829. (apply 'vector (mapcar
  1830. (lambda (f)
  1831. ;; TODO? truncate-string-to-width?
  1832. (substring f 0 (min maxlen (length f))))
  1833. full)))
  1834. (defcustom calendar-day-name-array
  1835. ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]
  1836. "Array of capitalized strings giving, in order from Sunday, the day names.
  1837. If you change this without using customize after the calendar has loaded,
  1838. then you may also want to change `calendar-day-abbrev-array'
  1839. and `calendar-day-header-array'."
  1840. :group 'calendar
  1841. :initialize 'custom-initialize-default
  1842. :set (lambda (symbol value)
  1843. (let ((dcustomized (calendar-customized-p 'calendar-day-abbrev-array))
  1844. (hcustomized (calendar-customized-p 'cal-html-day-abbrev-array))
  1845. (ccustomized (calendar-customized-p 'calendar-day-header-array)))
  1846. (set symbol value)
  1847. (or dcustomized
  1848. (setq calendar-day-abbrev-array
  1849. (calendar-abbrev-construct calendar-day-name-array)))
  1850. (and (not hcustomized)
  1851. (boundp 'cal-html-day-abbrev-array)
  1852. (setq cal-html-day-abbrev-array calendar-day-abbrev-array))
  1853. (or ccustomized
  1854. (equal calendar-day-header-array
  1855. (setq calendar-day-header-array
  1856. (calendar-day-header-construct)))
  1857. (calendar-redraw))))
  1858. :type '(vector (string :tag "Sunday")
  1859. (string :tag "Monday")
  1860. (string :tag "Tuesday")
  1861. (string :tag "Wednesday")
  1862. (string :tag "Thursday")
  1863. (string :tag "Friday")
  1864. (string :tag "Saturday")))
  1865. (defcustom calendar-abbrev-length 3
  1866. "Default length of abbreviations to use for day and month names.
  1867. If you change this without using customize after the calendar has loaded,
  1868. then you may also want to change `calendar-day-abbrev-array' and
  1869. `calendar-month-abbrev-array'."
  1870. :group 'calendar
  1871. :initialize 'custom-initialize-default
  1872. :set (lambda (symbol value)
  1873. (let ((dcustomized (calendar-customized-p 'calendar-day-abbrev-array))
  1874. (mcustomized (calendar-customized-p
  1875. 'calendar-month-abbrev-array))
  1876. (hcustomized (calendar-customized-p 'cal-html-day-abbrev-array))
  1877. (ccustomized (calendar-customized-p 'calendar-day-header-array)))
  1878. (set symbol value)
  1879. (or dcustomized
  1880. (setq calendar-day-abbrev-array
  1881. (calendar-abbrev-construct calendar-day-name-array)))
  1882. (or mcustomized
  1883. (setq calendar-month-abbrev-array
  1884. (calendar-abbrev-construct calendar-month-name-array)))
  1885. (and (not hcustomized)
  1886. (boundp 'cal-html-day-abbrev-array)
  1887. (setq cal-html-day-abbrev-array calendar-day-abbrev-array))
  1888. (or ccustomized
  1889. (equal calendar-day-header-array
  1890. (setq calendar-day-header-array
  1891. (calendar-day-header-construct)))
  1892. (calendar-redraw))))
  1893. :type 'integer)
  1894. (defcustom calendar-day-abbrev-array
  1895. (calendar-abbrev-construct calendar-day-name-array)
  1896. "Array of capitalized strings giving the abbreviated day names.
  1897. The order should be the same as that of the full names specified
  1898. in `calendar-day-name-array'. These abbreviations may be used
  1899. instead of the full names in the diary file. Do not include a
  1900. trailing `.' in the strings specified in this variable, though
  1901. you may use such in the diary file. By default, each string is
  1902. the first `calendar-abbrev-length' characters of the corresponding
  1903. full name."
  1904. :group 'calendar
  1905. :initialize 'custom-initialize-default
  1906. :set-after '(calendar-abbrev-length calendar-day-name-array)
  1907. :set (lambda (symbol value)
  1908. (let ((hcustomized (calendar-customized-p 'cal-html-day-abbrev-array))
  1909. (ccustomized (calendar-customized-p 'calendar-day-header-array)))
  1910. (set symbol value)
  1911. (and (not hcustomized)
  1912. (boundp 'cal-html-day-abbrev-array)
  1913. (setq cal-html-day-abbrev-array calendar-day-abbrev-array))
  1914. (or ccustomized
  1915. (equal calendar-day-header-array
  1916. (setq calendar-day-header-array
  1917. (calendar-day-header-construct)))
  1918. (calendar-redraw))))
  1919. :type '(vector (string :tag "Sun")
  1920. (string :tag "Mon")
  1921. (string :tag "Tue")
  1922. (string :tag "Wed")
  1923. (string :tag "Thu")
  1924. (string :tag "Fri")
  1925. (string :tag "Sat"))
  1926. ;; Made defcustom, changed defaults from nil nil...
  1927. :version "24.1")
  1928. (defcustom calendar-day-header-array (calendar-day-header-construct)
  1929. "Array of strings to use for the headers of the calendar's day columns.
  1930. The order should be the same as in `calendar-day-name-array'.
  1931. In use, the calendar truncates elements to no more than
  1932. `calendar-day-header-width' columns wide.
  1933. Emacs constructs the default from either `calendar-day-name-array'
  1934. \(if `calendar-day-header-width' is more than `calendar-abbrev-length'),
  1935. or from `calendar-day-abbrev-array' (assuming that the abbreviated
  1936. name are more likely to be unique when truncated)."
  1937. :group 'calendar
  1938. :initialize 'custom-initialize-default
  1939. :set-after '(calendar-day-header-width
  1940. calendar-abbrev-length calendar-day-name-array
  1941. calendar-day-abbrev-array)
  1942. :set (lambda (symbol value)
  1943. (or (equal calendar-day-header-array
  1944. (set symbol value))
  1945. (calendar-redraw)))
  1946. :type '(vector (string :tag "Su")
  1947. (string :tag "Mo")
  1948. (string :tag "Tu")
  1949. (string :tag "We")
  1950. (string :tag "Th")
  1951. (string :tag "Fr")
  1952. (string :tag "Sa"))
  1953. :version "24.4")
  1954. (defcustom calendar-month-name-array
  1955. ["January" "February" "March" "April" "May" "June"
  1956. "July" "August" "September" "October" "November" "December"]
  1957. "Array of capitalized strings giving, in order, the month names.
  1958. If you change this without using customize after the calendar has loaded,
  1959. then you may also want to change `calendar-month-abbrev-array'."
  1960. :group 'calendar
  1961. :initialize 'custom-initialize-default
  1962. :set (lambda (symbol value)
  1963. (let ((mcustomized (calendar-customized-p
  1964. 'calendar-month-abbrev-array)))
  1965. (set symbol value)
  1966. (or mcustomized
  1967. (setq calendar-month-abbrev-array
  1968. (calendar-abbrev-construct calendar-month-name-array)))))
  1969. :type '(vector (string :tag "January")
  1970. (string :tag "February")
  1971. (string :tag "March")
  1972. (string :tag "April")
  1973. (string :tag "May")
  1974. (string :tag "June")
  1975. (string :tag "July")
  1976. (string :tag "August")
  1977. (string :tag "September")
  1978. (string :tag "October")
  1979. (string :tag "November")
  1980. (string :tag "December")))
  1981. (defcustom calendar-month-abbrev-array
  1982. (calendar-abbrev-construct calendar-month-name-array)
  1983. "Array of capitalized strings giving the abbreviated month names.
  1984. The order should be the same as that of the full names specified
  1985. in `calendar-month-name-array'. These abbreviations are used in
  1986. the calendar menu entries, and can also be used in the diary
  1987. file. Do not include a trailing `.' in the strings specified in
  1988. this variable, though you may use such in the diary file. By
  1989. default, each string is the first `calendar-abbrev-length'
  1990. characters of the corresponding full name."
  1991. :group 'calendar
  1992. :set-after '(calendar-abbrev-length calendar-month-name-array)
  1993. :type '(vector (string :tag "Jan")
  1994. (string :tag "Feb")
  1995. (string :tag "Mar")
  1996. (string :tag "Apr")
  1997. (string :tag "May")
  1998. (string :tag "Jun")
  1999. (string :tag "Jul")
  2000. (string :tag "Aug")
  2001. (string :tag "Sep")
  2002. (string :tag "Oct")
  2003. (string :tag "Nov")
  2004. (string :tag "Dec"))
  2005. ;; Made defcustom, changed defaults from nil nil...
  2006. :version "24.1")
  2007. (defun calendar-make-alist (sequence &optional start-index filter
  2008. &rest sequences)
  2009. "Return an association list corresponding to SEQUENCE.
  2010. Associates each element of SEQUENCE with an incremented integer,
  2011. starting from START-INDEX (default 1). Applies the function FILTER,
  2012. if provided, to each key in the alist. Repeats the process, with
  2013. indices starting from START-INDEX each time, for any remaining
  2014. arguments SEQUENCES."
  2015. (or start-index (setq start-index 1))
  2016. (let (index alist)
  2017. (mapc (lambda (seq)
  2018. (setq index start-index)
  2019. (mapc (lambda (elem)
  2020. (setq alist (cons
  2021. (cons (if filter (funcall filter elem) elem)
  2022. index)
  2023. alist)
  2024. index (1+ index)))
  2025. seq))
  2026. (append (list sequence) sequences))
  2027. (reverse alist)))
  2028. (defun calendar-read-date (&optional noday)
  2029. "Prompt for Gregorian date. Return a list (month day year).
  2030. If optional NODAY is t, does not ask for day, but just returns
  2031. \(month 1 year); if NODAY is any other non-nil value the value returned is
  2032. \(month year)"
  2033. (let* ((year (calendar-read
  2034. "Year (>0): "
  2035. (lambda (x) (> x 0))
  2036. (number-to-string (calendar-extract-year
  2037. (calendar-current-date)))))
  2038. (month-array calendar-month-name-array)
  2039. (completion-ignore-case t)
  2040. (month (cdr (assoc-string
  2041. (completing-read
  2042. "Month name: "
  2043. (mapcar 'list (append month-array nil))
  2044. nil t)
  2045. (calendar-make-alist month-array 1) t)))
  2046. (last (calendar-last-day-of-month month year)))
  2047. (if noday
  2048. (if (eq noday t)
  2049. (list month 1 year)
  2050. (list month year))
  2051. (list month
  2052. (calendar-read (format "Day (1-%d): " last)
  2053. (lambda (x) (and (< 0 x) (<= x last))))
  2054. year))))
  2055. (defun calendar-interval (mon1 yr1 mon2 yr2)
  2056. "The number of months difference between MON1, YR1 and MON2, YR2.
  2057. The result is positive if the second date is later than the first.
  2058. Negative years are interpreted as years BC; -1 being 1 BC, and so on."
  2059. (if (< yr1 0) (setq yr1 (1+ yr1))) ; -1 BC -> 0 AD, etc
  2060. (if (< yr2 0) (setq yr2 (1+ yr2)))
  2061. (+ (* 12 (- yr2 yr1))
  2062. (- mon2 mon1)))
  2063. (defvar calendar-font-lock-keywords nil
  2064. "Default keywords to highlight in Calendar mode.")
  2065. (make-obsolete-variable 'calendar-font-lock-keywords
  2066. "set font-lock keywords in `calendar-mode-hook', \
  2067. or customize calendar faces." "24.4")
  2068. (defun calendar-day-name (date &optional abbrev absolute)
  2069. "Return a string with the name of the day of the week of DATE.
  2070. DATE should be a list in the format (MONTH DAY YEAR), unless the
  2071. optional argument ABSOLUTE is non-nil, in which case DATE should
  2072. be an integer in the range 0 to 6 corresponding to the day of the
  2073. week. Day names are taken from the variable `calendar-day-name-array',
  2074. unless the optional argument ABBREV is non-nil:
  2075. `header' means to use `calendar-day-header-array';
  2076. t to use `calendar-day-abbrev-array'."
  2077. (aref (cond ((eq abbrev 'header) calendar-day-header-array)
  2078. (abbrev calendar-day-abbrev-array)
  2079. (t calendar-day-name-array))
  2080. (if absolute date (calendar-day-of-week date))))
  2081. (defun calendar-month-name (month &optional abbrev)
  2082. "Return a string with the name of month number MONTH.
  2083. Months are numbered from one. Month names are taken from the
  2084. variable `calendar-month-name-array', unless the optional
  2085. argument ABBREV is non-nil, in which case
  2086. `calendar-month-abbrev-array' is used."
  2087. (aref (if abbrev calendar-month-abbrev-array calendar-month-name-array)
  2088. (1- month)))
  2089. (defun calendar-day-of-week (date)
  2090. "Return the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc.
  2091. DATE is a list of the form (month day year). A negative year is
  2092. interpreted as BC; -1 being 1 BC, and so on."
  2093. (mod (calendar-absolute-from-gregorian date) 7))
  2094. (defun calendar-week-end-day ()
  2095. "Return the index (0 for Sunday, etc.) of the last day of the week."
  2096. (mod (+ calendar-week-start-day 6) 7))
  2097. (defun calendar-unmark ()
  2098. "Delete all diary/holiday marks/highlighting from the calendar."
  2099. (interactive)
  2100. (setq calendar-mark-holidays-flag nil
  2101. calendar-mark-diary-entries-flag nil)
  2102. (with-current-buffer calendar-buffer
  2103. (mapc 'delete-overlay (overlays-in (point-min) (point-max)))))
  2104. (defun calendar-date-is-visible-p (date)
  2105. "Return non-nil if DATE is valid and is visible in the calendar window."
  2106. (and (calendar-date-is-valid-p date)
  2107. (< (abs (calendar-interval
  2108. displayed-month displayed-year
  2109. (calendar-extract-month date) (calendar-extract-year date)))
  2110. 2)))
  2111. ;; FIXME can this be generalized for holiday-chinese?
  2112. (defun calendar-nongregorian-visible-p (month day toabs fromabs switch)
  2113. "Return non-nil if MONTH, DAY is visible in the calendar window.
  2114. MONTH and DAY are in some non-Gregorian calendar system. The
  2115. functions TOABS and FROMABS convert that system to and from
  2116. absolute, respectively. SWITCH is a function that takes a single
  2117. argument (a local month number). It applies when the local year
  2118. changes across the calendar window, and returns non-nil if the
  2119. specified month should be associated with the higher year.
  2120. Returns the corresponding Gregorian date."
  2121. ;; We need to choose the local year associated with month and day
  2122. ;; that might make them visible.
  2123. (let* ((m1 displayed-month)
  2124. (y1 displayed-year)
  2125. (m2 displayed-month)
  2126. (y2 displayed-year)
  2127. ;; Absolute date of first/last dates in calendar window.
  2128. (start-date (progn
  2129. (calendar-increment-month m1 y1 -1)
  2130. (calendar-absolute-from-gregorian (list m1 1 y1))))
  2131. (end-date (progn
  2132. (calendar-increment-month m2 y2 1)
  2133. (calendar-absolute-from-gregorian
  2134. (list m2 (calendar-last-day-of-month m2 y2) y2))))
  2135. ;; Local date of first/last date in calendar window.
  2136. (local-start (funcall fromabs start-date))
  2137. (local-end (funcall fromabs end-date))
  2138. ;; Local year of first/last dates.
  2139. ;; Can only differ if displayed-month = 12, 1, 2.
  2140. (local-y1 (calendar-extract-year local-start))
  2141. (local-y2 (calendar-extract-year local-end))
  2142. ;; Choose which year might be visible in the window.
  2143. ;; Obviously it only matters when y1 and y2 differ, ie
  2144. ;; when the _local_ new year is visible.
  2145. (year (if (funcall switch month) local-y2 local-y1))
  2146. (date (calendar-gregorian-from-absolute
  2147. (funcall toabs (list month day year)))))
  2148. (if (calendar-date-is-visible-p date)
  2149. date)))
  2150. (defun calendar-date-is-valid-p (date)
  2151. "Return t if DATE is a valid date."
  2152. (let ((month (calendar-extract-month date))
  2153. (day (calendar-extract-day date))
  2154. (year (calendar-extract-year date)))
  2155. (and (<= 1 month) (<= month 12)
  2156. ;; (calendar-read-date t) used to return a date with day = nil.
  2157. ;; Should not be valid (?), since many funcs prob assume integer.
  2158. ;; (calendar-read-date 'noday) returns (month year), which
  2159. ;; currently results in calendar-extract-year returning nil.
  2160. day year (<= 1 day) (<= day (calendar-last-day-of-month month year))
  2161. ;; BC dates left as non-valid, to suppress errors from
  2162. ;; complex holiday algorithms not suitable for years BC.
  2163. ;; Note there are side effects on calendar navigation.
  2164. (<= 1 year))))
  2165. (defun calendar-date-equal (date1 date2)
  2166. "Return t if the DATE1 and DATE2 are the same."
  2167. (and
  2168. (= (calendar-extract-month date1) (calendar-extract-month date2))
  2169. (= (calendar-extract-day date1) (calendar-extract-day date2))
  2170. (= (calendar-extract-year date1) (calendar-extract-year date2))))
  2171. (defun calendar-make-temp-face (attrlist)
  2172. "Return a temporary face based on the attributes in ATTRLIST.
  2173. ATTRLIST is a list with elements of the form :face face :foreground color."
  2174. (let ((attrs attrlist)
  2175. faceinfo face temp-face)
  2176. ;; Separate :face from the other attributes. Use the last :face
  2177. ;; if there are more than one. FIXME is merging meaningful?
  2178. (while attrs
  2179. (if (eq (car attrs) :face)
  2180. (setq face (intern-soft (cadr attrs))
  2181. attrs (cddr attrs))
  2182. (push (car attrs) faceinfo)
  2183. (setq attrs (cdr attrs))))
  2184. (or (facep face) (setq face 'default))
  2185. (if (not faceinfo)
  2186. ;; No attributes to apply, so just use an existing-face.
  2187. face
  2188. ;; FIXME should we be using numbered temp-faces, re-using where poss?
  2189. (setq temp-face
  2190. (make-symbol
  2191. (concat ":caltemp"
  2192. (mapconcat (lambda (sym)
  2193. (cond
  2194. ((symbolp sym) (symbol-name sym))
  2195. ((numberp sym) (number-to-string sym))
  2196. (t sym)))
  2197. attrlist ""))))
  2198. (make-face temp-face)
  2199. (copy-face face temp-face)
  2200. ;; Apply the font aspects.
  2201. (apply 'set-face-attribute temp-face nil (nreverse faceinfo))
  2202. temp-face)))
  2203. (defun calendar-mark-visible-date (date &optional mark)
  2204. "Mark DATE in the calendar window with MARK.
  2205. MARK is a single-character string, a list of face attributes/values, or a face.
  2206. MARK defaults to `diary-entry-marker'."
  2207. (if (calendar-date-is-valid-p date)
  2208. (with-current-buffer calendar-buffer
  2209. (save-excursion
  2210. (calendar-cursor-to-visible-date date)
  2211. (setq mark
  2212. (or (and (stringp mark) (= (length mark) 1) mark) ; single-char
  2213. ;; The next two use to also check font-lock-mode.
  2214. ;; See comments above diary-entry-marker for why
  2215. ;; this was dropped.
  2216. ;;; (and font-lock-mode
  2217. ;;; (or
  2218. (and (listp mark) (> (length mark) 0) mark) ; attrs
  2219. (and (facep mark) mark) ; )) face-name
  2220. diary-entry-marker))
  2221. (cond
  2222. ;; Face or an attr-list that contained a face.
  2223. ((facep mark)
  2224. (overlay-put
  2225. (make-overlay (1- (point)) (1+ (point))) 'face mark))
  2226. ;; Single-character mark, goes after the date.
  2227. ((and (stringp mark) (= (length mark) 1))
  2228. (overlay-put
  2229. (make-overlay (1+ (point)) (+ 2 (point))) 'display mark))
  2230. (t ; attr list
  2231. (overlay-put
  2232. (make-overlay (1- (point)) (1+ (point))) 'face
  2233. (calendar-make-temp-face mark))))))))
  2234. (defun calendar-star-date ()
  2235. "Replace the date under the cursor in the calendar window with asterisks.
  2236. You might want to add this function to `calendar-today-visible-hook'."
  2237. (unless (catch 'found
  2238. (dolist (ol (overlays-at (point)))
  2239. (and (overlay-get ol 'calendar-star)
  2240. (throw 'found t))))
  2241. (let ((ol (make-overlay (1- (point)) (point))))
  2242. (overlay-put ol 'display "*")
  2243. (overlay-put ol 'calendar-star t)
  2244. ;; Use copy-sequence to avoid merging of identical 'display props.
  2245. ;; Use two overlays so as not to mess up
  2246. ;; calendar-cursor-to-nearest-date (and calendar-forward-day).
  2247. (overlay-put (setq ol (make-overlay (point) (1+ (point))))
  2248. 'display (copy-sequence "*"))
  2249. (overlay-put ol 'calendar-star t))))
  2250. (defun calendar-mark-today ()
  2251. "Mark the date under the cursor in the calendar window.
  2252. The date is marked with `calendar-today-marker'. You might want to add
  2253. this function to `calendar-today-visible-hook'."
  2254. (calendar-mark-visible-date (calendar-cursor-to-date) calendar-today-marker))
  2255. ;; FIXME why the car? Almost every usage calls list on the args.
  2256. (defun calendar-date-compare (date1 date2)
  2257. "Return t if DATE1 is before DATE2, nil otherwise.
  2258. The actual dates are in the car of DATE1 and DATE2."
  2259. (< (calendar-absolute-from-gregorian (car date1))
  2260. (calendar-absolute-from-gregorian (car date2))))
  2261. (defun calendar-date-string (date &optional abbreviate nodayname)
  2262. "A string form of DATE, driven by the variable `calendar-date-display-form'.
  2263. An optional parameter ABBREVIATE, when non-nil, causes the month
  2264. and day names to be abbreviated as specified by
  2265. `calendar-month-abbrev-array' and `calendar-day-abbrev-array',
  2266. respectively. An optional parameter NODAYNAME, when t, omits the
  2267. name of the day of the week."
  2268. (let* ((dayname (unless nodayname (calendar-day-name date abbreviate)))
  2269. (month (calendar-extract-month date))
  2270. (monthname (calendar-month-name month abbreviate))
  2271. (day (number-to-string (calendar-extract-day date)))
  2272. (month (number-to-string month))
  2273. (year (number-to-string (calendar-extract-year date))))
  2274. (mapconcat 'eval calendar-date-display-form "")))
  2275. (defun calendar-dayname-on-or-before (dayname date)
  2276. "Return the absolute date of the DAYNAME on or before absolute DATE.
  2277. DAYNAME=0 means Sunday, DAYNAME=1 means Monday, and so on.
  2278. Note: Applying this function to d+6 gives us the DAYNAME on or after an
  2279. absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
  2280. absolute date d, applying it to d-1 gives the DAYNAME previous to absolute
  2281. date d, and applying it to d+7 gives the DAYNAME following absolute date d."
  2282. (- date (% (- date dayname) 7)))
  2283. (defun calendar-nth-named-absday (n dayname month year &optional day)
  2284. "Absolute date of the Nth DAYNAME after/before MONTH YEAR DAY.
  2285. A DAYNAME of 0 means Sunday, 1 means Monday, and so on.
  2286. If N>0, return the Nth DAYNAME after MONTH DAY, YEAR (inclusive).
  2287. If N<0, return the Nth DAYNAME before MONTH DAY, YEAR (inclusive).
  2288. DAY defaults to 1 if N>0, and MONTH's last day otherwise."
  2289. (if (> n 0)
  2290. (+ (* 7 (1- n))
  2291. (calendar-dayname-on-or-before
  2292. dayname
  2293. (+ 6 (calendar-absolute-from-gregorian
  2294. (list month (or day 1) year)))))
  2295. (+ (* 7 (1+ n))
  2296. (calendar-dayname-on-or-before
  2297. dayname
  2298. (calendar-absolute-from-gregorian
  2299. (list month
  2300. (or day (calendar-last-day-of-month month year))
  2301. year))))))
  2302. (defun calendar-nth-named-day (n dayname month year &optional day)
  2303. "Date of the Nth DAYNAME after/before MONTH YEAR DAY.
  2304. Like `calendar-nth-named-absday', but returns a Gregorian date."
  2305. (calendar-gregorian-from-absolute
  2306. (calendar-nth-named-absday n dayname month year day)))
  2307. (defun calendar-day-of-year-string (&optional date)
  2308. "String of day number of year of Gregorian DATE.
  2309. Defaults to today's date if DATE is not given."
  2310. (let* ((d (or date (calendar-current-date)))
  2311. (year (calendar-extract-year d))
  2312. (day (calendar-day-number d))
  2313. (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
  2314. (format "Day %d of %d; %d day%s remaining in the year"
  2315. day year days-remaining (if (= days-remaining 1) "" "s"))))
  2316. (defun calendar-other-dates (date)
  2317. "Return a list of strings giving Gregorian DATE in other calendars.
  2318. DATE is (month day year). Calendars that do not apply are omitted."
  2319. (let (odate)
  2320. (delq nil
  2321. (list
  2322. (calendar-day-of-year-string date)
  2323. (format "ISO date: %s" (calendar-iso-date-string date))
  2324. (format "Julian date: %s"
  2325. (calendar-julian-date-string date))
  2326. (format "Astronomical (Julian) day number (at noon UTC): %s.0"
  2327. (calendar-astro-date-string date))
  2328. (format "Fixed (RD) date: %s"
  2329. (calendar-absolute-from-gregorian date))
  2330. (format "Hebrew date (before sunset): %s"
  2331. (calendar-hebrew-date-string date))
  2332. (format "Persian date: %s"
  2333. (calendar-persian-date-string date))
  2334. (unless (string-equal
  2335. (setq odate (calendar-islamic-date-string date))
  2336. "")
  2337. (format "Islamic date (before sunset): %s" odate))
  2338. (unless (string-equal
  2339. (setq odate (calendar-bahai-date-string date))
  2340. "")
  2341. (format "Bahá’í date: %s" odate))
  2342. (format "Chinese date: %s"
  2343. (calendar-chinese-date-string date))
  2344. (unless (string-equal
  2345. (setq odate (calendar-coptic-date-string date))
  2346. "")
  2347. (format "Coptic date: %s" odate))
  2348. (unless (string-equal
  2349. (setq odate (calendar-ethiopic-date-string date))
  2350. "")
  2351. (format "Ethiopic date: %s" odate))
  2352. (unless (string-equal
  2353. (setq odate (calendar-french-date-string date))
  2354. "")
  2355. (format "French Revolutionary date: %s" odate))
  2356. (format "Mayan date: %s"
  2357. (calendar-mayan-date-string date))))))
  2358. (declare-function x-popup-menu "menu.c" (position menu))
  2359. (defun calendar-print-other-dates (&optional event)
  2360. "Show dates on other calendars for date under the cursor.
  2361. If called by a mouse-event, pops up a menu with the result."
  2362. (interactive (list last-nonmenu-event))
  2363. (let* ((date (calendar-cursor-to-date t event))
  2364. (title (format "%s (Gregorian)" (calendar-date-string date)))
  2365. (others (calendar-other-dates date))
  2366. selection)
  2367. (if (mouse-event-p event)
  2368. (and (setq selection (cal-menu-x-popup-menu event title
  2369. (mapcar 'list others)))
  2370. (call-interactively selection))
  2371. (calendar-in-read-only-buffer calendar-other-calendars-buffer
  2372. (calendar-set-mode-line title)
  2373. (insert (mapconcat 'identity others "\n"))))))
  2374. (defun calendar-print-day-of-year ()
  2375. "Show day number in year/days remaining in year for date under the cursor."
  2376. (interactive)
  2377. (message "%s" (calendar-day-of-year-string (calendar-cursor-to-date t))))
  2378. (defun calendar-set-mode-line (str)
  2379. "Set mode line to STR, centered, surrounded by dashes."
  2380. (let* ((edges (window-edges))
  2381. ;; As per doc of window-width, total visible mode-line length.
  2382. (width (- (nth 2 edges) (car edges))))
  2383. ;; Hack for --daemon. See bug #2199.
  2384. ;; If no frame exists yet, we have no idea what width to use.
  2385. (and (= width 10)
  2386. (not window-system)
  2387. (setq width (string-to-number (or (getenv "COLUMNS") "80"))))
  2388. (setq mode-line-format
  2389. (if buffer-file-name
  2390. `("-" mode-line-modified
  2391. ,(calendar-string-spread (list str) ?- (- width 6))
  2392. "---")
  2393. (calendar-string-spread (list str) ?- width)))))
  2394. (run-hooks 'calendar-load-hook)
  2395. (provide 'calendar)
  2396. ;; Local variables:
  2397. ;; byte-compile-dynamic: t
  2398. ;; End:
  2399. ;;; calendar.el ends here