From xemacs-m  Sat Mar 22 14:52:04 1997
Received: from mecca.spd.louisville.edu (mecca.spd.louisville.edu [136.165.40.148])
	by xemacs.org (8.8.5/8.8.5) with SMTP id OAA00215
	for <xemacs-beta@xemacs.org>; Sat, 22 Mar 1997 14:52:03 -0600 (CST)
Received: (from tjchol01@localhost) by mecca.spd.louisville.edu (950413.SGI.8.6.12/8.6.12) id UAA25563; Sat, 22 Mar 1997 20:52:10 GMT
Date: Sat, 22 Mar 1997 20:52:10 GMT
Message-Id: <199703222052.UAA25563@mecca.spd.louisville.edu>
From: "Tomasz J. Cholewo" <tjchol01@mecca.spd.louisville.edu>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: XEmacs-Beta Mailing List <xemacs-beta@xemacs.org>
Subject: [patch] 20.1b9: Fancy diary corrections.

The following patch fixes a bug in appt.el which prevented it from
displaying a diary buffer at 12:00am when using fancy-diary-display.  It
also adds a new function diary-countdown which allows one to get
appointment entries like: "It is 6 days before vacation" or "It is 1 da
y after release deadline".  Several typos are also corrected.

Tom
===================
diff -urd xemacs-20.1-b9-orig/lisp/ChangeLog xemacs-20.1-b9/lisp/ChangeLog
--- xemacs-20.1-b9-orig/lisp/ChangeLog	Sat Mar 22 01:01:45 1997
+++ xemacs-20.1-b9/lisp/ChangeLog	Sat Mar 22 15:18:39 1997
@@ -1,7 +1,15 @@
+Sat Mar 22 14:25:47 1997  Tomasz J. Cholewo  <t.cholewo@ieee.org>
+
+	* calendar/diary-lib.el (diary-countdown): New function.
+	(fancy-diary-display): Use modeline-buffer-identification.
+
+	* calendar/appt.el (appt-diary-entries): Do not display diary.
+	(appt-check): Display diary buffer at midnight.  
+	
 Fri Mar 21 19:16:46 1997  Steven L Baur  <steve@altair.xemacs.org>
 
 	* mule/mule-coding.el (enable-multibyte-characters): MULE
-	compatabile variable.
+	compatible variable.
 
 Thu Mar 20 13:28:17 1997  Steven L Baur  <steve@altair.xemacs.org>
 
diff -urd xemacs-20.1-b9-orig/lisp/calendar/appt.el xemacs-20.1-b9/lisp/calendar/appt.el
--- xemacs-20.1-b9-orig/lisp/calendar/appt.el	Sat Mar  8 18:25:45 1997
+++ xemacs-20.1-b9/lisp/calendar/appt.el	Sat Mar 22 15:20:55 1997
@@ -24,7 +24,10 @@
 ;;; 29-nov-89	created by Neil Mager <neilm@juliet.ll.mit.edu>.
 ;;; 23-feb-91	hacked upon by Jamie Zawinski <jwz@lucid.com>.
 ;;;  1-apr-91	some more.
-;;; 12-jul-95   updated for XEmacs 19.12 by Greg Veres <gveres@cgl.uwaterloo.ca>
+;;; 12-jul-95   updated for XEmacs 19.12 by Greg Veres 
+;;;             <gveres@cgl.uwaterloo.ca>
+;;; 21-mar-97   better support for fancy diary display by Tomasz J. Cholewo 
+;;;             <t.cholewo@ieee.org>
 ;;;
 ;; appt.el - visible and/or audible notification of
 ;;           appointments from ~/diary file generated from
@@ -117,7 +120,7 @@
 ;;;
 ;;; This also interacts correctly with Benjamin Pierce's reportmail.el package.
 ;;;
-;;; Brief internal description - Skip this if your not interested!
+;;; Brief internal description - Skip this if you are not interested!
 ;;;
 ;;; The function appt-initialize invokes 'diary' to get a list of today's
 ;;; appointments, and parses the lines beginning with date descriptions.
@@ -133,7 +136,7 @@
 ;;;
 ;;; TO DO:
 ;;;
-;;;  o  multiple adjascent appointments are not handled gracefully.  If there 
+;;;  o  multiple adjacent appointments are not handled gracefully.  If there 
 ;;;     is an appointment at 3:30 and another at 3:35, and you have set things
 ;;;     up so that you get a notification twenty minutes before each appt,
 ;;;     then a notification should come at 3:10 for the first appt, and at
@@ -369,7 +372,7 @@
 ;;; Internal stuff
 
 (defun appt-convert-time (time2conv)
-  " Convert hour:min[am/pm] format to minutes from midnight."
+  "Convert hour:min[am/pm] format to minutes from midnight."
   (cond ((string-match "^[ \t]*midni\\(ght\\|te\\)[ \t]*\\'" time2conv)
 	 0)
 	((string-match "^[ \t]*noon[ \t]*\\'" time2conv)
@@ -401,8 +404,8 @@
 	   (+ (* hr 60) min)))))
 
 
-(defun appt-current-time-in-seconds ()
-  "returns the current time in seconds since midnight."
+(defun appt-current-time-in-minutes ()
+  "Returns the current time in minutes since midnight."
   (let* ((str (current-time-string))
 	 (hour (string-to-int (substring str 11 13)))
 	 (min  (string-to-int (substring str 14 16))))
@@ -415,17 +418,18 @@
 	  (< (car (car x)) (car (car y)))))))
 
 (defun appt-diary-entries ()
+  "Return an updated list of appointments for today."
   (let ((list-diary-entries-hook '(appt-make-list))
-	(diary-display-hook nil)
+	(diary-display-hook 'ignore)
 	(diary-list-include-blanks nil))
     ;; this will set appt-time-msg-list.
     (diary 1)
     appt-time-msg-list))
 
 (defun appt-initialize ()
-  " Read your `diary-file' and remember today's appointments.  Call this from 
+  "Read your `diary-file' and remember today's appointments.  Call this from 
  your .emacs file, or any time you want your .diary file re-read (this happens 
- automatically at midnight to move to notice the next day's appointments).
+ automatically at midnight to notice the next day's appointments).
  
  The time must be at the beginning of a line for it to be put in the 
  appointments list.
@@ -483,11 +487,11 @@
 	      (append (nreverse new-appts) appt-time-msg-list))))
   (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
   ;;
-  ;; Get the current time and convert it to minutes from midnight. ie. 12:01am
-  ;; = 1, midnight = 0, so that the elements in the list that are earlier than
-  ;; the present time can be removed.
+  ;; Get the current time and convert it to minutes from midnight, i.e.,
+  ;; 12:01am = 1, midnight = 0, so that the elements in the list that
+  ;; are earlier than the present time can be removed.
   ;;
-  (let ((cur-comp-time (appt-current-time-in-seconds))
+  (let ((cur-comp-time (appt-current-time-in-minutes))
 	(appt-comp-time (car (car (car appt-time-msg-list)))))
     (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
       (setq appt-time-msg-list (cdr appt-time-msg-list)) 
@@ -548,8 +552,8 @@
   (if appt-issue-message
    (let ((min-to-app -1))
      ;; Get the current time and convert it to minutes
-     ;; from midnight. ie. 12:01am = 1, midnight = 0.
-     (let* ((cur-comp-time (appt-current-time-in-seconds))
+     ;; from midnight, i.e., 12:01am = 1, midnight = 0.
+     (let* ((cur-comp-time (appt-current-time-in-minutes))
 	    ;; If the current time is the same as the tick, just return.
 	    ;; This means that this function has been called more than once
 	    ;; in the current minute, which is not useful.
@@ -559,8 +563,8 @@
        ;;
        ;; If it is now the next day (we have crossed midnight since the last
        ;; time this was called) then we should update our appointments to
-       ;; today's list.
-       (if turnover-p (appt-diary-entries))
+       ;; today's list.  Show the diary entries (tjc).
+       (if turnover-p (diary 1))
        ;;
        ;; Get the first time off of the list and calculate the number
        ;; of minutes until the appointment.
diff -urd xemacs-20.1-b9-orig/lisp/calendar/diary-lib.el xemacs-20.1-b9/lisp/calendar/diary-lib.el
--- xemacs-20.1-b9-orig/lisp/calendar/diary-lib.el	Wed Dec 18 17:42:35 1996
+++ xemacs-20.1-b9/lisp/calendar/diary-lib.el	Sat Mar 22 15:43:22 1997
@@ -359,8 +359,7 @@
     (save-excursion;; Prepare the fancy diary buffer.
       (set-buffer (get-buffer-create fancy-diary-buffer))
       (setq buffer-read-only nil)
-      (make-local-variable 'mode-line-format)
-      (calendar-set-mode-line "Diary Entries")
+      (setq modeline-buffer-identification '("Diary Entries"))
       (erase-buffer)
       (let ((entry-list diary-entries-list)
             (holiday-list)
@@ -1102,6 +1101,13 @@
                   order of the parameters should be changed to D1, M1, Y1,
                   D2, M2, Y2.)
 
+      %%(diary-countdown BEFORE AFTER M1 D1 Y1) text
+                  Entry will appear on dates between BEFORE days before
+                  and AFTER days after specified date.  (If
+                  `european-calendar-style' is t, the order of the
+                  parameters should be changed to BEFORE, AFTER, D1, M1,
+                  Y1.)
+
       %%(diary-anniversary MONTH DAY YEAR) text
                   Entry will appear on anniversary dates of MONTH DAY, YEAR.
                   (If `european-calendar-style' is t, the order of the
@@ -1261,7 +1267,7 @@
 (defun diary-block (m1 d1 y1 m2 d2 y2)
   "Block diary entry.
 Entry applies if date is between two dates.  Order of the parameters is
-M1, D1, Y1, M2, D2, Y2 `european-calendar-style' is nil, and
+M1, D1, Y1, M2, D2, Y2 if `european-calendar-style' is nil, and
 D1, M1, Y1, D2, M2, Y2 if `european-calendar-style' is t."
   (let ((date1 (calendar-absolute-from-gregorian
                 (if european-calendar-style
@@ -1274,6 +1280,28 @@
         (d (calendar-absolute-from-gregorian date)))
     (if (and (<= date1 d) (<= d date2))
         entry)))
+
+(defun diary-countdown (before after m1 d1 y1)
+  "Countdown diary entry.
+Entry applies if date is between BEFORE days before and AFTER days after
+specified date.  Order of the parameters is BEFORE, AFTER, M1, D1, Y1 if
+`european-calendar-style' is nil, and BEFORE, AFTER, D1, M1, Y1 if
+`european-calendar-style' is t."
+  (let* ((date1 (calendar-absolute-from-gregorian
+                 (if european-calendar-style
+                     (list d1 m1 y1)
+                   (list m1 d1 y1))))
+         (d (calendar-absolute-from-gregorian date))
+         (diff (- d date1)))
+    (cond
+     ((and (<= (- before) diff) (< diff 0))
+      (concat (format "It is %d day%s before " 
+                      (- diff) (if (= diff -1) "" "s")) entry))
+     ((= diff 0) (concat (format "TODAY: " diff) entry))
+     ((and (<= diff after) (> diff 0)) 
+      (concat (format "It is %d day%s after " 
+                      diff (if (= diff 1) "" "s")) entry))
+     (t nil))))
 
 (defun diary-float (month dayname n)
   "Floating diary entry--entry applies if date is the nth dayname of month.

