X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/3a35cf56e7c9951f6d99f54c65d7109654c854f0..dc3eeeb48af706de824b7b8bae62dc868d26637e:/lisp/calendar/appt.el diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el index 06b8387244..892c76bba0 100644 --- a/lisp/calendar/appt.el +++ b/lisp/calendar/appt.el @@ -1,9 +1,10 @@ ;;; appt.el --- appointment notification functions -;; Copyright (C) 1989, 1990, 1994, 1998, 2004 Free Software Foundation, Inc. +;; Copyright (C) 1989, 1990, 1994, 1998, 2001, 2002, 2003, 2004, 2005, +;; 2006 Free Software Foundation, Inc. ;; Author: Neil Mager -;; Maintainer: Glenn Morris +;; Maintainer: Glenn Morris ;; Keywords: calendar ;; This file is part of GNU Emacs. @@ -77,6 +78,7 @@ ;; Make sure calendar is loaded when we compile this. (require 'calendar) +(defvar diary-selective-display) ;;;###autoload (defcustom appt-issue-message t @@ -134,7 +136,9 @@ of the (obsolete) variables `appt-msg-window' and `appt-visible'." :type '(choice (const :tag "Separate window" window) (const :tag "Echo-area" echo) - (const :tag "No visible display" nil)) + (const :tag "No visible display" nil) + (const :tag "Backwards compatibility setting - choose another value" + ignore)) :group 'appt :version "22.1") @@ -195,7 +199,7 @@ STRING is the description of the appointment. FLAG, if non-nil, says that the element was made with `appt-add' so calling `appt-make-list' again should preserve it.") -(defconst appt-max-time 1439 +(defconst appt-max-time (1- (* 24 60)) "11:59pm in minutes - number of minutes in a day minus 1.") (defvar appt-mode-string nil @@ -235,6 +239,8 @@ The variable `appt-audible' controls the audible reminder." (cond ((eq appt-display-format 'window) (funcall appt-disp-window-function (number-to-string mins) + ;; TODO - use calendar-month-abbrev-array rather + ;; than %b? (format-time-string "%a %b %e " (current-time)) string) (run-at-time (format "%d sec" appt-display-duration) @@ -337,19 +343,19 @@ displayed in a window: diary-hook (cons 'appt-make-list diary-hook)))) (diary)) - (let ((diary-display-hook 'appt-make-list) - (d-buff (find-buffer-visiting - (substitute-in-file-name diary-file))) - selective) - (if d-buff ; diary buffer exists - (with-current-buffer d-buff - (setq selective selective-display))) + (let* ((diary-display-hook 'appt-make-list) + (d-buff (find-buffer-visiting + (substitute-in-file-name diary-file))) + (selective + (if d-buff ; Diary buffer exists. + (with-current-buffer d-buff + diary-selective-display)))) (diary) ;; If the diary buffer existed before this command, ;; restore its display state. Otherwise, kill it. (if d-buff ;; Displays the diary buffer. - (or selective (show-all-diary-entries)) + (or selective (diary-show-all-entries)) (and (setq d-buff (find-buffer-visiting (substitute-in-file-name diary-file))) @@ -388,8 +394,8 @@ displayed in a window: (if (and (< appt-comp-time appt-message-warning-time) (> (+ cur-comp-time appt-message-warning-time) appt-max-time)) - (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time)) - appt-comp-time)) + (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time) + appt-comp-time))) ;; issue warning if the appointment time is ;; within appt-message-warning time @@ -484,19 +490,21 @@ Usually just deletes the appointment buffer." lowest-window w))))) (select-window lowest-window))) +(defconst appt-time-regexp + "[0-9]?[0-9]\\(h\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]\\)\\(am\\|pm\\)?") + ;;;###autoload (defun appt-add (new-appt-time new-appt-msg) "Add an appointment for today at NEW-APPT-TIME with message NEW-APPT-MSG. The time should be in either 24 hour format or am/pm format." (interactive "sTime (hh:mm[am/pm]): \nsMessage: ") - (unless (string-match "[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?" - new-appt-time) + (unless (string-match appt-time-regexp new-appt-time) (error "Unacceptable time-string")) - (let* ((appt-time-string (concat new-appt-time " " new-appt-msg)) - (appt-time (list (appt-convert-time new-appt-time))) - (time-msg (list appt-time appt-time-string t))) - (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)))) + (let ((time-msg (list (list (appt-convert-time new-appt-time)) + (concat new-appt-time " " new-appt-msg) t))) + (unless (member time-msg appt-time-msg-list) + (setq appt-time-msg-list + (appt-sort-list (nconc appt-time-msg-list (list time-msg))))))) ;;;###autoload (defun appt-delete () @@ -530,7 +538,7 @@ The time should be in either 24 hour format or am/pm format." The time must be at the beginning of a line for it to be put in the appointments list (see examples in documentation of the function `appt-check'). We assume that the variables DATE and -NUMBER hold the arguments that `list-diary-entries' received. +NUMBER hold the arguments that `diary-list-entries' received. They specify the range of dates that the diary is being processed for. Any appointments made with `appt-add' are not affected by this @@ -577,16 +585,14 @@ appointment package (if it is not already active)." (calendar-date-equal (calendar-current-date) (car (car entry-list)))) (let ((time-string (cadr (car entry-list)))) - (while (string-match - "\\([0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?\\).*" - time-string) + (while (string-match appt-time-regexp time-string) (let* ((beg (match-beginning 0)) ;; Get just the time for this appointment. - (only-time (match-string 1 time-string)) + (only-time (match-string 0 time-string)) ;; Find the end of this appointment ;; (the start of the next). (end (string-match - "^[ \t]*[0-9]?[0-9][:.][0-9][0-9]\\(am\\|pm\\)?" + (concat "\n[ \t]*" appt-time-regexp) time-string (match-end 0))) ;; Get the whole string for this appointment. @@ -633,31 +639,23 @@ APPT-LIST is a list of the same format as `appt-time-msg-list'." "Convert hour:min[am/pm] format to minutes from midnight. A period (.) can be used instead of a colon (:) to separate the hour and minute parts." - (let ((conv-time 0) - (hr 0) - (min 0)) - - (string-match "[:.]\\([0-9][0-9]\\)" time2conv) - (setq min (string-to-number - (match-string 1 time2conv))) - - (string-match "[0-9]?[0-9][:.]" time2conv) - (setq hr (string-to-number - (match-string 0 time2conv))) + ;; Formats that should be accepted: + ;; 10:00 10.00 10h00 10h 10am 10:00am 10.00am + (let ((min (if (string-match "[h:.]\\([0-9][0-9]\\)" time2conv) + (string-to-number (match-string 1 time2conv)) + 0)) + (hr (if (string-match "[0-9]*[0-9]" time2conv) + (string-to-number (match-string 0 time2conv)) + 0))) ;; convert the time appointment time into 24 hour time - (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 - ;; against the actual time. - - (setq conv-time (+ (* hr 60) min)) - conv-time)) + ;; convert the actual time into minutes. + (+ (* hr 60) min))) (defun appt-update-list () @@ -719,5 +717,5 @@ ARG is positive, otherwise off." (provide 'appt) -;;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347 +;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347 ;;; appt.el ends here