13053
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
1 ;;; cal-islamic.el --- calendar functions for the Islamic calendar.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
2
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
4
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
6 ;; Keywords: calendar
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
7 ;; Human-Keywords: Islamic calendar, calendar, diary
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
8
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
10
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
14 ;; any later version.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
15
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
20
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
24
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
25 ;;; Commentary:
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
26
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
27 ;; This collection of functions implements the features of calendar.el and
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
28 ;; diary.el that deal with the Islamic calendar.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
29
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
30 ;; Comments, corrections, and improvements should be sent to
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
31 ;; Edward M. Reingold Department of Computer Science
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
32 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
33 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
34 ;; Urbana, Illinois 61801
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
35
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
36 ;;; Code:
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
37
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
38 (require 'cal-julian)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
39
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
40 (defvar calendar-islamic-month-name-array
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
41 ["Muharram" "Safar" "Rabi I" "Rabi II" "Jumada I" "Jumada II"
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
42 "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"])
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
43
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
44 (defvar calendar-islamic-epoch (calendar-absolute-from-julian '(7 16 622))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
45 "Absolute date of start of Islamic calendar = August 29, 284 A.D. (Julian).")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
46
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
47 (defun islamic-calendar-leap-year-p (year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
48 "Returns t if YEAR is a leap year on the Islamic calendar."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
49 (memq (% year 30)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
50 (list 2 5 7 10 13 16 18 21 24 26 29)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
51
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
52 (defun islamic-calendar-last-day-of-month (month year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
53 "The last day in MONTH during YEAR on the Islamic calendar."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
54 (cond
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
55 ((memq month (list 1 3 5 7 9 11)) 30)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
56 ((memq month (list 2 4 6 8 10)) 29)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
57 (t (if (islamic-calendar-leap-year-p year) 30 29))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
58
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
59 (defun islamic-calendar-day-number (date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
60 "Return the day number within the year of the Islamic date DATE."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
61 (let* ((month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
62 (day (extract-calendar-day date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
63 (+ (* 30 (/ month 2))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
64 (* 29 (/ (1- month) 2))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
65 day)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
66
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
67 (defun calendar-absolute-from-islamic (date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
68 "Absolute date of Islamic DATE.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
69 The absolute date is the number of days elapsed since the (imaginary)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
70 Gregorian date Sunday, December 31, 1 BC."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
71 (let* ((month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
72 (day (extract-calendar-day date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
73 (year (extract-calendar-year date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
74 (y (% year 30))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
75 (leap-years-in-cycle
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
76 (cond
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
77 ((< y 3) 0) ((< y 6) 1) ((< y 8) 2) ((< y 11) 3) ((< y 14) 4)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
78 ((< y 17) 5) ((< y 19) 6) ((< y 22) 7) ((< y 25) 8) ((< y 27) 9)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
79 (t 10))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
80 (+ (islamic-calendar-day-number date);; days so far this year
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
81 (* (1- year) 354) ;; days in all non-leap years
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
82 (* 11 (/ year 30)) ;; leap days in complete cycles
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
83 leap-years-in-cycle ;; leap days this cycle
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
84 (1- calendar-islamic-epoch)))) ;; days before start of calendar
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
85
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
86 (defun calendar-islamic-from-absolute (date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
87 "Compute the Islamic date (month day year) corresponding to absolute DATE.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
88 The absolute date is the number of days elapsed since the (imaginary)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
89 Gregorian date Sunday, December 31, 1 BC."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
90 (if (< date calendar-islamic-epoch)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
91 (list 0 0 0);; pre-Islamic date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
92 (let* ((approx (/ (- date calendar-islamic-epoch)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
93 355));; Approximation from below.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
94 (year ;; Search forward from the approximation.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
95 (+ approx
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
96 (calendar-sum y approx
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
97 (>= date (calendar-absolute-from-islamic
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
98 (list 1 1 (1+ y))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
99 1)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
100 (month ;; Search forward from Muharram.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
101 (1+ (calendar-sum m 1
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
102 (> date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
103 (calendar-absolute-from-islamic
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
104 (list m
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
105 (islamic-calendar-last-day-of-month
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
106 m year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
107 year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
108 1)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
109 (day ;; Calculate the day by subtraction.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
110 (- date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
111 (1- (calendar-absolute-from-islamic (list month 1 year))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
112 (list month day year))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
113
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
114 (defun calendar-islamic-date-string (&optional date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
115 "String of Islamic date before sunset of Gregorian DATE.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
116 Returns the empty string if DATE is pre-Islamic.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
117 Defaults to today's date if DATE is not given.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
118 Driven by the variable `calendar-date-display-form'."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
119 (let ((calendar-month-name-array calendar-islamic-month-name-array)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
120 (islamic-date (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
121 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
122 (or date (calendar-current-date))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
123 (if (< (extract-calendar-year islamic-date) 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
124 ""
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
125 (calendar-date-string islamic-date nil t))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
126
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
127 (defun calendar-print-islamic-date ()
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
128 "Show the Islamic calendar equivalent of the date under the cursor."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
129 (interactive)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
130 (let ((i (calendar-islamic-date-string (calendar-cursor-to-date t))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
131 (if (string-equal i "")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
132 (message "Date is pre-Islamic")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
133 (message "Islamic date (until sunset): %s" i))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
134
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
135 (defun calendar-goto-islamic-date (date &optional noecho)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
136 "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is t."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
137 (interactive
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
138 (let* ((today (calendar-current-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
139 (year (calendar-read
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
140 "Islamic calendar year (>0): "
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
141 '(lambda (x) (> x 0))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
142 (int-to-string
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
143 (extract-calendar-year
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
144 (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
145 (calendar-absolute-from-gregorian today))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
146 (month-array calendar-islamic-month-name-array)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
147 (completion-ignore-case t)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
148 (month (cdr (assoc
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
149 (capitalize
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
150 (completing-read
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
151 "Islamic calendar month name: "
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
152 (mapcar 'list (append month-array nil))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
153 nil t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
154 (calendar-make-alist month-array 1 'capitalize))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
155 (last (islamic-calendar-last-day-of-month month year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
156 (day (calendar-read
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
157 (format "Islamic calendar day (1-%d): " last)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
158 '(lambda (x) (and (< 0 x) (<= x last))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
159 (list (list month day year))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
160 (calendar-goto-date (calendar-gregorian-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
161 (calendar-absolute-from-islamic date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
162 (or noecho (calendar-print-islamic-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
163
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
164 (defun diary-islamic-date ()
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
165 "Islamic calendar equivalent of date diary entry."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
166 (let ((i (calendar-islamic-date-string (calendar-cursor-to-date t))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
167 (if (string-equal i "")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
168 "Date is pre-Islamic"
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
169 (format "Islamic date (until sunset): %s" i))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
170
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
171 (defun holiday-islamic (month day string)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
172 "Holiday on MONTH, DAY (Islamic) called STRING.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
173 If MONTH, DAY (Islamic) is visible, the value returned is corresponding
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
174 Gregorian date in the form of the list (((month day year) STRING)). Returns
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
175 nil if it is not visible in the current calendar window."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
176 (let* ((islamic-date (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
177 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
178 (list displayed-month 15 displayed-year))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
179 (m (extract-calendar-month islamic-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
180 (y (extract-calendar-year islamic-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
181 (date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
182 (if (< m 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
183 nil;; Islamic calendar doesn't apply.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
184 (increment-calendar-month m y (- 10 month))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
185 (if (> m 7);; Islamic date might be visible
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
186 (let ((date (calendar-gregorian-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
187 (calendar-absolute-from-islamic (list month day y)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
188 (if (calendar-date-is-visible-p date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
189 (list (list date string))))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
190
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
191 (defun list-islamic-diary-entries ()
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
192 "Add any Islamic date entries from the diary file to `diary-entries-list'.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
193 Islamic date diary entries must be prefaced by an `islamic-diary-entry-symbol'
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
194 \(normally an `I'). The same diary date forms govern the style of the Islamic
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
195 calendar entries, except that the Islamic month names must be spelled in full.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
196 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
197 Dhu al-Hijjah. If an Islamic date diary entry begins with a
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
198 `diary-nonmarking-symbol', the entry will appear in the diary listing, but will
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
199 not be marked in the calendar. This function is provided for use with the
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
200 `nongregorian-diary-listing-hook'."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
201 (if (< 0 number)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
202 (let ((buffer-read-only nil)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
203 (diary-modified (buffer-modified-p))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
204 (gdate original-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
205 (mark (regexp-quote diary-nonmarking-symbol)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
206 (calendar-for-loop i from 1 to number do
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
207 (let* ((d diary-date-forms)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
208 (idate (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
209 (calendar-absolute-from-gregorian gdate)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
210 (month (extract-calendar-month idate))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
211 (day (extract-calendar-day idate))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
212 (year (extract-calendar-year idate)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
213 (while d
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
214 (let*
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
215 ((date-form (if (equal (car (car d)) 'backup)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
216 (cdr (car d))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
217 (car d)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
218 (backup (equal (car (car d)) 'backup))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
219 (dayname
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
220 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
221 (calendar-day-name gdate) "\\|"
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
222 (substring (calendar-day-name gdate) 0 3) ".?"))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
223 (calendar-month-name-array
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
224 calendar-islamic-month-name-array)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
225 (monthname
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
226 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
227 "\\*\\|"
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
228 (calendar-month-name month)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
229 (month (concat "\\*\\|0*" (int-to-string month)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
230 (day (concat "\\*\\|0*" (int-to-string day)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
231 (year
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
232 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
233 "\\*\\|0*" (int-to-string year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
234 (if abbreviated-calendar-year
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
235 (concat "\\|" (int-to-string (% year 100)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
236 "")))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
237 (regexp
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
238 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
239 "\\(\\`\\|\^M\\|\n\\)" mark "?"
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
240 (regexp-quote islamic-diary-entry-symbol)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
241 "\\("
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
242 (mapconcat 'eval date-form "\\)\\(")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
243 "\\)"))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
244 (case-fold-search t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
245 (goto-char (point-min))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
246 (while (re-search-forward regexp nil t)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
247 (if backup (re-search-backward "\\<" nil t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
248 (if (and (or (char-equal (preceding-char) ?\^M)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
249 (char-equal (preceding-char) ?\n))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
250 (not (looking-at " \\|\^I")))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
251 ;; Diary entry that consists only of date.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
252 (backward-char 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
253 ;; Found a nonempty diary entry--make it visible and
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
254 ;; add it to the list.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
255 (let ((entry-start (point))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
256 (date-start))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
257 (re-search-backward "\^M\\|\n\\|\\`")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
258 (setq date-start (point))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
259 (re-search-forward "\^M\\|\n" nil t 2)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
260 (while (looking-at " \\|\^I")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
261 (re-search-forward "\^M\\|\n" nil t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
262 (backward-char 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
263 (subst-char-in-region date-start (point) ?\^M ?\n t)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
264 (add-to-diary-list
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
265 gdate (buffer-substring entry-start (point)))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
266 (setq d (cdr d))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
267 (setq gdate
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
268 (calendar-gregorian-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
269 (1+ (calendar-absolute-from-gregorian gdate)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
270 (set-buffer-modified-p diary-modified))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
271 (goto-char (point-min))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
272
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
273 (defun mark-islamic-diary-entries ()
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
274 "Mark days in the calendar window that have Islamic date diary entries.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
275 Each entry in diary-file (or included files) visible in the calendar window
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
276 is marked. Islamic date entries are prefaced by a islamic-diary-entry-symbol
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
277 \(normally an `I'). The same diary-date-forms govern the style of the Islamic
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
278 calendar entries, except that the Islamic month names must be spelled in full.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
279 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
280 Dhu al-Hijjah. Islamic date diary entries that begin with a
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
281 diary-nonmarking-symbol will not be marked in the calendar. This function is
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
282 provided for use as part of the nongregorian-diary-marking-hook."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
283 (let ((d diary-date-forms))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
284 (while d
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
285 (let*
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
286 ((date-form (if (equal (car (car d)) 'backup)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
287 (cdr (car d))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
288 (car d)));; ignore 'backup directive
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
289 (dayname (diary-name-pattern calendar-day-name-array))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
290 (monthname
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
291 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
292 (diary-name-pattern calendar-islamic-month-name-array t)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
293 "\\|\\*"))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
294 (month "[0-9]+\\|\\*")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
295 (day "[0-9]+\\|\\*")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
296 (year "[0-9]+\\|\\*")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
297 (l (length date-form))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
298 (d-name-pos (- l (length (memq 'dayname date-form))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
299 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
300 (m-name-pos (- l (length (memq 'monthname date-form))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
301 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
302 (d-pos (- l (length (memq 'day date-form))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
303 (d-pos (if (/= l d-pos) (+ 2 d-pos)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
304 (m-pos (- l (length (memq 'month date-form))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
305 (m-pos (if (/= l m-pos) (+ 2 m-pos)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
306 (y-pos (- l (length (memq 'year date-form))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
307 (y-pos (if (/= l y-pos) (+ 2 y-pos)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
308 (regexp
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
309 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
310 "\\(\\`\\|\^M\\|\n\\)"
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
311 (regexp-quote islamic-diary-entry-symbol)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
312 "\\("
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
313 (mapconcat 'eval date-form "\\)\\(")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
314 "\\)"))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
315 (case-fold-search t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
316 (goto-char (point-min))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
317 (while (re-search-forward regexp nil t)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
318 (let* ((dd-name
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
319 (if d-name-pos
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
320 (buffer-substring
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
321 (match-beginning d-name-pos)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
322 (match-end d-name-pos))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
323 (mm-name
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
324 (if m-name-pos
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
325 (buffer-substring
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
326 (match-beginning m-name-pos)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
327 (match-end m-name-pos))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
328 (mm (string-to-int
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
329 (if m-pos
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
330 (buffer-substring
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
331 (match-beginning m-pos)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
332 (match-end m-pos))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
333 "")))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
334 (dd (string-to-int
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
335 (if d-pos
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
336 (buffer-substring
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
337 (match-beginning d-pos)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
338 (match-end d-pos))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
339 "")))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
340 (y-str (if y-pos
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
341 (buffer-substring
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
342 (match-beginning y-pos)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
343 (match-end y-pos))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
344 (yy (if (not y-str)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
345 0
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
346 (if (and (= (length y-str) 2)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
347 abbreviated-calendar-year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
348 (let* ((current-y
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
349 (extract-calendar-year
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
350 (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
351 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
352 (calendar-current-date)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
353 (y (+ (string-to-int y-str)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
354 (* 100 (/ current-y 100)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
355 (if (> (- y current-y) 50)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
356 (- y 100)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
357 (if (> (- current-y y) 50)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
358 (+ y 100)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
359 y)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
360 (string-to-int y-str)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
361 (if dd-name
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
362 (mark-calendar-days-named
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
363 (cdr (assoc (capitalize (substring dd-name 0 3))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
364 (calendar-make-alist
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
365 calendar-day-name-array
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
366 0
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
367 '(lambda (x) (substring x 0 3))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
368 (if mm-name
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
369 (if (string-equal mm-name "*")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
370 (setq mm 0)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
371 (setq mm
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
372 (cdr (assoc
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
373 (capitalize mm-name)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
374 (calendar-make-alist
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
375 calendar-islamic-month-name-array))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
376 (mark-islamic-calendar-date-pattern mm dd yy)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
377 (setq d (cdr d)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
378
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
379 (defun mark-islamic-calendar-date-pattern (month day year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
380 "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
381 A value of 0 in any position is a wildcard."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
382 (save-excursion
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
383 (set-buffer calendar-buffer)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
384 (if (and (/= 0 month) (/= 0 day))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
385 (if (/= 0 year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
386 ;; Fully specified Islamic date.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
387 (let ((date (calendar-gregorian-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
388 (calendar-absolute-from-islamic
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
389 (list month day year)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
390 (if (calendar-date-is-visible-p date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
391 (mark-visible-calendar-date date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
392 ;; Month and day in any year--this taken from the holiday stuff.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
393 (let* ((islamic-date (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
394 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
395 (list displayed-month 15 displayed-year))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
396 (m (extract-calendar-month islamic-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
397 (y (extract-calendar-year islamic-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
398 (date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
399 (if (< m 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
400 nil;; Islamic calendar doesn't apply.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
401 (increment-calendar-month m y (- 10 month))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
402 (if (> m 7);; Islamic date might be visible
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
403 (let ((date (calendar-gregorian-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
404 (calendar-absolute-from-islamic
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
405 (list month day y)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
406 (if (calendar-date-is-visible-p date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
407 (mark-visible-calendar-date date)))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
408 ;; Not one of the simple cases--check all visible dates for match.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
409 ;; Actually, the following code takes care of ALL of the cases, but
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
410 ;; it's much too slow to be used for the simple (common) cases.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
411 (let ((m displayed-month)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
412 (y displayed-year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
413 (first-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
414 (last-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
415 (increment-calendar-month m y -1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
416 (setq first-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
417 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
418 (list m 1 y)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
419 (increment-calendar-month m y 2)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
420 (setq last-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
421 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
422 (list m (calendar-last-day-of-month m y) y)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
423 (calendar-for-loop date from first-date to last-date do
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
424 (let* ((i-date (calendar-islamic-from-absolute date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
425 (i-month (extract-calendar-month i-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
426 (i-day (extract-calendar-day i-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
427 (i-year (extract-calendar-year i-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
428 (and (or (zerop month)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
429 (= month i-month))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
430 (or (zerop day)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
431 (= day i-day))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
432 (or (zerop year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
433 (= year i-year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
434 (mark-visible-calendar-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
435 (calendar-gregorian-from-absolute date)))))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
436
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
437 (defun insert-islamic-diary-entry (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
438 "Insert a diary entry.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
439 For the Islamic date corresponding to the date indicated by point.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
440 Prefix arg will make the entry nonmarking."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
441 (interactive "P")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
442 (let* ((calendar-month-name-array calendar-islamic-month-name-array))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
443 (make-diary-entry
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
444 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
445 islamic-diary-entry-symbol
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
446 (calendar-date-string
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
447 (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
448 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
449 (calendar-cursor-to-date t)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
450 nil t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
451 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
452
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
453 (defun insert-monthly-islamic-diary-entry (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
454 "Insert a monthly diary entry.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
455 For the day of the Islamic month corresponding to the date indicated by point.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
456 Prefix arg will make the entry nonmarking."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
457 (interactive "P")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
458 (let* ((calendar-date-display-form
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
459 (if european-calendar-style '(day " * ") '("* " day )))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
460 (calendar-month-name-array calendar-islamic-month-name-array))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
461 (make-diary-entry
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
462 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
463 islamic-diary-entry-symbol
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
464 (calendar-date-string
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
465 (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
466 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
467 (calendar-cursor-to-date t)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
468 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
469
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
470 (defun insert-yearly-islamic-diary-entry (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
471 "Insert an annual diary entry.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
472 For the day of the Islamic year corresponding to the date indicated by point.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
473 Prefix arg will make the entry nonmarking."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
474 (interactive "P")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
475 (let* ((calendar-date-display-form
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
476 (if european-calendar-style
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
477 '(day " " monthname)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
478 '(monthname " " day)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
479 (calendar-month-name-array calendar-islamic-month-name-array))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
480 (make-diary-entry
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
481 (concat
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
482 islamic-diary-entry-symbol
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
483 (calendar-date-string
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
484 (calendar-islamic-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
485 (calendar-absolute-from-gregorian
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
486 (calendar-cursor-to-date t)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
487 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
488
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
489 (provide 'cal-islamic)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
490
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
491 ;;; cal-islamic.el ends here
|