;;; reads. This is all done automatically.
;;; It is invoked from the function list-diary-entries.
;;;
+;;; You can change the way the appointment window is created/deleted by
+;;; setting the variables
+;;;
+;;; appt-disp-window-function
+;;; and
+;;; appt-delete-window-function
+;;;
+;;; For instance, these variables can be set to functions that display
+;;; appointments in pop-up frames, which are lowered or iconified after
+;;; appt-display-interval seconds.
+;;;
;;; Code:
(defvar appt-display-interval 1
"*Number of minutes to wait between checking the appointment list.")
+
+(defvar appt-buffer-name " *appt-buf*"
+ "Name of the appointments buffer.")
+
+(defvar appt-disp-window-function 'appt-disp-window
+ "Function called to display appointment window.")
+
+(defvar appt-delete-window-function 'appt-delete-window
+ "Function called to remove appointment window and buffer.")
(defun appt-check ()
"Check for an appointment and update the mode line.
(setq new-time (substring display-time-string
(match-beginning 0)
(match-end 0)))
- (appt-disp-window min-to-app new-time
- (car (cdr (car appt-time-msg-list)))))
+ (funcall
+ appt-disp-window-function
+ min-to-app new-time
+ (car (cdr (car appt-time-msg-list))))
+
+ (run-at-time
+ (format "%d sec" appt-display-duration)
+ nil
+ appt-delete-window-function))
;;; else
(if appt-visible
;; Display appointment message in a separate buffer.
(defun appt-disp-window (min-to-app new-time appt-msg)
(require 'electric)
- (save-window-excursion
-
- ;; Make sure we're not in the minibuffer
- ;; before splitting the window.
-
- (if (= (frame-height)
- (nth 3 (window-edges (selected-window))))
- nil
- (appt-select-lowest-window)
- (split-window))
-
- (let* ((this-buffer (current-buffer))
- (appt-disp-buf (set-buffer (get-buffer-create "appt-buf"))))
- (setq mode-line-format
- (concat "-------------------- Appointment in "
- min-to-app " minutes. " new-time " %-"))
- (pop-to-buffer appt-disp-buf)
- (insert-string appt-msg)
- (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf))
- (set-buffer-modified-p nil)
- (if appt-audible
- (beep 1))
- (sit-for appt-display-duration)
- (if appt-audible
- (beep 1))
- (kill-buffer appt-disp-buf))))
+
+ ;; Make sure we're not in the minibuffer
+ ;; before splitting the window.
+
+ (if (equal (selected-window) (minibuffer-window))
+ (if (other-window 1)
+ (select-window (other-window 1))
+ (if window-system
+ (select-frame (other-frame 1)))))
+
+ (let* ((this-buffer (current-buffer))
+ (this-window (selected-window))
+ (appt-disp-buf (set-buffer (get-buffer-create appt-buffer-name))))
+
+ (appt-select-lowest-window)
+ (split-window)
+
+ (pop-to-buffer appt-disp-buf)
+ (setq mode-line-format
+ (concat "-------------------- Appointment in "
+ min-to-app " minutes. " new-time " %-"))
+ (insert-string appt-msg)
+ (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf))
+ (set-buffer-modified-p nil)
+ (select-window this-window)
+ (if appt-audible
+ (beep 1))))
+
+(defun appt-delete-window ()
+ "Function called to undisplay appointment messages.
+Usually just deletes the appointment buffer."
+ (delete-window (get-buffer-window appt-buffer-name))
+ (kill-buffer appt-buffer-name)
+ (if appt-audible
+ (beep 1)))
;; Select the lowest window on the frame.
(defun appt-select-lowest-window ()
(setq appt-time-msg-list (append 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-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. ie. 12:01am = 1, midnight = 0,
+ ;; so that the elements in the list
+ ;; that are earlier than the present time can
+ ;; be removed.
- (let* ((cur-hour(string-to-int
- (substring (current-time-string) 11 13)))
- (cur-min (string-to-int
- (substring (current-time-string) 14 16)))
- (cur-comp-time (+ (* cur-hour 60) cur-min))
- (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))
- (if appt-time-msg-list
- (setq appt-comp-time (car (car (car appt-time-msg-list)))))))))
+ (let* ((cur-hour(string-to-int
+ (substring (current-time-string) 11 13)))
+ (cur-min (string-to-int
+ (substring (current-time-string) 14 16)))
+ (cur-comp-time (+ (* cur-hour 60) cur-min))
+ (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))
+ (if appt-time-msg-list
+ (setq appt-comp-time (car (car (car appt-time-msg-list)))))))))
;;Simple sort to put the appointments list in order.
(setq display-time-hook 'appt-check)
;;; appt.el ends here
+