GNU bug report logs - #79217
[PATCH] display-time-mode: Include world-clock time in mode line.

Previous Next

Package: emacs;

Reported by: Wilko Meyer <w <at> wmeyer.eu>

Date: Mon, 11 Aug 2025 14:01:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 79217 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Mon, 11 Aug 2025 14:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Wilko Meyer <w <at> wmeyer.eu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 11 Aug 2025 14:01:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Wilko Meyer <w <at> wmeyer.eu>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] display-time-mode: Include world-clock time in mode line.
Date: Mon, 11 Aug 2025 16:00:15 +0200
[Message part 1 (text/plain, inline)]
Hi,

This patch introduces an user option to conditionally include
world-clock time, in addition to the localtime, when display-time-mode is
active, in mode line. Right now time in different timezones is only
available in a separate world-clock buffer, having this information
included in the mode line would be useful in my book. WDYT?

I'm not sure if I already have assigned copyright to the FSF before,
so I'll do that within the next hours as required.

[0001-display-time-mode-Add-option-to-show-world-clock-tim.patch (text/x-patch, inline)]
From ac5e6bb2be0c0636534be55a170b34dd8386ef5f Mon Sep 17 00:00:00 2001
From: Wilko Meyer <w <at> wmeyer.eu>
Date: Mon, 11 Aug 2025 15:34:07 +0200
Subject: [PATCH] display-time-mode: Include world-clock time in mode line.

* lisp/time.el (display-time-include-world-clock): Add user option.
(display-time-string-forms): Conditionally include world clock time.
---
 lisp/time.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lisp/time.el b/lisp/time.el
index 3750206d08e..f6da94d2e9a 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -177,6 +177,11 @@ depend on `display-time-day-and-date' and `display-time-24hr-format'."
   :type '(choice (const :tag "Default" nil)
 		 string))
 
+(defcustom display-time-include-world-clock nil
+  "Non-nil means time from `world-clock-list', `zoneinfo-style-world-list'
+or `legacy-style-world-list' entries are displayed in mode line."
+  :type 'boolean)
+
 (defcustom display-time-string-forms
   '((if (and (not display-time-format) display-time-day-and-date)
 	(format-time-string "%a %b %e " now)
@@ -187,6 +192,18 @@ depend on `display-time-day-and-date' and `display-time-24hr-format'."
 			 now)
      'face 'display-time-date-and-time
      'help-echo (format-time-string "%a %b %e, %Y" now))
+    (if display-time-include-world-clock
+        (mapconcat
+         (lambda (p)
+           (pcase-let ((`(,tz ,label) p))
+             (format " %s (%s)"
+                     (format-time-string
+                      (or display-time-format
+                          (if display-time-24hr-format "%H:%M" "%-I:%M%p"))
+                      now tz)
+                     label)))
+         (time--display-world-list))
+      "")
     load
     (if mail
 	;; Build the string every time to act on customization.
-- 
2.50.1

[Message part 3 (text/plain, inline)]
-- 
Kind regards,
Wilko Meyer

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Mon, 11 Aug 2025 23:16:02 GMT) Full text and rfc822 format available.

Message #8 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
To: Wilko Meyer <w <at> wmeyer.eu>
Cc: 79217 <at> debbugs.gnu.org
Subject: Re: bug#79217: [PATCH] display-time-mode: Include world-clock time in
 mode line.
Date: Mon, 11 Aug 2025 19:15:02 -0400
Hey Wilko,

On 2025-08-11 10:00, Wilko Meyer wrote:
> This patch introduces an user option to conditionally include
> world-clock time, in addition to the localtime, when display-time-mode is
> active, in mode line.

Sounds useful to me. Some thoughts:

+ When the world clock list is long, this takes up a big chunk of the
  mode line. Would it make sense to limit the # or width somehow?

+ When enabled, it might help to have something like “(local)” beside
  the current time as a separator, i.e. it could look like:

  6:56PM (local) 7:56AM (Tokyo)

  instead of:

  6:56PM 7:56AM (Tokyo)

+ Perhaps the order should reflect `world-clock-sort-order' (by
  calling `world-clock--sort-entries' with the list and time).

+ I’m not sure what the norm is for mode line entries, but maybe the
  :set of the defcustom could refresh the mode line.

Best,

--
Jacob S. Gordon
jacob.as.gordon <at> gmail.com
Please avoid sending me HTML emails and MS Office documents.
https://useplaintext.email/#etiquette




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Tue, 12 Aug 2025 12:38:01 GMT) Full text and rfc822 format available.

Message #11 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: Rudolf Adamkovič <rudolf <at> adamkovic.org>
To: Wilko Meyer <w <at> wmeyer.eu>, 79217 <at> debbugs.gnu.org
Subject: Re: bug#79217: [PATCH] display-time-mode: Include world-clock time
 in mode line.
Date: Tue, 12 Aug 2025 14:37:26 +0200
Wilko Meyer via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs <at> gnu.org> writes:

> +(defcustom display-time-include-world-clock nil
> +  "Non-nil means time from `world-clock-list', `zoneinfo-style-world-list'
> +or `legacy-style-world-list' entries are displayed in mode line."
> +  :type 'boolean)

I would like to use this feature but with only for one or two entries
from my `world-clock-list'.  Could this (optionally) be a list of entry
labels, e.g. '("Mike") to show only Mike's time in the mode line?

Rudy
-- 
"I do not fear death.  I had been dead for billions and billions of years
before I was born, and had not suffered the slightest inconvenience from it."
--- Mark Twain, paraphrased

Rudolf Adamkovič <rudolf <at> adamkovic.org> [he/him]
http://adamkovic.org




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Tue, 12 Aug 2025 20:08:02 GMT) Full text and rfc822 format available.

Message #14 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: Wilko Meyer <w <at> wmeyer.eu>
To: 79217 <at> debbugs.gnu.org
Cc: rudolf <at> adamkovic.org, jacob.as.gordon <at> gmail.com, Wilko Meyer <w <at> wmeyer.eu>
Subject: [PATCH v2] display-time-mode: Include world-clock time in mode line.
Date: Tue, 12 Aug 2025 22:07:01 +0200
* lisp/time.el (display-time-include-world-clock): Add user option.
(display-time-include-world-clock-labels): Add user option.
(display-time-string-forms): Conditionally include world clock time as
well as a local suffix for the users time.
(time--create-world-time-mode-line-string): Helper function to fetch the
entries to be included the right way.
---
 lisp/time.el | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/lisp/time.el b/lisp/time.el
index 3750206d08e..82dee91bfc3 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -177,16 +177,37 @@ display-time-format
   :type '(choice (const :tag "Default" nil)
 		 string))
 
+(defcustom display-time-include-world-clock t
+  "Include world times in the mode line. The value can be one of:
+t   => to include all entries from `time--display-world-list`.
+nil => to disable showing the world clock in mode line.
+NUM => to include at most NUM entries."
+  :type '(choice
+          (const :tag "Off" nil)
+          (const :tag "All" t)
+          (integer :tag "Max entries" 1)))
+
+(defcustom display-time-include-world-clock-labels nil
+  "Only include world-clock entries whose label is in this list."
+  :type '(repeat (string :tag "Label")))
+
 (defcustom display-time-string-forms
   '((if (and (not display-time-format) display-time-day-and-date)
 	(format-time-string "%a %b %e " now)
       "")
     (propertize
-     (format-time-string (or display-time-format
+     (concat (format-time-string (or display-time-format
 			     (if display-time-24hr-format "%H:%M" "%-I:%M%p"))
-			 now)
+			         now)
+             (if display-time-include-world-clock " (local)"))
      'face 'display-time-date-and-time
      'help-echo (format-time-string "%a %b %e, %Y" now))
+    (if display-time-include-world-clock
+      (propertize
+       (time--create-world-clock-mode-line-string now)
+       'face 'display-time-date-and-time
+       'help-echo "World clock entries")
+      "")
     load
     (if mail
 	;; Build the string every time to act on customization.
@@ -516,6 +537,26 @@ time--display-world-list
 	  legacy-style-world-list
 	zoneinfo-style-world-list))))
 
+(defun time--create-world-clock-mode-line-string (&optional now)
+  (let* ((now (or now (current-time)))
+         (entries (world-clock--sort-entries (time--display-world-list) now))
+	 (entries (if display-time-include-world-clock-labels
+		      (seq-filter (lambda (p) (member (cadr p) display-time-include-world-clock-labels)) entries)
+                    entries))
+	 (entries (cond ((integerp display-time-include-world-clock)
+			 (seq-take entries display-time-include-world-clock))
+			((eq display-time-include-world-clock t) entries))))
+    (mapconcat
+     (lambda (p)
+       (pcase-let ((`(,tz ,label) p))
+         (format " %s (%s)"
+                 (format-time-string
+                  (or display-time-format
+                      (if display-time-24hr-format "%H:%M" "%-I:%M%p"))
+                  now tz)
+                 label)))
+     entries)))
+
 (defcustom world-clock-time-format "%A %d %B %R %Z"
   "Time format for `world-clock', see `format-time-string'."
   :type 'string
-- 
2.50.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Tue, 12 Aug 2025 20:22:02 GMT) Full text and rfc822 format available.

Message #17 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: Wilko Meyer <w <at> wmeyer.eu>
To: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
Cc: Wilko Meyer <w <at> wmeyer.eu>, 79217 <at> debbugs.gnu.org
Subject: Re: bug#79217: [PATCH] display-time-mode: Include world-clock time
 in mode line.
Date: Tue, 12 Aug 2025 22:21:14 +0200
Hi Jacob,

thanks for the feedback!

"Jacob S. Gordon" <jacob.as.gordon <at> gmail.com> writes:
> + When the world clock list is long, this takes up a big chunk of the
>   mode line. Would it make sense to limit the # or width somehow?

I just prepared a second version of this patch that allows
display-time-include-world-clock to be either t (to include all
entries), nil (to disable mode line inclusion), or NUM. If it's set to a
number that number will be used as the max number of possible entries to
be displayed.

> + When enabled, it might help to have something like “(local)” beside
>   the current time as a separator, i.e. it could look like:

Also included this.

> + Perhaps the order should reflect `world-clock-sort-order' (by
>   calling `world-clock--sort-entries' with the list and time).

I am now fetching the entries like:

(world-clock--sort-entries (time--display-world-list) now)

so the sort-order is honored, didn't know that sorting the entries was
possible before.

> + I’m not sure what the norm is for mode line entries, but maybe the
>   :set of the defcustom could refresh the mode line.

that's a good question, haven't seen usage of :set in time.el, but I
also don't really know how other mode line entries are handling this
yet, will probably look that up during the next days if time permits.

-- 
Kind regards,
Wilko Meyer




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Thu, 14 Aug 2025 07:36:02 GMT) Full text and rfc822 format available.

Message #20 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
To: Wilko Meyer <w <at> wmeyer.eu>
Cc: 79217 <at> debbugs.gnu.org,
 Rudolf Adamkovič <rudolf <at> adamkovic.org>
Subject: Re: bug#79217: [PATCH] display-time-mode: Include world-clock time in
 mode line.
Date: Thu, 14 Aug 2025 03:35:21 -0400
Hey Wilko,

Thanks for considering my feedback!

On 2025-08-12 16:07, Wilko Meyer wrote:
>+(defcustom display-time-include-world-clock t

I think it should be nil by default (as in your first version).

>+NUM => to include at most NUM entries."
>--8<--
>+(defcustom display-time-include-world-clock-labels nil
>+  "Only include world-clock entries whose label is in this list."
>+  :type '(repeat (string :tag "Label")))

I wonder if the # of entries and the list of labels should be options of
the same variable, as they both limit the included zones. Is something
lost if they can’t both be specified?

>+(defcustom display-time-include-world-clock t
>+  "Include world times in the mode line. The value can be one of:

Nit: The opening sentence should be alone on the first line to act as a
summary.

>+t   => to include all entries from `time--display-world-list`.

Nit: This should link to something user-facing like world-clock-list
(and quoted `like this').

>+             (if display-time-include-world-clock " (local)"))

Nit: Maybe this could be factored into your helper function.

On 2025-08-12 16:21, Wilko Meyer wrote:
> so the sort-order is honored, didn't know that sorting the entries was
> possible before.

Thanks, it’s pretty new (and I have some selfish motivation to advocate
for it ;P).

> that's a good question, haven't seen usage of :set in time.el, but I
> also don't really know how other mode line entries are handling this
> yet, will probably look that up during the next days if time permits.

I could definitely be off-base here, maybe someone more experienced than
I can comment.

Best,

-- 
Jacob S. Gordon
jacob.as.gordon <at> gmail.com
Please avoid sending me HTML emails and MS Office documents.
https://useplaintext.email/#etiquette




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Thu, 14 Aug 2025 16:43:02 GMT) Full text and rfc822 format available.

Message #23 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
To: Wilko Meyer <w <at> wmeyer.eu>
Cc: 79217 <at> debbugs.gnu.org
Subject: Re: bug#79217: [PATCH] display-time-mode: Include world-clock time in
 mode line.
Date: Thu, 14 Aug 2025 12:42:01 -0400
On 2025-08-12 16:21, Wilko Meyer wrote:
> haven't seen usage of :set in time.el

Oh and in case it wasn’t clear: I don’t think this is essential, just
a potential nicety when customizing. As you pointed out, things like
display-time-format don’t do this, and the mode line will update
either way when the clock updates. So it’s more about my curiosity,
and you should feel free to ignore :)

Best,

-- 
Jacob S. Gordon
jacob.as.gordon <at> gmail.com
Please avoid sending me HTML emails and MS Office documents.
https://useplaintext.email/#etiquette




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79217; Package emacs. (Sat, 30 Aug 2025 07:42:02 GMT) Full text and rfc822 format available.

Message #26 received at 79217 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
Cc: w <at> wmeyer.eu, 79217 <at> debbugs.gnu.org
Subject: Re: bug#79217: [PATCH] display-time-mode: Include world-clock time in
 mode line.
Date: Sat, 30 Aug 2025 10:41:18 +0300
> Cc: 79217 <at> debbugs.gnu.org
> Date: Thu, 14 Aug 2025 12:42:01 -0400
> From: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
> 
> On 2025-08-12 16:21, Wilko Meyer wrote:
> > haven't seen usage of :set in time.el
> 
> Oh and in case it wasn’t clear: I don’t think this is essential, just
> a potential nicety when customizing. As you pointed out, things like
> display-time-format don’t do this, and the mode line will update
> either way when the clock updates. So it’s more about my curiosity,
> and you should feel free to ignore :)

So do we have an agreed-upon patch for this feature?  Is the last v2
posted here the one in which all the review comments were accounted
for and adjudicated?

If so, I have a few minor comments to that patch:

> * lisp/time.el (display-time-include-world-clock): Add user option.
> (display-time-include-world-clock-labels): Add user option.
> (display-time-string-forms): Conditionally include world clock time as
> well as a local suffix for the users time.
> (time--create-world-time-mode-line-string): Helper function to fetch the
> entries to be included the right way.

Please mention the bug number in the commit log message.

> +(defcustom display-time-include-world-clock t

This default of t changes past behavior.  I think the default should
be nil, to preserve past behavior.

> +  "Include world times in the mode line. The value can be one of:

The first line of a doc string should be a single complete sentence
(because some commands, like "M-x apropos", show only that first
line).

> +t   => to include all entries from `time--display-world-list`.
> +nil => to disable showing the world clock in mode line.
> +NUM => to include at most NUM entries."
> +  :type '(choice
> +          (const :tag "Off" nil)
> +          (const :tag "All" t)
> +          (integer :tag "Max entries" 1)))

All new defcustom's should have a :version tag.

> +(defcustom display-time-include-world-clock-labels nil
> +  "Only include world-clock entries whose label is in this list."
> +  :type '(repeat (string :tag "Label")))

So if the user customizes display-time-include-world-clock to a
non-nil value, no world clock will be shown unless this option is
_also_ customized to include some labels?  This might be confusing UI,
but in any case, the doc strings of both options should
cross-reference to the other option and explain the dependencies.

Also, how can a user know which label to add for a particular entry?
IOW, the format of these labels should be described in enough detail
for the users to know how to set up this option for a particular clock
to be shown.

Thanks.




This bug report was last modified 12 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.