Mercurial > emacs
annotate lisp/calendar/cal-islam.el @ 92594:674c88622bd9
Move many autoloads to separate file, cal-loaddefs.el.
Move defcustoms to start and re-order.
(calendar-month-name-array, calendar-starred-day): No need to declare
for compiler.
(cal-loaddefs): Require it.
(appt, chinese-calendar, calendar-tex): Move custom groups to the
appropriate file.
(diary-entry-marker, calendar-today-marker, calendar-holiday-marker):
Reverse logic.
(diary-face, diary-file-name-prefix-function, diary-include-string)
(diary-glob-file-regexp-prefix, diary-face-attrs)
(diary-file-name-prefix, sexp-diary-entry-symbol)
(print-diary-entries-hook, list-diary-entries-hook)
(nongregorian-diary-listing-hook, mark-diary-entries-hook)
(nongregorian-diary-marking-hook, diary-list-include-blanks):
Move to diary-lib.
(all-christian-calendar-holidays, all-islamic-calendar-holidays)
(all-bahai-calendar-holidays): Doc fix.
(calendar-mark-ring): Add doc-string.
(calendar-starred-day): Defvar it.
(calendar-mode): Make calendar-starred-day local.
(calendar-star-date): No need to make calendar-starred-day local.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 08 Mar 2008 03:47:03 +0000 |
parents | c9eb56890fe0 |
children | 6f4bd17c2adc |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38402
diff
changeset
|
1 ;;; cal-islam.el --- calendar functions for the Islamic calendar |
13053 | 2 |
79703 | 3 ;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65144
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
13053 | 5 |
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> | |
67465
a55ee709ec8d
Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
65144
diff
changeset
|
7 ;; Maintainer: Glenn Morris <rgm@gnu.org> |
13053 | 8 ;; Keywords: calendar |
9 ;; Human-Keywords: Islamic calendar, calendar, diary | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
78216
93e11478c954
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
13053 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
13053 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; This collection of functions implements the features of calendar.el and | |
31 ;; diary.el that deal with the Islamic calendar. | |
32 | |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20268
diff
changeset
|
33 ;; Technical details of all the calendrical calculations can be found in |
61148
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
54075
diff
changeset
|
34 ;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold |
7f7db25577d9
Update reference to "Calendrical Calculations" book; there's a new edition.
Paul Eggert <eggert@twinsun.com>
parents:
54075
diff
changeset
|
35 ;; and Nachum Dershowitz, Cambridge University Press (2001). |
20462
d179de7ad92e
Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents:
20268
diff
changeset
|
36 |
13053 | 37 ;;; Code: |
38 | |
65144
b3c4cec1dbcd
(date, number, original-date): Add defvars.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
39 (defvar date) |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
40 (defvar displayed-month) |
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
41 (defvar displayed-year) |
65144
b3c4cec1dbcd
(date, number, original-date): Add defvars.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
42 (defvar number) |
b3c4cec1dbcd
(date, number, original-date): Add defvars.
Juanma Barranquero <lekktu@gmail.com>
parents:
64085
diff
changeset
|
43 (defvar original-date) |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
44 |
13053 | 45 (require 'cal-julian) |
46 | |
47 (defvar calendar-islamic-month-name-array | |
48 ["Muharram" "Safar" "Rabi I" "Rabi II" "Jumada I" "Jumada II" | |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
49 "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"] |
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
50 "Array of strings giving the names of the Islamic months.") |
13053 | 51 |
52 (defvar calendar-islamic-epoch (calendar-absolute-from-julian '(7 16 622)) | |
53 "Absolute date of start of Islamic calendar = August 29, 284 A.D. (Julian).") | |
54 | |
55 (defun islamic-calendar-leap-year-p (year) | |
56 "Returns t if YEAR is a leap year on the Islamic calendar." | |
57 (memq (% year 30) | |
58 (list 2 5 7 10 13 16 18 21 24 26 29))) | |
59 | |
60 (defun islamic-calendar-last-day-of-month (month year) | |
61 "The last day in MONTH during YEAR on the Islamic calendar." | |
62 (cond | |
63 ((memq month (list 1 3 5 7 9 11)) 30) | |
64 ((memq month (list 2 4 6 8 10)) 29) | |
65 (t (if (islamic-calendar-leap-year-p year) 30 29)))) | |
66 | |
67 (defun islamic-calendar-day-number (date) | |
68 "Return the day number within the year of the Islamic date DATE." | |
69 (let* ((month (extract-calendar-month date)) | |
70 (day (extract-calendar-day date))) | |
71 (+ (* 30 (/ month 2)) | |
72 (* 29 (/ (1- month) 2)) | |
73 day))) | |
74 | |
75 (defun calendar-absolute-from-islamic (date) | |
76 "Absolute date of Islamic DATE. | |
77 The absolute date is the number of days elapsed since the (imaginary) | |
78 Gregorian date Sunday, December 31, 1 BC." | |
79 (let* ((month (extract-calendar-month date)) | |
80 (day (extract-calendar-day date)) | |
81 (year (extract-calendar-year date)) | |
82 (y (% year 30)) | |
83 (leap-years-in-cycle | |
84 (cond | |
85 ((< y 3) 0) ((< y 6) 1) ((< y 8) 2) ((< y 11) 3) ((< y 14) 4) | |
86 ((< y 17) 5) ((< y 19) 6) ((< y 22) 7) ((< y 25) 8) ((< y 27) 9) | |
87 (t 10)))) | |
88 (+ (islamic-calendar-day-number date);; days so far this year | |
89 (* (1- year) 354) ;; days in all non-leap years | |
90 (* 11 (/ year 30)) ;; leap days in complete cycles | |
91 leap-years-in-cycle ;; leap days this cycle | |
92 (1- calendar-islamic-epoch)))) ;; days before start of calendar | |
93 | |
94 (defun calendar-islamic-from-absolute (date) | |
95 "Compute the Islamic date (month day year) corresponding to absolute DATE. | |
96 The absolute date is the number of days elapsed since the (imaginary) | |
97 Gregorian date Sunday, December 31, 1 BC." | |
98 (if (< date calendar-islamic-epoch) | |
99 (list 0 0 0);; pre-Islamic date | |
100 (let* ((approx (/ (- date calendar-islamic-epoch) | |
101 355));; Approximation from below. | |
102 (year ;; Search forward from the approximation. | |
103 (+ approx | |
104 (calendar-sum y approx | |
105 (>= date (calendar-absolute-from-islamic | |
106 (list 1 1 (1+ y)))) | |
107 1))) | |
108 (month ;; Search forward from Muharram. | |
109 (1+ (calendar-sum m 1 | |
110 (> date | |
111 (calendar-absolute-from-islamic | |
112 (list m | |
113 (islamic-calendar-last-day-of-month | |
114 m year) | |
115 year))) | |
116 1))) | |
117 (day ;; Calculate the day by subtraction. | |
118 (- date | |
119 (1- (calendar-absolute-from-islamic (list month 1 year)))))) | |
120 (list month day year)))) | |
121 | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
122 ;;;###autoload |
13053 | 123 (defun calendar-islamic-date-string (&optional date) |
124 "String of Islamic date before sunset of Gregorian DATE. | |
125 Returns the empty string if DATE is pre-Islamic. | |
126 Defaults to today's date if DATE is not given. | |
127 Driven by the variable `calendar-date-display-form'." | |
128 (let ((calendar-month-name-array calendar-islamic-month-name-array) | |
129 (islamic-date (calendar-islamic-from-absolute | |
130 (calendar-absolute-from-gregorian | |
131 (or date (calendar-current-date)))))) | |
132 (if (< (extract-calendar-year islamic-date) 1) | |
133 "" | |
134 (calendar-date-string islamic-date nil t)))) | |
135 | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
136 ;;;###autoload |
13053 | 137 (defun calendar-print-islamic-date () |
138 "Show the Islamic calendar equivalent of the date under the cursor." | |
139 (interactive) | |
140 (let ((i (calendar-islamic-date-string (calendar-cursor-to-date t)))) | |
141 (if (string-equal i "") | |
142 (message "Date is pre-Islamic") | |
143 (message "Islamic date (until sunset): %s" i)))) | |
144 | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
145 ;;;###autoload |
13053 | 146 (defun calendar-goto-islamic-date (date &optional noecho) |
147 "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is t." | |
148 (interactive | |
149 (let* ((today (calendar-current-date)) | |
150 (year (calendar-read | |
151 "Islamic calendar year (>0): " | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
152 (lambda (x) (> x 0)) |
13053 | 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) | |
54075
5c162955af7a
(calendar-goto-islamic-date, mark-islamic-diary-entries): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
159 (month (cdr (assoc-string |
13053 | 160 (completing-read |
161 "Islamic calendar month name: " | |
162 (mapcar 'list (append month-array nil)) | |
24184
5b4ebdd66a82
(calendar-goto-islamic-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
163 nil t) |
54075
5c162955af7a
(calendar-goto-islamic-date, mark-islamic-diary-entries): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
164 (calendar-make-alist month-array 1) t))) |
13053 | 165 (last (islamic-calendar-last-day-of-month month year)) |
166 (day (calendar-read | |
167 (format "Islamic calendar day (1-%d): " last) | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
168 (lambda (x) (and (< 0 x) (<= x last)))))) |
13053 | 169 (list (list month day year)))) |
170 (calendar-goto-date (calendar-gregorian-from-absolute | |
171 (calendar-absolute-from-islamic date))) | |
172 (or noecho (calendar-print-islamic-date))) | |
173 | |
174 (defun diary-islamic-date () | |
175 "Islamic calendar equivalent of date diary entry." | |
17384
d7471b786af3
(diary-islamic-date): Use `date'.
Richard M. Stallman <rms@gnu.org>
parents:
14684
diff
changeset
|
176 (let ((i (calendar-islamic-date-string date))) |
13053 | 177 (if (string-equal i "") |
178 "Date is pre-Islamic" | |
179 (format "Islamic date (until sunset): %s" i)))) | |
180 | |
181 (defun holiday-islamic (month day string) | |
182 "Holiday on MONTH, DAY (Islamic) called STRING. | |
183 If MONTH, DAY (Islamic) is visible, the value returned is corresponding | |
184 Gregorian date in the form of the list (((month day year) STRING)). Returns | |
185 nil if it is not visible in the current calendar window." | |
186 (let* ((islamic-date (calendar-islamic-from-absolute | |
187 (calendar-absolute-from-gregorian | |
188 (list displayed-month 15 displayed-year)))) | |
189 (m (extract-calendar-month islamic-date)) | |
190 (y (extract-calendar-year islamic-date)) | |
191 (date)) | |
192 (if (< m 1) | |
193 nil;; Islamic calendar doesn't apply. | |
194 (increment-calendar-month m y (- 10 month)) | |
195 (if (> m 7);; Islamic date might be visible | |
196 (let ((date (calendar-gregorian-from-absolute | |
197 (calendar-absolute-from-islamic (list month day y))))) | |
198 (if (calendar-date-is-visible-p date) | |
199 (list (list date string)))))))) | |
200 | |
86490
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
201 ;; l-i-d-e should be called from diary code. |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
202 (declare-function add-to-diary-list "diary-lib" |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
203 (date string specifier &optional marker globcolor literal)) |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
204 |
13053 | 205 (defun list-islamic-diary-entries () |
206 "Add any Islamic date entries from the diary file to `diary-entries-list'. | |
207 Islamic date diary entries must be prefaced by an `islamic-diary-entry-symbol' | |
208 \(normally an `I'). The same diary date forms govern the style of the Islamic | |
209 calendar entries, except that the Islamic month names must be spelled in full. | |
210 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being | |
211 Dhu al-Hijjah. If an Islamic date diary entry begins with a | |
212 `diary-nonmarking-symbol', the entry will appear in the diary listing, but will | |
213 not be marked in the calendar. This function is provided for use with the | |
214 `nongregorian-diary-listing-hook'." | |
215 (if (< 0 number) | |
216 (let ((buffer-read-only nil) | |
217 (diary-modified (buffer-modified-p)) | |
218 (gdate original-date) | |
219 (mark (regexp-quote diary-nonmarking-symbol))) | |
82083
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
220 (dotimes (idummy number) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
221 (let* ((d diary-date-forms) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
222 (idate (calendar-islamic-from-absolute |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
223 (calendar-absolute-from-gregorian gdate))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
224 (month (extract-calendar-month idate)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
225 (day (extract-calendar-day idate)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
226 (year (extract-calendar-year idate))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
227 (while d |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
228 (let* |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
229 ((date-form (if (equal (car (car d)) 'backup) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
230 (cdr (car d)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
231 (car d))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
232 (backup (equal (car (car d)) 'backup)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
233 (dayname |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
234 (format "%s\\|%s\\.?" |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
235 (calendar-day-name gdate) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
236 (calendar-day-name gdate 'abbrev))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
237 (calendar-month-name-array |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
238 calendar-islamic-month-name-array) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
239 (monthname |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
240 (concat |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
241 "\\*\\|" |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
242 (calendar-month-name month))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
243 (month (concat "\\*\\|0*" (int-to-string month))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
244 (day (concat "\\*\\|0*" (int-to-string day))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
245 (year |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
246 (concat |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
247 "\\*\\|0*" (int-to-string year) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
248 (if abbreviated-calendar-year |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
249 (concat "\\|" (int-to-string (% year 100))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
250 ""))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
251 (regexp |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
252 (concat |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
253 "\\(\\`\\|\^M\\|\n\\)" mark "?" |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
254 (regexp-quote islamic-diary-entry-symbol) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
255 "\\(" |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
256 (mapconcat 'eval date-form "\\)\\(") |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
257 "\\)")) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
258 (case-fold-search t)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
259 (goto-char (point-min)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
260 (while (re-search-forward regexp nil t) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
261 (if backup (re-search-backward "\\<" nil t)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
262 (if (and (or (char-equal (preceding-char) ?\^M) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
263 (char-equal (preceding-char) ?\n)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
264 (not (looking-at " \\|\^I"))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
265 ;; Diary entry that consists only of date. |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
266 (backward-char 1) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
267 ;; Found a nonempty diary entry--make it visible and |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
268 ;; add it to the list. |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
269 (let ((entry-start (point)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
270 (date-start)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
271 (re-search-backward "\^M\\|\n\\|\\`") |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
272 (setq date-start (point)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
273 (re-search-forward "\^M\\|\n" nil t 2) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
274 (while (looking-at " \\|\^I") |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
275 (re-search-forward "\^M\\|\n" nil t)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
276 (backward-char 1) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
277 (subst-char-in-region date-start (point) ?\^M ?\n t) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
278 (add-to-diary-list |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
279 gdate |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
280 (buffer-substring-no-properties entry-start (point)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
281 (buffer-substring-no-properties |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
282 (1+ date-start) (1- entry-start)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
283 (copy-marker entry-start)))))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
284 (setq d (cdr d)))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
285 (setq gdate |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
286 (calendar-gregorian-from-absolute |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
287 (1+ (calendar-absolute-from-gregorian gdate))))) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
288 (set-buffer-modified-p diary-modified)) |
c2109b15d473
(list-islamic-diary-entries): Use dotimes rather than
Glenn Morris <rgm@gnu.org>
parents:
77279
diff
changeset
|
289 (goto-char (point-min)))) |
13053 | 290 |
86490
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
291 (declare-function diary-name-pattern "diary-lib" |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
292 (string-array &optional abbrev-array paren)) |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
293 |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
294 (declare-function mark-calendar-days-named "diary-lib" |
238c9b141506
(add-to-diary-list, diary-name-pattern)
Glenn Morris <rgm@gnu.org>
parents:
85502
diff
changeset
|
295 (dayname &optional color)) |
13053 | 296 |
297 (defun mark-islamic-diary-entries () | |
298 "Mark days in the calendar window that have Islamic date diary entries. | |
299 Each entry in diary-file (or included files) visible in the calendar window | |
300 is marked. Islamic date entries are prefaced by a islamic-diary-entry-symbol | |
301 \(normally an `I'). The same diary-date-forms govern the style of the Islamic | |
302 calendar entries, except that the Islamic month names must be spelled in full. | |
303 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being | |
304 Dhu al-Hijjah. Islamic date diary entries that begin with a | |
305 diary-nonmarking-symbol will not be marked in the calendar. This function is | |
306 provided for use as part of the nongregorian-diary-marking-hook." | |
307 (let ((d diary-date-forms)) | |
308 (while d | |
309 (let* | |
310 ((date-form (if (equal (car (car d)) 'backup) | |
311 (cdr (car d)) | |
312 (car d)));; ignore 'backup directive | |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
313 (dayname (diary-name-pattern calendar-day-name-array |
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
314 calendar-day-abbrev-array)) |
13053 | 315 (monthname |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
316 (format "%s\\|\\*" |
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
317 (diary-name-pattern calendar-islamic-month-name-array))) |
13053 | 318 (month "[0-9]+\\|\\*") |
319 (day "[0-9]+\\|\\*") | |
320 (year "[0-9]+\\|\\*") | |
321 (l (length date-form)) | |
322 (d-name-pos (- l (length (memq 'dayname date-form)))) | |
323 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | |
324 (m-name-pos (- l (length (memq 'monthname date-form)))) | |
325 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | |
326 (d-pos (- l (length (memq 'day date-form)))) | |
327 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | |
328 (m-pos (- l (length (memq 'month date-form)))) | |
329 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | |
330 (y-pos (- l (length (memq 'year date-form)))) | |
331 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | |
332 (regexp | |
333 (concat | |
334 "\\(\\`\\|\^M\\|\n\\)" | |
335 (regexp-quote islamic-diary-entry-symbol) | |
336 "\\(" | |
337 (mapconcat 'eval date-form "\\)\\(") | |
338 "\\)")) | |
339 (case-fold-search t)) | |
340 (goto-char (point-min)) | |
341 (while (re-search-forward regexp nil t) | |
342 (let* ((dd-name | |
343 (if d-name-pos | |
344 (buffer-substring | |
345 (match-beginning d-name-pos) | |
346 (match-end d-name-pos)))) | |
347 (mm-name | |
348 (if m-name-pos | |
349 (buffer-substring | |
350 (match-beginning m-name-pos) | |
351 (match-end m-name-pos)))) | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
61148
diff
changeset
|
352 (mm (string-to-number |
13053 | 353 (if m-pos |
354 (buffer-substring | |
355 (match-beginning m-pos) | |
356 (match-end m-pos)) | |
357 ""))) | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
61148
diff
changeset
|
358 (dd (string-to-number |
13053 | 359 (if d-pos |
360 (buffer-substring | |
361 (match-beginning d-pos) | |
362 (match-end d-pos)) | |
363 ""))) | |
364 (y-str (if y-pos | |
365 (buffer-substring | |
366 (match-beginning y-pos) | |
367 (match-end y-pos)))) | |
368 (yy (if (not y-str) | |
369 0 | |
370 (if (and (= (length y-str) 2) | |
371 abbreviated-calendar-year) | |
372 (let* ((current-y | |
373 (extract-calendar-year | |
374 (calendar-islamic-from-absolute | |
375 (calendar-absolute-from-gregorian | |
376 (calendar-current-date))))) | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
61148
diff
changeset
|
377 (y (+ (string-to-number y-str) |
13053 | 378 (* 100 (/ current-y 100))))) |
379 (if (> (- y current-y) 50) | |
380 (- y 100) | |
381 (if (> (- current-y y) 50) | |
382 (+ y 100) | |
383 y))) | |
62402
a7e02ef1e3d6
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
61148
diff
changeset
|
384 (string-to-number y-str))))) |
13053 | 385 (if dd-name |
386 (mark-calendar-days-named | |
54075
5c162955af7a
(calendar-goto-islamic-date, mark-islamic-diary-entries): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
387 (cdr (assoc-string dd-name |
24184
5b4ebdd66a82
(calendar-goto-islamic-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
388 (calendar-make-alist |
5b4ebdd66a82
(calendar-goto-islamic-date)
Richard M. Stallman <rms@gnu.org>
parents:
20462
diff
changeset
|
389 calendar-day-name-array |
54075
5c162955af7a
(calendar-goto-islamic-date, mark-islamic-diary-entries): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
390 0 nil calendar-day-abbrev-array) t))) |
13053 | 391 (if mm-name |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
392 (setq mm (if (string-equal mm-name "*") 0 |
54075
5c162955af7a
(calendar-goto-islamic-date, mark-islamic-diary-entries): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
393 (cdr (assoc-string |
52119
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
394 mm-name |
226327fe046f
(displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents:
49598
diff
changeset
|
395 (calendar-make-alist |
54075
5c162955af7a
(calendar-goto-islamic-date, mark-islamic-diary-entries): Use
Glenn Morris <rgm@gnu.org>
parents:
52401
diff
changeset
|
396 calendar-islamic-month-name-array) t))))) |
13053 | 397 (mark-islamic-calendar-date-pattern mm dd yy))))) |
398 (setq d (cdr d))))) | |
399 | |
400 (defun mark-islamic-calendar-date-pattern (month day year) | |
401 "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR. | |
402 A value of 0 in any position is a wildcard." | |
403 (save-excursion | |
404 (set-buffer calendar-buffer) | |
405 (if (and (/= 0 month) (/= 0 day)) | |
406 (if (/= 0 year) | |
407 ;; Fully specified Islamic date. | |
408 (let ((date (calendar-gregorian-from-absolute | |
409 (calendar-absolute-from-islamic | |
410 (list month day year))))) | |
411 (if (calendar-date-is-visible-p date) | |
412 (mark-visible-calendar-date date))) | |
413 ;; Month and day in any year--this taken from the holiday stuff. | |
414 (let* ((islamic-date (calendar-islamic-from-absolute | |
415 (calendar-absolute-from-gregorian | |
416 (list displayed-month 15 displayed-year)))) | |
417 (m (extract-calendar-month islamic-date)) | |
418 (y (extract-calendar-year islamic-date)) | |
419 (date)) | |
420 (if (< m 1) | |
421 nil;; Islamic calendar doesn't apply. | |
422 (increment-calendar-month m y (- 10 month)) | |
423 (if (> m 7);; Islamic date might be visible | |
424 (let ((date (calendar-gregorian-from-absolute | |
425 (calendar-absolute-from-islamic | |
426 (list month day y))))) | |
427 (if (calendar-date-is-visible-p date) | |
428 (mark-visible-calendar-date date))))))) | |
429 ;; Not one of the simple cases--check all visible dates for match. | |
430 ;; Actually, the following code takes care of ALL of the cases, but | |
431 ;; it's much too slow to be used for the simple (common) cases. | |
432 (let ((m displayed-month) | |
433 (y displayed-year) | |
434 (first-date) | |
435 (last-date)) | |
436 (increment-calendar-month m y -1) | |
437 (setq first-date | |
438 (calendar-absolute-from-gregorian | |
439 (list m 1 y))) | |
440 (increment-calendar-month m y 2) | |
441 (setq last-date | |
442 (calendar-absolute-from-gregorian | |
443 (list m (calendar-last-day-of-month m y) y))) | |
444 (calendar-for-loop date from first-date to last-date do | |
445 (let* ((i-date (calendar-islamic-from-absolute date)) | |
446 (i-month (extract-calendar-month i-date)) | |
447 (i-day (extract-calendar-day i-date)) | |
448 (i-year (extract-calendar-year i-date))) | |
449 (and (or (zerop month) | |
450 (= month i-month)) | |
451 (or (zerop day) | |
452 (= day i-day)) | |
453 (or (zerop year) | |
454 (= year i-year)) | |
455 (mark-visible-calendar-date | |
456 (calendar-gregorian-from-absolute date))))))))) | |
457 | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
458 ;;;###autoload |
13053 | 459 (defun insert-islamic-diary-entry (arg) |
460 "Insert a diary entry. | |
461 For the Islamic date corresponding to the date indicated by point. | |
462 Prefix arg will make the entry nonmarking." | |
463 (interactive "P") | |
464 (let* ((calendar-month-name-array calendar-islamic-month-name-array)) | |
465 (make-diary-entry | |
466 (concat | |
467 islamic-diary-entry-symbol | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38449
diff
changeset
|
468 (calendar-date-string |
13053 | 469 (calendar-islamic-from-absolute |
470 (calendar-absolute-from-gregorian | |
471 (calendar-cursor-to-date t))) | |
472 nil t)) | |
473 arg))) | |
474 | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
475 ;;;###autoload |
13053 | 476 (defun insert-monthly-islamic-diary-entry (arg) |
477 "Insert a monthly diary entry. | |
478 For the day of the Islamic month corresponding to the date indicated by point. | |
479 Prefix arg will make the entry nonmarking." | |
480 (interactive "P") | |
481 (let* ((calendar-date-display-form | |
482 (if european-calendar-style '(day " * ") '("* " day ))) | |
483 (calendar-month-name-array calendar-islamic-month-name-array)) | |
484 (make-diary-entry | |
485 (concat | |
486 islamic-diary-entry-symbol | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38449
diff
changeset
|
487 (calendar-date-string |
13053 | 488 (calendar-islamic-from-absolute |
489 (calendar-absolute-from-gregorian | |
490 (calendar-cursor-to-date t))))) | |
491 arg))) | |
492 | |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
493 ;;;###autoload |
13053 | 494 (defun insert-yearly-islamic-diary-entry (arg) |
495 "Insert an annual diary entry. | |
496 For the day of the Islamic year corresponding to the date indicated by point. | |
497 Prefix arg will make the entry nonmarking." | |
498 (interactive "P") | |
499 (let* ((calendar-date-display-form | |
500 (if european-calendar-style | |
501 '(day " " monthname) | |
502 '(monthname " " day))) | |
503 (calendar-month-name-array calendar-islamic-month-name-array)) | |
504 (make-diary-entry | |
505 (concat | |
506 islamic-diary-entry-symbol | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38449
diff
changeset
|
507 (calendar-date-string |
13053 | 508 (calendar-islamic-from-absolute |
509 (calendar-absolute-from-gregorian | |
510 (calendar-cursor-to-date t))))) | |
511 arg))) | |
512 | |
14684
66450c507ee4
Renamed from cal-islamic.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
513 (provide 'cal-islam) |
13053 | 514 |
92585
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
515 ;; Local Variables: |
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
516 ;; generated-autoload-file: "cal-loaddefs.el" |
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
517 ;; End: |
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
518 |
c9eb56890fe0
Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
519 ;; arch-tag: a951b6c1-6f47-48d5-bac3-1b505cd719f7 |
14684
66450c507ee4
Renamed from cal-islamic.el to avoid 14-character limitation.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
520 ;;; cal-islam.el ends here |