Subject: [PATCH] Improve the display-time-world UI

From: Stefan Kangas <[email-masked]>
Date: Sun, 26 Apr 2020 10:56:03 +0200

I have made some improvements to the display-time-world UI.  I divided
them up into four patches to ease review and merging of the individual
features.  Please let me know what you think.

(Of course I can squash the patches before pushing if that is preferable.)

Patch 4 adds an alias 'world-clock'.  Ideally, I would like to rename
the somewhat obscurely named 'display-world-time' to 'world-clock' and
make the old names into obsolete aliases.  It would be good to hear
any opinions on that too.

I'm also not sure if any of this should go into NEWS, so I didn't do
that work for now.  Let me know if that's desirable.

Best regards,
Stefan Kangas
From 3d8c091a03c25826755b3735eca9da4b342826ba Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sun, 26 Apr 2020 09:38:03 +0200
Subject: [PATCH 1/4] Kill display-time-world buffer on exit

* lisp/time.el (display-time-world-mode-map): New defvar.
(display-time-world-exit): New defun to kill buffer on exit.
(display-time-world): Doc fix.
---
 lisp/time.el | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lisp/time.el b/lisp/time.el
index 44fd1a7e33..a5e5b9b4a7 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -509,6 +509,13 @@ display-time-mode
 		 'display-time-event-handler)))

+(defvar display-time-world-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "g" nil)
+    (define-key map "q" 'display-time-world-exit)
+    map)
+  "Keymap for `display-time-world-mode'.")
+
 (define-derived-mode display-time-world-mode special-mode "World clock"
   "Major mode for buffer that displays times in various time zones.
 See `display-time-world'."
@@ -537,11 +544,17 @@ display-time-world-display
     (delete-char -1))
   (goto-char (point-min)))
 
+(defun display-time-world-exit ()
+  "Quit the world time buffer."
+  (interactive)
+  (quit-window t))
+
 ;;;###autoload
 (defun display-time-world ()
   "Enable updating display of times in various time zones.
+\\<display-time-world-mode-map>
 `display-time-world-list' specifies the zones.
-To turn off the world time display, go to that window and type `q'."
+To turn off the world time display, go to that window and type `\\[display-time-world-exit]'."
   (interactive)
   (when (and display-time-world-timer-enable
              (not (get-buffer display-time-world-buffer-name)))
-- 
2.26.2

From 6680705f464dd6e582e70beaf64b027ac57d0d43 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sun, 26 Apr 2020 10:16:06 +0200
Subject: [PATCH 2/4] New face for display-time-world label

* lisp/time.el (display-time-world-label): New face.
(display-time-world-display): Use the new face.
---
 lisp/time.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/time.el b/lisp/time.el
index a5e5b9b4a7..44885f74d1 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -516,6 +516,10 @@ display-time-world-mode-map
     map)
   "Keymap for `display-time-world-mode'.")
 
+(defface display-time-world-label
+  '((t :inherit font-lock-variable-name-face))
+  "Face for time zone label.")
+
 (define-derived-mode display-time-world-mode special-mode "World clock"
   "Major mode for buffer that displays times in various time zones.
 See `display-time-world'."
@@ -540,7 +544,10 @@ display-time-world-display
 	  (setq max-width width))))
     (setq fmt (concat "%-" (int-to-string max-width) "s %s\n"))
     (dolist (timedata (nreverse result))
-      (insert (format fmt (car timedata) (cdr timedata))))
+      (insert (format fmt
+                      (propertize (car timedata)
+                                  'face 'display-time-world-label)
+                      (cdr timedata))))
     (delete-char -1))
   (goto-char (point-min)))
 
-- 
2.26.2

From 0f2ca954e03b857554071ae48a98d44ba7030d69 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sun, 26 Apr 2020 10:44:00 +0200
Subject: [PATCH 3/4] Move point to new buffer for display-time-world

* lisp/time.el (display-time-world): Move point to created buffer.
---
 lisp/time.el | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lisp/time.el b/lisp/time.el
index 44885f74d1..84c0071b7d 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -566,11 +566,11 @@ display-time-world
   (when (and display-time-world-timer-enable
              (not (get-buffer display-time-world-buffer-name)))
     (run-at-time t display-time-world-timer-second 'display-time-world-timer))
-  (with-current-buffer (get-buffer-create display-time-world-buffer-name)
-    (display-time-world-display (time--display-world-list))
-    (display-buffer display-time-world-buffer-name
-		    (cons nil '((window-height . fit-window-to-buffer))))
-    (display-time-world-mode)))
+  (switch-to-buffer-other-window (get-buffer-create display-time-world-buffer-name))
+  (display-time-world-display (time--display-world-list))
+  (display-buffer display-time-world-buffer-name
+		  (cons nil '((window-height . fit-window-to-buffer))))
+  (display-time-world-mode))
 
 (defun display-time-world-timer ()
   (if (get-buffer display-time-world-buffer-name)
-- 
2.26.2

From 47401a1e10213d89cbdb6eaa2b66b44c2be37dfe Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sun, 26 Apr 2020 10:47:17 +0200
Subject: [PATCH 4/4] Improve the display-time-world UI

* lisp/time.el (display-time-world-buffer-name): Change default
buffer name.
(display-time-world): Add usage instructions to modeline.
(world-clock): New defalias for 'display-time-world'.
---
 lisp/time.el | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lisp/time.el b/lisp/time.el
index 84c0071b7d..18de3990c3 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -195,11 +195,11 @@ display-time-world-time-format
   :type 'string
   :version "23.1")
 
-(defcustom display-time-world-buffer-name "*wclock*"
+(defcustom display-time-world-buffer-name "*World Clock*"
   "Name of the world clock buffer."
   :group 'display-time
   :type 'string
-  :version "23.1")
+  :version "28.1")
 
 (defcustom display-time-world-timer-enable t
   "If non-nil, a timer will update the world clock."
@@ -570,7 +570,11 @@ display-time-world
   (display-time-world-display (time--display-world-list))
   (display-buffer display-time-world-buffer-name
 		  (cons nil '((window-height . fit-window-to-buffer))))
-  (display-time-world-mode))
+  (display-time-world-mode)
+  (setq mode-line-format (format "%15s %13s" "World Clock" "q to quit")))
+
+;; This would be a more intuitive name.
+(defalias 'world-clock 'display-time-world)
 
 (defun display-time-world-timer ()
   (if (get-buffer display-time-world-buffer-name)
-- 
2.26.2