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