From 5006e6344af9d8b870b32ba9cd228c2aab8fae32 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Fri, 6 May 2011 00:14:30 -0700 Subject: [PATCH] Allow per-appointment warning times. * lisp/calendar/appt.el (appt-message-warning-time): Doc fix. (appt-warning-time-regexp): New option. (appt-make-list): Respect appt-message-warning-time. * doc/emacs/calendar.texi (Appointments): Mention appt-warning-time-regexp. * etc/NEWS: Mention this. --- doc/emacs/ChangeLog | 2 ++ doc/emacs/calendar.texi | 6 +++++- etc/NEWS | 4 ++++ lisp/ChangeLog | 4 ++++ lisp/calendar/appt.el | 38 +++++++++++++++++++++++++++++++++----- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index dbb274360fd..bec432f6f23 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,5 +1,7 @@ 2011-05-06 Glenn Morris + * calendar.texi (Appointments): Mention appt-warning-time-regexp. + * cal-xtra.texi (Fancy Diary Display): Mention diary comments. 2011-05-02 Lars Magne Ingebrigtsen diff --git a/doc/emacs/calendar.texi b/doc/emacs/calendar.texi index 757dc3b4ac7..fabd38ecc18 100644 --- a/doc/emacs/calendar.texi +++ b/doc/emacs/calendar.texi @@ -1489,11 +1489,15 @@ Monday @end example @vindex appt-message-warning-time +@vindex appt-warning-time-regexp @noindent Then on Mondays, you will be reminded at around 9:20am about your coffee break and at around 11:50am about lunch. The variable @code{appt-message-warning-time} specifies how many minutes (default 12) -in advance to warn you. +in advance to warn you. This is a default warning time. Each +appointment can specify a different warning time by adding a piece +matching @code{appt-warning-time-regexp} (see that variable's +documentation for details). You can write times in am/pm style (with @samp{12:00am} standing for midnight and @samp{12:00pm} standing for noon), or 24-hour diff --git a/etc/NEWS b/etc/NEWS index 61713c71fc8..1728b852b75 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -451,6 +451,10 @@ You can get a comparable behavior with: *** Diary entries can contain non-printing `comments'. See the variable `diary-comment-start'. ++++ +*** Appointments can specify their individual warning times. +See the variable `appt-warning-time-regexp'. + *** New function `diary-hebrew-birthday'. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ef5e5422222..01c646412d4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,9 @@ 2011-05-06 Glenn Morris + * calendar/appt.el (appt-message-warning-time): Doc fix. + (appt-warning-time-regexp): New option. + (appt-make-list): Respect appt-message-warning-time. + * calendar/diary-lib.el (diary-comment-start, diary-comment-end): New options. (diary-add-to-list): Strip comments from the displayed string. diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el index 1394efa880e..f7ec64c5060 100644 --- a/lisp/calendar/appt.el +++ b/lisp/calendar/appt.el @@ -84,10 +84,22 @@ :group 'calendar) (defcustom appt-message-warning-time 12 - "Time in minutes before an appointment that the warning begins." + "Default time in minutes before an appointment that the warning begins." :type 'integer :group 'appt) +(defcustom appt-warning-time-regexp "warntime \\([0-9]+\\)" + "Regexp matching a string giving the warning time for an appointment. +The first subexpression matches the time in minutes (an integer). +This overrides the default `appt-message-warning-time'. +You may want to put this inside a diary comment (see `diary-comment-start'). +For example, to be warned 30 minutes in advance of an appointment: + 2011/06/01 12:00 Do something ## warntime 30 +" + :version "24.1" + :type 'regexp + :group 'appt) + (defcustom appt-audible t "Non-nil means beep to indicate appointment." :type 'boolean @@ -509,7 +521,7 @@ Any appointments made with `appt-add' are not affected by this function." ;; entry begins with a time, add it to the ;; appt-time-msg-list. Then sort the list. (let ((entry-list diary-entries-list) - time-string) + time-string literal) ;; Below, we assume diary-entries-list was in date ;; order. It is, unless something on ;; diary-list-entries-hook has changed it, eg @@ -530,7 +542,10 @@ Any appointments made with `appt-add' are not affected by this function." (while (and entry-list (calendar-date-equal (calendar-current-date) (caar entry-list))) - (setq time-string (cadr (car entry-list))) + (setq time-string (cadr (car entry-list)) + ;; Including any comments. + literal (or (nth 2 (nth 3 (car entry-list))) + time-string)) (while (string-match appt-time-regexp time-string) (let* ((beg (match-beginning 0)) ;; Get just the time for this appointment. @@ -541,17 +556,30 @@ Any appointments made with `appt-add' are not affected by this function." (concat "\n[ \t]*" appt-time-regexp) time-string (match-end 0))) + (warntime + (if (string-match appt-warning-time-regexp literal) + (string-to-number (match-string 1 literal)))) ;; Get the whole string for this appointment. (appt-time-string (substring time-string beg end)) (appt-time (list (appt-convert-time only-time))) - (time-msg (list appt-time appt-time-string))) + (time-msg (append + (list appt-time appt-time-string) + (if warntime (list nil warntime))))) ;; Add this appointment to appt-time-msg-list. (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg)) ;; Discard this appointment from the string. + ;; (This allows for multiple appts per entry.) time-string - (if end (substring time-string end) "")))) + (if end (substring time-string end) "")) + ;; Similarly, discard the start of literal. + (and (> (length time-string) 0) + (string-match appt-time-regexp literal) + (setq end (string-match + (concat "\n[ \t]*" appt-time-regexp) + literal (match-end 0))) + (setq literal (substring literal end))))) (setq entry-list (cdr entry-list))))) (setq appt-time-msg-list (appt-sort-list appt-time-msg-list)) ;; Convert current time to minutes after midnight (12:01am = 1), -- 2.39.5