comparison lisp/time.el @ 104:b6fb5f9cb739

Initial revision
author Richard M. Stallman <rms@gnu.org>
date Tue, 09 Oct 1990 19:49:09 +0000
parents
children 0cbdae7c532f
comparison
equal deleted inserted replaced
103:5f14cf951acb 104:b6fb5f9cb739
1 ;; Display time and load in mode line of Emacs.
2 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
3
4 ;; This file is part of GNU Emacs.
5
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)
9 ;; any later version.
10
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.
15
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.
19
20
21 (defvar display-time-process nil)
22
23 (defvar display-time-interval 60
24 "*Seconds between updates of time in the mode line.")
25
26 (defvar display-time-string nil)
27
28 (defvar display-time-hook nil
29 "* List of functions to be called when the time is updated on the mode line.")
30
31 (defun display-time ()
32 "Display current time and load level in mode line of each buffer.
33 Updates automatically every minute.
34 If `display-time-day-and-date' is non-nil, the current day and date
35 are displayed as well.
36 After each update, `display-time-hook' is run with `run-hooks'."
37 (interactive)
38 (let ((live (and display-time-process
39 (eq (process-status display-time-process) 'run))))
40 (if (not live)
41 (progn
42 (if display-time-process
43 (delete-process display-time-process))
44 (or global-mode-string (setq global-mode-string '("")))
45 (or (memq 'display-time-string global-mode-string)
46 (setq global-mode-string
47 (append global-mode-string '(display-time-string))))
48 (setq display-time-string "")
49 (setq display-time-process
50 (start-process "display-time" nil
51 "wakeup"
52 (int-to-string display-time-interval)))
53 (process-kill-without-query display-time-process)
54 (set-process-sentinel display-time-process 'display-time-sentinel)
55 (set-process-filter display-time-process 'display-time-filter)))))
56
57 (defun display-time-sentinel (proc reason)
58 (or (eq (process-status proc) 'run)
59 (setq display-time-string ""))
60 ;; Force mode-line updates
61 (save-excursion (set-buffer (other-buffer)))
62 (set-buffer-modified-p (buffer-modified-p))
63 (sit-for 0))
64
65 (defun display-time-filter (proc string)
66 (let ((time (current-time-string))
67 (load (format "%03d" (car (load-average))))
68 (mail-spool-file (concat rmail-spool-directory
69 (or (getenv "LOGNAME")
70 (getenv "USER")
71 (user-login-name))))
72 hour pm)
73 (setq hour (read (substring time 11 13)))
74 (setq pm (>= hour 12))
75 (if (> hour 12)
76 (setq hour (- hour 12))
77 (if (= hour 0)
78 (setq hour 12)))
79 (setq display-time-string
80 (concat (format "%d" hour) (substring time 13 16)
81 (if pm "pm " "am ")
82 (substring load 0 -2) "." (substring load -2)
83 (if (and (file-exists-p mail-spool-file)
84 ;; file not empty?
85 (> (nth 7 (file-attributes mail-spool-file)) 0))
86 " Mail"
87 "")))
88 ;; Append the date if desired.
89 (if display-time-day-and-date
90 (setq display-time-string
91 (concat (substring time 0 11) display-time-string))))
92 (run-hooks 'display-time-hook)
93 ;; Force redisplay of all buffers' mode lines to be considered.
94 (save-excursion (set-buffer (other-buffer)))
95 (set-buffer-modified-p (buffer-modified-p))
96 ;; Do redisplay right now, if no input pending.
97 (sit-for 0))