time.el 21 KB

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