aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2008-03-16 01:25:11 +0000
committerGlenn Morris2008-03-16 01:25:11 +0000
commit28c0279602d6004f51e679fee1acd31dc13af7f3 (patch)
tree7bc89e2395a6c516c864904d597c0594da83f538
parentdb274c7a061fd40e54fdd3b4a590959bda03c48e (diff)
downloademacs-28c0279602d6004f51e679fee1acd31dc13af7f3.tar.gz
emacs-28c0279602d6004f51e679fee1acd31dc13af7f3.zip
(calendar-mark-complex): Autoload it.
(mark-hebrew-calendar-date-pattern): Add optional argument `color'. Use calendar-mark-complex. (calendar-absolute-from-hebrew, hebrew-calendar-yahrzeit) (insert-hebrew-diary-entry, insert-monthly-hebrew-diary-entry) (insert-yearly-hebrew-diary-entry): Use let rather than let*. (calendar-hebrew-prompt-for-date): New function. (calendar-goto-hebrew-date): Use calendar-hebrew-prompt-for-date. (holiday-tisha-b-av-etc): Use unless, let.
-rw-r--r--lisp/calendar/cal-hebrew.el219
1 files changed, 93 insertions, 126 deletions
diff --git a/lisp/calendar/cal-hebrew.el b/lisp/calendar/cal-hebrew.el
index 8fcc88a6382..93a8e2c17cc 100644
--- a/lisp/calendar/cal-hebrew.el
+++ b/lisp/calendar/cal-hebrew.el
@@ -111,9 +111,9 @@
111 "Absolute date of Hebrew DATE. 111 "Absolute date of Hebrew DATE.
112The absolute date is the number of days elapsed since the (imaginary) 112The absolute date is the number of days elapsed since the (imaginary)
113Gregorian date Sunday, December 31, 1 BC." 113Gregorian date Sunday, December 31, 1 BC."
114 (let* ((month (extract-calendar-month date)) 114 (let ((month (extract-calendar-month date))
115 (day (extract-calendar-day date)) 115 (day (extract-calendar-day date))
116 (year (extract-calendar-year date))) 116 (year (extract-calendar-year date)))
117 (+ day ; days so far this month 117 (+ day ; days so far this month
118 (if (< month 7) ; before Tishri 118 (if (< month 7) ; before Tishri
119 ;; Then add days in prior months this year before and after Nisan. 119 ;; Then add days in prior months this year before and after Nisan.
@@ -135,10 +135,10 @@ Gregorian date Sunday, December 31, 1 BC."
135The absolute date is the number of days elapsed since the (imaginary) 135The absolute date is the number of days elapsed since the (imaginary)
136Gregorian date Sunday, December 31, 1 BC." 136Gregorian date Sunday, December 31, 1 BC."
137 (let* ((greg-date (calendar-gregorian-from-absolute date)) 137 (let* ((greg-date (calendar-gregorian-from-absolute date))
138 (year (+ 3760 (extract-calendar-year greg-date)))
138 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8] 139 (month (aref [9 10 11 12 1 2 3 4 7 7 7 8]
139 (1- (extract-calendar-month greg-date)))) 140 (1- (extract-calendar-month greg-date))))
140 (day) 141 day)
141 (year (+ 3760 (extract-calendar-year greg-date))))
142 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year)))) 142 (while (>= date (calendar-absolute-from-hebrew (list 7 1 (1+ year))))
143 (setq year (1+ year))) 143 (setq year (1+ year)))
144 (let ((length (hebrew-calendar-last-month-of-year year))) 144 (let ((length (hebrew-calendar-last-month-of-year year)))
@@ -185,9 +185,9 @@ Driven by the variable `calendar-date-display-form'."
185 185
186(defun hebrew-calendar-yahrzeit (death-date year) 186(defun hebrew-calendar-yahrzeit (death-date year)
187 "Absolute date of the anniversary of Hebrew DEATH-DATE in Hebrew YEAR." 187 "Absolute date of the anniversary of Hebrew DEATH-DATE in Hebrew YEAR."
188 (let* ((death-day (extract-calendar-day death-date)) 188 (let ((death-day (extract-calendar-day death-date))
189 (death-month (extract-calendar-month death-date)) 189 (death-month (extract-calendar-month death-date))
190 (death-year (extract-calendar-year death-date))) 190 (death-year (extract-calendar-year death-date)))
191 (cond 191 (cond
192 ;; If it's Heshvan 30 it depends on the first anniversary; if 192 ;; If it's Heshvan 30 it depends on the first anniversary; if
193 ;; that was not Heshvan 30, use the day before Kislev 1. 193 ;; that was not Heshvan 30, use the day before Kislev 1.
@@ -216,49 +216,52 @@ Driven by the variable `calendar-date-display-form'."
216 (t (calendar-absolute-from-hebrew 216 (t (calendar-absolute-from-hebrew
217 (list death-month death-day year)))))) 217 (list death-month death-day year))))))
218 218
219(defun calendar-hebrew-prompt-for-date ()
220 "Ask for a Hebrew date."
221 (let* ((today (calendar-current-date))
222 (year (calendar-read
223 "Hebrew calendar year (>3760): "
224 (lambda (x) (> x 3760))
225 (int-to-string
226 (extract-calendar-year
227 (calendar-hebrew-from-absolute
228 (calendar-absolute-from-gregorian today))))))
229 (month-array (if (hebrew-calendar-leap-year-p year)
230 calendar-hebrew-month-name-array-leap-year
231 calendar-hebrew-month-name-array-common-year))
232 (completion-ignore-case t)
233 (month (cdr (assoc-string
234 (completing-read
235 "Hebrew calendar month name: "
236 (mapcar 'list (append month-array nil))
237 (if (= year 3761)
238 (lambda (x)
239 (let ((m (cdr
240 (assoc-string
241 (car x)
242 (calendar-make-alist month-array)
243 t))))
244 (< 0
245 (calendar-absolute-from-hebrew
246 (list m
247 (hebrew-calendar-last-day-of-month
248 m year)
249 year))))))
250 t)
251 (calendar-make-alist month-array 1) t)))
252 (last (hebrew-calendar-last-day-of-month month year))
253 (first (if (and (= year 3761) (= month 10))
254 18 1))
255 (day (calendar-read
256 (format "Hebrew calendar day (%d-%d): "
257 first last)
258 (lambda (x) (and (<= first x) (<= x last))))))
259 (list (list month day year))))
260
219;;;###cal-autoload 261;;;###cal-autoload
220(defun calendar-goto-hebrew-date (date &optional noecho) 262(defun calendar-goto-hebrew-date (date &optional noecho)
221 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is non-nil." 263 "Move cursor to Hebrew DATE; echo Hebrew date unless NOECHO is non-nil."
222 (interactive 264 (interactive (calendar-hebrew-prompt-for-date))
223 (let* ((today (calendar-current-date))
224 (year (calendar-read
225 "Hebrew calendar year (>3760): "
226 (lambda (x) (> x 3760))
227 (int-to-string
228 (extract-calendar-year
229 (calendar-hebrew-from-absolute
230 (calendar-absolute-from-gregorian today))))))
231 (month-array (if (hebrew-calendar-leap-year-p year)
232 calendar-hebrew-month-name-array-leap-year
233 calendar-hebrew-month-name-array-common-year))
234 (completion-ignore-case t)
235 (month (cdr (assoc-string
236 (completing-read
237 "Hebrew calendar month name: "
238 (mapcar 'list (append month-array nil))
239 (if (= year 3761)
240 (lambda (x)
241 (let ((m (cdr
242 (assoc-string
243 (car x)
244 (calendar-make-alist month-array)
245 t))))
246 (< 0
247 (calendar-absolute-from-hebrew
248 (list m
249 (hebrew-calendar-last-day-of-month
250 m year)
251 year))))))
252 t)
253 (calendar-make-alist month-array 1) t)))
254 (last (hebrew-calendar-last-day-of-month month year))
255 (first (if (and (= year 3761) (= month 10))
256 18 1))
257 (day (calendar-read
258 (format "Hebrew calendar day (%d-%d): "
259 first last)
260 (lambda (x) (and (<= first x) (<= x last))))))
261 (list (list month day year))))
262 (calendar-goto-date (calendar-gregorian-from-absolute 265 (calendar-goto-date (calendar-gregorian-from-absolute
263 (calendar-absolute-from-hebrew date))) 266 (calendar-absolute-from-hebrew date)))
264 (or noecho (calendar-print-hebrew-date))) 267 (or noecho (calendar-print-hebrew-date)))
@@ -308,9 +311,8 @@ nil if it is not visible in the current calendar window."
308;;;###holiday-autoload 311;;;###holiday-autoload
309(defun holiday-rosh-hashanah-etc () 312(defun holiday-rosh-hashanah-etc ()
310 "List of dates related to Rosh Hashanah, as visible in calendar window." 313 "List of dates related to Rosh Hashanah, as visible in calendar window."
311 (if (or (< displayed-month 8) 314 (unless (or (< displayed-month 8) ; none of the dates is visible
312 (> displayed-month 11)) 315 (> displayed-month 11))
313 nil ; none of the dates is visible
314 (let* ((abs-r-h (calendar-absolute-from-hebrew 316 (let* ((abs-r-h (calendar-absolute-from-hebrew
315 (list 7 1 (+ displayed-year 3761)))) 317 (list 7 1 (+ displayed-year 3761))))
316 (mandatory 318 (mandatory
@@ -403,8 +405,7 @@ nil if it is not visible in the current calendar window."
403;;;###holiday-autoload 405;;;###holiday-autoload
404(defun holiday-passover-etc () 406(defun holiday-passover-etc ()
405 "List of dates related to Passover, as visible in calendar window." 407 "List of dates related to Passover, as visible in calendar window."
406 (if (< 7 displayed-month) 408 (unless (< 7 displayed-month) ; none of the dates is visible
407 nil ; none of the dates is visible
408 (let* ((abs-p (calendar-absolute-from-hebrew 409 (let* ((abs-p (calendar-absolute-from-hebrew
409 (list 1 15 (+ displayed-year 3760)))) 410 (list 1 15 (+ displayed-year 3760))))
410 (mandatory 411 (mandatory
@@ -488,12 +489,10 @@ nil if it is not visible in the current calendar window."
488;;;###holiday-autoload 489;;;###holiday-autoload
489(defun holiday-tisha-b-av-etc () 490(defun holiday-tisha-b-av-etc ()
490 "List of dates around Tisha B'Av, as visible in calendar window." 491 "List of dates around Tisha B'Av, as visible in calendar window."
491 (if (or (< displayed-month 5) 492 (unless (or (< displayed-month 5) ; none of the dates is visible
492 (> displayed-month 9)) 493 (> displayed-month 9))
493 nil ; none of the dates is visible 494 (let ((abs-t-a (calendar-absolute-from-hebrew
494 (let* ((abs-t-a (calendar-absolute-from-hebrew 495 (list 5 9 (+ displayed-year 3760)))))
495 (list 5 9 (+ displayed-year 3760)))))
496
497 (holiday-filter-visible-calendar 496 (holiday-filter-visible-calendar
498 (list 497 (list
499 (list (calendar-gregorian-from-absolute 498 (list (calendar-gregorian-from-absolute
@@ -528,10 +527,15 @@ is provided for use with `nongregorian-diary-listing-hook'."
528 hebrew-diary-entry-symbol 527 hebrew-diary-entry-symbol
529 'calendar-hebrew-from-absolute)) 528 'calendar-hebrew-from-absolute))
530 529
530(autoload 'calendar-mark-complex "diary-lib")
531
531;;;###diary-autoload 532;;;###diary-autoload
532(defun mark-hebrew-calendar-date-pattern (month day year) 533(defun mark-hebrew-calendar-date-pattern (month day year &optional color)
533 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR. 534 "Mark dates in calendar window that conform to Hebrew date MONTH/DAY/YEAR.
534A value of 0 in any position is a wildcard." 535A value of 0 in any position is a wildcard. Optional argument COLOR is
536passed to `mark-visible-calendar-date' as MARK."
537 ;; FIXME not the same as the Bahai and Islamic cases, so can't use
538 ;; calendar-mark-1.
535 (save-excursion 539 (save-excursion
536 (set-buffer calendar-buffer) 540 (set-buffer calendar-buffer)
537 (if (and (not (zerop month)) (not (zerop day))) 541 (if (and (not (zerop month)) (not (zerop day)))
@@ -541,7 +545,7 @@ A value of 0 in any position is a wildcard."
541 (calendar-absolute-from-hebrew 545 (calendar-absolute-from-hebrew
542 (list month day year))))) 546 (list month day year)))))
543 (if (calendar-date-is-visible-p date) 547 (if (calendar-date-is-visible-p date)
544 (mark-visible-calendar-date date))) 548 (mark-visible-calendar-date date color)))
545 ;; Month and day in any year--this taken from the holiday stuff. 549 ;; Month and day in any year--this taken from the holiday stuff.
546 ;; This test is only to speed things up a bit, it works 550 ;; This test is only to speed things up a bit, it works
547 ;; fine without it. 551 ;; fine without it.
@@ -556,7 +560,7 @@ A value of 0 in any position is a wildcard."
556 (y1 displayed-year) 560 (y1 displayed-year)
557 (m2 displayed-month) 561 (m2 displayed-month)
558 (y2 displayed-year) 562 (y2 displayed-year)
559 (year)) 563 year)
560 (increment-calendar-month m1 y1 -1) 564 (increment-calendar-month m1 y1 -1)
561 (increment-calendar-month m2 y2 1) 565 (increment-calendar-month m2 y2 1)
562 (let* ((start-date (calendar-absolute-from-gregorian 566 (let* ((start-date (calendar-absolute-from-gregorian
@@ -565,8 +569,7 @@ A value of 0 in any position is a wildcard."
565 (list m2 569 (list m2
566 (calendar-last-day-of-month m2 y2) 570 (calendar-last-day-of-month m2 y2)
567 y2))) 571 y2)))
568 (hebrew-start 572 (hebrew-start (calendar-hebrew-from-absolute start-date))
569 (calendar-hebrew-from-absolute start-date))
570 (hebrew-end (calendar-hebrew-from-absolute end-date)) 573 (hebrew-end (calendar-hebrew-from-absolute end-date))
571 (hebrew-y1 (extract-calendar-year hebrew-start)) 574 (hebrew-y1 (extract-calendar-year hebrew-start))
572 (hebrew-y2 (extract-calendar-year hebrew-end))) 575 (hebrew-y2 (extract-calendar-year hebrew-end)))
@@ -575,36 +578,9 @@ A value of 0 in any position is a wildcard."
575 (calendar-absolute-from-hebrew 578 (calendar-absolute-from-hebrew
576 (list month day year))))) 579 (list month day year)))))
577 (if (calendar-date-is-visible-p date) 580 (if (calendar-date-is-visible-p date)
578 (mark-visible-calendar-date date))))))) 581 (mark-visible-calendar-date date color)))))))
579 ;; Not one of the simple cases--check all visible dates for match. 582 (calendar-mark-complex month day year
580 ;; Actually, the following code takes care of ALL of the cases, but 583 'calendar-hebrew-from-absolute color))))
581 ;; it's much too slow to be used for the simple (common) cases.
582 (let ((m displayed-month)
583 (y displayed-year)
584 (first-date)
585 (last-date))
586 (increment-calendar-month m y -1)
587 (setq first-date
588 (calendar-absolute-from-gregorian
589 (list m 1 y)))
590 (increment-calendar-month m y 2)
591 (setq last-date
592 (calendar-absolute-from-gregorian
593 (list m (calendar-last-day-of-month m y) y)))
594 (calendar-for-loop date from first-date to last-date do
595 (let* ((h-date (calendar-hebrew-from-absolute date))
596 (h-month (extract-calendar-month h-date))
597 (h-day (extract-calendar-day h-date))
598 (h-year (extract-calendar-year h-date)))
599 (and (or (zerop month)
600 (= month h-month))
601 (or (zerop day)
602 (= day h-day))
603 (or (zerop year)
604 (= year h-year))
605 (mark-visible-calendar-date
606 (calendar-gregorian-from-absolute date)))))
607 ))))
608 584
609(autoload 'diary-mark-entries-1 "diary-lib") 585(autoload 'diary-mark-entries-1 "diary-lib")
610 586
@@ -624,16 +600,13 @@ window. See `list-hebrew-diary-entries' for more information."
624For the Hebrew date corresponding to the date indicated by point. 600For the Hebrew date corresponding to the date indicated by point.
625Prefix argument ARG makes the entry nonmarking." 601Prefix argument ARG makes the entry nonmarking."
626 (interactive "P") 602 (interactive "P")
627 (let* ((calendar-month-name-array 603 (let ((calendar-month-name-array calendar-hebrew-month-name-array-leap-year))
628 calendar-hebrew-month-name-array-leap-year))
629 (make-diary-entry 604 (make-diary-entry
630 (concat 605 (concat hebrew-diary-entry-symbol
631 hebrew-diary-entry-symbol 606 (calendar-date-string
632 (calendar-date-string 607 (calendar-hebrew-from-absolute
633 (calendar-hebrew-from-absolute 608 (calendar-absolute-from-gregorian (calendar-cursor-to-date t)))
634 (calendar-absolute-from-gregorian 609 nil t))
635 (calendar-cursor-to-date t)))
636 nil t))
637 arg))) 610 arg)))
638 611
639;;;###cal-autoload 612;;;###cal-autoload
@@ -642,17 +615,15 @@ Prefix argument ARG makes the entry nonmarking."
642For the day of the Hebrew month corresponding to the date indicated by point. 615For the day of the Hebrew month corresponding to the date indicated by point.
643Prefix argument ARG makes the entry nonmarking." 616Prefix argument ARG makes the entry nonmarking."
644 (interactive "P") 617 (interactive "P")
645 (let* ((calendar-date-display-form 618 (let ((calendar-date-display-form (if european-calendar-style
646 (if european-calendar-style '(day " * ") '("* " day ))) 619 '(day " * ")
647 (calendar-month-name-array 620 '("* " day )))
648 calendar-hebrew-month-name-array-leap-year)) 621 (calendar-month-name-array calendar-hebrew-month-name-array-leap-year))
649 (make-diary-entry 622 (make-diary-entry
650 (concat 623 (concat hebrew-diary-entry-symbol
651 hebrew-diary-entry-symbol 624 (calendar-date-string
652 (calendar-date-string 625 (calendar-hebrew-from-absolute
653 (calendar-hebrew-from-absolute 626 (calendar-absolute-from-gregorian (calendar-cursor-to-date t)))))
654 (calendar-absolute-from-gregorian
655 (calendar-cursor-to-date t)))))
656 arg))) 627 arg)))
657 628
658;;;###cal-autoload 629;;;###cal-autoload
@@ -661,19 +632,15 @@ Prefix argument ARG makes the entry nonmarking."
661For the day of the Hebrew year corresponding to the date indicated by point. 632For the day of the Hebrew year corresponding to the date indicated by point.
662Prefix argument ARG makes the entry nonmarking." 633Prefix argument ARG makes the entry nonmarking."
663 (interactive "P") 634 (interactive "P")
664 (let* ((calendar-date-display-form 635 (let ((calendar-date-display-form (if european-calendar-style
665 (if european-calendar-style 636 '(day " " monthname)
666 '(day " " monthname) 637 '(monthname " " day)))
667 '(monthname " " day))) 638 (calendar-month-name-array calendar-hebrew-month-name-array-leap-year))
668 (calendar-month-name-array
669 calendar-hebrew-month-name-array-leap-year))
670 (make-diary-entry 639 (make-diary-entry
671 (concat 640 (concat hebrew-diary-entry-symbol
672 hebrew-diary-entry-symbol 641 (calendar-date-string
673 (calendar-date-string 642 (calendar-hebrew-from-absolute
674 (calendar-hebrew-from-absolute 643 (calendar-absolute-from-gregorian (calendar-cursor-to-date t)))))
675 (calendar-absolute-from-gregorian
676 (calendar-cursor-to-date t)))))
677 arg))) 644 arg)))
678 645
679;;;###autoload 646;;;###autoload