aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2003-08-03 14:01:40 +0000
committerGlenn Morris2003-08-03 14:01:40 +0000
commitda3fc02028ebc71a9aa247d1cb688c8e3766a2a1 (patch)
treee3355e4b50ff5ba64ec88ca031c81271c8b4e0e8
parentca2a5950cfe3f0184aba945ee9bc5a086857a876 (diff)
downloademacs-da3fc02028ebc71a9aa247d1cb688c8e3766a2a1.tar.gz
emacs-da3fc02028ebc71a9aa247d1cb688c8e3766a2a1.zip
Reposition some code so defined before used.
(displayed-month, displayed-year): Define for compiler. (calendar-hebrew-month-name-array-common-year) (calendar-hebrew-month-name-array-leap-year): Add doc strings. (list-hebrew-diary-entries): Adapt for new behaviours of `calendar-day-name' and `add-to-diary-list' functions. (mark-hebrew-diary-entries): Adapt for new behaviours of `diary-name-pattern' and `calendar-make-alist' functions.
-rw-r--r--lisp/calendar/cal-hebrew.el305
1 files changed, 154 insertions, 151 deletions
diff --git a/lisp/calendar/cal-hebrew.el b/lisp/calendar/cal-hebrew.el
index 29abaebb9b4..46d593bae64 100644
--- a/lisp/calendar/cal-hebrew.el
+++ b/lisp/calendar/cal-hebrew.el
@@ -1,6 +1,6 @@
1;;; cal-hebrew.el --- calendar functions for the Hebrew calendar 1;;; cal-hebrew.el --- calendar functions for the Hebrew calendar
2 2
3;; Copyright (C) 1995, 1997 Free Software Foundation, Inc. 3;; Copyright (C) 1995, 1997, 2003 Free Software Foundation, Inc.
4 4
5;; Author: Nachum Dershowitz <nachum@cs.uiuc.edu> 5;; Author: Nachum Dershowitz <nachum@cs.uiuc.edu>
6;; Edward M. Reingold <reingold@cs.uiuc.edu> 6;; Edward M. Reingold <reingold@cs.uiuc.edu>
@@ -41,29 +41,10 @@
41 41
42;;; Code: 42;;; Code:
43 43
44(require 'calendar) 44(defvar displayed-month)
45(defvar displayed-year)
45 46
46(defun calendar-hebrew-from-absolute (date) 47(require 'calendar)
47 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
48The absolute date is the number of days elapsed since the (imaginary)
49Gregorian date Sunday, December 31, 1 BC."
50 (let* ((greg-date (calendar-gregorian-from-absolute date))
51 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
52 (1- (extract-calendar-month greg-date))))
53 (day)
54 (year (+ 3760 (extract-calendar-year greg-date))))
55 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year))))
56 (setq year (1+ year)))
57 (let ((length (hebrew-calendar-last-month-of-year year)))
58 (while (> date
59 (calendar-absolute-from-hebrew
60 (list month
61 (hebrew-calendar-last-day-of-month month year)
62 year)))
63 (setq month (1+ (% month length)))))
64 (setq day (1+
65 (- date (calendar-absolute-from-hebrew (list month 1 year)))))
66 (list month day year)))
67 48
68(defun hebrew-calendar-leap-year-p (year) 49(defun hebrew-calendar-leap-year-p (year)
69 "t if YEAR is a Hebrew calendar leap year." 50 "t if YEAR is a Hebrew calendar leap year."
@@ -75,15 +56,6 @@ Gregorian date Sunday, December 31, 1 BC."
75 13 56 13
76 12)) 57 12))
77 58
78(defun hebrew-calendar-last-day-of-month (month year)
79 "The last day of MONTH in YEAR."
80 (if (or (memq month (list 2 4 6 10 13))
81 (and (= month 12) (not (hebrew-calendar-leap-year-p year)))
82 (and (= month 8) (not (hebrew-calendar-long-heshvan-p year)))
83 (and (= month 9) (hebrew-calendar-short-kislev-p year)))
84 29
85 30))
86
87(defun hebrew-calendar-elapsed-days (year) 59(defun hebrew-calendar-elapsed-days (year)
88 "Days from Sun. prior to start of Hebrew calendar to mean conjunction of Tishri of Hebrew YEAR." 60 "Days from Sun. prior to start of Hebrew calendar to mean conjunction of Tishri of Hebrew YEAR."
89 (let* ((months-elapsed 61 (let* ((months-elapsed
@@ -133,6 +105,15 @@ Gregorian date Sunday, December 31, 1 BC."
133 "t if Kislev is short in Hebrew YEAR." 105 "t if Kislev is short in Hebrew YEAR."
134 (= (% (hebrew-calendar-days-in-year year) 10) 3)) 106 (= (% (hebrew-calendar-days-in-year year) 10) 3))
135 107
108(defun hebrew-calendar-last-day-of-month (month year)
109 "The last day of MONTH in YEAR."
110 (if (or (memq month (list 2 4 6 10 13))
111 (and (= month 12) (not (hebrew-calendar-leap-year-p year)))
112 (and (= month 8) (not (hebrew-calendar-long-heshvan-p year)))
113 (and (= month 9) (hebrew-calendar-short-kislev-p year)))
114 29
115 30))
116
136(defun calendar-absolute-from-hebrew (date) 117(defun calendar-absolute-from-hebrew (date)
137 "Absolute date of Hebrew DATE. 118 "Absolute date of Hebrew DATE.
138The absolute date is the number of days elapsed since the (imaginary) 119The absolute date is the number of days elapsed since the (imaginary)
@@ -156,13 +137,37 @@ Gregorian date Sunday, December 31, 1 BC."
156 (hebrew-calendar-elapsed-days year);; Days in prior years. 137 (hebrew-calendar-elapsed-days year);; Days in prior years.
157 -1373429))) ;; Days elapsed before absolute date 1. 138 -1373429))) ;; Days elapsed before absolute date 1.
158 139
140(defun calendar-hebrew-from-absolute (date)
141 "Compute the Hebrew date (month day year) corresponding to absolute DATE.
142The absolute date is the number of days elapsed since the (imaginary)
143Gregorian date Sunday, December 31, 1 BC."
144 (let* ((greg-date (calendar-gregorian-from-absolute date))
145 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
146 (1- (extract-calendar-month greg-date))))
147 (day)
148 (year (+ 3760 (extract-calendar-year greg-date))))
149 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year))))
150 (setq year (1+ year)))
151 (let ((length (hebrew-calendar-last-month-of-year year)))
152 (while (> date
153 (calendar-absolute-from-hebrew
154 (list month
155 (hebrew-calendar-last-day-of-month month year)
156 year)))
157 (setq month (1+ (% month length)))))
158 (setq day (1+
159 (- date (calendar-absolute-from-hebrew (list month 1 year)))))
160 (list month day year)))
161
159(defvar calendar-hebrew-month-name-array-common-year 162(defvar calendar-hebrew-month-name-array-common-year
160 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri" 163 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
161 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"]) 164 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar"]
165"Array of strings giving the names of the Hebrew months in a common year.")
162 166
163(defvar calendar-hebrew-month-name-array-leap-year 167(defvar calendar-hebrew-month-name-array-leap-year
164 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri" 168 ["Nisan" "Iyar" "Sivan" "Tammuz" "Av" "Elul" "Tishri"
165 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"]) 169 "Heshvan" "Kislev" "Teveth" "Shevat" "Adar I" "Adar II"]
170"Array of strings giving the names of the Hebrew months in a leap year.")
166 171
167(defun calendar-hebrew-date-string (&optional date) 172(defun calendar-hebrew-date-string (&optional date)
168 "String of Hebrew date before sunset of Gregorian DATE. 173 "String of Hebrew date before sunset of Gregorian DATE.
@@ -525,9 +530,9 @@ not be marked in the calendar. This function is provided for use with the
525 (car d))) 530 (car d)))
526 (backup (equal (car (car d)) 'backup)) 531 (backup (equal (car (car d)) 'backup))
527 (dayname 532 (dayname
528 (concat 533 (format "%s\\|%s\\.?"
529 (calendar-day-name gdate) "\\|" 534 (calendar-day-name gdate)
530 (substring (calendar-day-name gdate) 0 3) ".?")) 535 (calendar-day-name gdate 'abbrev)))
531 (calendar-month-name-array 536 (calendar-month-name-array
532 calendar-hebrew-month-name-array-leap-year) 537 calendar-hebrew-month-name-array-leap-year)
533 (monthname 538 (monthname
@@ -573,7 +578,8 @@ not be marked in the calendar. This function is provided for use with the
573 gdate 578 gdate
574 (buffer-substring-no-properties entry-start (point)) 579 (buffer-substring-no-properties entry-start (point))
575 (buffer-substring-no-properties 580 (buffer-substring-no-properties
576 (1+ date-start) (1- entry-start))))))) 581 (1+ date-start) (1- entry-start))
582 (copy-marker entry-start))))))
577 (setq d (cdr d)))) 583 (setq d (cdr d))))
578 (setq gdate 584 (setq gdate
579 (calendar-gregorian-from-absolute 585 (calendar-gregorian-from-absolute
@@ -581,6 +587,80 @@ not be marked in the calendar. This function is provided for use with the
581 (set-buffer-modified-p diary-modified)) 587 (set-buffer-modified-p diary-modified))
582 (goto-char (point-min)))) 588 (goto-char (point-min))))
583 589
590(defun mark-hebrew-calendar-date-pattern (month day year)
591 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.
592A value of 0 in any position is a wildcard."
593 (save-excursion
594 (set-buffer calendar-buffer)
595 (if (and (/= 0 month) (/= 0 day))
596 (if (/= 0 year)
597 ;; Fully specified Hebrew date.
598 (let ((date (calendar-gregorian-from-absolute
599 (calendar-absolute-from-hebrew
600 (list month day year)))))
601 (if (calendar-date-is-visible-p date)
602 (mark-visible-calendar-date date)))
603 ;; Month and day in any year--this taken from the holiday stuff.
604 (if (memq displayed-month;; This test is only to speed things up a
605 (list ;; bit; it works fine without the test too.
606 (if (< 11 month) (- month 11) (+ month 1))
607 (if (< 10 month) (- month 10) (+ month 2))
608 (if (< 9 month) (- month 9) (+ month 3))
609 (if (< 8 month) (- month 8) (+ month 4))
610 (if (< 7 month) (- month 7) (+ month 5))))
611 (let ((m1 displayed-month)
612 (y1 displayed-year)
613 (m2 displayed-month)
614 (y2 displayed-year)
615 (year))
616 (increment-calendar-month m1 y1 -1)
617 (increment-calendar-month m2 y2 1)
618 (let* ((start-date (calendar-absolute-from-gregorian
619 (list m1 1 y1)))
620 (end-date (calendar-absolute-from-gregorian
621 (list m2
622 (calendar-last-day-of-month m2 y2)
623 y2)))
624 (hebrew-start
625 (calendar-hebrew-from-absolute start-date))
626 (hebrew-end (calendar-hebrew-from-absolute end-date))
627 (hebrew-y1 (extract-calendar-year hebrew-start))
628 (hebrew-y2 (extract-calendar-year hebrew-end)))
629 (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
630 (let ((date (calendar-gregorian-from-absolute
631 (calendar-absolute-from-hebrew
632 (list month day year)))))
633 (if (calendar-date-is-visible-p date)
634 (mark-visible-calendar-date date)))))))
635 ;; Not one of the simple cases--check all visible dates for match.
636 ;; Actually, the following code takes care of ALL of the cases, but
637 ;; it's much too slow to be used for the simple (common) cases.
638 (let ((m displayed-month)
639 (y displayed-year)
640 (first-date)
641 (last-date))
642 (increment-calendar-month m y -1)
643 (setq first-date
644 (calendar-absolute-from-gregorian
645 (list m 1 y)))
646 (increment-calendar-month m y 2)
647 (setq last-date
648 (calendar-absolute-from-gregorian
649 (list m (calendar-last-day-of-month m y) y)))
650 (calendar-for-loop date from first-date to last-date do
651 (let* ((h-date (calendar-hebrew-from-absolute date))
652 (h-month (extract-calendar-month h-date))
653 (h-day (extract-calendar-day h-date))
654 (h-year (extract-calendar-year h-date)))
655 (and (or (zerop month)
656 (= month h-month))
657 (or (zerop day)
658 (= day h-day))
659 (or (zerop year)
660 (= year h-year))
661 (mark-visible-calendar-date
662 (calendar-gregorian-from-absolute date)))))))))
663
584(defun mark-hebrew-diary-entries () 664(defun mark-hebrew-diary-entries ()
585 "Mark days in the calendar window that have Hebrew date diary entries. 665 "Mark days in the calendar window that have Hebrew date diary entries.
586Each entry in diary-file (or included files) visible in the calendar window 666Each entry in diary-file (or included files) visible in the calendar window
@@ -598,11 +678,12 @@ is provided for use as part of the nongregorian-diary-marking-hook."
598 ((date-form (if (equal (car (car d)) 'backup) 678 ((date-form (if (equal (car (car d)) 'backup)
599 (cdr (car d)) 679 (cdr (car d))
600 (car d)));; ignore 'backup directive 680 (car d)));; ignore 'backup directive
601 (dayname (diary-name-pattern calendar-day-name-array)) 681 (dayname (diary-name-pattern calendar-day-name-array
682 calendar-day-abbrev-array))
602 (monthname 683 (monthname
603 (concat 684 (format "%s\\|\\*"
604 (diary-name-pattern calendar-hebrew-month-name-array-leap-year t) 685 (diary-name-pattern
605 "\\|\\*")) 686 calendar-hebrew-month-name-array-leap-year)))
606 (month "[0-9]+\\|\\*") 687 (month "[0-9]+\\|\\*")
607 (day "[0-9]+\\|\\*") 688 (day "[0-9]+\\|\\*")
608 (year "[0-9]+\\|\\*") 689 (year "[0-9]+\\|\\*")
@@ -672,99 +753,21 @@ is provided for use as part of the nongregorian-diary-marking-hook."
672 (string-to-int y-str))))) 753 (string-to-int y-str)))))
673 (if dd-name 754 (if dd-name
674 (mark-calendar-days-named 755 (mark-calendar-days-named
675 (cdr (assoc-ignore-case 756 (cdr (assoc-ignore-case dd-name
676 (substring dd-name 0 3) 757 (calendar-make-alist
677 (calendar-make-alist 758 calendar-day-name-array
678 calendar-day-name-array 759 0 nil calendar-day-abbrev-array))))
679 0
680 '(lambda (x) (substring x 0 3))))))
681 (if mm-name 760 (if mm-name
682 (if (string-equal mm-name "*") 761 (setq mm
683 (setq mm 0) 762 (if (string-equal mm-name "*") 0
684 (setq 763 (cdr
685 mm 764 (assoc-ignore-case
686 (cdr 765 mm-name
687 (assoc-ignore-case 766 (calendar-make-alist
688 mm-name 767 calendar-hebrew-month-name-array-leap-year))))))
689 (calendar-make-alist
690 calendar-hebrew-month-name-array-leap-year))))))
691 (mark-hebrew-calendar-date-pattern mm dd yy))))) 768 (mark-hebrew-calendar-date-pattern mm dd yy)))))
692 (setq d (cdr d))))) 769 (setq d (cdr d)))))
693 770
694(defun mark-hebrew-calendar-date-pattern (month day year)
695 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.
696A value of 0 in any position is a wildcard."
697 (save-excursion
698 (set-buffer calendar-buffer)
699 (if (and (/= 0 month) (/= 0 day))
700 (if (/= 0 year)
701 ;; Fully specified Hebrew date.
702 (let ((date (calendar-gregorian-from-absolute
703 (calendar-absolute-from-hebrew
704 (list month day year)))))
705 (if (calendar-date-is-visible-p date)
706 (mark-visible-calendar-date date)))
707 ;; Month and day in any year--this taken from the holiday stuff.
708 (if (memq displayed-month;; This test is only to speed things up a
709 (list ;; bit; it works fine without the test too.
710 (if (< 11 month) (- month 11) (+ month 1))
711 (if (< 10 month) (- month 10) (+ month 2))
712 (if (< 9 month) (- month 9) (+ month 3))
713 (if (< 8 month) (- month 8) (+ month 4))
714 (if (< 7 month) (- month 7) (+ month 5))))
715 (let ((m1 displayed-month)
716 (y1 displayed-year)
717 (m2 displayed-month)
718 (y2 displayed-year)
719 (year))
720 (increment-calendar-month m1 y1 -1)
721 (increment-calendar-month m2 y2 1)
722 (let* ((start-date (calendar-absolute-from-gregorian
723 (list m1 1 y1)))
724 (end-date (calendar-absolute-from-gregorian
725 (list m2
726 (calendar-last-day-of-month m2 y2)
727 y2)))
728 (hebrew-start
729 (calendar-hebrew-from-absolute start-date))
730 (hebrew-end (calendar-hebrew-from-absolute end-date))
731 (hebrew-y1 (extract-calendar-year hebrew-start))
732 (hebrew-y2 (extract-calendar-year hebrew-end)))
733 (setq year (if (< 6 month) hebrew-y2 hebrew-y1))
734 (let ((date (calendar-gregorian-from-absolute
735 (calendar-absolute-from-hebrew
736 (list month day year)))))
737 (if (calendar-date-is-visible-p date)
738 (mark-visible-calendar-date date)))))))
739 ;; Not one of the simple cases--check all visible dates for match.
740 ;; Actually, the following code takes care of ALL of the cases, but
741 ;; it's much too slow to be used for the simple (common) cases.
742 (let ((m displayed-month)
743 (y displayed-year)
744 (first-date)
745 (last-date))
746 (increment-calendar-month m y -1)
747 (setq first-date
748 (calendar-absolute-from-gregorian
749 (list m 1 y)))
750 (increment-calendar-month m y 2)
751 (setq last-date
752 (calendar-absolute-from-gregorian
753 (list m (calendar-last-day-of-month m y) y)))
754 (calendar-for-loop date from first-date to last-date do
755 (let* ((h-date (calendar-hebrew-from-absolute date))
756 (h-month (extract-calendar-month h-date))
757 (h-day (extract-calendar-day h-date))
758 (h-year (extract-calendar-year h-date)))
759 (and (or (zerop month)
760 (= month h-month))
761 (or (zerop day)
762 (= day h-day))
763 (or (zerop year)
764 (= year h-year))
765 (mark-visible-calendar-date
766 (calendar-gregorian-from-absolute date)))))))))
767
768(defun insert-hebrew-diary-entry (arg) 771(defun insert-hebrew-diary-entry (arg)
769 "Insert a diary entry. 772 "Insert a diary entry.
770For the Hebrew date corresponding to the date indicated by point. 773For the Hebrew date corresponding to the date indicated by point.
@@ -1016,6 +1019,26 @@ use when highlighting the day in the calendar."
1016 h-year)) 1019 h-year))
1017 0 h-month))))))))) 1020 0 h-month)))))))))
1018 1021
1022(defvar hebrew-calendar-parashiot-names
1023["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth"
1024 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi"
1025 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim"
1026 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra"
1027 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim"
1028 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha"
1029 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth"
1030 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim"
1031 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"]
1032 "The names of the parashiot in the Torah.")
1033
1034(defun hebrew-calendar-parasha-name (p)
1035 "Name(s) corresponding to parasha P."
1036 (if (arrayp p);; combined parasha
1037 (format "%s/%s"
1038 (aref hebrew-calendar-parashiot-names (aref p 0))
1039 (aref hebrew-calendar-parashiot-names (aref p 1)))
1040 (aref hebrew-calendar-parashiot-names p)))
1041
1019(defun diary-parasha (&optional mark) 1042(defun diary-parasha (&optional mark)
1020 "Parasha diary entry--entry applies if date is a Saturday. 1043 "Parasha diary entry--entry applies if date is a Saturday.
1021 1044
@@ -1061,18 +1084,6 @@ use when highlighting the day in the calendar."
1061 (hebrew-calendar-parasha-name (cdr parasha)))) 1084 (hebrew-calendar-parasha-name (cdr parasha))))
1062 (hebrew-calendar-parasha-name parasha))))))))) 1085 (hebrew-calendar-parasha-name parasha)))))))))
1063 1086
1064(defvar hebrew-calendar-parashiot-names
1065["Bereshith" "Noah" "Lech L'cha" "Vayera" "Hayei Sarah" "Toledoth"
1066 "Vayetze" "Vayishlah" "Vayeshev" "Mikketz" "Vayiggash" "Vayhi"
1067 "Shemoth" "Vaera" "Bo" "Beshallah" "Yithro" "Mishpatim"
1068 "Terumah" "Tetzavveh" "Ki Tissa" "Vayakhel" "Pekudei" "Vayikra"
1069 "Tzav" "Shemini" "Tazria" "Metzora" "Aharei Moth" "Kedoshim"
1070 "Emor" "Behar" "Behukkotai" "Bemidbar" "Naso" "Behaalot'cha"
1071 "Shelah L'cha" "Korah" "Hukkath" "Balak" "Pinhas" "Mattoth"
1072 "Masei" "Devarim" "Vaethanan" "Ekev" "Reeh" "Shofetim"
1073 "Ki Tetze" "Ki Tavo" "Nitzavim" "Vayelech" "Haazinu"]
1074 "The names of the parashiot in the Torah.")
1075
1076;; The seven ordinary year types (keviot) 1087;; The seven ordinary year types (keviot)
1077 1088
1078(defconst hebrew-calendar-year-Saturday-incomplete-Sunday 1089(defconst hebrew-calendar-year-Saturday-incomplete-Sunday
@@ -1192,14 +1203,6 @@ have 29 days), and has Passover start on Sunday.")
1192Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev both 1203Hebrew year that starts on Thursday, is `complete' (Heshvan and Kislev both
1193have 30 days), and has Passover start on Tuesday.") 1204have 30 days), and has Passover start on Tuesday.")
1194 1205
1195(defun hebrew-calendar-parasha-name (p)
1196 "Name(s) corresponding to parasha P."
1197 (if (arrayp p);; combined parasha
1198 (format "%s/%s"
1199 (aref hebrew-calendar-parashiot-names (aref p 0))
1200 (aref hebrew-calendar-parashiot-names (aref p 1)))
1201 (aref hebrew-calendar-parashiot-names p)))
1202
1203(provide 'cal-hebrew) 1206(provide 'cal-hebrew)
1204 1207
1205;;; cal-hebrew.el ends here 1208;;; cal-hebrew.el ends here