diff options
| author | Glenn Morris | 2008-03-16 01:24:21 +0000 |
|---|---|---|
| committer | Glenn Morris | 2008-03-16 01:24:21 +0000 |
| commit | b2fba0132f2714bbcf13984833aad43f24035b85 (patch) | |
| tree | 598fde64d58ee4672da9c5529b047ba04471a6ab | |
| parent | d07a05c2fbe3e0fbf41daa88bf3aae450c0906a8 (diff) | |
| download | emacs-b2fba0132f2714bbcf13984833aad43f24035b85.tar.gz emacs-b2fba0132f2714bbcf13984833aad43f24035b85.zip | |
(calendar-mark-1): Autoload it.
(mark-islamic-calendar-date-pattern): Add optional argument `color'.
Use calendar-mark-1.
(calendar-islamic-prompt-for-date): New function.
(calendar-goto-islamic-date): Use calendar-islamic-prompt-for-date.
| -rw-r--r-- | lisp/calendar/cal-islam.el | 132 |
1 files changed, 43 insertions, 89 deletions
diff --git a/lisp/calendar/cal-islam.el b/lisp/calendar/cal-islam.el index 05b629f3c32..b862c0db007 100644 --- a/lisp/calendar/cal-islam.el +++ b/lisp/calendar/cal-islam.el | |||
| @@ -73,18 +73,17 @@ Gregorian date Sunday, December 31, 1 BC." | |||
| 73 | (day (extract-calendar-day date)) | 73 | (day (extract-calendar-day date)) |
| 74 | (year (extract-calendar-year date)) | 74 | (year (extract-calendar-year date)) |
| 75 | (y (% year 30)) | 75 | (y (% year 30)) |
| 76 | (leap-years-in-cycle | 76 | (leap-years-in-cycle (cond ((< y 3) 0) |
| 77 | (cond ((< y 3) 0) | 77 | ((< y 6) 1) |
| 78 | ((< y 6) 1) | 78 | ((< y 8) 2) |
| 79 | ((< y 8) 2) | 79 | ((< y 11) 3) |
| 80 | ((< y 11) 3) | 80 | ((< y 14) 4) |
| 81 | ((< y 14) 4) | 81 | ((< y 17) 5) |
| 82 | ((< y 17) 5) | 82 | ((< y 19) 6) |
| 83 | ((< y 19) 6) | 83 | ((< y 22) 7) |
| 84 | ((< y 22) 7) | 84 | ((< y 25) 8) |
| 85 | ((< y 25) 8) | 85 | ((< y 27) 9) |
| 86 | ((< y 27) 9) | 86 | (t 10)))) |
| 87 | (t 10)))) | ||
| 88 | (+ (islamic-calendar-day-number date) ; days so far this year | 87 | (+ (islamic-calendar-day-number date) ; days so far this year |
| 89 | (* (1- year) 354) ; days in all non-leap years | 88 | (* (1- year) 354) ; days in all non-leap years |
| 90 | (* 11 (/ year 30)) ; leap days in complete cycles | 89 | (* 11 (/ year 30)) ; leap days in complete cycles |
| @@ -142,31 +141,34 @@ Driven by the variable `calendar-date-display-form'." | |||
| 142 | (message "Date is pre-Islamic") | 141 | (message "Date is pre-Islamic") |
| 143 | (message "Islamic date (until sunset): %s" i)))) | 142 | (message "Islamic date (until sunset): %s" i)))) |
| 144 | 143 | ||
| 144 | (defun calendar-islamic-prompt-for-date () | ||
| 145 | "Ask for an Islamic date." | ||
| 146 | (let* ((today (calendar-current-date)) | ||
| 147 | (year (calendar-read | ||
| 148 | "Islamic calendar year (>0): " | ||
| 149 | (lambda (x) (> x 0)) | ||
| 150 | (int-to-string | ||
| 151 | (extract-calendar-year | ||
| 152 | (calendar-islamic-from-absolute | ||
| 153 | (calendar-absolute-from-gregorian today)))))) | ||
| 154 | (month-array calendar-islamic-month-name-array) | ||
| 155 | (completion-ignore-case t) | ||
| 156 | (month (cdr (assoc-string | ||
| 157 | (completing-read | ||
| 158 | "Islamic calendar month name: " | ||
| 159 | (mapcar 'list (append month-array nil)) | ||
| 160 | nil t) | ||
| 161 | (calendar-make-alist month-array 1) t))) | ||
| 162 | (last (islamic-calendar-last-day-of-month month year)) | ||
| 163 | (day (calendar-read | ||
| 164 | (format "Islamic calendar day (1-%d): " last) | ||
| 165 | (lambda (x) (and (< 0 x) (<= x last)))))) | ||
| 166 | (list (list month day year)))) | ||
| 167 | |||
| 145 | ;;;###cal-autoload | 168 | ;;;###cal-autoload |
| 146 | (defun calendar-goto-islamic-date (date &optional noecho) | 169 | (defun calendar-goto-islamic-date (date &optional noecho) |
| 147 | "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is non-nil." | 170 | "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is non-nil." |
| 148 | (interactive | 171 | (interactive (calendar-islamic-prompt-for-date)) |
| 149 | (let* ((today (calendar-current-date)) | ||
| 150 | (year (calendar-read | ||
| 151 | "Islamic calendar year (>0): " | ||
| 152 | (lambda (x) (> x 0)) | ||
| 153 | (int-to-string | ||
| 154 | (extract-calendar-year | ||
| 155 | (calendar-islamic-from-absolute | ||
| 156 | (calendar-absolute-from-gregorian today)))))) | ||
| 157 | (month-array calendar-islamic-month-name-array) | ||
| 158 | (completion-ignore-case t) | ||
| 159 | (month (cdr (assoc-string | ||
| 160 | (completing-read | ||
| 161 | "Islamic calendar month name: " | ||
| 162 | (mapcar 'list (append month-array nil)) | ||
| 163 | nil t) | ||
| 164 | (calendar-make-alist month-array 1) t))) | ||
| 165 | (last (islamic-calendar-last-day-of-month month year)) | ||
| 166 | (day (calendar-read | ||
| 167 | (format "Islamic calendar day (1-%d): " last) | ||
| 168 | (lambda (x) (and (< 0 x) (<= x last)))))) | ||
| 169 | (list (list month day year)))) | ||
| 170 | (calendar-goto-date (calendar-gregorian-from-absolute | 172 | (calendar-goto-date (calendar-gregorian-from-absolute |
| 171 | (calendar-absolute-from-islamic date))) | 173 | (calendar-absolute-from-islamic date))) |
| 172 | (or noecho (calendar-print-islamic-date))) | 174 | (or noecho (calendar-print-islamic-date))) |
| @@ -212,63 +214,15 @@ marked in the calendar. This function is provided for use with | |||
| 212 | islamic-diary-entry-symbol | 214 | islamic-diary-entry-symbol |
| 213 | 'calendar-islamic-from-absolute)) | 215 | 'calendar-islamic-from-absolute)) |
| 214 | 216 | ||
| 217 | (autoload 'calendar-mark-1 "diary-lib") | ||
| 218 | |||
| 215 | ;;;###diary-autoload | 219 | ;;;###diary-autoload |
| 216 | (defun mark-islamic-calendar-date-pattern (month day year) | 220 | (defun mark-islamic-calendar-date-pattern (month day year &optional color) |
| 217 | "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR. | 221 | "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR. |
| 218 | A value of 0 in any position is a wildcard." | 222 | A value of 0 in any position is a wildcard. Optional argument COLOR is |
| 219 | (save-excursion | 223 | passed to `mark-visible-calendar-date' as MARK." |
| 220 | (set-buffer calendar-buffer) | 224 | (calendar-mark-1 month day year 'calendar-islamic-from-absolute |
| 221 | (if (and (not (zerop month)) (not (zerop day))) | 225 | 'calendar-absolute-from-islamic color)) |
| 222 | (if (not (zerop year)) | ||
| 223 | ;; Fully specified Islamic date. | ||
| 224 | (let ((date (calendar-gregorian-from-absolute | ||
| 225 | (calendar-absolute-from-islamic | ||
| 226 | (list month day year))))) | ||
| 227 | (if (calendar-date-is-visible-p date) | ||
| 228 | (mark-visible-calendar-date date))) | ||
| 229 | ;; Month and day in any year--this taken from the holiday stuff. | ||
| 230 | (let* ((islamic-date (calendar-islamic-from-absolute | ||
| 231 | (calendar-absolute-from-gregorian | ||
| 232 | (list displayed-month 15 displayed-year)))) | ||
| 233 | (m (extract-calendar-month islamic-date)) | ||
| 234 | (y (extract-calendar-year islamic-date)) | ||
| 235 | (date)) | ||
| 236 | (unless (< m 1) ; Islamic calendar doesn't apply | ||
| 237 | (increment-calendar-month m y (- 10 month)) | ||
| 238 | (if (> m 7) ; Islamic date might be visible | ||
| 239 | (let ((date (calendar-gregorian-from-absolute | ||
| 240 | (calendar-absolute-from-islamic | ||
| 241 | (list month day y))))) | ||
| 242 | (if (calendar-date-is-visible-p date) | ||
| 243 | (mark-visible-calendar-date date))))))) | ||
| 244 | ;; Not one of the simple cases--check all visible dates for match. | ||
| 245 | ;; Actually, the following code takes care of ALL of the cases, but | ||
| 246 | ;; it's much too slow to be used for the simple (common) cases. | ||
| 247 | (let ((m displayed-month) | ||
| 248 | (y displayed-year) | ||
| 249 | (first-date) | ||
| 250 | (last-date)) | ||
| 251 | (increment-calendar-month m y -1) | ||
| 252 | (setq first-date | ||
| 253 | (calendar-absolute-from-gregorian | ||
| 254 | (list m 1 y))) | ||
| 255 | (increment-calendar-month m y 2) | ||
| 256 | (setq last-date | ||
| 257 | (calendar-absolute-from-gregorian | ||
| 258 | (list m (calendar-last-day-of-month m y) y))) | ||
| 259 | (calendar-for-loop date from first-date to last-date do | ||
| 260 | (let* ((i-date (calendar-islamic-from-absolute date)) | ||
| 261 | (i-month (extract-calendar-month i-date)) | ||
| 262 | (i-day (extract-calendar-day i-date)) | ||
| 263 | (i-year (extract-calendar-year i-date))) | ||
| 264 | (and (or (zerop month) | ||
| 265 | (= month i-month)) | ||
| 266 | (or (zerop day) | ||
| 267 | (= day i-day)) | ||
| 268 | (or (zerop year) | ||
| 269 | (= year i-year)) | ||
| 270 | (mark-visible-calendar-date | ||
| 271 | (calendar-gregorian-from-absolute date))))))))) | ||
| 272 | 226 | ||
| 273 | (autoload 'diary-mark-entries-1 "diary-lib") | 227 | (autoload 'diary-mark-entries-1 "diary-lib") |
| 274 | 228 | ||