;; appt.el - visible and/or audible notification of
;; appointments from ~/diary file.
;;
-;;
-;; Comments, corrections, and improvements should be sent to
-;; Neil M. Mager
-;; Net <neilm@juliet.ll.mit.edu>
-;; Voice (617) 981-4803
;;;
-;;; Thanks to Edward M. Reingold for much help and many suggestions,
+;;; Thanks to Edward M. Reingold for much help and many suggestions,
;;; And to many others for bug fixes and suggestions.
;;;
;;;
;;; at 12:01am for those who do not logout every day or are programming
;;; late.
;;;
-;;; Brief internal description - Skip this if your not interested!
+;;; Brief internal description - Skip this if you are not interested!
;;;
;;; The function appt-make-list creates the appointments list which appt-check
;;; reads. This is all done automatically.
(current-time)))
(funcall
appt-disp-window-function
- min-to-app new-time
+ (number-to-string min-to-app) new-time
(car (cdr (car appt-time-msg-list))))
(run-at-time
(when appt-display-mode-line
(setq appt-mode-string
- (concat " App't in " min-to-app " min. ")))
+ (concat " App't in "
+ (number-to-string min-to-app)
+ " min. ")))
;; When an appointment is reached,
;; delete it from the list.
(sit-for 0)))))))))
-;; Display appointment message in a separate buffer.
(defun appt-disp-window (min-to-app new-time appt-msg)
+ "Display appointment message APPT-MSG in a separate buffer."
(require 'electric)
;; Make sure we're not in the minibuffer
(if (equal (selected-window) (minibuffer-window))
(if (other-window 1)
(select-window (other-window 1))
- (if window-system
+ (if (display-multi-frame-p)
(select-frame (other-frame 1)))))
(let* ((this-buffer (current-buffer))
Usually just deletes the appointment buffer."
(let ((window (get-buffer-window appt-buffer-name t)))
(and window
- (or (and (fboundp 'frame-root-window)
- (eq window (frame-root-window (window-frame window))))
+ (or (eq window (frame-root-window (window-frame window)))
(delete-window window))))
(kill-buffer appt-buffer-name)
(if appt-audible
(beep 1)))
-;; Select the lowest window on the frame.
(defun appt-select-lowest-window ()
- (let* ((lowest-window (selected-window))
- (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
- (last-window (previous-window))
- (window-search t))
- (while window-search
- (let* ((this-window (next-window))
- (next-bottom-edge (car (cdr (cdr (cdr
- (window-edges this-window)))))))
- (if (< bottom-edge next-bottom-edge)
- (progn
- (setq bottom-edge next-bottom-edge)
- (setq lowest-window this-window)))
-
- (select-window this-window)
- (if (eq last-window this-window)
- (progn
- (select-window lowest-window)
- (setq window-search nil)))))))
-
+"Select the lowest window on the frame."
+ (let ((lowest-window (selected-window))
+ (bottom-edge (nth 3 (window-edges))))
+ (walk-windows (lambda (w)
+ (let ((next-bottom-edge (nth 3 (window-edges w))))
+ (when (< bottom-edge next-bottom-edge)
+ (setq bottom-edge next-bottom-edge
+ lowest-window w)))))
+ (select-window lowest-window)))
;;;###autoload
(defun appt-add (new-appt-time new-appt-msg)
- "Add an appointment for the day at TIME and issue MESSAGE.
+ "Add an appointment for the day at NEW-APPT-TIME and issue message NEW-APPT-MSG.
The time should be in either 24 hour format or am/pm format."
(interactive "sTime (hh:mm[am/pm]): \nsMessage: ")
(let* ((appt-time-string (concat new-appt-time " " new-appt-msg))
(appt-time (list (appt-convert-time new-appt-time)))
(time-msg (cons appt-time (list appt-time-string))))
- (setq appt-time-msg-list (append appt-time-msg-list
- (list time-msg)))
+ (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg)))
(setq appt-time-msg-list (appt-sort-list appt-time-msg-list))))
;;;###autoload
(setq tmp-msg-list (cdr tmp-msg-list))
(if test-input
(setq appt-time-msg-list (delq element appt-time-msg-list)))))
+ (appt-check)
(message "")))
-;; Create the appointments list from todays diary buffer.
-;; The time must be at the beginning of a line for it to be
-;; put in the appointments list.
-;; 02/23/89
-;; 12:00pm lunch
-;; Wednesday
-;; 10:00am group meeting
-;; We assume that the variables DATE and NUMBER
-;; hold the arguments that list-diary-entries received.
-;; They specify the range of dates that the diary is being processed for.
-
+(eval-when-compile (defvar number)
+ (defvar original-date)
+ (defvar diary-entries-list))
;;;###autoload
(defun appt-make-list ()
+ "Create the appointments list from todays diary buffer.
+The time must be at the beginning of a line for it to be
+put in the appointments list.
+ 02/23/89
+ 12:00pm lunch
+ Wednesday
+ 10:00am group meeting
+We assume that the variables DATE and NUMBER
+hold the arguments that `list-diary-entries' received.
+They specify the range of dates that the diary is being processed for."
+
;; We have something to do if the range of dates that the diary is
;; considering includes the current date.
(if (and (not (calendar-date-compare
(calendar-date-equal
(calendar-current-date) (car (car entry-list))))
(let ((time-string (substring (prin1-to-string
- (cadr (car entry-list))) 2 -1)))
+ (cadr (car entry-list))) 1 -1)))
(while (string-match
- "[0-9]?[0-9]:[0-9][0-9]\\(am\\|pm\\)?.*"
+ "[0-9]?[0-9]:[0-9][0-9]\\(am\\|pm\\)?\\(.*\n\\)*.*"
time-string)
- (let* ((appt-time-string (substring time-string
- (match-beginning 0)
- (match-end 0))))
+ (let* ((appt-time-string (match-string 0 time-string)))
(if (< (match-end 0) (length time-string))
(setq new-time-string (substring time-string
time-string)
(let* ((appt-time (list (appt-convert-time
- (substring time-string
- (match-beginning 0)
- (match-end 0)))))
+ (match-string 0 time-string))))
(time-msg (cons appt-time
(list appt-time-string))))
(setq time-string new-time-string)
- (setq appt-time-msg-list (append appt-time-msg-list
- (list time-msg)))))))
+ (setq appt-time-msg-list (nconc appt-time-msg-list
+ (list time-msg)))))))
(setq entry-list (cdr entry-list)))))
(setq appt-time-msg-list (appt-sort-list appt-time-msg-list))
(setq appt-comp-time (car (car (car appt-time-msg-list))))))))))
-;;Simple sort to put the appointments list in order.
-;;Scan the list for the smallest element left in the list.
-;;Append the smallest element left into the new list, and remove
-;;it from the original list.
(defun appt-sort-list (appt-list)
+ "Simple sort to put the appointments list APPT-LIST in order.
+Scan the list for the smallest element left in the list.
+Append the smallest element left into the new list, and remove
+it from the original list."
(let ((order-list nil))
(while appt-list
(let* ((element (car appt-list))
(setq element (car tmp-list))
(setq element-time (car (car element))))
(setq tmp-list (cdr tmp-list)))
- (setq order-list (append order-list (list element)))
+ (setq order-list (nconc order-list (list element)))
(setq appt-list (delq element appt-list))))
order-list))
(hr 0)
(min 0))
- (string-match ":[0-9][0-9]" time2conv)
+ (string-match ":\\([0-9][0-9]\\)" time2conv)
(setq min (string-to-int
- (substring time2conv
- (+ (match-beginning 0) 1) (match-end 0))))
+ (match-string 1 time2conv)))
(string-match "[0-9]?[0-9]:" time2conv)
(setq hr (string-to-int
- (substring time2conv
- (match-beginning 0)
- (match-end 0))))
+ (match-string 0 time2conv)))
;; convert the time appointment time into 24 hour time
- (if (and (string-match "[p][m]" time2conv) (< hr 12))
- (progn
- (string-match "[0-9]?[0-9]:" time2conv)
- (setq hr (+ 12 hr))))
+ (cond ((and (string-match "pm" time2conv) (< hr 12))
+ (setq hr (+ 12 hr)))
+ ((and (string-match "am" time2conv) (= hr 12))
+ (setq hr 0)))
;; convert the actual time
;; into minutes for comparison