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