Mercurial > emacs
annotate lisp/time.el @ 5020:94de08fd8a7c
(Fnext_single_property_change): Fix missing \n\.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 15 Nov 1993 06:41:45 +0000 |
| parents | d7374f1828b5 |
| children | e277328474cc |
| 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 |
|
4014
d7374f1828b5
(display-time-file-nonempty-p): Use file-chase-links.
Roland McGrath <roland@gnu.org>
parents:
3483
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc. |
| 841 | 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 | |
|
2319
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2293
diff
changeset
|
23 ;;; Commentary: |
|
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2293
diff
changeset
|
24 |
|
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2293
diff
changeset
|
25 ;;; Facilities to display current time/date and a new-mail indicator |
|
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2293
diff
changeset
|
26 ;;; in the Emacs mode line. The single entry point is `display-time'. |
|
d98c49df2acd
Added or corrected Commentary section
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2293
diff
changeset
|
27 |
|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
657
diff
changeset
|
28 ;;; Code: |
| 104 | 29 |
|
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
30 (defvar display-time-mail-file nil |
|
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
31 "*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
|
32 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
|
33 |
| 268 | 34 ;;;###autoload |
|
3167
e4bcdaa214b1
(display-time-day-and-date): Use defvar, not defconst.
Richard M. Stallman <rms@gnu.org>
parents:
2319
diff
changeset
|
35 (defvar display-time-day-and-date nil "\ |
| 268 | 36 *Non-nil means \\[display-time] should display day and date as well as time.") |
| 256 | 37 |
| 104 | 38 (defvar display-time-process nil) |
| 39 | |
| 40 (defvar display-time-interval 60 | |
| 41 "*Seconds between updates of time in the mode line.") | |
| 42 | |
| 387 | 43 (defvar display-time-24hr-format nil |
|
3483
965b015a4aef
(display-time-24hr-format): Make it a user option.
Richard M. Stallman <rms@gnu.org>
parents:
3167
diff
changeset
|
44 "*Non-nill indicates time should be displayed as hh:mm, 0 <= hh <= 23. |
| 387 | 45 Nil means 1 <= hh <= 12, and an AM/PM suffix is used.") |
| 46 | |
| 104 | 47 (defvar display-time-string nil) |
| 48 | |
| 49 (defvar display-time-hook nil | |
| 50 "* List of functions to be called when the time is updated on the mode line.") | |
| 51 | |
| 256 | 52 ;;;###autoload |
| 104 | 53 (defun display-time () |
|
2293
6c5e38aeb94b
* time.el (display-time): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
841
diff
changeset
|
54 "Display current time, load level, and mail flag in mode line of each buffer. |
| 104 | 55 Updates automatically every minute. |
| 56 If `display-time-day-and-date' is non-nil, the current day and date | |
| 57 are displayed as well. | |
| 58 After each update, `display-time-hook' is run with `run-hooks'." | |
| 59 (interactive) | |
| 60 (let ((live (and display-time-process | |
| 61 (eq (process-status display-time-process) 'run)))) | |
| 62 (if (not live) | |
| 63 (progn | |
| 64 (if display-time-process | |
| 65 (delete-process display-time-process)) | |
| 66 (or global-mode-string (setq global-mode-string '(""))) | |
| 67 (or (memq 'display-time-string global-mode-string) | |
| 68 (setq global-mode-string | |
| 69 (append global-mode-string '(display-time-string)))) | |
| 70 (setq display-time-string "") | |
| 71 (setq display-time-process | |
| 72 (start-process "display-time" nil | |
| 256 | 73 (concat exec-directory "wakeup") |
| 104 | 74 (int-to-string display-time-interval))) |
| 75 (process-kill-without-query display-time-process) | |
| 76 (set-process-sentinel display-time-process 'display-time-sentinel) | |
| 77 (set-process-filter display-time-process 'display-time-filter))))) | |
| 78 | |
| 79 (defun display-time-sentinel (proc reason) | |
| 80 (or (eq (process-status proc) 'run) | |
| 81 (setq display-time-string "")) | |
| 82 ;; Force mode-line updates | |
| 83 (save-excursion (set-buffer (other-buffer))) | |
| 84 (set-buffer-modified-p (buffer-modified-p)) | |
| 85 (sit-for 0)) | |
| 86 | |
| 87 (defun display-time-filter (proc string) | |
| 88 (let ((time (current-time-string)) | |
| 256 | 89 (load (condition-case () |
| 90 (if (zerop (car (load-average))) "" | |
| 387 | 91 (let ((str (format " %03d" (car (load-average))))) |
| 92 (concat (substring str 0 -2) "." (substring str -2)))) | |
| 256 | 93 (error ""))) |
|
132
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
94 (mail-spool-file (or display-time-mail-file |
|
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
95 (getenv "MAIL") |
|
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
96 (concat rmail-spool-directory |
|
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
97 (or (getenv "LOGNAME") |
|
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
98 (getenv "USER") |
|
0cbdae7c532f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
104
diff
changeset
|
99 (user-login-name))))) |
| 387 | 100 hour am-pm-flag) |
| 104 | 101 (setq hour (read (substring time 11 13))) |
| 387 | 102 (if (not display-time-24hr-format) |
| 103 (progn | |
| 104 (setq am-pm-flag (if (>= hour 12) "pm" "am")) | |
| 105 (if (> hour 12) | |
| 106 (setq hour (- hour 12)) | |
| 107 (if (= hour 0) | |
| 108 (setq hour 12)))) | |
| 109 (setq am-pm-flag "")) | |
| 104 | 110 (setq display-time-string |
| 111 (concat (format "%d" hour) (substring time 13 16) | |
| 387 | 112 am-pm-flag |
| 113 load | |
| 104 | 114 (if (and (file-exists-p mail-spool-file) |
| 115 ;; file not empty? | |
| 256 | 116 (display-time-file-nonempty-p mail-spool-file)) |
| 104 | 117 " Mail" |
| 118 ""))) | |
| 119 ;; Append the date if desired. | |
| 120 (if display-time-day-and-date | |
| 121 (setq display-time-string | |
| 122 (concat (substring time 0 11) display-time-string)))) | |
| 123 (run-hooks 'display-time-hook) | |
| 124 ;; Force redisplay of all buffers' mode lines to be considered. | |
| 125 (save-excursion (set-buffer (other-buffer))) | |
| 126 (set-buffer-modified-p (buffer-modified-p)) | |
| 127 ;; Do redisplay right now, if no input pending. | |
| 128 (sit-for 0)) | |
| 256 | 129 |
| 130 (defun display-time-file-nonempty-p (file) | |
|
4014
d7374f1828b5
(display-time-file-nonempty-p): Use file-chase-links.
Roland McGrath <roland@gnu.org>
parents:
3483
diff
changeset
|
131 (< 0 (nth 7 (file-attributes (file-chase-links file))))) |
|
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
387
diff
changeset
|
132 |
|
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
387
diff
changeset
|
133 ;;; time.el ends here |
