-
Notifications
You must be signed in to change notification settings - Fork 2
/
emacs-uptime.el
40 lines (35 loc) · 1.7 KB
/
emacs-uptime.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;;;----------------------------------------------------------------------------
;;; emacs-uptime.el
;;;
;;; Copyright (C) 1998, 2000, 2002, 2004, 2007, 2008 Thien-Thi Nguyen
;;;
;;; This file is part of ttn's personal elisp library, released under
;;; the terms of the GNU General Public License as published by the
;;; Free Software Foundation; either version 3, or (at your option) any
;;; later version. There is NO WARRANTY. See file COPYING for details.
;;; Description: Give Emacs' uptime and some other stats in the modeline.
(defvar *emacs-start-time* (current-time) "For (emacs-uptime);")
;;;###autoload
(defun emacs-uptime ()
"Gives Emacs' uptime, based on global var `*emacs-start-time*'."
(interactive)
(let* ((st *emacs-start-time*) ; set in do-it-now.el
(cur (current-time))
(hi-diff (- (car cur) (car st)))
(tot-sec (+ (ash hi-diff 16) (- (cadr cur) (cadr st))))
(days (/ tot-sec (* 60 60 24)))
(hrs (/ (- tot-sec (* days 60 60 24)) (* 60 60)))
(mins (/ (- tot-sec (* days 60 60 24) (* hrs 60 60)) 60))
(secs (/ (- tot-sec (* days 60 60 24) (* hrs 60 60) (* mins 60)) 1)))
(message "Up %dd %dh %dm %ds (%s), %d buffers, %d files"
days hrs mins secs
(format-time-string "%a %Y-%m-%d %T" st)
(length (buffer-list))
(count t (buffer-list)
:test-not
(lambda (ignore buf)
(null (cdr (assoc 'buffer-file-truename
(buffer-local-variables buf)))))))))
(provide 'emacs-uptime)
;;; emacs-uptime.el ends here
;;;----------------------------------------------------------------------------