]> code.delx.au - gnu-emacs/blobdiff - lisp/time.el
(vc-admin): Pass t as noquery arg to vc-resynch-window.
[gnu-emacs] / lisp / time.el
index 8a1f37f8e18d0cfc06c606c60deca03cf42a74f7..8f8385937bc3619af07153f5c913c126f8d15c7c 100644 (file)
@@ -1,11 +1,14 @@
-;; Display time and load in mode line of Emacs.
+;;; time.el --- display time and load in mode line of Emacs.
+
 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
 
+;; Maintainer: FSF
+
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 1, or (at your option)
+;; the Free Software Foundation; either version 2, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; along with GNU Emacs; see the file COPYING.  If not, write to
 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
+;;; Code:
 
 (defvar display-time-mail-file nil
   "*File name of mail inbox file, for indicating existence of new mail.
 Default is system-dependent, and is the same as used by Rmail.")
 
+;;;###autoload
+(defconst display-time-day-and-date nil "\
+*Non-nil means \\[display-time] should display day and date as well as time.")
+
 (defvar display-time-process nil)
 
 (defvar display-time-interval 60
   "*Seconds between updates of time in the mode line.")
 
+(defvar display-time-24hr-format nil
+  "Non-nill indicates time should be displayed as hh:mm, 0 <= hh <= 23.
+Nil means 1 <= hh <= 12, and an AM/PM suffix is used.")
+
 (defvar display-time-string nil)
 
 (defvar display-time-hook nil
   "* List of functions to be called when the time is updated on the mode line.")
 
+;;;###autoload
 (defun display-time ()
   "Display current time and load level in mode line of each buffer.
 Updates automatically every minute.
@@ -52,7 +65,7 @@ After each update, `display-time-hook' is run with `run-hooks'."
          (setq display-time-string "")
          (setq display-time-process
                (start-process "display-time" nil
-                              "wakeup"
+                              (concat exec-directory "wakeup")
                               (int-to-string display-time-interval)))
          (process-kill-without-query display-time-process)
          (set-process-sentinel display-time-process 'display-time-sentinel)
@@ -68,27 +81,34 @@ After each update, `display-time-hook' is run with `run-hooks'."
 
 (defun display-time-filter (proc string)
   (let ((time (current-time-string))
-       (load (format "%03d" (car (load-average))))
+       (load (condition-case ()
+                 (if (zerop (car (load-average))) ""
+                   (let ((str (format " %03d" (car (load-average)))))
+                     (concat (substring str 0 -2) "." (substring str -2))))
+               (error "")))
        (mail-spool-file (or display-time-mail-file
                             (getenv "MAIL")
                             (concat rmail-spool-directory
                                     (or (getenv "LOGNAME")
                                         (getenv "USER")
                                         (user-login-name)))))
-       hour pm)
+       hour am-pm-flag)
     (setq hour (read (substring time 11 13)))
-    (setq pm (>= hour 12))
-    (if (> hour 12)
-       (setq hour (- hour 12))
-      (if (= hour 0)
-         (setq hour 12)))
+    (if (not display-time-24hr-format)
+       (progn
+         (setq am-pm-flag (if (>= hour 12) "pm" "am"))
+         (if (> hour 12)
+             (setq hour (- hour 12))
+           (if (= hour 0)
+               (setq hour 12))))
+      (setq am-pm-flag ""))
     (setq display-time-string
          (concat (format "%d" hour) (substring time 13 16)
-                 (if pm "pm " "am ")
-                 (substring load 0 -2) "." (substring load -2)
+                 am-pm-flag
+                 load
                  (if (and (file-exists-p mail-spool-file)
                           ;; file not empty?
-                          (> (nth 7 (file-attributes mail-spool-file)) 0))
+                          (display-time-file-nonempty-p mail-spool-file))
                      " Mail"
                    "")))
     ;; Append the date if desired.
@@ -101,3 +121,10 @@ After each update, `display-time-hook' is run with `run-hooks'."
   (set-buffer-modified-p (buffer-modified-p))
   ;; Do redisplay right now, if no input pending.
   (sit-for 0))
+
+(defun display-time-file-nonempty-p (file)
+  (while (file-symlink-p file)
+    (setq file (file-symlink-p file)))
+  (> (nth 7 (file-attributes file)) 0))
+
+;;; time.el ends here