emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/calendar/cal-islam.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/calendar/cal-islam.el,v
Date: Fri, 14 Mar 2008 07:13:35 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       08/03/14 07:13:35

Index: cal-islam.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/calendar/cal-islam.el,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- cal-islam.el        13 Mar 2008 05:43:27 -0000      1.34
+++ cal-islam.el        14 Mar 2008 07:13:35 -0000      1.35
@@ -36,10 +36,6 @@
 
 ;;; Code:
 
-(defvar displayed-month)
-(defvar displayed-year)
-(defvar original-date)
-
 (require 'cal-julian)
 
 (defvar calendar-islamic-month-name-array
@@ -64,11 +60,10 @@
 
 (defun islamic-calendar-day-number (date)
   "Return the day number within the year of the Islamic date DATE."
-    (let* ((month (extract-calendar-month date))
-           (day (extract-calendar-day date)))
+  (let ((month (extract-calendar-month date)))
       (+ (* 30 (/ month 2))
          (* 29 (/ (1- month) 2))
-         day)))
+       (extract-calendar-day date))))
 
 (defun calendar-absolute-from-islamic (date)
   "Absolute date of Islamic DATE.
@@ -79,9 +74,16 @@
          (year (extract-calendar-year date))
          (y (% year 30))
          (leap-years-in-cycle
-          (cond
-           ((< y 3) 0)  ((< y 6) 1)  ((< y 8) 2)  ((< y 11) 3) ((< y 14) 4)
-           ((< y 17) 5) ((< y 19) 6) ((< y 22) 7) ((< y 25) 8) ((< y 27) 9)
+          (cond ((< y 3) 0)
+                ((< y 6) 1)
+                ((< y 8) 2)
+                ((< y 11) 3)
+                ((< y 14) 4)
+                ((< y 17) 5)
+                ((< y 19) 6)
+                ((< y 22) 7)
+                ((< y 25) 8)
+                ((< y 27) 9)
            (t 10))))
     (+ (islamic-calendar-day-number date) ; days so far this year
        (* (1- year) 354)                  ; days in all non-leap years
@@ -142,7 +144,7 @@
 
 ;;;###cal-autoload
 (defun calendar-goto-islamic-date (date &optional noecho)
-  "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is t."
+  "Move cursor to Islamic DATE; echo Islamic date unless NOECHO is non-nil."
   (interactive
    (let* ((today (calendar-current-date))
           (year (calendar-read
@@ -169,6 +171,9 @@
                        (calendar-absolute-from-islamic date)))
   (or noecho (calendar-print-islamic-date)))
 
+(defvar displayed-month)                ; from generate-calendar
+(defvar displayed-year)
+
 ;;;###holiday-autoload
 (defun holiday-islamic (month day string)
   "Holiday on MONTH, DAY (Islamic) called STRING.
@@ -181,8 +186,7 @@
          (m (extract-calendar-month islamic-date))
          (y (extract-calendar-year islamic-date))
         (date))
-    (if (< m 1)
-        nil                        ;   Islamic calendar doesn't apply
+    (unless (< m 1)                   ; Islamic calendar doesn't apply
       (increment-calendar-month m y (- 10 month))
       (if (> m 7)                     ;  Islamic date might be visible
           (let ((date (calendar-gregorian-from-absolute
@@ -195,6 +199,7 @@
                   (date string specifier &optional marker globcolor literal))
 
 (defvar number)                         ; from diary-list-entries
+(defvar original-date)
 
 ;;;###diary-autoload
 (defun list-islamic-diary-entries ()
@@ -214,36 +219,31 @@
             (gdate original-date)
             (mark (regexp-quote diary-nonmarking-symbol)))
         (dotimes (idummy number)
-          (let* ((d diary-date-forms)
-                 (idate (calendar-islamic-from-absolute
+          (let* ((idate (calendar-islamic-from-absolute
                          (calendar-absolute-from-gregorian gdate)))
                  (month (extract-calendar-month idate))
                  (day (extract-calendar-day idate))
-                 (year (extract-calendar-year idate)))
-            (while d
-              (let*
-                  ((date-form (if (equal (car (car d)) 'backup)
-                                  (cdr (car d))
-                                (car d)))
-                   (backup (equal (car (car d)) 'backup))
-                   (dayname
+                 (year (extract-calendar-year idate))
+                 backup)
+            (dolist (date-form diary-date-forms)
+              (if (setq backup (eq (car date-form) 'backup))
+                  (setq date-form (cdr date-form)))
+              (let* ((dayname
                     (format "%s\\|%s\\.?"
                             (calendar-day-name gdate)
                             (calendar-day-name gdate 'abbrev)))
                    (calendar-month-name-array
                     calendar-islamic-month-name-array)
                    (monthname
-                    (concat
-                     "\\*\\|"
-                     (calendar-month-name month)))
+                      (concat "\\*\\|" (calendar-month-name month)))
                    (month (concat "\\*\\|0*" (int-to-string month)))
                    (day (concat "\\*\\|0*" (int-to-string day)))
                    (year
-                    (concat
-                     "\\*\\|0*" (int-to-string year)
+                      (concat "\\*\\|0*" (int-to-string year)
                      (if abbreviated-calendar-year
                          (concat "\\|" (int-to-string (% year 100)))
                        "")))
+                     ;; FIXME ^M can go now.
                    (regexp
                     (concat
                      "\\(\\`\\|\^M\\|\n\\)" mark "?"
@@ -276,14 +276,71 @@
                        (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))))
+                       (copy-marker entry-start))))))))
           (setq gdate
                 (calendar-gregorian-from-absolute
                  (1+ (calendar-absolute-from-gregorian gdate)))))
         (set-buffer-modified-p diary-modified))
     (goto-char (point-min))))
 
+;;;###diary-autoload
+(defun mark-islamic-calendar-date-pattern (month day year)
+  "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR.
+A value of 0 in any position is a wildcard."
+  (save-excursion
+    (set-buffer calendar-buffer)
+    (if (and (not (zerop month)) (not (zerop day)))
+        (if (not (zerop year))
+            ;; Fully specified Islamic date.
+            (let ((date (calendar-gregorian-from-absolute
+                         (calendar-absolute-from-islamic
+                          (list month day year)))))
+              (if (calendar-date-is-visible-p date)
+                  (mark-visible-calendar-date date)))
+          ;; Month and day in any year--this taken from the holiday stuff.
+          (let* ((islamic-date (calendar-islamic-from-absolute
+                                (calendar-absolute-from-gregorian
+                                 (list displayed-month 15 displayed-year))))
+                 (m (extract-calendar-month islamic-date))
+                 (y (extract-calendar-year islamic-date))
+                 (date))
+            (unless (< m 1)           ; Islamic calendar doesn't apply
+              (increment-calendar-month m y (- 10 month))
+              (if (> m 7)              ; Islamic date might be visible
+                  (let ((date (calendar-gregorian-from-absolute
+                               (calendar-absolute-from-islamic
+                                (list month day y)))))
+                    (if (calendar-date-is-visible-p date)
+                        (mark-visible-calendar-date date)))))))
+      ;; Not one of the simple cases--check all visible dates for match.
+      ;; Actually, the following code takes care of ALL of the cases, but
+      ;; it's much too slow to be used for the simple (common) cases.
+      (let ((m displayed-month)
+            (y displayed-year)
+            (first-date)
+            (last-date))
+        (increment-calendar-month m y -1)
+        (setq first-date
+              (calendar-absolute-from-gregorian
+               (list m 1 y)))
+        (increment-calendar-month m y 2)
+        (setq last-date
+              (calendar-absolute-from-gregorian
+               (list m (calendar-last-day-of-month m y) y)))
+        (calendar-for-loop date from first-date to last-date do
+          (let* ((i-date (calendar-islamic-from-absolute date))
+                 (i-month (extract-calendar-month i-date))
+                 (i-day (extract-calendar-day i-date))
+                 (i-year (extract-calendar-year i-date)))
+            (and (or (zerop month)
+                     (= month i-month))
+                 (or (zerop day)
+                     (= day i-day))
+                 (or (zerop year)
+                     (= year i-year))
+                 (mark-visible-calendar-date
+                  (calendar-gregorian-from-absolute date)))))))))
+
 (declare-function diary-name-pattern "diary-lib"
                   (string-array &optional abbrev-array paren))
 
@@ -293,21 +350,16 @@
 ;;;###diary-autoload
 (defun mark-islamic-diary-entries ()
   "Mark days in the calendar window that have Islamic date diary entries.
-Each entry in `diary-file' (or included files) visible in the calendar window
-is marked.  Islamic date entries are prefaced by `islamic-diary-entry-symbol'
-\(normally an `I').  The same `diary-date-forms' govern the style of the 
Islamic
-calendar entries, except that the Islamic month names must be spelled in full.
-The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
-Dhu al-Hijjah.  Islamic date diary entries that begin with a
-`diary-nonmarking-symbol' will not be marked in the calendar.  This function is
-provided for use as part of the `nongregorian-diary-marking-hook'."
-  (let ((d diary-date-forms))
-    (while d
-      (let*
-          ((date-form (if (equal (car (car d)) 'backup)
-                          (cdr (car d))
-                        (car d)))       ; ignore 'backup directive
-           (dayname (diary-name-pattern calendar-day-name-array
+Mark each entry in `diary-file' (or included files) visible in the calendar
+window.  Islamic date entries are prefaced by `islamic-diary-entry-symbol'
+\(normally an `I').  The same `diary-date-forms' govern the style
+of the Islamic calendar entries, except that the Islamic month
+names must be spelled in full.  The Islamic months are numbered
+from 1 to 12 with Muharram being 1 and 12 being Dhu al-Hijjah.
+Islamic date diary entries that begin with `diary-nonmarking-symbol'
+are not marked.  This function is provided for use as part of
+`nongregorian-diary-marking-hook'."
+  (let ((dayname (diary-name-pattern calendar-day-name-array
                                         calendar-day-abbrev-array))
            (monthname
             (format "%s\\|\\*"
@@ -315,7 +367,11 @@
            (month "[0-9]+\\|\\*")
            (day "[0-9]+\\|\\*")
            (year "[0-9]+\\|\\*")
-           (l (length date-form))
+        (case-fold-search t))
+    (dolist (date-form diary-date-forms)
+      (if (eq (car date-form) 'backup)  ; ignore 'backup directive
+          (setq date-form (cdr date-form)))
+      (let* ((l (length date-form))
            (d-name-pos (- l (length (memq 'dayname date-form))))
            (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos)))
            (m-name-pos (- l (length (memq 'monthname date-form))))
@@ -332,8 +388,7 @@
              (regexp-quote islamic-diary-entry-symbol)
              "\\("
              (mapconcat 'eval date-form "\\)\\(")
-             "\\)"))
-           (case-fold-search t))
+               "\\)")))
         (goto-char (point-min))
         (while (re-search-forward regexp nil t)
           (let* ((dd-name
@@ -391,67 +446,7 @@
                                    mm-name
                                    (calendar-make-alist
                                     calendar-islamic-month-name-array) t)))))
-              (mark-islamic-calendar-date-pattern mm dd yy)))))
-      (setq d (cdr d)))))
-
-;;;###diary-autoload
-(defun mark-islamic-calendar-date-pattern (month day year)
-  "Mark dates in calendar window that conform to Islamic date MONTH/DAY/YEAR.
-A value of 0 in any position is a wildcard."
-  (save-excursion
-    (set-buffer calendar-buffer)
-    (if (and (not (zerop month)) (not (zerop day)))
-        (if (not (zerop year))
-            ;; Fully specified Islamic date.
-            (let ((date (calendar-gregorian-from-absolute
-                         (calendar-absolute-from-islamic
-                          (list month day year)))))
-              (if (calendar-date-is-visible-p date)
-                  (mark-visible-calendar-date date)))
-          ;; Month and day in any year--this taken from the holiday stuff.
-          (let* ((islamic-date (calendar-islamic-from-absolute
-                                (calendar-absolute-from-gregorian
-                                 (list displayed-month 15 displayed-year))))
-                 (m (extract-calendar-month islamic-date))
-                 (y (extract-calendar-year islamic-date))
-                 (date))
-            (if (< m 1)
-                nil                ;   Islamic calendar doesn't apply
-              (increment-calendar-month m y (- 10 month))
-              (if (> m 7)             ;  Islamic date might be visible
-                  (let ((date (calendar-gregorian-from-absolute
-                               (calendar-absolute-from-islamic
-                                (list month day y)))))
-                    (if (calendar-date-is-visible-p date)
-                        (mark-visible-calendar-date date)))))))
-      ;; Not one of the simple cases--check all visible dates for match.
-      ;; Actually, the following code takes care of ALL of the cases, but
-      ;; it's much too slow to be used for the simple (common) cases.
-      (let ((m displayed-month)
-            (y displayed-year)
-            (first-date)
-            (last-date))
-        (increment-calendar-month m y -1)
-        (setq first-date
-              (calendar-absolute-from-gregorian
-               (list m 1 y)))
-        (increment-calendar-month m y 2)
-        (setq last-date
-              (calendar-absolute-from-gregorian
-               (list m (calendar-last-day-of-month m y) y)))
-        (calendar-for-loop date from first-date to last-date do
-          (let* ((i-date (calendar-islamic-from-absolute date))
-                 (i-month (extract-calendar-month i-date))
-                 (i-day (extract-calendar-day i-date))
-                 (i-year (extract-calendar-year i-date)))
-            (and (or (zerop month)
-                     (= month i-month))
-                 (or (zerop day)
-                     (= day i-day))
-                 (or (zerop year)
-                     (= year i-year))
-                 (mark-visible-calendar-date
-                  (calendar-gregorian-from-absolute date)))))))))
+              (mark-islamic-calendar-date-pattern mm dd yy))))))))
 
 ;;;###cal-autoload
 (defun insert-islamic-diary-entry (arg)
@@ -459,14 +454,12 @@
 For the Islamic date corresponding to the date indicated by point.
 Prefix argument ARG makes the entry nonmarking."
   (interactive "P")
-  (let* ((calendar-month-name-array calendar-islamic-month-name-array))
+  (let ((calendar-month-name-array calendar-islamic-month-name-array))
     (make-diary-entry
-     (concat
-      islamic-diary-entry-symbol
+     (concat islamic-diary-entry-symbol
       (calendar-date-string
        (calendar-islamic-from-absolute
-        (calendar-absolute-from-gregorian
-         (calendar-cursor-to-date t)))
+               (calendar-absolute-from-gregorian (calendar-cursor-to-date t)))
        nil t))
      arg)))
 
@@ -476,16 +469,15 @@
 For the day of the Islamic month corresponding to the date indicated by point.
 Prefix argument ARG makes the entry nonmarking."
   (interactive "P")
-  (let* ((calendar-date-display-form
-          (if european-calendar-style '(day " * ") '("* " day )))
+  (let ((calendar-date-display-form (if european-calendar-style
+                                        '(day " * ")
+                                      '("* " day )))
          (calendar-month-name-array calendar-islamic-month-name-array))
     (make-diary-entry
-     (concat
-      islamic-diary-entry-symbol
+     (concat islamic-diary-entry-symbol
       (calendar-date-string
        (calendar-islamic-from-absolute
-        (calendar-absolute-from-gregorian
-         (calendar-cursor-to-date t)))))
+               (calendar-absolute-from-gregorian (calendar-cursor-to-date 
t)))))
      arg)))
 
 ;;;###cal-autoload
@@ -494,18 +486,15 @@
 For the day of the Islamic year corresponding to the date indicated by point.
 Prefix argument ARG makes the entry nonmarking."
   (interactive "P")
-  (let* ((calendar-date-display-form
-          (if european-calendar-style
+  (let ((calendar-date-display-form (if european-calendar-style
               '(day " " monthname)
             '(monthname " " day)))
          (calendar-month-name-array calendar-islamic-month-name-array))
     (make-diary-entry
-     (concat
-      islamic-diary-entry-symbol
+     (concat islamic-diary-entry-symbol
       (calendar-date-string
        (calendar-islamic-from-absolute
-        (calendar-absolute-from-gregorian
-         (calendar-cursor-to-date t)))))
+               (calendar-absolute-from-gregorian (calendar-cursor-to-date 
t)))))
      arg)))
 
 (defvar date)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]