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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; Display time and load in mode line of Emacs.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; any later version.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU General Public License for more details.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 (defvar display-time-process nil)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 (defvar display-time-interval 60
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 "*Seconds between updates of time in the mode line.")
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (defvar display-time-string nil)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defvar display-time-hook nil
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 "* List of functions to be called when the time is updated on the mode line.")
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (defun display-time ()
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 "Display current time and load level in mode line of each buffer.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 Updates automatically every minute.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 If `display-time-day-and-date' is non-nil, the current day and date
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 are displayed as well.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 After each update, `display-time-hook' is run with `run-hooks'."
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (interactive)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (let ((live (and display-time-process
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (eq (process-status display-time-process) 'run))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (if (not live)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (progn
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (if display-time-process
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (delete-process display-time-process))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (or global-mode-string (setq global-mode-string '("")))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (or (memq 'display-time-string global-mode-string)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (setq global-mode-string
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (append global-mode-string '(display-time-string))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (setq display-time-string "")
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (setq display-time-process
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (start-process "display-time" nil
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 "wakeup"
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (int-to-string display-time-interval)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (process-kill-without-query display-time-process)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (set-process-sentinel display-time-process 'display-time-sentinel)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (set-process-filter display-time-process 'display-time-filter)))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (defun display-time-sentinel (proc reason)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (or (eq (process-status proc) 'run)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (setq display-time-string ""))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; Force mode-line updates
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (save-excursion (set-buffer (other-buffer)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (set-buffer-modified-p (buffer-modified-p))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (sit-for 0))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (defun display-time-filter (proc string)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (let ((time (current-time-string))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 hour pm)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (setq hour (read (substring time 11 13)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (setq pm (>= hour 12))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (if (> hour 12)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (setq hour (- hour 12))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (if (= hour 0)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (setq hour 12)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (setq display-time-string
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (concat (format "%d" hour) (substring time 13 16)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (if pm "pm " "am ")
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (substring load 0 -2) "." (substring load -2)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (if (and (file-exists-p mail-spool-file)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; file not empty?
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (> (nth 7 (file-attributes mail-spool-file)) 0))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 " Mail"
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "")))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; Append the date if desired.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (if display-time-day-and-date
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (setq display-time-string
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (concat (substring time 0 11) display-time-string))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (run-hooks 'display-time-hook)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; Force redisplay of all buffers' mode lines to be considered.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (save-excursion (set-buffer (other-buffer)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (set-buffer-modified-p (buffer-modified-p))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; Do redisplay right now, if no input pending.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (sit-for 0))