annotate lisp/time.el @ 387:8f76cc1e1067

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Tue, 13 Aug 1991 15:58:15 +0000
parents d548f9619751
children fec3f9a1e3e5
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
268
2dd411fe2f72 *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 262
diff changeset
25 ;;;###autoload
271
d548f9619751 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 268
diff changeset
26 (defconst display-time-day-and-date nil "\
268
2dd411fe2f72 *** empty log message ***
Brian Preble <rassilon@gnu.org>
parents: 262
diff changeset
27 *Non-nil means \\[display-time] should display day and date as well as time.")
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
28
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (defvar display-time-process nil)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (defvar display-time-interval 60
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 "*Seconds between updates of time in the mode line.")
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
387
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
34 (defvar display-time-24hr-format nil
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
35 "Non-nill indicates time should be displayed as hh:mm, 0 <= hh <= 23.
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
36 Nil means 1 <= hh <= 12, and an AM/PM suffix is used.")
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
37
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defvar display-time-string nil)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (defvar display-time-hook nil
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 "* 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
42
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
43 ;;;###autoload
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (defun display-time ()
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 "Display current time and load level in mode line of each buffer.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 Updates automatically every minute.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 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
48 are displayed as well.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 After each update, `display-time-hook' is run with `run-hooks'."
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (interactive)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (let ((live (and display-time-process
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (eq (process-status display-time-process) 'run))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (if (not live)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (progn
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (if display-time-process
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (delete-process display-time-process))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (or global-mode-string (setq global-mode-string '("")))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (or (memq 'display-time-string global-mode-string)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (setq global-mode-string
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (append global-mode-string '(display-time-string))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (setq display-time-string "")
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (setq display-time-process
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (start-process "display-time" nil
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
64 (concat exec-directory "wakeup")
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (int-to-string display-time-interval)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (process-kill-without-query display-time-process)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (set-process-sentinel display-time-process 'display-time-sentinel)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (set-process-filter display-time-process 'display-time-filter)))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (defun display-time-sentinel (proc reason)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (or (eq (process-status proc) 'run)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (setq display-time-string ""))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; Force mode-line updates
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (save-excursion (set-buffer (other-buffer)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (set-buffer-modified-p (buffer-modified-p))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (sit-for 0))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (defun display-time-filter (proc string)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (let ((time (current-time-string))
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
80 (load (condition-case ()
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
81 (if (zerop (car (load-average))) ""
387
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
82 (let ((str (format " %03d" (car (load-average)))))
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
83 (concat (substring str 0 -2) "." (substring str -2))))
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
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
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
91 hour am-pm-flag)
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (setq hour (read (substring time 11 13)))
387
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
93 (if (not display-time-24hr-format)
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
94 (progn
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
95 (setq am-pm-flag (if (>= hour 12) "pm" "am"))
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
96 (if (> hour 12)
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
97 (setq hour (- hour 12))
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
98 (if (= hour 0)
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
99 (setq hour 12))))
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
100 (setq am-pm-flag ""))
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (setq display-time-string
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (concat (format "%d" hour) (substring time 13 16)
387
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
103 am-pm-flag
8f76cc1e1067 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 271
diff changeset
104 load
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (if (and (file-exists-p mail-spool-file)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; file not empty?
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
107 (display-time-file-nonempty-p mail-spool-file))
104
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 " Mail"
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "")))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; Append the date if desired.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (if display-time-day-and-date
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (setq display-time-string
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (concat (substring time 0 11) display-time-string))))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (run-hooks 'display-time-hook)
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;; Force redisplay of all buffers' mode lines to be considered.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (save-excursion (set-buffer (other-buffer)))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (set-buffer-modified-p (buffer-modified-p))
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; Do redisplay right now, if no input pending.
b6fb5f9cb739 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (sit-for 0))
256
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
120
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
121 (defun display-time-file-nonempty-p (file)
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
122 (while (file-symlink-p file)
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
123 (setq file (file-symlink-p file)))
7e4c7ef44243 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 132
diff changeset
124 (> (nth 7 (file-attributes file)) 0))