1 ;; Display time and load in mode line of Emacs.
2 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
4 ;; 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 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 (defvar display-time-mail-file nil
22 "*File name of mail inbox file, for indicating existence of new mail.
23 Default is system-dependent, and is the same as used by Rmail.")
26 (defconst display-time-day-and-date nil
"\
27 *Non-nil means \\[display-time] should display day and date as well as time.")
29 (defvar display-time-process nil
)
31 (defvar display-time-interval
60
32 "*Seconds between updates of time in the mode line.")
34 (defvar display-time-24hr-format nil
35 "Non-nill indicates time should be displayed as hh:mm, 0 <= hh <= 23.
36 Nil means 1 <= hh <= 12, and an AM/PM suffix is used.")
38 (defvar display-time-string nil
)
40 (defvar display-time-hook nil
41 "* List of functions to be called when the time is updated on the mode line.")
44 (defun display-time ()
45 "Display current time and load level in mode line of each buffer.
46 Updates automatically every minute.
47 If `display-time-day-and-date' is non-nil, the current day and date
48 are displayed as well.
49 After each update, `display-time-hook' is run with `run-hooks'."
51 (let ((live (and display-time-process
52 (eq (process-status display-time-process
) 'run
))))
55 (if display-time-process
56 (delete-process display-time-process
))
57 (or global-mode-string
(setq global-mode-string
'("")))
58 (or (memq 'display-time-string global-mode-string
)
59 (setq global-mode-string
60 (append global-mode-string
'(display-time-string))))
61 (setq display-time-string
"")
62 (setq display-time-process
63 (start-process "display-time" nil
64 (concat exec-directory
"wakeup")
65 (int-to-string display-time-interval
)))
66 (process-kill-without-query display-time-process
)
67 (set-process-sentinel display-time-process
'display-time-sentinel
)
68 (set-process-filter display-time-process
'display-time-filter
)))))
70 (defun display-time-sentinel (proc reason
)
71 (or (eq (process-status proc
) 'run
)
72 (setq display-time-string
""))
73 ;; Force mode-line updates
74 (save-excursion (set-buffer (other-buffer)))
75 (set-buffer-modified-p (buffer-modified-p))
78 (defun display-time-filter (proc string
)
79 (let ((time (current-time-string))
80 (load (condition-case ()
81 (if (zerop (car (load-average))) ""
82 (let ((str (format " %03d" (car (load-average)))))
83 (concat (substring str
0 -
2) "." (substring str -
2))))
85 (mail-spool-file (or display-time-mail-file
87 (concat rmail-spool-directory
88 (or (getenv "LOGNAME")
92 (setq hour
(read (substring time
11 13)))
93 (if (not display-time-24hr-format
)
95 (setq am-pm-flag
(if (>= hour
12) "pm" "am"))
97 (setq hour
(- hour
12))
100 (setq am-pm-flag
""))
101 (setq display-time-string
102 (concat (format "%d" hour
) (substring time
13 16)
105 (if (and (file-exists-p mail-spool-file
)
107 (display-time-file-nonempty-p mail-spool-file
))
110 ;; Append the date if desired.
111 (if display-time-day-and-date
112 (setq display-time-string
113 (concat (substring time
0 11) display-time-string
))))
114 (run-hooks 'display-time-hook
)
115 ;; Force redisplay of all buffers' mode lines to be considered.
116 (save-excursion (set-buffer (other-buffer)))
117 (set-buffer-modified-p (buffer-modified-p))
118 ;; Do redisplay right now, if no input pending.
121 (defun display-time-file-nonempty-p (file)
122 (while (file-symlink-p file
)
123 (setq file
(file-symlink-p file
)))
124 (> (nth 7 (file-attributes file
)) 0))