Mercurial > emacs
annotate lisp/time.el @ 147:0f50f1badd75
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 26 Dec 1990 22:28:51 +0000 |
parents | 0cbdae7c532f |
children | 7e4c7ef44243 |
rev | line source |
---|---|
104 | 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 | |
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
21 (defvar display-time-mail-file nil |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
22 "*File name of mail inbox file, for indicating existence of new mail. |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
23 Default is system-dependent, and is the same as used by Rmail.") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
24 |
104 | 25 (defvar display-time-process nil) |
26 | |
27 (defvar display-time-interval 60 | |
28 "*Seconds between updates of time in the mode line.") | |
29 | |
30 (defvar display-time-string nil) | |
31 | |
32 (defvar display-time-hook nil | |
33 "* List of functions to be called when the time is updated on the mode line.") | |
34 | |
35 (defun display-time () | |
36 "Display current time and load level in mode line of each buffer. | |
37 Updates automatically every minute. | |
38 If `display-time-day-and-date' is non-nil, the current day and date | |
39 are displayed as well. | |
40 After each update, `display-time-hook' is run with `run-hooks'." | |
41 (interactive) | |
42 (let ((live (and display-time-process | |
43 (eq (process-status display-time-process) 'run)))) | |
44 (if (not live) | |
45 (progn | |
46 (if display-time-process | |
47 (delete-process display-time-process)) | |
48 (or global-mode-string (setq global-mode-string '(""))) | |
49 (or (memq 'display-time-string global-mode-string) | |
50 (setq global-mode-string | |
51 (append global-mode-string '(display-time-string)))) | |
52 (setq display-time-string "") | |
53 (setq display-time-process | |
54 (start-process "display-time" nil | |
55 "wakeup" | |
56 (int-to-string display-time-interval))) | |
57 (process-kill-without-query display-time-process) | |
58 (set-process-sentinel display-time-process 'display-time-sentinel) | |
59 (set-process-filter display-time-process 'display-time-filter))))) | |
60 | |
61 (defun display-time-sentinel (proc reason) | |
62 (or (eq (process-status proc) 'run) | |
63 (setq display-time-string "")) | |
64 ;; Force mode-line updates | |
65 (save-excursion (set-buffer (other-buffer))) | |
66 (set-buffer-modified-p (buffer-modified-p)) | |
67 (sit-for 0)) | |
68 | |
69 (defun display-time-filter (proc string) | |
70 (let ((time (current-time-string)) | |
71 (load (format "%03d" (car (load-average)))) | |
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
72 (mail-spool-file (or display-time-mail-file |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
73 (getenv "MAIL") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
74 (concat rmail-spool-directory |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
75 (or (getenv "LOGNAME") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
76 (getenv "USER") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
77 (user-login-name))))) |
104 | 78 hour pm) |
79 (setq hour (read (substring time 11 13))) | |
80 (setq pm (>= hour 12)) | |
81 (if (> hour 12) | |
82 (setq hour (- hour 12)) | |
83 (if (= hour 0) | |
84 (setq hour 12))) | |
85 (setq display-time-string | |
86 (concat (format "%d" hour) (substring time 13 16) | |
87 (if pm "pm " "am ") | |
88 (substring load 0 -2) "." (substring load -2) | |
89 (if (and (file-exists-p mail-spool-file) | |
90 ;; file not empty? | |
91 (> (nth 7 (file-attributes mail-spool-file)) 0)) | |
92 " Mail" | |
93 ""))) | |
94 ;; Append the date if desired. | |
95 (if display-time-day-and-date | |
96 (setq display-time-string | |
97 (concat (substring time 0 11) display-time-string)))) | |
98 (run-hooks 'display-time-hook) | |
99 ;; Force redisplay of all buffers' mode lines to be considered. | |
100 (save-excursion (set-buffer (other-buffer))) | |
101 (set-buffer-modified-p (buffer-modified-p)) | |
102 ;; Do redisplay right now, if no input pending. | |
103 (sit-for 0)) |