0
|
1 ;;; time.el --- display time and load in mode line of Emacs.
|
|
2
|
2
|
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 1996 Free Software Foundation, Inc.
|
0
|
4
|
108
|
5 ;; Maintainer: FSF, XEmacs add-ons (C) by Jens T. Lautenbacher
|
|
6 ;; mail <jens@lemming0.lem.uni-karlsruhe.de>
|
|
7 ;; for comments/fixes about the enhancements.
|
0
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
0
|
25
|
2
|
26 ;;; Synched up with: Not synched with FSF.
|
0
|
27
|
|
28 ;;; Commentary:
|
|
29
|
2
|
30 ;; Facilities to display current time/date and a new-mail indicator
|
|
31 ;; in the Emacs mode line. The single entry point is `display-time'.
|
0
|
32
|
2
|
33 ;; See also reportmail.el.
|
|
34 ;; This uses the XEmacs timeout-event mechanism, via a version
|
|
35 ;; of Kyle Jones' itimer package.
|
0
|
36
|
108
|
37 ;;; JTL: This is in a wide part reworked for XEmacs so it won't use
|
|
38 ;;; the old mechanism for specifying what is to be displayed.
|
|
39 ;;; The starting variable to look at is `display-time-form-list'
|
|
40
|
114
|
41 ;;; Thanks to Mike Scheidler for the idea to make the time led's fore- and
|
|
42 ;;; background color customizable
|
|
43
|
0
|
44 ;;; Code:
|
|
45
|
|
46 (require 'itimer)
|
|
47
|
110
|
48 (defgroup display-time nil
|
|
49 "Facilities to display the current time/date/load and a new-mail indicator
|
|
50 in the XEmacs mode line or echo area."
|
|
51 :group 'applications)
|
108
|
52
|
110
|
53 (defcustom display-time-compatible nil
|
|
54 "*This variable may be set to t to get the old behaviour of display-time.
|
|
55 This means no display of a spiffy mail icon or use of the
|
|
56 display-time-form-list instead of the old display-time-string-form."
|
|
57 :group 'display-time
|
|
58 :type 'boolean)
|
|
59
|
|
60 (defcustom display-time-mail-file nil
|
0
|
61 "*File name of mail inbox file, for indicating existence of new mail.
|
|
62 Non-nil and not a string means don't check for mail. nil means use
|
110
|
63 default, which is system-dependent, and is the same as used by Rmail."
|
|
64 :group 'display-time)
|
0
|
65
|
|
66 ;;;###autoload
|
110
|
67 (defcustom display-time-day-and-date nil
|
|
68 "*Non-nil means \\[display-time] should display day,date and time.
|
|
69 This affects the spec 'date in the variable display-time-form-list."
|
|
70 :group 'display-time
|
|
71 :type 'boolean)
|
0
|
72
|
110
|
73 (defcustom display-time-interval 20
|
|
74 "*Seconds between updates of time in the mode line."
|
|
75 :group 'display-time
|
|
76 :type 'integer)
|
0
|
77
|
110
|
78 (defcustom display-time-24hr-format nil
|
0
|
79 "*Non-nil indicates time should be displayed as hh:mm, 0 <= hh <= 23.
|
110
|
80 Nil means 1 <= hh <= 12, and an AM/PM suffix is used.
|
|
81 This affects the spec 'time in the variable display-time-form-list."
|
|
82 :group 'display-time
|
|
83 :type 'boolean)
|
0
|
84
|
110
|
85 (defcustom display-time-echo-area nil
|
|
86 "*If non-nil, display-time will use the echo area instead of the mode line."
|
|
87 :group 'display-time
|
|
88 :type 'boolean)
|
0
|
89
|
|
90 (defvar display-time-string nil)
|
|
91
|
110
|
92 (defcustom display-time-hook nil
|
|
93 "*List of functions to be called when the time is updated on the mode line."
|
|
94 :group 'display-time
|
|
95 :type 'hook)
|
0
|
96
|
|
97 (defvar display-time-server-down-time nil
|
|
98 "Time when mail file's file system was recorded to be down.
|
|
99 If that file system seems to be up, the value is nil.")
|
|
100
|
110
|
101 (defcustom display-time-ignore-read-mail nil
|
|
102 "*Non-nil means displays the mail icon on any non-empty mailbox."
|
|
103 :group 'display-time
|
|
104 :type 'boolean)
|
|
105
|
0
|
106 ;;;###autoload
|
|
107 (defun display-time ()
|
|
108 "Display current time, load level, and mail flag in mode line of each buffer.
|
|
109 Updates automatically every minute.
|
|
110 If `display-time-day-and-date' is non-nil, the current day and date
|
|
111 are displayed as well.
|
|
112 After each update, `display-time-hook' is run with `run-hooks'.
|
|
113 If `display-time-echo-area' is non-nil, the time is displayed in the
|
|
114 echo area instead of in the mode-line."
|
|
115 (interactive)
|
|
116 ;; if the "display-time" itimer already exists, nuke it first.
|
|
117 (let ((old (get-itimer "display-time")))
|
|
118 (if old (delete-itimer old)))
|
108
|
119
|
|
120 (if (memq 'display-time-string global-mode-string)
|
|
121 (setq global-mode-string
|
|
122 (remove 'display-time-string global-mode-string)))
|
0
|
123 ;; If we're not displaying the time in the echo area
|
|
124 ;; and the global mode string does not have a non-nil value
|
|
125 ;; then initialize the global mode string's value.
|
|
126 (or display-time-echo-area
|
|
127 global-mode-string
|
|
128 (setq global-mode-string '("")))
|
|
129 ;; If we're not displaying the time in the echo area
|
108
|
130 ;; then we add our variable to the list. This will make the time
|
0
|
131 ;; appear on the modeline.
|
|
132 (or display-time-echo-area
|
|
133 (setq global-mode-string
|
108
|
134 (append global-mode-string '(display-time-string))))
|
0
|
135 ;; Display the time initially...
|
|
136 (display-time-function)
|
|
137 ;; ... and start an itimer to do it automatically thereafter.
|
|
138 ;;
|
|
139 ;; If we wanted to be really clever about this, we could have the itimer
|
|
140 ;; not be automatically restarted, but have it re-add itself each time.
|
|
141 ;; Then we could look at (current-time) and arrange for the itimer to
|
|
142 ;; wake up exactly at the minute boundary. But that's just a little
|
|
143 ;; more work than it's worth...
|
|
144 (start-itimer "display-time" 'display-time-function
|
|
145 display-time-interval display-time-interval))
|
|
146
|
114
|
147 (defun display-time-stop ()
|
|
148 (interactive)
|
|
149 (delete-itimer "display-time")
|
|
150 (setq display-time-string nil))
|
|
151
|
110
|
152 (defcustom display-time-show-icons-maybe t
|
|
153 "Use icons for time, load and mail status if possible
|
|
154 and not specified different explicitely"
|
|
155 :group 'display-time
|
|
156 :type 'boolean)
|
104
|
157
|
110
|
158 (defvar display-time-icons-dir (concat data-directory "time/"))
|
104
|
159
|
110
|
160 (defcustom display-time-mail-sign-string " Mail"
|
|
161 "The string used as mail indicator in the echo area
|
108
|
162 (and in the modeline if display-time-show-icons-maybe is nil)
|
110
|
163 if display-time-echo-area is t"
|
|
164 :group 'display-time
|
|
165 :type 'string)
|
104
|
166
|
110
|
167 (defcustom display-time-no-mail-sign-string ""
|
108
|
168 "The string used as no-mail indicator in the echo area
|
|
169 (and in the modeline if display-time-show-icons-maybe is nil)
|
110
|
170 if display-time-echo-area is t"
|
|
171 :group 'display-time
|
|
172 :type 'string)
|
|
173
|
114
|
174 (defcustom display-time-display-pad "grey35"
|
|
175 "How the load indicator's trapezoidal \"pad\" is to be displayed.
|
|
176 This can be 'transparent or a string describing the color it should have"
|
|
177 :group 'display-time
|
|
178 :type '(choice :tag "Value"
|
|
179 (const transparent)
|
|
180 (string :tag "Color")))
|
|
181
|
|
182 (defcustom display-time-display-time-foreground "firebrick"
|
|
183 "How the time LEDs foreground is to be displayed.
|
|
184 This can be 'modeline (foreground color of the Modeline)
|
|
185 or a string describing the color it should have"
|
110
|
186 :group 'display-time
|
114
|
187 :type '(choice :tag "Value"
|
|
188 (const modline)
|
|
189 (string :tag "Color")))
|
|
190
|
|
191 (defcustom display-time-display-time-background 'transparent
|
|
192 "How the time LEDs background is to be displayed.
|
|
193 This can be 'transparent or a string describing the color it should have"
|
|
194 :group 'display-time
|
|
195 :type '(choice :tag "Value"
|
|
196 (const transparent)
|
|
197 (string :tag "Color")))
|
|
198
|
|
199
|
|
200 (defvar display-time-display-pad-old nil)
|
|
201
|
|
202 (defvar display-time-display-time-fg-old nil)
|
|
203
|
|
204 (defvar display-time-display-time-bg-old nil)
|
104
|
205
|
110
|
206 (defcustom display-time-load-list
|
|
207 (list 0.2 0.5 0.8 1.1 1.8 2.6)
|
|
208 "*A list giving six thresholds for the load
|
|
209 which correspond to the six different icons to be displayed
|
|
210 as a load indicator"
|
|
211 :group 'display-time
|
114
|
212 :type '(list (number :tag "Threshold 1")
|
|
213 (number :tag "Threshold 2")
|
|
214 (number :tag "Threshold 3")
|
|
215 (number :tag "Threshold 4")
|
|
216 (number :tag "Threshold 5")
|
|
217 (number :tag "Threshold 6")))
|
108
|
218
|
|
219 (defun display-time-string-to-char-list (str)
|
|
220 (mapcar (function identity) str))
|
|
221
|
114
|
222 (defun display-time-generate-load-glyphs (&optional force)
|
|
223 (let* ((pad-color (if (symbolp display-time-display-pad)
|
|
224 (list "pad-color" '(face-background 'modeline))
|
|
225 (list "pad-color" display-time-display-pad)))
|
|
226 (xpm-color-symbols (append (list pad-color) xpm-color-symbols)))
|
|
227 (if (and (featurep 'xpm)
|
|
228 (or force (not (equal display-time-display-pad
|
|
229 display-time-display-pad-old))))
|
|
230 (progn
|
|
231 (setq display-time-load-0.0-glyph
|
|
232 (cons (make-extent nil nil)
|
|
233 (make-glyph
|
|
234 (concat display-time-icons-dir "l-0.0.xpm"))))
|
|
235 (setq display-time-load-0.5-glyph
|
|
236 (cons (make-extent nil nil)
|
|
237 (make-glyph
|
|
238 (concat display-time-icons-dir "l-0.5.xpm"))))
|
|
239 (setq display-time-load-1.0-glyph
|
|
240 (cons (make-extent nil nil)
|
|
241 (make-glyph
|
|
242 (concat display-time-icons-dir "l-1.0.xpm"))))
|
|
243 (setq display-time-load-1.5-glyph
|
|
244 (cons (make-extent nil nil)
|
|
245 (make-glyph
|
|
246 (concat display-time-icons-dir "l-1.5.xpm"))))
|
|
247 (setq display-time-load-2.0-glyph
|
|
248 (cons (make-extent nil nil)
|
|
249 (make-glyph
|
|
250 (concat display-time-icons-dir "l-2.0.xpm"))))
|
|
251 (setq display-time-load-2.5-glyph
|
|
252 (cons (make-extent nil nil)
|
|
253 (make-glyph
|
|
254 (concat display-time-icons-dir "l-2.5.xpm"))))
|
|
255 (setq display-time-load-3.0-glyph
|
|
256 (cons (make-extent nil nil)
|
|
257 (make-glyph
|
|
258 (concat display-time-icons-dir "l-3.0.xpm"))))
|
|
259 (setq display-time-display-pad-old display-time-display-pad)
|
|
260 ))))
|
|
261
|
|
262
|
|
263 (defun display-time-generate-time-glyphs (&optional force)
|
|
264 (let* ((ledbg (if (symbolp display-time-display-time-background)
|
|
265 (list "ledbg" '(face-background 'modeline))
|
|
266 (list "ledbg" display-time-display-time-background)))
|
|
267 (ledfg (if (symbolp display-time-display-time-foreground)
|
|
268 (list "ledfg" '(face-foreground 'modeline))
|
|
269 (list "ledfg" display-time-display-time-foreground)))
|
|
270 (xpm-color-symbols (append (list ledbg)
|
|
271 (list ledfg) xpm-color-symbols)))
|
|
272 (if (and (featurep 'xpm)
|
|
273 (or force (not (equal display-time-display-time-background
|
|
274 display-time-display-time-bg-old))
|
|
275 (not (equal display-time-display-time-foreground
|
|
276 display-time-display-time-fg-old))))
|
|
277 (progn
|
|
278 (setq display-time-1-glyph
|
|
279 (cons (make-extent nil nil)
|
|
280 (make-glyph (concat display-time-icons-dir "1.xpm"))))
|
|
281 (setq display-time-2-glyph
|
|
282 (cons (make-extent nil nil)
|
|
283 (make-glyph (concat display-time-icons-dir "2.xpm"))))
|
|
284 (setq display-time-3-glyph
|
|
285 (cons (make-extent nil nil)
|
|
286 (make-glyph (concat display-time-icons-dir "3.xpm"))))
|
|
287 (setq display-time-4-glyph
|
|
288 (cons (make-extent nil nil)
|
|
289 (make-glyph (concat display-time-icons-dir "4.xpm"))))
|
|
290 (setq display-time-5-glyph
|
|
291 (cons (make-extent nil nil)
|
|
292 (make-glyph (concat display-time-icons-dir "5.xpm"))))
|
|
293 (setq display-time-6-glyph
|
|
294 (cons (make-extent nil nil)
|
|
295 (make-glyph (concat display-time-icons-dir "6.xpm"))))
|
|
296 (setq display-time-7-glyph
|
|
297 (cons (make-extent nil nil)
|
|
298 (make-glyph (concat display-time-icons-dir "7.xpm"))))
|
|
299 (setq display-time-8-glyph
|
|
300 (cons (make-extent nil nil)
|
|
301 (make-glyph (concat display-time-icons-dir "8.xpm"))))
|
|
302 (setq display-time-9-glyph
|
|
303 (cons (make-extent nil nil)
|
|
304 (make-glyph (concat display-time-icons-dir "9.xpm"))))
|
|
305 (setq display-time-0-glyph
|
|
306 (cons (make-extent nil nil)
|
|
307 (make-glyph (concat display-time-icons-dir "0.xpm"))))
|
|
308 (setq display-time-:-glyph
|
|
309 (cons (make-extent nil nil)
|
|
310 (make-glyph (concat display-time-icons-dir "dp.xpm"))))
|
|
311 (setq display-time-am-glyph
|
|
312 (cons (make-extent nil nil)
|
|
313 (make-glyph (concat display-time-icons-dir "am.xpm"))))
|
|
314 (setq display-time-pm-glyph
|
|
315 (cons (make-extent nil nil)
|
|
316 (make-glyph (concat display-time-icons-dir "pm.xpm"))))
|
|
317 (setq display-time-display-time-fg-old
|
|
318 display-time-display-time-foreground
|
|
319 display-time-display-time-bg-old
|
|
320 display-time-display-time-background)
|
|
321 ))))
|
|
322
|
|
323 (if (featurep 'xpm)
|
108
|
324 (progn
|
110
|
325 (defvar display-time-mail-sign
|
|
326 (cons (make-extent nil nil)
|
114
|
327 (make-glyph (concat display-time-icons-dir "letter.xpm"))))
|
110
|
328 (defvar display-time-no-mail-sign
|
|
329 (cons (make-extent nil nil)
|
114
|
330 (make-glyph (concat display-time-icons-dir "no-letter.xpm"))))
|
|
331 (defvar display-time-1-glyph nil)
|
|
332 (defvar display-time-2-glyph nil)
|
|
333 (defvar display-time-3-glyph nil)
|
|
334 (defvar display-time-4-glyph nil)
|
|
335 (defvar display-time-5-glyph nil)
|
|
336 (defvar display-time-6-glyph nil)
|
|
337 (defvar display-time-7-glyph nil)
|
|
338 (defvar display-time-8-glyph nil)
|
|
339 (defvar display-time-9-glyph nil)
|
|
340 (defvar display-time-0-glyph nil)
|
|
341 (defvar display-time-:-glyph nil)
|
|
342 (defvar display-time-am-glyph nil)
|
|
343 (defvar display-time-pm-glyph nil)
|
|
344 (defvar display-time-load-0.0-glyph nil)
|
|
345 (defvar display-time-load-0.5-glyph nil)
|
|
346 (defvar display-time-load-1.0-glyph nil)
|
|
347 (defvar display-time-load-1.5-glyph nil)
|
|
348 (defvar display-time-load-2.0-glyph nil)
|
|
349 (defvar display-time-load-2.5-glyph nil)
|
|
350 (defvar display-time-load-3.0-glyph nil)
|
|
351 (display-time-generate-time-glyphs 'force)
|
|
352 (display-time-generate-load-glyphs 'force)
|
110
|
353 ))
|
104
|
354
|
110
|
355 (defun display-time-can-do-graphical-display (&optional textual)
|
|
356 (and display-time-show-icons-maybe
|
|
357 (not textual)
|
|
358 (eq (console-type) 'x)
|
|
359 (featurep 'xpm)
|
|
360 (not display-time-echo-area)))
|
|
361
|
|
362
|
|
363 (defun display-time-convert-num (time-string &optional textual)
|
|
364 (let ((list (display-time-string-to-char-list time-string))
|
|
365 elem tmp)
|
|
366 (if (not (display-time-can-do-graphical-display textual)) time-string
|
114
|
367 (display-time-generate-time-glyphs)
|
108
|
368 (while (setq elem (pop list))
|
|
369 (push (eval (intern-soft (concat "display-time-"
|
|
370 (char-to-string elem)
|
|
371 "-glyph"))) tmp))
|
110
|
372 (reverse tmp))))
|
108
|
373
|
110
|
374 (defun display-time-convert-load (load-string &optional textual)
|
|
375 (let ((load-number (string-to-number load-string))
|
108
|
376 (alist (list (cons 0.0 0.0)
|
|
377 (cons 0.5 (car display-time-load-list))
|
|
378 (cons 1.0 (cadr display-time-load-list))
|
|
379 (cons 1.5 (caddr display-time-load-list))
|
|
380 (cons 2.0 (cadddr display-time-load-list))
|
|
381 (cons 2.5 (cadr (cdddr display-time-load-list)))
|
|
382 (cons 3.0 (caddr (cdddr display-time-load-list)))
|
|
383 (cons 100000 100000)))
|
|
384 result elem)
|
110
|
385 (if (not (display-time-can-do-graphical-display textual))
|
|
386 load-string
|
114
|
387 (display-time-generate-load-glyphs)
|
108
|
388 (while (>= load-number (cdr (setq elem (pop alist))))
|
|
389 (setq result (eval (intern-soft (concat
|
|
390 "display-time-load-"
|
|
391 (number-to-string (car elem))
|
|
392 "-glyph")))))
|
|
393 result)))
|
|
394
|
110
|
395 (defun display-time-convert-am-pm (ampm-string &optional textual)
|
|
396 (if (not (display-time-can-do-graphical-display textual))
|
|
397 ampm-string
|
|
398 (cond ((equal ampm-string "am") display-time-am-glyph)
|
|
399 ((equal ampm-string "pm") display-time-pm-glyph))))
|
108
|
400
|
|
401
|
110
|
402 (defun display-time-mail-sign (&optional textual)
|
108
|
403 "*A function giving back the object indicating 'mail' which
|
|
404 is the value of display-time-mail-sign when running under X,
|
|
405 display-time-echo-area is nil and display-time-show-icons-maybe is t.
|
|
406 It is the value of display-time-mail-sign-string otherwise."
|
110
|
407 (if (not (display-time-can-do-graphical-display textual))
|
108
|
408 display-time-mail-sign-string
|
|
409 display-time-mail-sign))
|
|
410
|
110
|
411 (defun display-time-no-mail-sign (&optional textual)
|
108
|
412 "*A function giving back the object indicating 'no mail' which
|
|
413 is the value of display-time-no-mail-sign when running under X,
|
|
414 display-time-echo-area is nil and display-time-show-icons-maybe is t.
|
|
415 It is the value of display-time-no-mail-sign-string otherwise."
|
110
|
416 (if (not (display-time-can-do-graphical-display textual))
|
108
|
417 display-time-no-mail-sign-string
|
|
418 display-time-no-mail-sign))
|
|
419
|
110
|
420 (defcustom display-time-form-list
|
|
421 (list 'date 'time 'load 'mail)
|
|
422 "*This list describes the format of the strings/glyphs
|
|
423 which are to be displayed by display-time.
|
|
424 The old variable display-time-string-forms is only used if
|
|
425 display-time-compatible is non-nil. It is a list consisting of
|
108
|
426 strings or any of the following symbols:
|
|
427
|
110
|
428 There are three complex specs whose behaviour is changed via
|
|
429 the setting of various variables
|
108
|
430
|
110
|
431 date: This prints out the date in a manner compatible to
|
|
432 the default value of the obsolete variable
|
|
433 display-time-string-forms. It respects the variable
|
|
434 display-time-day-and-date. If this is t it will print
|
|
435 out the current date in the form DAYNAME MONTH DAY
|
|
436 otherwise it will print nothing.
|
|
437
|
|
438 time: This prints out the time in a manner compatible to
|
|
439 the default value of the obsolete variable
|
|
440 display-time-string-forms. It respects the variable
|
|
441 display-time-24hr-format. If this is t it will print
|
|
442 out the current hours in 24-hour format, if nil the
|
|
443 hours will be printed in 12-hour format and the
|
|
444 minutes will be followed by 'AM' or 'PM'.
|
|
445
|
|
446 time-text: The same as above, but will not use a glyph
|
|
447
|
|
448 The other specs are simpler, as their meaning is not changed via
|
|
449 variables.
|
108
|
450
|
110
|
451 24-hours: This prints the hours in 24-hours format
|
|
452
|
|
453 24-hours-text: The same as above, but will not use a glyph
|
|
454
|
|
455 12-hours: This prints the hours in 12-hours format
|
|
456
|
|
457 12-hours-text: The same as above, but will not use a glyph
|
|
458
|
|
459 am-pm: This prints am or pm.
|
108
|
460
|
110
|
461 Timezone: This prints out the local timezone
|
|
462
|
|
463 am-pm-text: The same as above, but will not use a glyph
|
|
464
|
|
465 minutes: This prints the minutes.
|
|
466
|
|
467 minutes-text: The same as above, but will not use a glyph
|
|
468
|
|
469 day: This prints out the current day as a number.
|
|
470
|
|
471 dayname: This prints out today's name.
|
|
472
|
|
473 month: This prints out the current month as a number
|
|
474
|
|
475 monthname: This prints out the current month's name
|
108
|
476
|
110
|
477 year: This prints out the current year.
|
|
478
|
|
479 load: This prints out the system's load.
|
|
480
|
|
481 load-text: The same as above, but will not use a glyph
|
|
482
|
|
483 mail: This displays a mail indicator. Under X this will
|
|
484 normally be a small icon which changes depending if
|
|
485 there is new mail or not.
|
|
486
|
|
487 mail-text: The same as above, but will not use a glyph"
|
|
488 :group 'display-time
|
114
|
489 :type '(repeat (choice :tag "Symbol/String"
|
110
|
490 (const :tag "Date" date)
|
|
491 (const :tag "Time" time)
|
|
492 (const :tag "Time (text)" time-text)
|
|
493 (const :tag "24 hour format" 24-hours)
|
|
494 (const :tag "24 hour format (text)" 24-hours-text)
|
|
495 (const :tag "12 hour format" 12-hours)
|
|
496 (const :tag "12 hour format (text)" 12-hours-text)
|
|
497 (const :tag "AM/PM indicator" am-pm)
|
|
498 (const :tag "AM/PM indicator (text)" am-pm-text)
|
|
499 (const :tag "Timezone" timezone)
|
|
500 (const :tag "Minutes" minutes)
|
|
501 (const :tag "Minutes (text)" minutes-text)
|
|
502 (const :tag "Day" day)
|
|
503 (const :tag "Dayname" dayname)
|
|
504 (const :tag "Month" month)
|
|
505 (const :tag "Monthname" monthname)
|
|
506 (const :tag "Year" year)
|
|
507 (const :tag "Load" load)
|
|
508 (const :tag "Load (text)" load-text)
|
|
509 (const :tag "Mail sign" mail)
|
|
510 (const :tag "Mail sign (text)" mail-text)
|
|
511 (string :tag "String"))))
|
108
|
512
|
|
513 (defun display-time-evaluate-list ()
|
|
514 "Evalute the variable display-time-form-list"
|
|
515 (let ((list display-time-form-list) elem tmp result)
|
|
516 (while (setq elem (pop list))
|
|
517 (cond ((stringp elem) (push elem tmp))
|
110
|
518 ((eq elem 'date)
|
108
|
519 (push (if display-time-day-and-date
|
|
520 (format "%s %s %s " dayname monthname day) "") tmp))
|
110
|
521 ((eq elem 'time)
|
108
|
522 (progn
|
110
|
523 (push (display-time-convert-num
|
108
|
524 (format "%s:%s"
|
|
525 (if display-time-24hr-format 24-hours 12-hours)
|
110
|
526 minutes)) tmp)
|
108
|
527 (if (not display-time-24hr-format)
|
|
528 (push (display-time-convert-am-pm am-pm) tmp))))
|
110
|
529 ((eq elem 'time-text)
|
|
530 (push (display-time-convert-num
|
|
531 (format "%s:%s"
|
|
532 (if display-time-24hr-format 24-hours 12-hours)
|
|
533 minutes) t) tmp)
|
|
534 (if (not display-time-24hr-format)
|
|
535 (push (display-time-convert-am-pm am-pm t) tmp)))
|
108
|
536 ((eq elem 'day) (push day tmp))
|
|
537 ((eq elem 'dayname) (push dayname tmp))
|
|
538 ((eq elem 'month) (push month tmp))
|
|
539 ((eq elem 'monthname) (push monthname tmp))
|
110
|
540 ((eq elem '24-hours)
|
|
541 (push (display-time-convert-num 24-hours) tmp))
|
|
542 ((eq elem 'year)
|
|
543 (push year tmp))
|
|
544 ((eq elem '24-hours-text)
|
|
545 (push (display-time-convert-num 24-hours t) tmp))
|
|
546 ((eq elem '12-hours)
|
|
547 (push (display-time-convert-num 12-hours) tmp))
|
|
548 ((eq elem '12-hours-text)
|
|
549 (push (display-time-convert-num 12-hours t) tmp))
|
|
550 ((eq elem 'minutes)
|
|
551 (push (display-time-convert-num minutes) tmp))
|
|
552 ((eq elem 'minutes-text)
|
|
553 (push (display-time-convert-num minutes t) tmp))
|
|
554 ((eq elem 'am-pm)
|
|
555 (push (display-time-convert-am-pm am-pm) tmp))
|
|
556 ((eq elem 'am-pm-text)
|
|
557 (push (display-time-convert-am-pm am-pm t) tmp))
|
|
558 ((eq elem 'timezone)
|
|
559 (push time-zone tmp))
|
108
|
560 ((eq elem 'load)
|
110
|
561 (push (display-time-convert-load load) tmp))
|
|
562 ((eq elem 'load-text)
|
|
563 (push (display-time-convert-load load t) tmp))
|
|
564 ((eq elem 'mail)
|
|
565 (push (if mail (display-time-mail-sign)
|
|
566 (display-time-no-mail-sign)) tmp))
|
|
567 ((eq elem 'mail-text)
|
|
568 (push (if mail (display-time-mail-sign t)
|
|
569 (display-time-no-mail-sign t)) tmp))
|
|
570 ))
|
108
|
571 ;; We know that we have a list containing only of strings if
|
|
572 ;; display-time-echo-area is t. So we construct this string from
|
|
573 ;; the list. Else we just reverse the list and give it as result.
|
|
574 (if (not display-time-echo-area) (setq result (reverse tmp))
|
|
575 (while (setq elem (pop tmp))
|
|
576 (setq result (concat elem result))))
|
|
577 result))
|
|
578
|
|
579
|
0
|
580 (defvar display-time-string-forms
|
|
581 '((if display-time-day-and-date
|
|
582 (format "%s %s %s " dayname monthname day)
|
|
583 "")
|
|
584 (format "%s:%s%s"
|
|
585 (if display-time-24hr-format 24-hours 12-hours)
|
|
586 minutes
|
|
587 (if display-time-24hr-format "" am-pm))
|
108
|
588 load
|
|
589 (if mail " Mail" ""))
|
|
590 "*THIS IS OBSOLETE! It will only be used if display-time-compatible is t.
|
|
591 A list of expressions governing display of the time in the mode line.
|
0
|
592 This expression is a list of expressions that can involve the keywords
|
|
593 `load', `day', `month', and `year', `12-hours', `24-hours', `minutes',
|
|
594 `seconds', all numbers in string form, and `monthname', `dayname', `am-pm',
|
104
|
595 and `time-zone' all alphabetic strings and `mail' a true/nil string value.
|
0
|
596
|
|
597 For example, the form
|
|
598
|
|
599 '((substring year -2) \"/\" month \"/\" day
|
|
600 \" \" 24-hours \":\" minutes \":\" seconds
|
104
|
601 (if time-zone \" (\") time-zone (if time-zone \")\"))
|
0
|
602
|
|
603 would give mode line times like `94/12/30 21:07:48 (UTC)'.")
|
|
604
|
|
605 (defun display-time-function ()
|
|
606 (let* ((now (current-time))
|
|
607 (time (current-time-string now))
|
|
608 (load (condition-case ()
|
|
609 (if (zerop (car (load-average))) ""
|
|
610 (let ((str (format " %03d" (car (load-average)))))
|
|
611 (concat (substring str 0 -2) "." (substring str -2))))
|
|
612 (error "")))
|
|
613 (mail-spool-file (or display-time-mail-file
|
|
614 (getenv "MAIL")
|
|
615 (concat rmail-spool-directory
|
|
616 (user-login-name))))
|
|
617 (mail (and (stringp mail-spool-file)
|
|
618 (or (null display-time-server-down-time)
|
|
619 ;; If have been down for 20 min, try again.
|
|
620 (> (- (nth 1 (current-time))
|
|
621 display-time-server-down-time)
|
|
622 1200))
|
|
623 (let ((start-time (current-time)))
|
|
624 (prog1
|
|
625 (display-time-file-nonempty-p mail-spool-file)
|
|
626 (if (> (- (nth 1 (current-time)) (nth 1 start-time))
|
|
627 20)
|
|
628 ;; Record that mail file is not accessible.
|
|
629 (setq display-time-server-down-time
|
|
630 (nth 1 (current-time)))
|
|
631 ;; Record that mail file is accessible.
|
|
632 (setq display-time-server-down-time nil))))))
|
|
633 (24-hours (substring time 11 13))
|
|
634 (hour (string-to-int 24-hours))
|
|
635 (12-hours (int-to-string (1+ (% (+ hour 11) 12))))
|
|
636 (am-pm (if (>= hour 12) "pm" "am"))
|
|
637 (minutes (substring time 14 16))
|
|
638 (seconds (substring time 17 19))
|
|
639 (time-zone (car (cdr (current-time-zone now))))
|
|
640 (day (substring time 8 10))
|
|
641 (year (substring time 20 24))
|
|
642 (monthname (substring time 4 7))
|
|
643 (month
|
|
644 (cdr
|
|
645 (assoc
|
|
646 monthname
|
|
647 '(("Jan" . "1") ("Feb" . "2") ("Mar" . "3") ("Apr" . "4")
|
|
648 ("May" . "5") ("Jun" . "6") ("Jul" . "7") ("Aug" . "8")
|
|
649 ("Sep" . "9") ("Oct" . "10") ("Nov" . "11") ("Dec" . "12")))))
|
|
650 (dayname (substring time 0 3)))
|
|
651 (setq display-time-string
|
108
|
652 (if display-time-compatible
|
|
653 (mapconcat 'eval display-time-string-forms "")
|
|
654 (display-time-evaluate-list)))
|
0
|
655 ;; This is inside the let binding, but we are not going to document
|
|
656 ;; what variables are available.
|
|
657 (run-hooks 'display-time-hook))
|
|
658 (if display-time-echo-area
|
|
659 (or (> (minibuffer-depth) 0)
|
|
660 ;; don't stomp echo-area-buffer if reading from minibuffer now.
|
|
661 (save-excursion
|
|
662 (save-window-excursion
|
|
663 (select-window (minibuffer-window))
|
|
664 (erase-buffer)
|
110
|
665 (indent-to (- (frame-width) (length display-time-string) 1))
|
0
|
666 (insert display-time-string)
|
|
667 (message (buffer-string)))))
|
|
668 (force-mode-line-update)
|
|
669 ;; Do redisplay right now, if no input pending.
|
|
670 (sit-for 0)))
|
|
671
|
|
672 (defun display-time-file-nonempty-p (file)
|
110
|
673 (let ((attributes (file-attributes (file-chase-links file))))
|
|
674 (and attributes
|
|
675 (< 0 (nth 7 attributes))
|
|
676 (or display-time-ignore-read-mail
|
|
677 (> (car (nth 5 attributes)) (car (nth 4 attributes)))
|
|
678 (and (= (car (nth 5 attributes)) (car (nth 4 attributes)))
|
|
679 (> (cadr (nth 5 attributes)) (cadr (nth 4 attributes))))))))
|
0
|
680
|
|
681 (provide 'time)
|
|
682
|
|
683 ;;; time.el ends here
|