aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2011-06-08 22:08:11 -0700
committerGlenn Morris2011-06-08 22:08:11 -0700
commit35d7dbd3f36a3a75736b45d9f1541a2f59235588 (patch)
treec5a8b30afadc4f0a888ebc748d7f6d5165c39158
parent7e2aa385adee11a135231dba9d11cd47ffbc8ff1 (diff)
downloademacs-35d7dbd3f36a3a75736b45d9f1541a2f59235588.tar.gz
emacs-35d7dbd3f36a3a75736b45d9f1541a2f59235588.zip
Allow some appt.el display functions to handle lists.
* lisp/calendar/appt.el (appt-display-message, appt-disp-window): Handle lists of appointments.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/calendar/appt.el89
2 files changed, 73 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2341c0c973a..2d1fb9ffceb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12011-06-09 Glenn Morris <rgm@gnu.org>
2
3 * calendar/appt.el (appt-display-message, appt-disp-window):
4 Handle lists of appointments.
5
12011-06-08 Martin Rudalics <rudalics@gmx.at> 62011-06-08 Martin Rudalics <rudalics@gmx.at>
2 7
3 * window.el (one-window-p): Move down in code. Rewrite 8 * window.el (one-window-p): Move down in code. Rewrite
diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el
index 5089df1d8ed..34631640265 100644
--- a/lisp/calendar/appt.el
+++ b/lisp/calendar/appt.el
@@ -214,20 +214,42 @@ If this is non-nil, appointment checking is active.")
214(defun appt-display-message (string mins) 214(defun appt-display-message (string mins)
215 "Display a reminder about an appointment. 215 "Display a reminder about an appointment.
216The string STRING describes the appointment, due in integer MINS minutes. 216The string STRING describes the appointment, due in integer MINS minutes.
217The format of the visible reminder is controlled by `appt-display-format'. 217The arguments may also be lists, where each element relates to a
218The variable `appt-audible' controls the audible reminder." 218separate appointment. The variable `appt-display-format' controls
219the format of the visible reminder. If `appt-audible' is non-nil,
220also calls `beep' for an audible reminder."
219 (if appt-audible (beep 1)) 221 (if appt-audible (beep 1))
222 ;; Backwards compatibility: avoid passing lists to a-d-w-f if not necessary.
223 (and (listp mins)
224 (= (length mins) 1)
225 (setq mins (car mins)
226 string (car string)))
220 (cond ((eq appt-display-format 'window) 227 (cond ((eq appt-display-format 'window)
221 (funcall appt-disp-window-function 228 ;; TODO use calendar-month-abbrev-array rather than %b?
222 (number-to-string mins) 229 (let ((time (format-time-string "%a %b %e " (current-time)))
223 ;; TODO - use calendar-month-abbrev-array rather than %b? 230 err)
224 (format-time-string "%a %b %e " (current-time)) 231 (condition-case err
225 string) 232 (funcall appt-disp-window-function
233 (if (listp mins)
234 (mapcar 'number-to-string mins)
235 (number-to-string mins))
236 time string)
237 (wrong-type-argument
238 (if (not (listp mins))
239 (signal (car err) (cdr err))
240 (message "Argtype error in `appt-disp-window-function' - \
241update it for multiple appts?")
242 ;; Fallback to just displaying the first appt, as we used to.
243 (funcall appt-disp-window-function
244 (number-to-string (car mins)) time
245 (car string))))))
226 (run-at-time (format "%d sec" appt-display-duration) 246 (run-at-time (format "%d sec" appt-display-duration)
227 nil 247 nil
228 appt-delete-window-function)) 248 appt-delete-window-function))
229 ((eq appt-display-format 'echo) 249 ((eq appt-display-format 'echo)
230 (message "%s" string)))) 250 (message "%s" (if (listp string)
251 (mapconcat 'identity string "\n")
252 string)))))
231 253
232 254
233(defun appt-check (&optional force) 255(defun appt-check (&optional force)
@@ -373,8 +395,10 @@ displayed in a window:
373 395
374(defun appt-disp-window (min-to-app new-time appt-msg) 396(defun appt-disp-window (min-to-app new-time appt-msg)
375 "Display appointment due in MIN-TO-APP (a string) minutes. 397 "Display appointment due in MIN-TO-APP (a string) minutes.
376NEW-TIME is a string giving the date. Displays the appointment 398NEW-TIME is a string giving the current date.
377message APPT-MSG in a separate buffer." 399Displays the appointment message APPT-MSG in a separate buffer.
400The arguments may also be lists, where each element relates to a
401separate appointment."
378 (let ((this-window (selected-window)) 402 (let ((this-window (selected-window))
379 (appt-disp-buf (get-buffer-create appt-buffer-name))) 403 (appt-disp-buf (get-buffer-create appt-buffer-name)))
380 ;; Make sure we're not in the minibuffer before splitting the window. 404 ;; Make sure we're not in the minibuffer before splitting the window.
@@ -395,17 +419,40 @@ message APPT-MSG in a separate buffer."
395 (when (>= (window-height) (* 2 window-min-height)) 419 (when (>= (window-height) (* 2 window-min-height))
396 (select-window (split-window)))) 420 (select-window (split-window))))
397 (switch-to-buffer appt-disp-buf)) 421 (switch-to-buffer appt-disp-buf))
398 ;; FIXME Link to diary entry? 422 (or (listp min-to-app)
399 (calendar-set-mode-line 423 (setq min-to-app (list min-to-app)
400 (format " Appointment %s. %s " 424 appt-msg (list appt-msg)))
401 (if (string-equal "0" min-to-app) "now" 425 ;; I don't really see the point of the new-time argument.
402 (format "in %s minute%s" min-to-app 426 ;; It repeatedly reminds you of the date?
403 (if (string-equal "1" min-to-app) "" "s"))) 427 ;; It would make more sense if it was eg the time of the appointment.
404 new-time)) 428 ;; Let's allow it to be a list or not independent of the other elements.
405 (setq buffer-read-only nil 429 (or (listp new-time)
406 buffer-undo-list t) 430 (setq new-time (list new-time)))
407 (erase-buffer) 431 ;; All this silliness is just to make the formatting slightly nicer.
408 (insert appt-msg) 432 (let* ((multiple (> (length min-to-app) 1))
433 (sametime (or (not multiple)
434 (not (delete (car min-to-app) min-to-app))))
435 (imin (if sametime (car min-to-app))))
436 ;; FIXME Link to diary entry?
437 (calendar-set-mode-line
438 (format " Appointment%s %s. %s "
439 (if multiple "s" "")
440 (if (equal imin "0")
441 "now"
442 (format "in %s minute%s"
443 (or imin (mapconcat 'identity min-to-app ","))
444 (if (equal imin "1")
445 "" "s")))
446 (mapconcat 'identity new-time ", ")))
447 (setq buffer-read-only nil
448 buffer-undo-list t)
449 (erase-buffer)
450 ;; If we have appointments at different times, prepend the times.
451 (if sametime
452 (insert (mapconcat 'identity appt-msg "\n"))
453 (dotimes (i (length appt-msg))
454 (insert (format "%s%sm: %s" (if (> i 0) "\n" "")
455 (nth i min-to-app) (nth i appt-msg))))))
409 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t)) 456 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t))
410 (set-buffer-modified-p nil) 457 (set-buffer-modified-p nil)
411 (setq buffer-read-only t) 458 (setq buffer-read-only t)