aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2005-06-21 13:10:39 +0000
committerGlenn Morris2005-06-21 13:10:39 +0000
commit871ce75345201d7db44fbc9cfb0496419dc0269d (patch)
tree72187dce1d6ce6ab359b6b568862af6bd6ac2a70
parent006b1390cb5d4b66f6dffa7046180e5f869a45e8 (diff)
downloademacs-871ce75345201d7db44fbc9cfb0496419dc0269d.tar.gz
emacs-871ce75345201d7db44fbc9cfb0496419dc0269d.zip
(appt-make-list): Activate the package, if not already active (for
backwards compatibility).
-rw-r--r--lisp/calendar/appt.el193
1 files changed, 111 insertions, 82 deletions
diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el
index c3f29e3d371..a66ef9cec6e 100644
--- a/lisp/calendar/appt.el
+++ b/lisp/calendar/appt.el
@@ -534,88 +534,93 @@ NUMBER hold the arguments that `list-diary-entries' received.
534They specify the range of dates that the diary is being processed for. 534They specify the range of dates that the diary is being processed for.
535 535
536Any appointments made with `appt-add' are not affected by this 536Any appointments made with `appt-add' are not affected by this
537function." 537function.
538 538
539 ;; We have something to do if the range of dates that the diary is 539For backwards compatibility, this function activates the
540 ;; considering includes the current date. 540appointment package (if it is not already active)."
541 (if (and (not (calendar-date-compare 541 ;; See comments above appt-activate defun.
542 (list (calendar-current-date)) 542 (if (not appt-timer)
543 (list original-date))) 543 (appt-activate 1)
544 (calendar-date-compare 544 ;; We have something to do if the range of dates that the diary is
545 (list (calendar-current-date)) 545 ;; considering includes the current date.
546 (list (calendar-gregorian-from-absolute 546 (if (and (not (calendar-date-compare
547 (+ (calendar-absolute-from-gregorian original-date) 547 (list (calendar-current-date))
548 number))))) 548 (list original-date)))
549 (save-excursion 549 (calendar-date-compare
550 ;; Clear the appointments list, then fill it in from the diary. 550 (list (calendar-current-date))
551 (dolist (elt appt-time-msg-list) 551 (list (calendar-gregorian-from-absolute
552 ;; Delete any entries that were not made with appt-add. 552 (+ (calendar-absolute-from-gregorian original-date)
553 (unless (nth 2 elt) 553 number)))))
554 (setq appt-time-msg-list 554 (save-excursion
555 (delq elt appt-time-msg-list)))) 555 ;; Clear the appointments list, then fill it in from the diary.
556 (if diary-entries-list 556 (dolist (elt appt-time-msg-list)
557 557 ;; Delete any entries that were not made with appt-add.
558 ;; Cycle through the entry-list (diary-entries-list) 558 (unless (nth 2 elt)
559 ;; looking for entries beginning with a time. If 559 (setq appt-time-msg-list
560 ;; the entry begins with a time, add it to the 560 (delq elt appt-time-msg-list))))
561 ;; appt-time-msg-list. Then sort the list. 561 (if diary-entries-list
562 562
563 (let ((entry-list diary-entries-list) 563 ;; Cycle through the entry-list (diary-entries-list)
564 (new-time-string "")) 564 ;; looking for entries beginning with a time. If
565 ;; Skip diary entries for dates before today. 565 ;; the entry begins with a time, add it to the
566 (while (and entry-list 566 ;; appt-time-msg-list. Then sort the list.
567 (calendar-date-compare 567
568 (car entry-list) (list (calendar-current-date)))) 568 (let ((entry-list diary-entries-list)
569 (setq entry-list (cdr entry-list))) 569 (new-time-string ""))
570 ;; Parse the entries for today. 570 ;; Skip diary entries for dates before today.
571 (while (and entry-list 571 (while (and entry-list
572 (calendar-date-equal 572 (calendar-date-compare
573 (calendar-current-date) (car (car entry-list)))) 573 (car entry-list) (list (calendar-current-date))))
574 (let ((time-string (cadr (car entry-list)))) 574 (setq entry-list (cdr entry-list)))
575 (while (string-match 575 ;; Parse the entries for today.
576 "\\([0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?\\).*" 576 (while (and entry-list
577 time-string) 577 (calendar-date-equal
578 (let* ((beg (match-beginning 0)) 578 (calendar-current-date) (car (car entry-list))))
579 ;; Get just the time for this appointment. 579 (let ((time-string (cadr (car entry-list))))
580 (only-time (match-string 1 time-string)) 580 (while (string-match
581 ;; Find the end of this appointment 581 "\\([0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?\\).*"
582 ;; (the start of the next). 582 time-string)
583 (end (string-match 583 (let* ((beg (match-beginning 0))
584 "^[ \t]*[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?" 584 ;; Get just the time for this appointment.
585 time-string 585 (only-time (match-string 1 time-string))
586 (match-end 0))) 586 ;; Find the end of this appointment
587 ;; Get the whole string for this appointment. 587 ;; (the start of the next).
588 (appt-time-string 588 (end (string-match
589 (substring time-string beg (if end (1- end))))) 589 "^[ \t]*[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?"
590 590 time-string
591 ;; Add this appointment to appt-time-msg-list. 591 (match-end 0)))
592 (let* ((appt-time (list (appt-convert-time only-time))) 592 ;; Get the whole string for this appointment.
593 (time-msg (list appt-time appt-time-string))) 593 (appt-time-string
594 (setq appt-time-msg-list 594 (substring time-string beg (if end (1- end)))))
595 (nconc appt-time-msg-list (list time-msg)))) 595
596 596 ;; Add this appointment to appt-time-msg-list.
597 ;; Discard this appointment from the string. 597 (let* ((appt-time (list (appt-convert-time only-time)))
598 (setq time-string 598 (time-msg (list appt-time appt-time-string)))
599 (if end (substring time-string end) ""))))) 599 (setq appt-time-msg-list
600 (setq entry-list (cdr entry-list))))) 600 (nconc appt-time-msg-list (list time-msg))))
601 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list)) 601
602 602 ;; Discard this appointment from the string.
603 ;; Get the current time and convert it to minutes 603 (setq time-string
604 ;; from midnight. ie. 12:01am = 1, midnight = 0, 604 (if end (substring time-string end) "")))))
605 ;; so that the elements in the list 605 (setq entry-list (cdr entry-list)))))
606 ;; that are earlier than the present time can 606 (setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
607 ;; be removed. 607
608 608 ;; Get the current time and convert it to minutes
609 (let* ((now (decode-time)) 609 ;; from midnight. ie. 12:01am = 1, midnight = 0,
610 (cur-hour (nth 2 now)) 610 ;; so that the elements in the list
611 (cur-min (nth 1 now)) 611 ;; that are earlier than the present time can
612 (cur-comp-time (+ (* cur-hour 60) cur-min)) 612 ;; be removed.
613 (appt-comp-time (car (caar appt-time-msg-list)))) 613
614 614 (let* ((now (decode-time))
615 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time)) 615 (cur-hour (nth 2 now))
616 (setq appt-time-msg-list (cdr appt-time-msg-list)) 616 (cur-min (nth 1 now))
617 (if appt-time-msg-list 617 (cur-comp-time (+ (* cur-hour 60) cur-min))
618 (setq appt-comp-time (car (caar appt-time-msg-list))))))))) 618 (appt-comp-time (car (caar appt-time-msg-list))))
619
620 (while (and appt-time-msg-list (< appt-comp-time cur-comp-time))
621 (setq appt-time-msg-list (cdr appt-time-msg-list))
622 (if appt-time-msg-list
623 (setq appt-comp-time (car (caar appt-time-msg-list))))))))))
619 624
620 625
621(defun appt-sort-list (appt-list) 626(defun appt-sort-list (appt-list)
@@ -665,6 +670,30 @@ This function is intended for use with `write-file-functions'."
665 nil) 670 nil)
666 671
667 672
673;; In Emacs-21.3, the manual documented the following procedure to
674;; activate this package:
675;; (display-time)
676;; (add-hook 'diary-hook 'appt-make-list)
677;; (diary 0)
678;; The display-time call was not necessary, AFAICS.
679;; What was really needed was to add the hook and load this file.
680;; Calling (diary 0) once the hook had been added was in some sense a
681;; roundabout way of loading this file. This file used to have code at
682;; the top-level that set up the appt-timer and global-mode-string.
683;; One way to maintain backwards compatibility would be to call
684;; (appt-activate 1) at top-level. However, this goes against the
685;; convention that just loading an Emacs package should not activate
686;; it. Instead, we make appt-make-list activate the package (after a
687;; suggestion from rms). This means that one has to call diary in
688;; order to get it to work, but that is in line with the old (weird,
689;; IMO) documented behavior for activating the package.
690;; Actually, since (diary 0) does not run diary-hook, I don't think
691;; the documented behavior in Emacs-21.3 would ever have worked.
692;; Oh well, at least with the changes to appt-make-list it will now
693;; work as well as it ever did.
694;; The new method is just to use (appt-activate 1).
695;; -- gmorris
696
668;;;###autoload 697;;;###autoload
669(defun appt-activate (&optional arg) 698(defun appt-activate (&optional arg)
670"Toggle checking of appointments. 699"Toggle checking of appointments.