GNU bug report logs -
#79217
[PATCH] display-time-mode: Include world-clock time in mode line.
Previous Next
Full log
Message #14 received at 79217 <at> debbugs.gnu.org (full text, mbox):
* 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
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.