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