changeset 109465:1d31012de150

time.el: Use `define-derived-mode'. Simplify. * time.el (display-time-world-mode): Define with `define-derived-mode'. Set `show-trailing-whitespace' to nil. (display-time-world-display): Simplify.
author Juanma Barranquero <lekktu@gmail.com>
date Mon, 19 Jul 2010 13:06:42 +0200
parents cb59bcad6ad9
children 91bbf4e4290f f2f8baec8e43
files lisp/ChangeLog lisp/time.el
diffstat 2 files changed, 16 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Jul 19 12:26:48 2010 +0200
+++ b/lisp/ChangeLog	Mon Jul 19 13:06:42 2010 +0200
@@ -1,3 +1,9 @@
+2010-07-19  Juanma Barranquero  <lekktu@gmail.com>
+
+	* time.el (display-time-world-mode): Define with `define-derived-mode'.
+	Set `show-trailing-whitespace' to nil.
+	(display-time-world-display): Simplify.
+
 2010-07-18  Alan Mackenzie  <acm@muc.de>
 
 	Enhance `c-file-style' in file/directory local variables.
--- a/lisp/time.el	Mon Jul 19 12:26:48 2010 +0200
+++ b/lisp/time.el	Mon Jul 19 13:06:42 2010 +0200
@@ -490,15 +490,10 @@
 		 'display-time-event-handler)))
 
 
-(defun display-time-world-mode ()
+(define-derived-mode display-time-world-mode nil "World clock"
   "Major mode for buffer that displays times in various time zones.
 See `display-time-world'."
-  (interactive)
-  (kill-all-local-variables)
-  (setq
-   major-mode 'display-time-world-mode
-   mode-name "World clock")
-  (use-local-map display-time-world-mode-map))
+  (setq show-trailing-whitespace nil))
 
 (defun display-time-world-display (alist)
   "Replace current buffer text with times in various zones, based on ALIST."
@@ -506,24 +501,22 @@
 	(buffer-undo-list t))
     (erase-buffer)
     (let ((max-width 0)
-	  (result ()))
+	  (result ())
+	  fmt)
       (unwind-protect
 	  (dolist (zone alist)
 	    (let* ((label (cadr zone))
 		   (width (string-width label)))
 	      (set-time-zone-rule (car zone))
-	      (setq result
-		    (append result
-			    (list
-			     label width
-			     (format-time-string display-time-world-time-format))))
+	      (push (cons label
+			  (format-time-string display-time-world-time-format))
+		    result)
 	      (when (> width max-width)
 		(setq max-width width))))
 	(set-time-zone-rule nil))
-      (while result
-	(insert (pop result)
-		(make-string (1+ (- max-width (pop result))) ?\s)
-		(pop result) "\n")))
+      (setq fmt (concat "%-" (int-to-string max-width) "s %s\n"))
+      (dolist (timedata (nreverse result))
+	(insert (format fmt (car timedata) (cdr timedata)))))
     (delete-char -1)))
 
 ;;;###autoload