Mercurial > emacs
annotate lisp/time.el @ 835:bb2da66da13c
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Tue, 21 Jul 1992 23:40:16 +0000 |
parents | 4f28bd14272c |
children | 2cdce064065f |
rev | line source |
---|---|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
387
diff
changeset
|
1 ;;; time.el --- display time and load in mode line of Emacs. |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
387
diff
changeset
|
2 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
3 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
4 ;; Last-Modified: 09 Oct 1990 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
5 |
104 | 6 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
104 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
24 ;;; Code: |
104 | 25 |
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
26 (defvar display-time-mail-file nil |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
27 "*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
|
28 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
|
29 |
268 | 30 ;;;###autoload |
271 | 31 (defconst display-time-day-and-date nil "\ |
268 | 32 *Non-nil means \\[display-time] should display day and date as well as time.") |
256 | 33 |
104 | 34 (defvar display-time-process nil) |
35 | |
36 (defvar display-time-interval 60 | |
37 "*Seconds between updates of time in the mode line.") | |
38 | |
387 | 39 (defvar display-time-24hr-format nil |
40 "Non-nill indicates time should be displayed as hh:mm, 0 <= hh <= 23. | |
41 Nil means 1 <= hh <= 12, and an AM/PM suffix is used.") | |
42 | |
104 | 43 (defvar display-time-string nil) |
44 | |
45 (defvar display-time-hook nil | |
46 "* List of functions to be called when the time is updated on the mode line.") | |
47 | |
256 | 48 ;;;###autoload |
104 | 49 (defun display-time () |
50 "Display current time and load level in mode line of each buffer. | |
51 Updates automatically every minute. | |
52 If `display-time-day-and-date' is non-nil, the current day and date | |
53 are displayed as well. | |
54 After each update, `display-time-hook' is run with `run-hooks'." | |
55 (interactive) | |
56 (let ((live (and display-time-process | |
57 (eq (process-status display-time-process) 'run)))) | |
58 (if (not live) | |
59 (progn | |
60 (if display-time-process | |
61 (delete-process display-time-process)) | |
62 (or global-mode-string (setq global-mode-string '(""))) | |
63 (or (memq 'display-time-string global-mode-string) | |
64 (setq global-mode-string | |
65 (append global-mode-string '(display-time-string)))) | |
66 (setq display-time-string "") | |
67 (setq display-time-process | |
68 (start-process "display-time" nil | |
256 | 69 (concat exec-directory "wakeup") |
104 | 70 (int-to-string display-time-interval))) |
71 (process-kill-without-query display-time-process) | |
72 (set-process-sentinel display-time-process 'display-time-sentinel) | |
73 (set-process-filter display-time-process 'display-time-filter))))) | |
74 | |
75 (defun display-time-sentinel (proc reason) | |
76 (or (eq (process-status proc) 'run) | |
77 (setq display-time-string "")) | |
78 ;; Force mode-line updates | |
79 (save-excursion (set-buffer (other-buffer))) | |
80 (set-buffer-modified-p (buffer-modified-p)) | |
81 (sit-for 0)) | |
82 | |
83 (defun display-time-filter (proc string) | |
84 (let ((time (current-time-string)) | |
256 | 85 (load (condition-case () |
86 (if (zerop (car (load-average))) "" | |
387 | 87 (let ((str (format " %03d" (car (load-average))))) |
88 (concat (substring str 0 -2) "." (substring str -2)))) | |
256 | 89 (error ""))) |
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
90 (mail-spool-file (or display-time-mail-file |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
91 (getenv "MAIL") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
92 (concat rmail-spool-directory |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
93 (or (getenv "LOGNAME") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
94 (getenv "USER") |
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
95 (user-login-name))))) |
387 | 96 hour am-pm-flag) |
104 | 97 (setq hour (read (substring time 11 13))) |
387 | 98 (if (not display-time-24hr-format) |
99 (progn | |
100 (setq am-pm-flag (if (>= hour 12) "pm" "am")) | |
101 (if (> hour 12) | |
102 (setq hour (- hour 12)) | |
103 (if (= hour 0) | |
104 (setq hour 12)))) | |
105 (setq am-pm-flag "")) | |
104 | 106 (setq display-time-string |
107 (concat (format "%d" hour) (substring time 13 16) | |
387 | 108 am-pm-flag |
109 load | |
104 | 110 (if (and (file-exists-p mail-spool-file) |
111 ;; file not empty? | |
256 | 112 (display-time-file-nonempty-p mail-spool-file)) |
104 | 113 " Mail" |
114 ""))) | |
115 ;; Append the date if desired. | |
116 (if display-time-day-and-date | |
117 (setq display-time-string | |
118 (concat (substring time 0 11) display-time-string)))) | |
119 (run-hooks 'display-time-hook) | |
120 ;; Force redisplay of all buffers' mode lines to be considered. | |
121 (save-excursion (set-buffer (other-buffer))) | |
122 (set-buffer-modified-p (buffer-modified-p)) | |
123 ;; Do redisplay right now, if no input pending. | |
124 (sit-for 0)) | |
256 | 125 |
126 (defun display-time-file-nonempty-p (file) | |
127 (while (file-symlink-p file) | |
128 (setq file (file-symlink-p file))) | |
129 (> (nth 7 (file-attributes file)) 0)) | |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
387
diff
changeset
|
130 |
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
387
diff
changeset
|
131 ;;; time.el ends here |