emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104548: Eliminate some code duplicat


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104548: Eliminate some code duplication in appt.el.
Date: Thu, 09 Jun 2011 16:25:34 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104548
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Thu 2011-06-09 16:25:34 -0400
message:
  Eliminate some code duplication in appt.el.
  
  * lisp/calendar/appt.el (appt-mode-line): New function.
  (appt-check, appt-disp-window): Use it.
modified:
  lisp/ChangeLog
  lisp/calendar/appt.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-06-09 20:22:06 +0000
+++ b/lisp/ChangeLog    2011-06-09 20:25:34 +0000
@@ -1,5 +1,8 @@
 2011-06-09  Glenn Morris  <address@hidden>
 
+       * calendar/appt.el (appt-mode-line): New function.
+       (appt-check, appt-disp-window): Use it.
+
        * files.el (hack-one-local-variable-eval-safep):
        Allow minor-modes with explicit +/-1 arguments.
 

=== modified file 'lisp/calendar/appt.el'
--- a/lisp/calendar/appt.el     2011-06-09 05:08:11 +0000
+++ b/lisp/calendar/appt.el     2011-06-09 20:25:34 +0000
@@ -251,6 +251,23 @@
                            (mapconcat 'identity string "\n")
                          string)))))
 
+(defun appt-mode-line (min-to-app &optional abbrev)
+  "Return an appointment string suitable for use in the mode-line.
+MIN-TO-APP is a list of minutes, as strings.
+If ABBREV is non-nil, abbreviates some text."
+  ;; All this silliness is just to make the formatting slightly nicer.
+  (let* ((multiple (> (length min-to-app) 1))
+         (sametime (or (not multiple)
+                       (not (delete (car min-to-app) min-to-app))))
+         (imin (if sametime (car min-to-app))))
+    (format "%s%s %s"
+            (if abbrev "App't" "Appointment")
+            (if multiple "s" "")
+            (if (equal imin "0") "now"
+              (format "in %s %s"
+                      (or imin (mapconcat 'identity min-to-app ","))
+                      (if abbrev "min."
+                        (format "minute%s" (if (equal imin "1") "" "s"))))))))
 
 (defun appt-check (&optional force)
   "Check for an appointment and update any reminder display.
@@ -373,9 +390,8 @@
           (when appt-display-mode-line
             (setq appt-mode-string
                   (concat " " (propertize
-                               (format "App't %s"
-                                       (if (zerop min-to-app) "NOW"
-                                         (format "in %s min." min-to-app)))
+                               (appt-mode-line (mapcar 'number-to-string
+                                                       (list min-to-app)) t)
                                'face 'mode-line-emphasis))))
           ;; When an appointment is reached, delete it from the
           ;; list.  Reset the count to 0 in case we display another
@@ -428,31 +444,20 @@
     ;; Let's allow it to be a list or not independent of the other elements.
     (or (listp new-time)
         (setq new-time (list new-time)))
-    ;; All this silliness is just to make the formatting slightly nicer.
-    (let* ((multiple (> (length min-to-app) 1))
-           (sametime (or (not multiple)
-                         (not (delete (car min-to-app) min-to-app))))
-           (imin (if sametime (car min-to-app))))
-      ;; FIXME Link to diary entry?
-      (calendar-set-mode-line
-       (format " Appointment%s %s. %s "
-               (if multiple "s" "")
-               (if (equal imin "0")
-                   "now"
-                 (format "in %s minute%s"
-                         (or imin (mapconcat 'identity min-to-app ","))
-                         (if (equal imin "1")
-                             "" "s")))
-               (mapconcat 'identity new-time ", ")))
-      (setq buffer-read-only nil
-            buffer-undo-list t)
-      (erase-buffer)
-      ;; If we have appointments at different times, prepend the times.
-      (if sametime
-          (insert (mapconcat 'identity appt-msg "\n"))
-        (dotimes (i (length appt-msg))
-          (insert (format "%s%sm: %s" (if (> i 0) "\n" "")
-                          (nth i min-to-app) (nth i appt-msg))))))
+    ;; FIXME Link to diary entry?
+    (calendar-set-mode-line
+     (format " %s. %s" (appt-mode-line min-to-app)
+             (mapconcat 'identity new-time ", ")))
+    (setq buffer-read-only nil
+          buffer-undo-list t)
+    (erase-buffer)
+    ;; If we have appointments at different times, prepend the times.
+    (if (or (= 1 (length min-to-app))
+            (not (delete (car min-to-app) min-to-app)))
+        (insert (mapconcat 'identity appt-msg "\n"))
+      (dotimes (i (length appt-msg))
+        (insert (format "%s%sm: %s" (if (> i 0) "\n" "")
+                        (nth i min-to-app) (nth i appt-msg)))))
     (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t))
     (set-buffer-modified-p nil)
     (setq buffer-read-only t)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]