Mercurial > emacs
annotate lisp/time.el @ 444:4cec2e6d4f9e
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 05 Dec 1991 18:54:06 +0000 |
parents | 8f76cc1e1067 |
children | fec3f9a1e3e5 |
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 |
268 | 25 ;;;###autoload |
271 | 26 (defconst display-time-day-and-date nil "\ |
268 | 27 *Non-nil means \\[display-time] should display day and date as well as time.") |
256 | 28 |
104 | 29 (defvar display-time-process nil) |
30 | |
31 (defvar display-time-interval 60 | |
32 "*Seconds between updates of time in the mode line.") | |
33 | |
387 | 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.") | |
37 | |
104 | 38 (defvar display-time-string nil) |
39 | |
40 (defvar display-time-hook nil | |
41 "* List of functions to be called when the time is updated on the mode line.") | |
42 | |
256 | 43 ;;;###autoload |
104 | 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'." | |
50 (interactive) | |
51 (let ((live (and display-time-process | |
52 (eq (process-status display-time-process) 'run)))) | |
53 (if (not live) | |
54 (progn | |
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 | |
256 | 64 (concat exec-directory "wakeup") |
104 | 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))))) | |
69 | |
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)) | |
76 (sit-for 0)) | |
77 | |
78 (defun display-time-filter (proc string) | |
79 (let ((time (current-time-string)) | |
256 | 80 (load (condition-case () |
81 (if (zerop (car (load-average))) "" | |
387 | 82 (let ((str (format " %03d" (car (load-average))))) |
83 (concat (substring str 0 -2) "." (substring str -2)))) | |
256 | 84 (error ""))) |
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
85 (mail-spool-file (or display-time-mail-file |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
86 (getenv "MAIL") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
87 (concat rmail-spool-directory |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
88 (or (getenv "LOGNAME") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
89 (getenv "USER") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
90 (user-login-name))))) |
387 | 91 hour am-pm-flag) |
104 | 92 (setq hour (read (substring time 11 13))) |
387 | 93 (if (not display-time-24hr-format) |
94 (progn | |
95 (setq am-pm-flag (if (>= hour 12) "pm" "am")) | |
96 (if (> hour 12) | |
97 (setq hour (- hour 12)) | |
98 (if (= hour 0) | |
99 (setq hour 12)))) | |
100 (setq am-pm-flag "")) | |
104 | 101 (setq display-time-string |
102 (concat (format "%d" hour) (substring time 13 16) | |
387 | 103 am-pm-flag |
104 load | |
104 | 105 (if (and (file-exists-p mail-spool-file) |
106 ;; file not empty? | |
256 | 107 (display-time-file-nonempty-p mail-spool-file)) |
104 | 108 " Mail" |
109 ""))) | |
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. | |
119 (sit-for 0)) | |
256 | 120 |
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)) |