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