Mercurial > emacs
comparison lisp/calendar/calendar.el @ 92697:001682fd0516
(diary-file, hebrew-holidays-1)
(hebrew-holidays-2, hebrew-holidays-3, hebrew-holidays-4)
(calendar, calendar-basic-setup, calendar-mode-map, calendar-set-mark)
(calendar-version): Doc fixes.
(calendar-absolute-from-gregorian): Use zerop.
(calendar-mode-line-format): Make it a defcustom.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Mon, 10 Mar 2008 02:45:26 +0000 |
parents | 28746000b6be |
children | 0002224f12ec |
comparison
equal
deleted
inserted
replaced
92696:f656dd57b318 | 92697:001682fd0516 |
---|---|
91 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and | 91 ;; reingold@cs.uiuc.edu with the SUBJECT "send-paper-cal" (no quotes) and |
92 ;; the message BODY containing your mailing address (snail). | 92 ;; the message BODY containing your mailing address (snail). |
93 | 93 |
94 ;;; Code: | 94 ;;; Code: |
95 | 95 |
96 (defvar displayed-month) | |
97 (defvar displayed-year) | |
98 | 96 |
99 (require 'cal-loaddefs) | 97 (require 'cal-loaddefs) |
100 (require 'cal-menu) | 98 (require 'cal-menu) |
101 | 99 |
102 | 100 |
332 | 330 |
333 with the remainder of the line being the diary entry string for | 331 with the remainder of the line being the diary entry string for |
334 that date. MONTH and DAY are one or two digit numbers, YEAR is a | 332 that date. MONTH and DAY are one or two digit numbers, YEAR is a |
335 number and may be written in full or abbreviated to the final two | 333 number and may be written in full or abbreviated to the final two |
336 digits (if `abbreviated-calendar-year' is non-nil). MONTHNAME | 334 digits (if `abbreviated-calendar-year' is non-nil). MONTHNAME |
337 and DAYNAME can be spelled in full (as specified by the variables | 335 and DAYNAME can be spelt in full (as specified by the variables |
338 `calendar-month-name-array' and `calendar-day-name-array'), | 336 `calendar-month-name-array' and `calendar-day-name-array'), |
339 abbreviated (as specified by `calendar-month-abbrev-array' and | 337 abbreviated (as specified by `calendar-month-abbrev-array' and |
340 `calendar-day-abbrev-array') with or without a period, | 338 `calendar-day-abbrev-array') with or without a period, |
341 capitalized or not. Any of DAY, MONTH, or MONTHNAME, YEAR can be | 339 capitalized or not. Any of DAY, MONTH, or MONTHNAME, YEAR can be |
342 `*' which matches any day, month, or year, respectively. If the | 340 `*' which matches any day, month, or year, respectively. If the |
343 date does not contain a year, it is generic and applies to any | 341 date does not contain a year, it is generic and applies to any |
344 year. A DAYNAME entry applies to the appropriate day of the week | 342 year. A DAYNAME entry applies to the appropriate day of the week |
345 in every week. | 343 in every week. |
346 | 344 |
347 The European style (in which the day precedes the month) can be | 345 The European style (in which the day precedes the month) can be |
757 (calendar-julian-from-absolute | 755 (calendar-julian-from-absolute |
758 (calendar-absolute-from-gregorian | 756 (calendar-absolute-from-gregorian |
759 (list m 1 y)))))) | 757 (list m 1 y)))))) |
760 (if (zerop (% (1+ year) 4)) | 758 (if (zerop (% (1+ year) 4)) |
761 22 | 759 22 |
762 21))) "\"Tal Umatar\" (evening)")))) | 760 21))) "\"Tal Umatar\" (evening)"))) |
761 "Component of the default value of `hebrew-holidays'.") | |
763 ;;;###autoload | 762 ;;;###autoload |
764 (put 'hebrew-holidays-1 'risky-local-variable t) | 763 (put 'hebrew-holidays-1 'risky-local-variable t) |
765 | 764 |
766 ;;;###autoload | 765 ;;;###autoload |
767 (defvar hebrew-holidays-2 | 766 (defvar hebrew-holidays-2 |
779 7) | 778 7) |
780 6) | 779 6) |
781 11 10)) | 780 11 10)) |
782 "Tzom Teveth")) | 781 "Tzom Teveth")) |
783 (if all-hebrew-calendar-holidays | 782 (if all-hebrew-calendar-holidays |
784 (holiday-hebrew 11 15 "Tu B'Shevat")))) | 783 (holiday-hebrew 11 15 "Tu B'Shevat"))) |
784 "Component of the default value of `hebrew-holidays'.") | |
785 ;;;###autoload | 785 ;;;###autoload |
786 (put 'hebrew-holidays-2 'risky-local-variable t) | 786 (put 'hebrew-holidays-2 'risky-local-variable t) |
787 | 787 |
788 ;;;###autoload | 788 ;;;###autoload |
789 (defvar hebrew-holidays-3 | 789 (defvar hebrew-holidays-3 |
812 (calendar-dayname-on-or-before | 812 (calendar-dayname-on-or-before |
813 6 (calendar-absolute-from-hebrew | 813 6 (calendar-absolute-from-hebrew |
814 (list 11 16 h-year)))))) | 814 (list 11 16 h-year)))))) |
815 (day (extract-calendar-day s-s))) | 815 (day (extract-calendar-day s-s))) |
816 day)) | 816 day)) |
817 "Shabbat Shirah")))) | 817 "Shabbat Shirah"))) |
818 "Component of the default value of `hebrew-holidays'.") | |
818 ;;;###autoload | 819 ;;;###autoload |
819 (put 'hebrew-holidays-3 'risky-local-variable t) | 820 (put 'hebrew-holidays-3 'risky-local-variable t) |
820 | 821 |
821 ;;;###autoload | 822 ;;;###autoload |
822 (defvar hebrew-holidays-4 | 823 (defvar hebrew-holidays-4 |
826 (y displayed-year) | 827 (y displayed-year) |
827 (year)) | 828 (year)) |
828 (increment-calendar-month m y -1) | 829 (increment-calendar-month m y -1) |
829 (let ((year (extract-calendar-year | 830 (let ((year (extract-calendar-year |
830 (calendar-julian-from-absolute | 831 (calendar-julian-from-absolute |
831 (calendar-absolute-from-gregorian | 832 cd - (calendar-absolute-from-gregorian |
832 (list m 1 y)))))) | 833 (list m 1 y)))))) |
833 (= 21 (% year 28))))) | 834 (= 21 (% year 28))))) |
834 (holiday-julian 3 26 "Kiddush HaHamah")) | 835 (holiday-julian 3 26 "Kiddush HaHamah")) |
835 (if all-hebrew-calendar-holidays | 836 (if all-hebrew-calendar-holidays |
836 (holiday-tisha-b-av-etc)))) | 837 (holiday-tisha-b-av-etc))) |
838 "Component of the default value of `hebrew-holidays'.") | |
837 ;;;###autoload | 839 ;;;###autoload |
838 (put 'hebrew-holidays-4 'risky-local-variable t) | 840 (put 'hebrew-holidays-4 'risky-local-variable t) |
839 | 841 |
840 ;;;###autoload | 842 ;;;###autoload |
841 (defcustom hebrew-holidays (append hebrew-holidays-1 hebrew-holidays-2 | 843 (defcustom hebrew-holidays (append hebrew-holidays-1 hebrew-holidays-2 |
842 hebrew-holidays-3 hebrew-holidays-4) | 844 hebrew-holidays-3 hebrew-holidays-4) |
843 "Jewish holidays. | 845 "Jewish holidays. |
844 See the documentation for `calendar-holidays' for details." | 846 See the documentation for `calendar-holidays' for details." |
845 :type 'sexp | 847 :type 'sexp |
846 :group 'holidays) | 848 :group 'holidays) |
847 ;;;###autoload | 849 ;;;###autoload |
1170 ,mon (1+ (mod macro-y 12)) | 1172 ,mon (1+ (mod macro-y 12)) |
1171 ,yr (/ macro-y 12)) | 1173 ,yr (/ macro-y 12)) |
1172 (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr))) | 1174 (and (< macro-y 0) (> ,mon 1) (setq ,yr (1- ,yr))) |
1173 (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc | 1175 (if (< ,yr 1) (setq ,yr (1- ,yr))))) ; 0 AD -> -1 BC, etc |
1174 | 1176 |
1177 (defvar displayed-month) | |
1178 (defvar displayed-year) | |
1179 | |
1175 (defun calendar-increment-month (n &optional mon yr) | 1180 (defun calendar-increment-month (n &optional mon yr) |
1176 "Return the Nth month after MON/YR. | 1181 "Return the Nth month after MON/YR. |
1177 The return value is a pair (MONTH . YEAR). | 1182 The return value is a pair (MONTH . YEAR). |
1178 MON defaults to `displayed-month'. YR defaults to `displayed-year'." | 1183 MON defaults to `displayed-month'. YR defaults to `displayed-year'." |
1179 (unless mon (setq mon displayed-month)) | 1184 (unless mon (setq mon displayed-month)) |
1222 ;; 60 calendar-absolute-from-julian | 1227 ;; 60 calendar-absolute-from-julian |
1223 ;; 50 calendar-absolute-from-hebrew | 1228 ;; 50 calendar-absolute-from-hebrew |
1224 ;; 43 calendar-date-equal | 1229 ;; 43 calendar-date-equal |
1225 ;; 38 calendar-gregorian-from-absolute | 1230 ;; 38 calendar-gregorian-from-absolute |
1226 ;; . | 1231 ;; . |
1227 ;; . | |
1228 ;; . | |
1229 ;; | 1232 ;; |
1230 ;; The use of these seven macros eliminates the overhead of 92% of the function | 1233 ;; The use of these seven macros eliminates the overhead of 92% of the function |
1231 ;; calls; it's faster this way. | 1234 ;; calls; it's faster this way. |
1232 | 1235 |
1233 (defsubst extract-calendar-month (date) | 1236 (defsubst extract-calendar-month (date) |
1253 (zerop (% year 400))))) | 1256 (zerop (% year 400))))) |
1254 | 1257 |
1255 ;; The foregoing is a bit faster, but not as clear as the following: | 1258 ;; The foregoing is a bit faster, but not as clear as the following: |
1256 ;; | 1259 ;; |
1257 ;;(defsubst calendar-leap-year-p (year) | 1260 ;;(defsubst calendar-leap-year-p (year) |
1258 ;; "Returns t if YEAR is a Gregorian leap year." | 1261 ;; "Return t if YEAR is a Gregorian leap year." |
1259 ;; (or | 1262 ;; (or |
1260 ;; (and (= (% year 4) 0) | 1263 ;; (and (zerop (% year 4)) |
1261 ;; (/= (% year 100) 0)) | 1264 ;; (not (zerop (% year 100)))) |
1262 ;; (= (% year 400) 0))) | 1265 ;; (zerop (% year 400))) |
1263 | 1266 |
1264 (defsubst calendar-last-day-of-month (month year) | 1267 (defsubst calendar-last-day-of-month (month year) |
1265 "The last day in MONTH during YEAR." | 1268 "The last day in MONTH during YEAR." |
1266 (if (and (= month 2) (calendar-leap-year-p year)) | 1269 (if (and (= month 2) (calendar-leap-year-p year)) |
1267 29 | 1270 29 |
1291 DATE is a list of the form (month day year). A negative year is | 1294 DATE is a list of the form (month day year). A negative year is |
1292 interpreted as BC; -1 being 1 BC, and so on. Dates before 12/31/1 BC | 1295 interpreted as BC; -1 being 1 BC, and so on. Dates before 12/31/1 BC |
1293 return negative results." | 1296 return negative results." |
1294 (let ((year (extract-calendar-year date)) | 1297 (let ((year (extract-calendar-year date)) |
1295 offset-years) | 1298 offset-years) |
1296 (cond ((= year 0) | 1299 (cond ((zerop year) |
1297 (error "There was no year zero")) | 1300 (error "There was no year zero")) |
1298 ((> year 0) | 1301 ((> year 0) |
1299 (setq offset-years (1- year)) | 1302 (setq offset-years (1- year)) |
1300 (+ (calendar-day-number date) ; Days this year | 1303 (+ (calendar-day-number date) ; days this year |
1301 (* 365 offset-years) ; + Days in prior years | 1304 (* 365 offset-years) ; + days in prior years |
1302 (/ offset-years 4) ; + Julian leap years | 1305 (/ offset-years 4) ; + Julian leap years |
1303 (- (/ offset-years 100)) ; - century years | 1306 (- (/ offset-years 100)) ; - century years |
1304 (/ offset-years 400))) ; + Gregorian leap years | 1307 (/ offset-years 400))) ; + Gregorian leap years |
1305 (t | 1308 (t |
1306 ;; Years between date and 1 BC, excluding 1 BC (1 for 2 BC, etc). | 1309 ;; Years between date and 1 BC, excluding 1 BC (1 for 2 BC, etc). |
1313 (calendar-day-number '(12 31 -1))))))) ; days in year 1 BC | 1316 (calendar-day-number '(12 31 -1))))))) ; days in year 1 BC |
1314 | 1317 |
1315 ;;;###autoload | 1318 ;;;###autoload |
1316 (defun calendar (&optional arg) | 1319 (defun calendar (&optional arg) |
1317 "Choose between the one frame, two frame, or basic calendar displays. | 1320 "Choose between the one frame, two frame, or basic calendar displays. |
1318 If called with an optional prefix argument, prompts for month and year. | 1321 If called with an optional prefix argument ARG, prompts for month and year. |
1319 | 1322 |
1320 The original function `calendar' has been renamed `calendar-basic-setup'. | 1323 The original function `calendar' has been renamed `calendar-basic-setup'. |
1321 See the documentation of that function for more information." | 1324 See the documentation of that function for more information." |
1322 (interactive "P") | 1325 (interactive "P") |
1323 (cond ((equal calendar-setup 'one-frame) (calendar-one-frame-setup arg)) | 1326 (cond ((equal calendar-setup 'one-frame) (calendar-one-frame-setup arg)) |
1342 (defun calendar-basic-setup (&optional arg) | 1345 (defun calendar-basic-setup (&optional arg) |
1343 "Display a three-month calendar in another window. | 1346 "Display a three-month calendar in another window. |
1344 The three months appear side by side, with the current month in the middle | 1347 The three months appear side by side, with the current month in the middle |
1345 surrounded by the previous and next months. The cursor is put on today's date. | 1348 surrounded by the previous and next months. The cursor is put on today's date. |
1346 | 1349 |
1347 If called with an optional prefix argument, prompts for month and year. | 1350 If called with an optional prefix argument ARG, prompts for month and year. |
1348 | 1351 |
1349 This function is suitable for execution in a .emacs file; appropriate setting | 1352 This function is suitable for execution in a .emacs file; appropriate setting |
1350 of the variable `view-diary-entries-initially' will cause the diary entries for | 1353 of the variable `view-diary-entries-initially' will cause the diary entries for |
1351 the current date to be displayed in another window. The value of the variable | 1354 the current date to be displayed in another window. The value of the variable |
1352 `number-of-diary-entries' controls the number of days of diary entries | 1355 `number-of-diary-entries' controls the number of days of diary entries |
1368 | 1371 |
1369 The Gregorian calendar is assumed. | 1372 The Gregorian calendar is assumed. |
1370 | 1373 |
1371 After loading the calendar, the hooks given by the variable | 1374 After loading the calendar, the hooks given by the variable |
1372 `calendar-load-hook' are run. This is the place to add key bindings to the | 1375 `calendar-load-hook' are run. This is the place to add key bindings to the |
1373 calendar-mode-map. | 1376 `calendar-mode-map'. |
1374 | 1377 |
1375 After preparing the calendar window initially, the hooks given by the variable | 1378 After preparing the calendar window initially, the hooks given by the variable |
1376 `initial-calendar-window-hook' are run. | 1379 `initial-calendar-window-hook' are run. |
1377 | 1380 |
1378 The hooks given by the variable `today-visible-calendar-hook' are run | 1381 The hooks given by the variable `today-visible-calendar-hook' are run |
1519 (update-calendar-mode-line) | 1522 (update-calendar-mode-line) |
1520 (calendar-cursor-to-visible-date | 1523 (calendar-cursor-to-visible-date |
1521 (if today-visible today (list displayed-month 1 displayed-year))) | 1524 (if today-visible today (list displayed-month 1 displayed-year))) |
1522 (set-buffer-modified-p nil) | 1525 (set-buffer-modified-p nil) |
1523 ;; Don't do any window-related stuff if we weren't called from a | 1526 ;; Don't do any window-related stuff if we weren't called from a |
1524 ;; window displaying the calendar | 1527 ;; window displaying the calendar. |
1525 (when in-calendar-window | 1528 (when in-calendar-window |
1526 (if (or (one-window-p t) (not (window-full-width-p))) | 1529 (if (or (one-window-p t) (not (window-full-width-p))) |
1527 ;; Don't mess with the window size, but ensure that the first | 1530 ;; Don't mess with the window size, but ensure that the first |
1528 ;; line is fully visible | 1531 ;; line is fully visible. |
1529 (set-window-vscroll nil 0) | 1532 (set-window-vscroll nil 0) |
1530 ;; Adjust the window to exactly fit the displayed calendar | 1533 ;; Adjust the window to exactly fit the displayed calendar. |
1531 (fit-window-to-buffer nil nil calendar-minimum-window-height)) | 1534 (fit-window-to-buffer nil nil calendar-minimum-window-height)) |
1532 (sit-for 0)) | 1535 (sit-for 0)) |
1533 (if (and (boundp 'font-lock-mode) | 1536 (if (and (boundp 'font-lock-mode) |
1534 font-lock-mode) | 1537 font-lock-mode) |
1535 (font-lock-fontify-buffer)) | 1538 (font-lock-fontify-buffer)) |
1563 "Produce a calendar for MONTH, YEAR on the Gregorian calendar. | 1566 "Produce a calendar for MONTH, YEAR on the Gregorian calendar. |
1564 The calendar is inserted at the top of the buffer in which point is currently | 1567 The calendar is inserted at the top of the buffer in which point is currently |
1565 located, but indented INDENT spaces. The indentation is done from the first | 1568 located, but indented INDENT spaces. The indentation is done from the first |
1566 character on the line and does not disturb the first INDENT characters on the | 1569 character on the line and does not disturb the first INDENT characters on the |
1567 line." | 1570 line." |
1568 (let* ((blank-days;; at start of month | 1571 (let* ((blank-days ; at start of month |
1569 (mod | 1572 (mod |
1570 (- (calendar-day-of-week (list month 1 year)) | 1573 (- (calendar-day-of-week (list month 1 year)) |
1571 calendar-week-start-day) | 1574 calendar-week-start-day) |
1572 7)) | 1575 7)) |
1573 (last (calendar-last-day-of-month month year))) | 1576 (last (calendar-last-day-of-month month year))) |
1574 (goto-char (point-min)) | 1577 (goto-char (point-min)) |
1575 (calendar-insert-indented | 1578 (calendar-insert-indented |
1576 (calendar-string-spread | 1579 (calendar-string-spread |
1577 (list (format "%s %d" (calendar-month-name month) year)) ? 20) | 1580 (list (format "%s %d" (calendar-month-name month) year)) ? 20) |
1578 indent t) | 1581 indent t) |
1579 (calendar-insert-indented "" indent);; Go to proper spot | 1582 (calendar-insert-indented "" indent) ; go to proper spot |
1580 ;; Use the first two characters of each day to head the columns. | 1583 ;; Use the first two characters of each day to head the columns. |
1581 (dotimes (i 7) | 1584 (dotimes (i 7) |
1582 (insert | 1585 (insert |
1583 (let ((string | 1586 (let ((string |
1584 (calendar-day-name (mod (+ calendar-week-start-day i) 7) nil t))) | 1587 (calendar-day-name (mod (+ calendar-week-start-day i) 7) nil t))) |
1585 (if enable-multibyte-characters | 1588 (if enable-multibyte-characters |
1586 (truncate-string-to-width string 2) | 1589 (truncate-string-to-width string 2) |
1587 (substring string 0 2))) | 1590 (substring string 0 2))) |
1588 " ")) | 1591 " ")) |
1589 (calendar-insert-indented "" 0 t);; Force onto following line | 1592 (calendar-insert-indented "" 0 t) ; force onto following line |
1590 (calendar-insert-indented "" indent);; Go to proper spot | 1593 (calendar-insert-indented "" indent) ; go to proper spot |
1591 ;; Add blank days before the first of the month | 1594 ;; Add blank days before the first of the month. |
1592 (dotimes (idummy blank-days) (insert " ")) | 1595 (dotimes (idummy blank-days) (insert " ")) |
1593 ;; Put in the days of the month | 1596 ;; Put in the days of the month. |
1594 (calendar-for-loop i from 1 to last do | 1597 (calendar-for-loop i from 1 to last do |
1595 (insert (format "%2d " i)) | 1598 (insert (format "%2d " i)) |
1596 (add-text-properties | 1599 (add-text-properties |
1597 (- (point) 3) (1- (point)) | 1600 (- (point) 3) (1- (point)) |
1598 '(mouse-face highlight | 1601 '(mouse-face highlight |
1599 help-echo "mouse-2: menu of operations for this date")) | 1602 help-echo "mouse-2: menu of operations for this date")) |
1600 (and (zerop (mod (+ i blank-days) 7)) | 1603 (and (zerop (mod (+ i blank-days) 7)) |
1601 (/= i last) | 1604 (/= i last) |
1602 (calendar-insert-indented "" 0 t) ;; Force onto following line | 1605 (calendar-insert-indented "" 0 t) ; force onto following line |
1603 (calendar-insert-indented "" indent)))));; Go to proper spot | 1606 (calendar-insert-indented "" indent))))) ; go to proper spot |
1604 | 1607 |
1605 (defun calendar-insert-indented (string indent &optional newline) | 1608 (defun calendar-insert-indented (string indent &optional newline) |
1606 "Insert STRING at column INDENT. | 1609 "Insert STRING at column INDENT. |
1607 If the optional parameter NEWLINE is t, leave point at start of next line, | 1610 If the optional parameter NEWLINE is t, leave point at start of next line, |
1608 inserting a newline if there was no next line; otherwise, leave point after | 1611 inserting a newline if there was no next line; otherwise, leave point after |
1771 (define-key map [down-mouse-3] | 1774 (define-key map [down-mouse-3] |
1772 (easy-menu-binding cal-menu-context-mouse-menu)) | 1775 (easy-menu-binding cal-menu-context-mouse-menu)) |
1773 (define-key map [down-mouse-2] | 1776 (define-key map [down-mouse-2] |
1774 (easy-menu-binding cal-menu-global-mouse-menu)) | 1777 (easy-menu-binding cal-menu-global-mouse-menu)) |
1775 | 1778 |
1776 map)) | 1779 map) |
1780 "Keymap for `calendar-mode'.") | |
1777 | 1781 |
1778 (defun describe-calendar-mode () | 1782 (defun describe-calendar-mode () |
1779 "Create a help buffer with a brief description of the `calendar-mode'." | 1783 "Create a help buffer with a brief description of the `calendar-mode'." |
1780 (interactive) | 1784 (interactive) |
1781 (help-setup-xref (list #'describe-calendar-mode) (interactive-p)) | 1785 (help-setup-xref (list #'describe-calendar-mode) (interactive-p)) |
1789 (print-help-return-message))) | 1793 (print-help-return-message))) |
1790 | 1794 |
1791 ;; Calendar mode is suitable only for specially formatted data. | 1795 ;; Calendar mode is suitable only for specially formatted data. |
1792 (put 'calendar-mode 'mode-class 'special) | 1796 (put 'calendar-mode 'mode-class 'special) |
1793 | 1797 |
1794 (defvar calendar-mode-line-format | 1798 ;; After calendar-mode-map. |
1799 (defcustom calendar-mode-line-format | |
1795 (list | 1800 (list |
1796 (propertize "<" | 1801 (propertize "<" |
1797 'help-echo "mouse-1: previous month" | 1802 'help-echo "mouse-1: previous month" |
1798 'mouse-face 'mode-line-highlight | 1803 'mouse-face 'mode-line-highlight |
1799 'keymap (make-mode-line-mouse-map 'mouse-1 | 1804 'keymap (make-mode-line-mouse-map 'mouse-1 |
1833 evaluated and concatenated together, evenly separated by blanks. The variable | 1838 evaluated and concatenated together, evenly separated by blanks. The variable |
1834 `date' is available for use as the date under (or near) the cursor; `date' | 1839 `date' is available for use as the date under (or near) the cursor; `date' |
1835 defaults to the current date if it is otherwise undefined. Here is an example | 1840 defaults to the current date if it is otherwise undefined. Here is an example |
1836 value that has the Hebrew date, the day number/days remaining in the year, | 1841 value that has the Hebrew date, the day number/days remaining in the year, |
1837 and the ISO week/year numbers in the mode. When `calendar-move-hook' is set | 1842 and the ISO week/year numbers in the mode. When `calendar-move-hook' is set |
1838 to `update-calendar-mode-line', these mode line shows these values for the date | 1843 to `update-calendar-mode-line', the mode line shows these values for the date |
1839 under the cursor: | 1844 under the cursor: |
1840 | 1845 |
1841 (list | 1846 (list |
1842 \"\" | 1847 \"\" |
1843 '(calendar-hebrew-date-string date) | 1848 '(calendar-hebrew-date-string date) |
1849 '(let* ((d (calendar-absolute-from-gregorian date)) | 1854 '(let* ((d (calendar-absolute-from-gregorian date)) |
1850 (iso-date (calendar-iso-from-absolute d))) | 1855 (iso-date (calendar-iso-from-absolute d))) |
1851 (format \"ISO week %d of %d\" | 1856 (format \"ISO week %d of %d\" |
1852 (extract-calendar-month iso-date) | 1857 (extract-calendar-month iso-date) |
1853 (extract-calendar-year iso-date))) | 1858 (extract-calendar-year iso-date))) |
1854 \"\"))") | 1859 \"\"))" |
1860 :type 'sexp | |
1861 :group 'calendar) | |
1855 | 1862 |
1856 (defun mouse-calendar-other-month (event) | 1863 (defun mouse-calendar-other-month (event) |
1857 "Display a three-month calendar centered around a specified month and year." | 1864 "Display a three-month calendar centered around a specified month and year." |
1858 (interactive "e") | 1865 (interactive "e") |
1859 (save-selected-window | 1866 (save-selected-window |
1885 indent-tabs-mode nil) | 1892 indent-tabs-mode nil) |
1886 (use-local-map calendar-mode-map) | 1893 (use-local-map calendar-mode-map) |
1887 (update-calendar-mode-line) | 1894 (update-calendar-mode-line) |
1888 (make-local-variable 'calendar-mark-ring) | 1895 (make-local-variable 'calendar-mark-ring) |
1889 (make-local-variable 'calendar-starred-day) | 1896 (make-local-variable 'calendar-starred-day) |
1890 (make-local-variable 'displayed-month) ;; Month in middle of window. | 1897 (make-local-variable 'displayed-month) ; month in middle of window |
1891 (make-local-variable 'displayed-year) ;; Year in middle of window. | 1898 (make-local-variable 'displayed-year) ; year in middle of window |
1892 ;; Most functions only work if displayed-month and displayed-year are set, | 1899 ;; Most functions only work if displayed-month and displayed-year are set, |
1893 ;; so let's make sure they're always set. Most likely, this will be reset | 1900 ;; so let's make sure they're always set. Most likely, this will be reset |
1894 ;; soon in generate-calendar, but better safe than sorry. | 1901 ;; soon in generate-calendar, but better safe than sorry. |
1895 (unless (boundp 'displayed-month) (setq displayed-month 1)) | 1902 (unless (boundp 'displayed-month) (setq displayed-month 1)) |
1896 (unless (boundp 'displayed-year) (setq displayed-year 2001)) | 1903 (unless (boundp 'displayed-year) (setq displayed-year 2001)) |
1904 possible. Each item of STRINGS is evaluated before concatenation so it can | 1911 possible. Each item of STRINGS is evaluated before concatenation so it can |
1905 actually be an expression that evaluates to a string. If LENGTH is too short, | 1912 actually be an expression that evaluates to a string. If LENGTH is too short, |
1906 the STRINGS are just concatenated and the result truncated." | 1913 the STRINGS are just concatenated and the result truncated." |
1907 ;; The algorithm is based on equation (3.25) on page 85 of Concrete | 1914 ;; The algorithm is based on equation (3.25) on page 85 of Concrete |
1908 ;; Mathematics by Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, | 1915 ;; Mathematics by Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, |
1909 ;; Addison-Wesley, Reading, MA, 1989 | 1916 ;; Addison-Wesley, Reading, MA, 1989. |
1910 (let* ((strings (mapcar 'eval | 1917 (let* ((strings (mapcar 'eval |
1911 (if (< (length strings) 2) | 1918 (if (< (length strings) 2) |
1912 (append (list "") strings (list "")) | 1919 (append (list "") strings (list "")) |
1913 strings))) | 1920 strings))) |
1914 (n (- length (length (apply 'concat strings)))) | 1921 (n (- length (length (apply 'concat strings)))) |
1967 (if (or (not diary-buffer) | 1974 (if (or (not diary-buffer) |
1968 (not (buffer-modified-p diary-buffer)) | 1975 (not (buffer-modified-p diary-buffer)) |
1969 (yes-or-no-p | 1976 (yes-or-no-p |
1970 "Diary modified; do you really want to exit the calendar? ")) | 1977 "Diary modified; do you really want to exit the calendar? ")) |
1971 ;; Need to do this multiple times because one time can replace some | 1978 ;; Need to do this multiple times because one time can replace some |
1972 ;; calendar-related buffers with other calendar-related buffers | 1979 ;; calendar-related buffers with other calendar-related buffers. |
1973 (mapc (lambda (x) | 1980 (mapc (lambda (x) |
1974 (mapc 'calendar-hide-window (calendar-window-list))) | 1981 (mapc 'calendar-hide-window (calendar-window-list))) |
1975 (calendar-window-list))))) | 1982 (calendar-window-list))))) |
1976 | 1983 |
1977 (defun calendar-hide-window (window) | 1984 (defun calendar-hide-window (window) |
2032 | 2039 |
2033 ;;(defun calendar-gregorian-from-absolute (date) | 2040 ;;(defun calendar-gregorian-from-absolute (date) |
2034 ;; "Compute the list (month day year) corresponding to the absolute DATE. | 2041 ;; "Compute the list (month day year) corresponding to the absolute DATE. |
2035 ;;The absolute date is the number of days elapsed since the (imaginary) | 2042 ;;The absolute date is the number of days elapsed since the (imaginary) |
2036 ;;Gregorian date Sunday, December 31, 1 BC." | 2043 ;;Gregorian date Sunday, December 31, 1 BC." |
2037 ;; (let* ((approx (/ date 366));; Approximation from below. | 2044 ;; (let* ((approx (/ date 366)) ; approximation from below |
2038 ;; (year ;; Search forward from the approximation. | 2045 ;; (year ; search forward from the approximation |
2039 ;; (+ approx | 2046 ;; (+ approx |
2040 ;; (calendar-sum y approx | 2047 ;; (calendar-sum y approx |
2041 ;; (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y)))) | 2048 ;; (>= date (calendar-absolute-from-gregorian (list 1 1 (1+ y)))) |
2042 ;; 1))) | 2049 ;; 1))) |
2043 ;; (month ;; Search forward from January. | 2050 ;; (month ; search forward from January |
2044 ;; (1+ (calendar-sum m 1 | 2051 ;; (1+ (calendar-sum m 1 |
2045 ;; (> date | 2052 ;; (> date |
2046 ;; (calendar-absolute-from-gregorian | 2053 ;; (calendar-absolute-from-gregorian |
2047 ;; (list m (calendar-last-day-of-month m year) year))) | 2054 ;; (list m (calendar-last-day-of-month m year) year))) |
2048 ;; 1))) | 2055 ;; 1))) |
2049 ;; (day ;; Calculate the day by subtraction. | 2056 ;; (day ; calculate the day by subtraction |
2050 ;; (- date | 2057 ;; (- date |
2051 ;; (1- (calendar-absolute-from-gregorian (list month 1 year)))))) | 2058 ;; (1- (calendar-absolute-from-gregorian (list month 1 year)))))) |
2052 ;; (list month day year))) | 2059 ;; (list month day year))) |
2053 | 2060 |
2054 (defun calendar-gregorian-from-absolute (date) | 2061 (defun calendar-gregorian-from-absolute (date) |
2055 "Compute the list (month day year) corresponding to the absolute DATE. | 2062 "Compute the list (month day year) corresponding to the absolute DATE. |
2056 The absolute date is the number of days elapsed since the (imaginary) | 2063 The absolute date is the number of days elapsed since the (imaginary) |
2057 Gregorian date Sunday, December 31, 1 BC. This function does not | 2064 Gregorian date Sunday, December 31, 1 BC. This function does not |
2058 handle dates in years BC." | 2065 handle dates in years BC." |
2059 ;; See the footnote on page 384 of ``Calendrical Calculations, Part II: | 2066 ;; See the footnote on page 384 of ``Calendrical Calculations, Part II: |
2060 ;; Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. | 2067 ;; Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M. |
2061 ;; Clamen, Software--Practice and Experience, Volume 23, Number 4 | 2068 ;; Clamen, Software--Practice and Experience, Volume 23, Number 4 |
2062 ;; (April, 1993), pages 383-404 for an explanation. | 2069 ;; (April, 1993), pages 383-404 for an explanation. |
2063 (let* ((d0 (1- date)) | 2070 (let* ((d0 (1- date)) |
2064 (n400 (/ d0 146097)) | 2071 (n400 (/ d0 146097)) |
2065 (d1 (% d0 146097)) | 2072 (d1 (% d0 146097)) |
2066 (n100 (/ d1 36524)) | 2073 (n100 (/ d1 36524)) |
2067 (d2 (% d1 36524)) | 2074 (d2 (% d1 36524)) |
2096 (t (list month 1 year))))))) | 2103 (t (list month 1 year))))))) |
2097 | 2104 |
2098 (defun calendar-set-mark (arg) | 2105 (defun calendar-set-mark (arg) |
2099 "Mark the date under the cursor, or jump to marked date. | 2106 "Mark the date under the cursor, or jump to marked date. |
2100 With no prefix argument, push current date onto marked date ring. | 2107 With no prefix argument, push current date onto marked date ring. |
2101 With argument, jump to mark, pop it, and put point at end of ring." | 2108 With argument ARG, jump to mark, pop it, and put point at end of ring." |
2102 (interactive "P") | 2109 (interactive "P") |
2103 (let ((date (calendar-cursor-to-date t))) | 2110 (let ((date (calendar-cursor-to-date t))) |
2104 (if (null arg) | 2111 (if (null arg) |
2105 (progn | 2112 (progn |
2106 (push date calendar-mark-ring) | 2113 (push date calendar-mark-ring) |
2255 " -?[0-9]+") | 2262 " -?[0-9]+") |
2256 . font-lock-function-name-face) ; month and year | 2263 . font-lock-function-name-face) ; month and year |
2257 (,(regexp-opt | 2264 (,(regexp-opt |
2258 (list (substring (aref calendar-day-name-array 6) 0 2) | 2265 (list (substring (aref calendar-day-name-array 6) 0 2) |
2259 (substring (aref calendar-day-name-array 0) 0 2))) | 2266 (substring (aref calendar-day-name-array 0) 0 2))) |
2260 ;; Saturdays and Sundays are hilited differently. | 2267 ;; Saturdays and Sundays are highlighted differently. |
2261 . font-lock-comment-face) | 2268 . font-lock-comment-face) |
2262 ;; First two chars of each day are used in the calendar. | 2269 ;; First two chars of each day are used in the calendar. |
2263 (,(regexp-opt (mapcar (lambda (x) (substring x 0 2)) calendar-day-name-array)) | 2270 (,(regexp-opt (mapcar (lambda (x) (substring x 0 2)) |
2271 calendar-day-name-array)) | |
2264 . font-lock-reference-face)) | 2272 . font-lock-reference-face)) |
2265 "Default keywords to highlight in Calendar mode.") | 2273 "Default keywords to highlight in Calendar mode.") |
2266 | 2274 |
2267 (defun calendar-day-name (date &optional abbrev absolute) | 2275 (defun calendar-day-name (date &optional abbrev absolute) |
2268 "Return a string with the name of the day of the week of DATE. | 2276 "Return a string with the name of the day of the week of DATE. |
2377 (or (and (stringp mark) (= (length mark) 1) mark) ; single-char | 2385 (or (and (stringp mark) (= (length mark) 1) mark) ; single-char |
2378 (and (listp mark) (> (length mark) 0) mark) ; attr list | 2386 (and (listp mark) (> (length mark) 0) mark) ; attr list |
2379 (and (facep mark) mark) ; face-name | 2387 (and (facep mark) mark) ; face-name |
2380 diary-entry-marker)) | 2388 diary-entry-marker)) |
2381 (cond | 2389 (cond |
2382 ;; face or an attr-list that contained a face | 2390 ;; Face or an attr-list that contained a face. |
2383 ((facep mark) | 2391 ((facep mark) |
2384 (overlay-put | 2392 (overlay-put |
2385 (make-overlay (1- (point)) (1+ (point))) 'face mark)) | 2393 (make-overlay (1- (point)) (1+ (point))) 'face mark)) |
2386 ;; single-char | 2394 ;; Single-character. |
2387 ((and (stringp mark) (= (length mark) 1)) | 2395 ((and (stringp mark) (= (length mark) 1)) |
2388 (let ((inhibit-read-only t)) | 2396 (let ((inhibit-read-only t)) |
2389 (forward-char 1) | 2397 (forward-char 1) |
2390 ;; Insert before delete so as to better preserve markers. | 2398 ;; Insert before delete so as to better preserve markers. |
2391 (insert mark) | 2399 (insert mark) |
2392 (delete-char 1) | 2400 (delete-char 1) |
2393 (forward-char -2))) | 2401 (forward-char -2))) |
2394 (t ;; attr list | 2402 (t ; attr list |
2395 (let ((temp-face | 2403 (let ((temp-face |
2396 (make-symbol | 2404 (make-symbol |
2397 (apply 'concat "temp-" | 2405 (apply 'concat "temp-" |
2398 (mapcar (lambda (sym) | 2406 (mapcar (lambda (sym) |
2399 (cond | 2407 (cond |
2401 ((numberp sym) (number-to-string sym)) | 2409 ((numberp sym) (number-to-string sym)) |
2402 (t sym))) | 2410 (t sym))) |
2403 mark)))) | 2411 mark)))) |
2404 (faceinfo mark)) | 2412 (faceinfo mark)) |
2405 (make-face temp-face) | 2413 (make-face temp-face) |
2406 ;; Remove :face info from the mark, copy the face info into | 2414 ;; Remove :face info from mark, copy the face info into temp-face. |
2407 ;; temp-face | |
2408 (while (setq faceinfo (memq :face faceinfo)) | 2415 (while (setq faceinfo (memq :face faceinfo)) |
2409 (copy-face (read (nth 1 faceinfo)) temp-face) | 2416 (copy-face (read (nth 1 faceinfo)) temp-face) |
2410 (setcar faceinfo nil) | 2417 (setcar faceinfo nil) |
2411 (setcar (cdr faceinfo) nil)) | 2418 (setcar (cdr faceinfo) nil)) |
2412 (setq mark (delq nil mark)) | 2419 (setq mark (delq nil mark)) |
2413 ;; Apply the font aspects | 2420 ;; Apply the font aspects. |
2414 (apply 'set-face-attribute temp-face nil mark) | 2421 (apply 'set-face-attribute temp-face nil mark) |
2415 (overlay-put | 2422 (overlay-put |
2416 (make-overlay (1- (point)) (1+ (point))) 'face temp-face)))))))) | 2423 (make-overlay (1- (point)) (1+ (point))) 'face temp-face)))))))) |
2417 | 2424 |
2418 (defun calendar-star-date () | 2425 (defun calendar-star-date () |
2584 "Non-negative remainder of M/N with N instead of 0." | 2591 "Non-negative remainder of M/N with N instead of 0." |
2585 (1+ (mod (1- m) n))) | 2592 (1+ (mod (1- m) n))) |
2586 | 2593 |
2587 | 2594 |
2588 (defun calendar-version () | 2595 (defun calendar-version () |
2596 "Display the Calendar version." | |
2589 (interactive) | 2597 (interactive) |
2590 (message "GNU Emacs %s" emacs-version)) | 2598 (message "GNU Emacs %s" emacs-version)) |
2591 | 2599 |
2592 (make-obsolete 'calendar-version 'emacs-version "23.1") | 2600 (make-obsolete 'calendar-version 'emacs-version "23.1") |
2593 | 2601 |