aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2011-06-09 16:25:34 -0400
committerGlenn Morris2011-06-09 16:25:34 -0400
commit80675c21afd40351ab3c181eb9012d1b8f7e5ce8 (patch)
treef66e609870dcfc851fc6248e7f65484add159b36
parentf0da764a5c9bd61df5892ea9a377ab677dd5b612 (diff)
downloademacs-80675c21afd40351ab3c181eb9012d1b8f7e5ce8.tar.gz
emacs-80675c21afd40351ab3c181eb9012d1b8f7e5ce8.zip
Eliminate some code duplication in appt.el.
* lisp/calendar/appt.el (appt-mode-line): New function. (appt-check, appt-disp-window): Use it.
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/calendar/appt.el61
2 files changed, 36 insertions, 28 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index af36f8c9b98..ae1da48b477 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
12011-06-09 Glenn Morris <rgm@gnu.org> 12011-06-09 Glenn Morris <rgm@gnu.org>
2 2
3 * calendar/appt.el (appt-mode-line): New function.
4 (appt-check, appt-disp-window): Use it.
5
3 * files.el (hack-one-local-variable-eval-safep): 6 * files.el (hack-one-local-variable-eval-safep):
4 Allow minor-modes with explicit +/-1 arguments. 7 Allow minor-modes with explicit +/-1 arguments.
5 8
diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el
index 34631640265..821a981cdcb 100644
--- a/lisp/calendar/appt.el
+++ b/lisp/calendar/appt.el
@@ -251,6 +251,23 @@ update it for multiple appts?")
251 (mapconcat 'identity string "\n") 251 (mapconcat 'identity string "\n")
252 string))))) 252 string)))))
253 253
254(defun appt-mode-line (min-to-app &optional abbrev)
255 "Return an appointment string suitable for use in the mode-line.
256MIN-TO-APP is a list of minutes, as strings.
257If ABBREV is non-nil, abbreviates some text."
258 ;; All this silliness is just to make the formatting slightly nicer.
259 (let* ((multiple (> (length min-to-app) 1))
260 (sametime (or (not multiple)
261 (not (delete (car min-to-app) min-to-app))))
262 (imin (if sametime (car min-to-app))))
263 (format "%s%s %s"
264 (if abbrev "App't" "Appointment")
265 (if multiple "s" "")
266 (if (equal imin "0") "now"
267 (format "in %s %s"
268 (or imin (mapconcat 'identity min-to-app ","))
269 (if abbrev "min."
270 (format "minute%s" (if (equal imin "1") "" "s"))))))))
254 271
255(defun appt-check (&optional force) 272(defun appt-check (&optional force)
256 "Check for an appointment and update any reminder display. 273 "Check for an appointment and update any reminder display.
@@ -373,9 +390,8 @@ displayed in a window:
373 (when appt-display-mode-line 390 (when appt-display-mode-line
374 (setq appt-mode-string 391 (setq appt-mode-string
375 (concat " " (propertize 392 (concat " " (propertize
376 (format "App't %s" 393 (appt-mode-line (mapcar 'number-to-string
377 (if (zerop min-to-app) "NOW" 394 (list min-to-app)) t)
378 (format "in %s min." min-to-app)))
379 'face 'mode-line-emphasis)))) 395 'face 'mode-line-emphasis))))
380 ;; When an appointment is reached, delete it from the 396 ;; When an appointment is reached, delete it from the
381 ;; list. Reset the count to 0 in case we display another 397 ;; list. Reset the count to 0 in case we display another
@@ -428,31 +444,20 @@ separate appointment."
428 ;; Let's allow it to be a list or not independent of the other elements. 444 ;; Let's allow it to be a list or not independent of the other elements.
429 (or (listp new-time) 445 (or (listp new-time)
430 (setq new-time (list new-time))) 446 (setq new-time (list new-time)))
431 ;; All this silliness is just to make the formatting slightly nicer. 447 ;; FIXME Link to diary entry?
432 (let* ((multiple (> (length min-to-app) 1)) 448 (calendar-set-mode-line
433 (sametime (or (not multiple) 449 (format " %s. %s" (appt-mode-line min-to-app)
434 (not (delete (car min-to-app) min-to-app)))) 450 (mapconcat 'identity new-time ", ")))
435 (imin (if sametime (car min-to-app)))) 451 (setq buffer-read-only nil
436 ;; FIXME Link to diary entry? 452 buffer-undo-list t)
437 (calendar-set-mode-line 453 (erase-buffer)
438 (format " Appointment%s %s. %s " 454 ;; If we have appointments at different times, prepend the times.
439 (if multiple "s" "") 455 (if (or (= 1 (length min-to-app))
440 (if (equal imin "0") 456 (not (delete (car min-to-app) min-to-app)))
441 "now" 457 (insert (mapconcat 'identity appt-msg "\n"))
442 (format "in %s minute%s" 458 (dotimes (i (length appt-msg))
443 (or imin (mapconcat 'identity min-to-app ",")) 459 (insert (format "%s%sm: %s" (if (> i 0) "\n" "")
444 (if (equal imin "1") 460 (nth i min-to-app) (nth i appt-msg)))))
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))))))
456 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t)) 461 (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t))
457 (set-buffer-modified-p nil) 462 (set-buffer-modified-p nil)
458 (setq buffer-read-only t) 463 (setq buffer-read-only t)