Mention in NEWS the change in 2012-01-06T08:10:22Z!rgm@gnu.org with `e' binding in...
[bpt/emacs.git] / lisp / time.el
CommitLineData
b7eb6e8a 1;;; time.el --- display time, load and mail indicator in mode line of Emacs -*-coding: utf-8 -*-
c2acf685 2
acaf905b 3;; Copyright (C) 1985-1987, 1993-1994, 1996, 2000-2012
95df8112 4;; Free Software Foundation, Inc.
c2acf685
SM
5
6;; Maintainer: FSF
7
8;; This file is part of GNU Emacs.
9
eb3fa2cf 10;; GNU Emacs is free software: you can redistribute it and/or modify
c2acf685 11;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
c2acf685
SM
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
eb3fa2cf 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
c2acf685
SM
22
23;;; Commentary:
24
25;; Facilities to display current time/date and a new-mail indicator
aff2ba04
RS
26;; in the Emacs mode line. The entry point is `display-time'.
27
28;; Display time world in a buffer, the entry point is
29;; `display-time-world'.
c2acf685
SM
30
31;;; Code:
32
33(defgroup display-time nil
34 "Display time and load in mode line of Emacs."
97904e51 35 :group 'mode-line
c2acf685
SM
36 :group 'mail)
37
38
c2acf685 39(defcustom display-time-mail-file nil
9201cc28 40 "File name of mail inbox file, for indicating existence of new mail.
cbb7527f 41Non-nil and not a string means don't check for mail; nil means use
c2acf685 42default, which is system-dependent, and is the same as used by Rmail."
fe6456af 43 :type '(choice (const :tag "None" none)
c2acf685
SM
44 (const :tag "Default" nil)
45 (file :format "%v"))
46 :group 'display-time)
47
cc351ed4 48(defcustom display-time-mail-directory nil
9201cc28 49 "Name of mail inbox directory, for indicating existence of new mail.
ad68bb68
RS
50Any nonempty regular file in the directory is regarded as newly arrived mail.
51If nil, do not check a directory for arriving mail."
cc351ed4
PJ
52 :type '(choice (const :tag "None" nil)
53 (directory :format "%v"))
54 :group 'display-time)
55
c2acf685 56(defcustom display-time-mail-function nil
9201cc28 57 "Function to call, for indicating existence of new mail.
ad68bb68
RS
58If nil, that means use the default method: check that the file
59specified by `display-time-mail-file' is nonempty or that the
60directory `display-time-mail-directory' contains nonempty files."
c2acf685
SM
61 :type '(choice (const :tag "Default" nil)
62 (function))
63 :group 'display-time)
64
4b05e68d 65(defcustom display-time-default-load-average 0
9201cc28 66 "Which load average value will be shown in the mode line.
4b05e68d 67Almost every system can provide values of load for past 1 minute, past 5 or
f2f56691 68past 15 minutes. The default is to display 1 minute load average.
3deeb46b
GM
69The value can be one of:
70
71 0 => 1 minute load
72 1 => 5 minutes load
73 2 => 15 minutes load"
4b05e68d
PJ
74 :type '(choice (const :tag "1 minute load" 0)
75 (const :tag "5 minutes load" 1)
fe6456af
RS
76 (const :tag "15 minutes load" 2)
77 (const :tag "None" nil))
4b05e68d
PJ
78 :group 'display-time)
79
fe6456af 80(defvar display-time-load-average nil
2bb4227e
GM
81 "Load average currently being shown in mode line.
82See `display-time-default-load-average'.")
4b05e68d
PJ
83
84(defcustom display-time-load-average-threshold 0.1
9201cc28 85 "Load-average values below this value won't be shown in the mode line."
b7b4e4d4
PJ
86 :type 'number
87 :group 'display-time)
4b05e68d 88
c2acf685
SM
89;;;###autoload
90(defcustom display-time-day-and-date nil "\
7c7c04c0 91Non-nil means \\[display-time] should display day and date as well as time."
c2acf685
SM
92 :type 'boolean
93 :group 'display-time)
94
95(defvar display-time-timer nil)
96
97(defcustom display-time-interval 60
9201cc28 98 "Seconds between updates of time in the mode line."
c2acf685
SM
99 :type 'integer
100 :group 'display-time)
101
102(defcustom display-time-24hr-format nil
9201cc28 103 "Non-nil indicates time should be displayed as hh:mm, 0 <= hh <= 23.
7d326782 104A value of nil means 1 <= hh <= 12, and an AM/PM suffix is used."
c2acf685
SM
105 :type 'boolean
106 :group 'display-time)
107
108(defvar display-time-string nil)
6dc3311d 109;;;###autoload(put 'display-time-string 'risky-local-variable t)
c2acf685
SM
110
111(defcustom display-time-hook nil
9201cc28 112 "List of functions to be called when the time is updated on the mode line."
c2acf685
SM
113 :type 'hook
114 :group 'display-time)
115
116(defvar display-time-server-down-time nil
117 "Time when mail file's file system was recorded to be down.
118If that file system seems to be up, the value is nil.")
119
dca2168c 120(defcustom zoneinfo-style-world-list
aff2ba04
RS
121 '(("America/Los_Angeles" "Seattle")
122 ("America/New_York" "New York")
123 ("Europe/London" "London")
124 ("Europe/Paris" "Paris")
125 ("Asia/Calcutta" "Bangalore")
126 ("Asia/Tokyo" "Tokyo"))
dca2168c
EZ
127 "Alist of zoneinfo-style time zones and places for `display-time-world'.
128Each element has the form (TIMEZONE LABEL).
129TIMEZONE should be a string of the form AREA/LOCATION, where AREA is
130the name of a region -- a continent or ocean, and LOCATION is the name
131of a specific location, e.g., a city, within that region.
132LABEL is a string to display as the label of that TIMEZONE's time."
133 :group 'display-time
134 :type '(repeat (list string string))
135 :version "23.1")
136
137(defcustom legacy-style-world-list
138 '(("PST8PDT" "Seattle")
139 ("EST5EDT" "New York")
9db0c29b 140 ("GMT0BST" "London")
dca2168c 141 ("CET-1CDT" "Paris")
9db0c29b
EZ
142 ("IST-5:30" "Bangalore")
143 ("JST-9" "Tokyo"))
dca2168c
EZ
144 "Alist of traditional-style time zones and places for `display-time-world'.
145Each element has the form (TIMEZONE LABEL).
146TIMEZONE should be a string of the form:
147
148 std[+|-]offset[dst[offset][,date[/time],date[/time]]]
149
150See the documentation of the TZ environment variable on your system,
151for more details about the format of TIMEZONE.
152LABEL is a string to display as the label of that TIMEZONE's time."
153 :group 'display-time
154 :type '(repeat (list string string))
155 :version "23.1")
156
157(defcustom display-time-world-list
36d4b145
JR
158 ;; Determine if zoneinfo style timezones are supported by testing that
159 ;; America/New York and Europe/London return different timezones.
37e11a63
CY
160 (let ((old-tz (getenv "TZ"))
161 gmt nyt)
162 (unwind-protect
163 (progn
164 (setenv "TZ" "America/New_York")
165 (setq nyt (format-time-string "%z"))
166 (setenv "TZ" "Europe/London")
167 (setq gmt (format-time-string "%z")))
168 (setenv "TZ" old-tz))
36d4b145
JR
169 (if (string-equal nyt gmt)
170 legacy-style-world-list
171 zoneinfo-style-world-list))
dca2168c 172 "Alist of time zones and places for `display-time-world' to display.
aff2ba04 173Each element has the form (TIMEZONE LABEL).
37e11a63
CY
174TIMEZONE should be in a format supported by your system. See the
175documentation of `zoneinfo-style-world-list' and
176\`legacy-style-world-list' for two widely used formats. LABEL is
177a string to display as the label of that TIMEZONE's time."
aff2ba04
RS
178 :group 'display-time
179 :type '(repeat (list string string))
180 :version "23.1")
181
658dcd47 182(defcustom display-time-world-time-format "%A %d %B %R %Z"
aff2ba04
RS
183 "Format of the time displayed, see `format-time-string'."
184 :group 'display-time
185 :type 'string
186 :version "23.1")
187
188(defcustom display-time-world-buffer-name "*wclock*"
7c7c04c0 189 "Name of the world clock buffer."
aff2ba04
RS
190 :group 'display-time
191 :type 'string
192 :version "23.1")
193
194(defcustom display-time-world-timer-enable t
195 "If non-nil, a timer will update the world clock."
196 :group 'display-time
197 :type 'boolean
198 :version "23.1")
199
200(defcustom display-time-world-timer-second 60
201 "Interval in seconds for updating the world clock."
202 :group 'display-time
203 :type 'integer
204 :version "23.1")
205
206(defvar display-time-world-mode-map
207 (let ((map (make-sparse-keymap)))
208 (define-key map "q" 'kill-this-buffer)
209 map)
7c7c04c0 210 "Keymap of Display Time World mode.")
aff2ba04 211
c2acf685
SM
212;;;###autoload
213(defun display-time ()
214 "Enable display of time, load level, and mail flag in mode lines.
215This display updates automatically every minute.
216If `display-time-day-and-date' is non-nil, the current day and date
217are displayed as well.
218This runs the normal hook `display-time-hook' after each update."
219 (interactive)
220 (display-time-mode 1))
221
b7eb6e8a
DL
222;; This business used to be simpler when all mode lines had the same
223;; face and the image could just be pbm. Now we try to rely on an xpm
224;; image with a transparent background. Otherwise, set the background
225;; for pbm.
226
227(defcustom display-time-mail-face nil
c2acf685 228 "Face to use for `display-time-mail-string'.
b7eb6e8a 229If `display-time-use-mail-icon' is non-nil, the image's
6bd47b39
JB
230background color is the background of this face. Set this to
231make the mail indicator stand out on a color display."
83033a3a 232 :group 'mode-line-faces
c2acf685 233 :group 'display-time
bf247b6e 234 :version "22.1"
b7eb6e8a 235 :type '(choice (const :tag "None" nil) face))
c2acf685
SM
236
237(defvar display-time-mail-icon
cc351ed4 238 (find-image '((:type xpm :file "letter.xpm" :ascent center)
b7eb6e8a
DL
239 (:type pbm :file "letter.pbm" :ascent center)))
240 "Image specification to offer as the mail indicator on a graphic display.
241See `display-time-use-mail-icon' and `display-time-mail-face'.")
c2acf685 242
b7eb6e8a 243;; Fixme: Default to icon on graphical display?
c2acf685 244(defcustom display-time-use-mail-icon nil
d7baab9c 245 "Non-nil means use an icon as mail indicator on a graphic display.
b7eb6e8a
DL
246Otherwise use `display-time-mail-string'. The icon may consume less
247of the mode line. It is specified by `display-time-mail-icon'."
c2acf685
SM
248 :group 'display-time
249 :type 'boolean)
250
b7eb6e8a
DL
251;; Fixme: maybe default to the character if we can display Unicode.
252(defcustom display-time-mail-string "Mail"
253 "String to use as the mail indicator in `display-time-string-forms'.
254This can use the Unicode letter character if you can display it."
255 :group 'display-time
bf247b6e 256 :version "22.1"
b7eb6e8a
DL
257 :type '(choice (const "Mail")
258 ;; Use :tag here because the Lucid menu won't display
259 ;; multibyte text.
260 (const :tag "Unicode letter character" "✉")
261 string))
262
c2acf685 263(defcustom display-time-format nil
9201cc28 264 "String specifying format for displaying the time in the mode line.
c2acf685
SM
265See the function `format-time-string' for an explanation of
266how to write this string. If this is nil, the defaults
267depend on `display-time-day-and-date' and `display-time-24hr-format'."
268 :type '(choice (const :tag "Default" nil)
269 string)
270 :group 'display-time)
271
272(defcustom display-time-string-forms
273 '((if (and (not display-time-format) display-time-day-and-date)
274 (format-time-string "%a %b %e " now)
275 "")
e93b2f39
SM
276 (propertize
277 (format-time-string (or display-time-format
278 (if display-time-24hr-format "%H:%M" "%-I:%M%p"))
279 now)
ef3e9175 280 'help-echo (format-time-string "%a %b %e, %Y" now))
c2acf685
SM
281 load
282 (if mail
283 ;; Build the string every time to act on customization.
b7eb6e8a
DL
284 ;; :set-after doesn't help for `customize-option'. I think it
285 ;; should.
286 (concat
287 " "
288 (propertize
289 display-time-mail-string
290 'display `(when (and display-time-use-mail-icon
291 (display-graphic-p))
292 ,@display-time-mail-icon
293 ,@(if (and display-time-mail-face
294 (memq (plist-get (cdr display-time-mail-icon)
295 :type)
296 '(pbm xbm)))
297 (let ((bg (face-attribute display-time-mail-face
298 :background)))
299 (if (stringp bg)
300 (list :background bg)))))
301 'face display-time-mail-face
302 'help-echo "You have new mail; mouse-2: Read mail"
3a02b63e 303 'mouse-face 'mode-line-highlight
b7eb6e8a
DL
304 'local-map (make-mode-line-mouse-map 'mouse-2
305 read-mail-command)))
c2acf685 306 ""))
9201cc28 307 "List of expressions governing display of the time in the mode line.
c2acf685
SM
308For most purposes, you can control the time format using `display-time-format'
309which is a more standard interface.
310
311This expression is a list of expressions that can involve the keywords
312`load', `day', `month', and `year', `12-hours', `24-hours', `minutes',
313`seconds', all numbers in string form, and `monthname', `dayname', `am-pm',
314and `time-zone' all alphabetic strings, and `mail' a true/nil value.
315
316For example, the form
317
318 '((substring year -2) \"/\" month \"/\" day
319 \" \" 24-hours \":\" minutes \":\" seconds
320 (if time-zone \" (\") time-zone (if time-zone \")\")
321 (if mail \" Mail\" \"\"))
322
323would give mode line times like `94/12/30 21:07:48 (UTC)'."
324 :type 'sexp
325 :group 'display-time)
326
327(defun display-time-event-handler ()
328 (display-time-update)
329 ;; Do redisplay right now, if no input pending.
330 (sit-for 0)
331 (let* ((current (current-time))
332 (timer display-time-timer)
333 ;; Compute the time when this timer will run again, next.
334 (next-time (timer-relative-time
335 (list (aref timer 1) (aref timer 2) (aref timer 3))
336 (* 5 (aref timer 4)) 0)))
337 ;; If the activation time is far in the past,
338 ;; skip executions until we reach a time in the future.
339 ;; This avoids a long pause if Emacs has been suspended for hours.
340 (or (> (nth 0 next-time) (nth 0 current))
341 (and (= (nth 0 next-time) (nth 0 current))
342 (> (nth 1 next-time) (nth 1 current)))
343 (and (= (nth 0 next-time) (nth 0 current))
344 (= (nth 1 next-time) (nth 1 current))
345 (> (nth 2 next-time) (nth 2 current)))
346 (progn
347 (timer-set-time timer (timer-next-integral-multiple-of-time
348 current display-time-interval)
349 display-time-interval)
350 (timer-activate timer)))))
351
4b05e68d 352(defun display-time-next-load-average ()
2bb4227e
GM
353 "Switch between different load averages in the mode line.
354Switches from the 1 to 5 to 15 minute load average, and then back to 1."
4b05e68d
PJ
355 (interactive)
356 (if (= 3 (setq display-time-load-average (1+ display-time-load-average)))
357 (setq display-time-load-average 0))
358 (display-time-update)
359 (sit-for 0))
360
cc351ed4
PJ
361(defun display-time-mail-check-directory ()
362 (let ((mail-files (directory-files display-time-mail-directory t))
363 (size 0))
364 (while (and mail-files (= size 0))
365 ;; Count size of regular files only.
366 (setq size (+ size (or (and (file-regular-p (car mail-files))
367 (nth 7 (file-attributes (car mail-files))))
368 0)))
369 (setq mail-files (cdr mail-files)))
370 (if (> size 0)
371 size
372 nil)))
373
06b60517 374(with-no-warnings
c80e3b4a 375 ;; Warnings are suppressed to avoid "global/dynamic var `X' lacks a prefix".
06b60517
JB
376 (defvar now)
377 (defvar time)
378 (defvar load)
379 (defvar mail)
380 (defvar 24-hours)
381 (defvar hour)
382 (defvar 12-hours)
383 (defvar am-pm)
384 (defvar minutes)
385 (defvar seconds)
386 (defvar time-zone)
387 (defvar day)
388 (defvar year)
389 (defvar monthname)
390 (defvar month)
391 (defvar dayname))
392
c2acf685 393(defun display-time-update ()
b7eb6e8a
DL
394 "Update the display-time info for the mode line.
395However, don't redisplay right now.
396
397This is used for things like Rmail `g' that want to force an
398update which can wait for the next redisplay."
c2acf685
SM
399 (let* ((now (current-time))
400 (time (current-time-string now))
fe6456af
RS
401 (load (if (null display-time-load-average)
402 ""
403 (condition-case ()
404 ;; Do not show values less than
405 ;; `display-time-load-average-threshold'.
406 (if (> (* display-time-load-average-threshold 100)
407 (nth display-time-load-average (load-average)))
408 ""
409 ;; The load average number is mysterious, so
410 ;; provide some help.
b7eb6e8a
DL
411 (let ((str (format " %03d"
412 (nth display-time-load-average
413 (load-average)))))
fe6456af
RS
414 (propertize
415 (concat (substring str 0 -2) "." (substring str -2))
b7eb6e8a
DL
416 'local-map (make-mode-line-mouse-map
417 'mouse-2 'display-time-next-load-average)
3a02b63e 418 'mouse-face 'mode-line-highlight
b7eb6e8a
DL
419 'help-echo (concat
420 "System load average for past "
421 (if (= 0 display-time-load-average)
422 "1 minute"
423 (if (= 1 display-time-load-average)
424 "5 minutes"
425 "15 minutes"))
426 "; mouse-2: next"))))
fe6456af 427 (error ""))))
c2acf685
SM
428 (mail-spool-file (or display-time-mail-file
429 (getenv "MAIL")
430 (concat rmail-spool-directory
431 (user-login-name))))
ab283561
LMI
432 (mail (cond
433 (display-time-mail-function
434 (funcall display-time-mail-function))
435 (display-time-mail-directory
436 (display-time-mail-check-directory))
437 ((and (stringp mail-spool-file)
438 (or (null display-time-server-down-time)
439 ;; If have been down for 20 min, try again.
440 (> (- (nth 1 now) display-time-server-down-time)
441 1200)
442 (and (< (nth 1 now) display-time-server-down-time)
443 (> (- (nth 1 now)
444 display-time-server-down-time)
445 -64336))))
446 (let ((start-time (current-time)))
447 (prog1
448 (display-time-file-nonempty-p mail-spool-file)
449 (if (> (- (nth 1 (current-time))
450 (nth 1 start-time))
451 20)
452 ;; Record that mail file is not accessible.
453 (setq display-time-server-down-time
454 (nth 1 (current-time)))
455 ;; Record that mail file is accessible.
456 (setq display-time-server-down-time nil)))))))
c2acf685 457 (24-hours (substring time 11 13))
027a4b6b 458 (hour (string-to-number 24-hours))
c2acf685
SM
459 (12-hours (int-to-string (1+ (% (+ hour 11) 12))))
460 (am-pm (if (>= hour 12) "pm" "am"))
461 (minutes (substring time 14 16))
462 (seconds (substring time 17 19))
463 (time-zone (car (cdr (current-time-zone now))))
464 (day (substring time 8 10))
465 (year (substring time 20 24))
466 (monthname (substring time 4 7))
467 (month
468 (cdr
469 (assoc
470 monthname
471 '(("Jan" . "1") ("Feb" . "2") ("Mar" . "3") ("Apr" . "4")
472 ("May" . "5") ("Jun" . "6") ("Jul" . "7") ("Aug" . "8")
473 ("Sep" . "9") ("Oct" . "10") ("Nov" . "11") ("Dec" . "12")))))
474 (dayname (substring time 0 3)))
475 (setq display-time-string
476 (mapconcat 'eval display-time-string-forms ""))
477 ;; This is inside the let binding, but we are not going to document
478 ;; what variables are available.
479 (run-hooks 'display-time-hook))
480 (force-mode-line-update))
481
482(defun display-time-file-nonempty-p (file)
4bc3c53d
MA
483 (let ((remote-file-name-inhibit-cache (- display-time-interval 5)))
484 (and (file-exists-p file)
485 (< 0 (nth 7 (file-attributes (file-chase-links file)))))))
c2acf685 486
57ce63c4
SM
487;;;###autoload
488(define-minor-mode display-time-mode
489 "Toggle display of time, load level, and mail flag in mode lines.
06e21633
CY
490With a prefix argument ARG, enable Display Time mode if ARG is
491positive, and disable it otherwise. If called from Lisp, enable
492it if ARG is omitted or nil.
493
494When Display Time mode is enabled, it updates every minute (you
495can control the number of seconds between updates by customizing
496`display-time-interval'). If `display-time-day-and-date' is
497non-nil, the current day and date are displayed as well. This
498runs the normal hook `display-time-hook' after each update."
bb7a71c5 499 :global t :group 'display-time
fe6456af
RS
500 (and display-time-timer (cancel-timer display-time-timer))
501 (setq display-time-timer nil)
502 (setq display-time-string "")
503 (or global-mode-string (setq global-mode-string '("")))
504 (setq display-time-load-average display-time-default-load-average)
505 (if display-time-mode
506 (progn
507 (or (memq 'display-time-string global-mode-string)
508 (setq global-mode-string
509 (append global-mode-string '(display-time-string))))
510 ;; Set up the time timer.
511 (setq display-time-timer
512 (run-at-time t display-time-interval
513 'display-time-event-handler))
514 ;; Make the time appear right away.
515 (display-time-update)
516 ;; When you get new mail, clear "Mail" from the mode line.
517 (add-hook 'rmail-after-get-new-mail-hook
518 'display-time-event-handler))
519 (remove-hook 'rmail-after-get-new-mail-hook
520 'display-time-event-handler)))
c2acf685 521
aff2ba04 522
16f3ade5 523(define-derived-mode display-time-world-mode nil "World clock"
aff2ba04
RS
524 "Major mode for buffer that displays times in various time zones.
525See `display-time-world'."
16f3ade5 526 (setq show-trailing-whitespace nil))
aff2ba04
RS
527
528(defun display-time-world-display (alist)
529 "Replace current buffer text with times in various zones, based on ALIST."
530 (let ((inhibit-read-only t)
37e11a63
CY
531 (buffer-undo-list t)
532 (old-tz (getenv "TZ"))
533 (max-width 0)
534 result fmt)
aff2ba04 535 (erase-buffer)
37e11a63
CY
536 (unwind-protect
537 (dolist (zone alist)
538 (let* ((label (cadr zone))
539 (width (string-width label)))
540 (setenv "TZ" (car zone))
541 (push (cons label
542 (format-time-string display-time-world-time-format))
543 result)
544 (when (> width max-width)
545 (setq max-width width))))
546 (setenv "TZ" old-tz))
547 (setq fmt (concat "%-" (int-to-string max-width) "s %s\n"))
548 (dolist (timedata (nreverse result))
549 (insert (format fmt (car timedata) (cdr timedata)))))
550 (delete-char -1))
aff2ba04
RS
551
552;;;###autoload
553(defun display-time-world ()
554 "Enable updating display of times in various time zones.
555`display-time-world-list' specifies the zones.
556To turn off the world time display, go to that window and type `q'."
557 (interactive)
558 (when (and display-time-world-timer-enable
559 (not (get-buffer display-time-world-buffer-name)))
560 (run-at-time t display-time-world-timer-second 'display-time-world-timer))
561 (with-current-buffer (get-buffer-create display-time-world-buffer-name)
562 (display-time-world-display display-time-world-list))
563 (pop-to-buffer display-time-world-buffer-name)
564 (fit-window-to-buffer)
565 (display-time-world-mode))
566
567(defun display-time-world-timer ()
568 (if (get-buffer display-time-world-buffer-name)
569 (with-current-buffer (get-buffer display-time-world-buffer-name)
570 (display-time-world-display display-time-world-list))
571 ;; cancel timer
572 (let ((list timer-list))
573 (while list
574 (let ((elt (pop list)))
575 (when (equal (symbol-name (aref elt 5)) "display-time-world-timer")
576 (cancel-timer elt)))))))
577
2736785a 578;;;###autoload
04e56139
GM
579(defun emacs-uptime (&optional format)
580 "Return a string giving the uptime of this instance of Emacs.
581FORMAT is a string to format the result, using `format-seconds'.
582For example, the Unix uptime command format is \"%D, %z%2h:%.2m\"."
2736785a
GM
583 (interactive)
584 (let ((str
04e56139 585 (format-seconds (or format "%Y, %D, %H, %M, %z%S")
0d00c61c 586 (float-time
e279593d 587 (time-subtract (current-time) before-init-time)))))
32226619 588 (if (called-interactively-p 'interactive)
2736785a
GM
589 (message "%s" str)
590 str)))
591
24d6c292
JL
592;;;###autoload
593(defun emacs-init-time ()
594 "Return a string giving the duration of the Emacs initialization."
595 (interactive)
596 (let ((str
ac1efd51 597 (format "%.1f seconds"
0d00c61c 598 (float-time
ac1efd51 599 (time-subtract after-init-time before-init-time)))))
32226619 600 (if (called-interactively-p 'interactive)
24d6c292
JL
601 (message "%s" str)
602 str)))
603
c2acf685
SM
604(provide 'time)
605
606;;; time.el ends here