]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-islam.el
(ido-enable-prefix): Improve previous doc fix.
[gnu-emacs] / lisp / calendar / cal-islam.el
index a8e038e52eb2b33c6dd581398c511b74558f8794..105bb288eb0b18d10d0a7778e5365d6a0571bf3d 100644 (file)
@@ -1,8 +1,10 @@
-;;; cal-islam.el --- calendar functions for the Islamic calendar.
+;;; cal-islam.el --- calendar functions for the Islamic calendar
 
-;; Copyright (C) 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1997, 2001, 2002, 2003, 2004, 2005, 2006
+;;   Free Software Foundation, Inc.
 
 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
+;; Maintainer: Glenn Morris <rgm@gnu.org>
 ;; Keywords: calendar
 ;; Human-Keywords: Islamic calendar, calendar, diary
 
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;; This collection of functions implements the features of calendar.el and
 ;; diary.el that deal with the Islamic calendar.
 
+;; Technical details of all the calendrical calculations can be found in
+;; ``Calendrical Calculations: The Millennium Edition'' by Edward M. Reingold
+;; and Nachum Dershowitz, Cambridge University Press (2001).
+
 ;; Comments, corrections, and improvements should be sent to
 ;;  Edward M. Reingold               Department of Computer Science
 ;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
 
 ;;; Code:
 
+(defvar date)
+(defvar displayed-month)
+(defvar displayed-year)
+(defvar number)
+(defvar original-date)
+
 (require 'cal-julian)
 
 (defvar calendar-islamic-month-name-array
   ["Muharram" "Safar" "Rabi I" "Rabi II" "Jumada I" "Jumada II"
-   "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"])
+   "Rajab" "Sha'ban" "Ramadan" "Shawwal" "Dhu al-Qada" "Dhu al-Hijjah"]
+"Array of strings giving the names of the Islamic months.")
 
 (defvar calendar-islamic-epoch (calendar-absolute-from-julian '(7 16 622))
   "Absolute date of start of Islamic calendar = August 29, 284 A.D. (Julian).")
@@ -146,13 +159,12 @@ Driven by the variable `calendar-date-display-form'."
                     (calendar-absolute-from-gregorian today))))))
           (month-array calendar-islamic-month-name-array)
           (completion-ignore-case t)
-          (month (cdr (assoc
-                       (capitalize
+          (month (cdr (assoc-string
                         (completing-read
                          "Islamic calendar month name: "
                          (mapcar 'list (append month-array nil))
-                         nil t))
-                       (calendar-make-alist month-array 1 'capitalize))))
+                         nil t)
+                       (calendar-make-alist month-array 1) t)))
           (last (islamic-calendar-last-day-of-month month year))
           (day (calendar-read
                 (format "Islamic calendar day (1-%d): " last)
@@ -164,7 +176,7 @@ Driven by the variable `calendar-date-display-form'."
 
 (defun diary-islamic-date ()
   "Islamic calendar equivalent of date diary entry."
-  (let ((i (calendar-islamic-date-string (calendar-cursor-to-date t))))
+  (let ((i (calendar-islamic-date-string date)))
     (if (string-equal i "")
         "Date is pre-Islamic"
       (format "Islamic date (until sunset): %s" i))))
@@ -206,7 +218,7 @@ not be marked in the calendar.  This function is provided for use with the
             (mark (regexp-quote diary-nonmarking-symbol)))
         (calendar-for-loop i from 1 to number do
            (let* ((d diary-date-forms)
-                  (idate (calendar-islamic-from-absolute 
+                  (idate (calendar-islamic-from-absolute
                           (calendar-absolute-from-gregorian gdate)))
                   (month (extract-calendar-month idate))
                   (day (extract-calendar-day idate))
@@ -218,9 +230,9 @@ not be marked in the calendar.  This function is provided for use with the
                                  (car d)))
                     (backup (equal (car (car d)) 'backup))
                     (dayname
-                     (concat
-                      (calendar-day-name gdate) "\\|"
-                      (substring (calendar-day-name gdate) 0 3) ".?"))
+                     (format "%s\\|%s\\.?"
+                      (calendar-day-name gdate)
+                      (calendar-day-name gdate 'abbrev)))
                     (calendar-month-name-array
                      calendar-islamic-month-name-array)
                     (monthname
@@ -263,7 +275,11 @@ not be marked in the calendar.  This function is provided for use with the
                        (backward-char 1)
                        (subst-char-in-region date-start (point) ?\^M ?\n t)
                        (add-to-diary-list
-                         gdate (buffer-substring entry-start (point)))))))
+                        gdate
+                        (buffer-substring-no-properties entry-start (point))
+                        (buffer-substring-no-properties
+                         (1+ date-start) (1- entry-start))
+                        (copy-marker entry-start))))))
                (setq d (cdr d))))
            (setq gdate
                  (calendar-gregorian-from-absolute
@@ -287,11 +303,11 @@ provided for use as part of the nongregorian-diary-marking-hook."
           ((date-form (if (equal (car (car d)) 'backup)
                           (cdr (car d))
                         (car d)));; ignore 'backup directive
-           (dayname (diary-name-pattern calendar-day-name-array))
+           (dayname (diary-name-pattern calendar-day-name-array
+                                        calendar-day-abbrev-array))
            (monthname
-            (concat
-             (diary-name-pattern calendar-islamic-month-name-array t)
-             "\\|\\*"))
+            (format "%s\\|\\*"
+                    (diary-name-pattern calendar-islamic-month-name-array)))
            (month "[0-9]+\\|\\*")
            (day "[0-9]+\\|\\*")
            (year "[0-9]+\\|\\*")
@@ -326,13 +342,13 @@ provided for use as part of the nongregorian-diary-marking-hook."
                       (buffer-substring
                        (match-beginning m-name-pos)
                        (match-end m-name-pos))))
-                 (mm (string-to-int
+                 (mm (string-to-number
                       (if m-pos
                           (buffer-substring
                            (match-beginning m-pos)
                            (match-end m-pos))
                         "")))
-                 (dd (string-to-int
+                 (dd (string-to-number
                       (if d-pos
                           (buffer-substring
                            (match-beginning d-pos)
@@ -351,29 +367,26 @@ provided for use as part of the nongregorian-diary-marking-hook."
                                     (calendar-islamic-from-absolute
                                      (calendar-absolute-from-gregorian
                                       (calendar-current-date)))))
-                                  (y (+ (string-to-int y-str)
+                                  (y (+ (string-to-number y-str)
                                         (* 100 (/ current-y 100)))))
                              (if (> (- y current-y) 50)
                                  (- y 100)
                                (if (> (- current-y y) 50)
                                    (+ y 100)
                                  y)))
-                         (string-to-int y-str)))))
+                         (string-to-number y-str)))))
             (if dd-name
                 (mark-calendar-days-named
-                 (cdr (assoc (capitalize (substring dd-name 0 3))
-                             (calendar-make-alist
-                               calendar-day-name-array
-                               0
-                               '(lambda (x) (substring x 0 3))))))
+                 (cdr (assoc-string dd-name
+                                         (calendar-make-alist
+                                          calendar-day-name-array
+                                          0 nil calendar-day-abbrev-array) t)))
               (if mm-name
-                  (if (string-equal mm-name "*")
-                      (setq mm 0)
-                    (setq mm
-                          (cdr (assoc
-                                (capitalize mm-name)
-                                (calendar-make-alist
-                                  calendar-islamic-month-name-array))))))
+                  (setq mm (if (string-equal mm-name "*") 0
+                             (cdr (assoc-string
+                                   mm-name
+                                   (calendar-make-alist
+                                    calendar-islamic-month-name-array) t)))))
               (mark-islamic-calendar-date-pattern mm dd yy)))))
       (setq d (cdr d)))))
 
@@ -444,7 +457,7 @@ Prefix arg will make the entry nonmarking."
     (make-diary-entry
      (concat
       islamic-diary-entry-symbol
-      (calendar-date-string 
+      (calendar-date-string
        (calendar-islamic-from-absolute
         (calendar-absolute-from-gregorian
          (calendar-cursor-to-date t)))
@@ -462,7 +475,7 @@ Prefix arg will make the entry nonmarking."
     (make-diary-entry
      (concat
       islamic-diary-entry-symbol
-      (calendar-date-string 
+      (calendar-date-string
        (calendar-islamic-from-absolute
         (calendar-absolute-from-gregorian
          (calendar-cursor-to-date t)))))
@@ -481,7 +494,7 @@ Prefix arg will make the entry nonmarking."
     (make-diary-entry
      (concat
       islamic-diary-entry-symbol
-      (calendar-date-string 
+      (calendar-date-string
        (calendar-islamic-from-absolute
         (calendar-absolute-from-gregorian
          (calendar-cursor-to-date t)))))
@@ -489,4 +502,5 @@ Prefix arg will make the entry nonmarking."
 
 (provide 'cal-islam)
 
+;;; arch-tag: a951b6c1-6f47-48d5-bac3-1b505cd719f7
 ;;; cal-islam.el ends here