- (setq display-time-string "")
- ;; Using a pty is wasteful, and the separate session causes
- ;; annoyance sometimes (some systems kill idle sessions).
- (let ((process-connection-type nil))
- (setq display-time-process
- (start-process "display-time" nil
- (expand-file-name "wakeup" exec-directory)
- (int-to-string display-time-interval))))
- (process-kill-without-query display-time-process)
- (set-process-sentinel display-time-process 'display-time-sentinel)
- (set-process-filter display-time-process 'display-time-filter)))))
-
-(defun display-time-sentinel (proc reason)
- (or (eq (process-status proc) 'run)
- (setq display-time-string ""))
- ;; Force mode-line updates
- (save-excursion (set-buffer (other-buffer)))
- (set-buffer-modified-p (buffer-modified-p))
- (sit-for 0))
-
-(defun display-time-filter (proc string)
- (let ((time (current-time-string))
- (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
- (user-login-name))))
- hour am-pm-flag mail-flag)
- (setq hour (read (substring time 11 13)))
- (if (not display-time-24hr-format)
+ ;; Set up the time timer.
+ (setq display-time-timer
+ (run-at-time t display-time-interval
+ 'display-time-event-handler))
+ ;; Make the time appear right away.
+ (display-time-update)
+ ;; When you get new mail, clear "Mail" from the mode line.
+ (add-hook 'rmail-after-get-new-mail-hook
+ 'display-time-event-handler))
+ (remove-hook 'rmail-after-get-new-mail-hook
+ 'display-time-event-handler))))
+
+
+(defcustom display-time-format nil
+ "*A string specifying the format for displaying the time in the mode line.
+See the function `format-time-string' for an explanation of
+how to write this string. If this is nil, the defaults
+depend on `display-time-day-and-date' and `display-time-24hr-format'."
+ :type '(choice (const :tag "Default" nil)
+ string)
+ :group 'display-time)
+
+(defcustom display-time-string-forms
+ '((if (and (not display-time-format) display-time-day-and-date)
+ (format-time-string "%a %b %e " now)
+ "")
+ (format-time-string (or display-time-format
+ (if display-time-24hr-format "%H:%M" "%-I:%M%p"))
+ now)
+ load
+ (if mail " Mail" ""))
+ "*A list of expressions governing display of the time in the mode line.
+For most purposes, you can control the time format using `display-time-format'
+which is a more standard interface.
+
+This expression is a list of expressions that can involve the keywords
+`load', `day', `month', and `year', `12-hours', `24-hours', `minutes',
+`seconds', all numbers in string form, and `monthname', `dayname', `am-pm',
+and `time-zone' all alphabetic strings, and `mail' a true/nil value.
+
+For example, the form
+
+ '((substring year -2) \"/\" month \"/\" day
+ \" \" 24-hours \":\" minutes \":\" seconds
+ (if time-zone \" (\") time-zone (if time-zone \")\")
+ (if mail \" Mail\" \"\"))
+
+would give mode line times like `94/12/30 21:07:48 (UTC)'."
+ :type 'sexp
+ :group 'display-time)
+
+(defun display-time-event-handler ()
+ (display-time-update)
+ ;; Do redisplay right now, if no input pending.
+ (sit-for 0)
+ (let* ((current (current-time))
+ (timer display-time-timer)
+ ;; Compute the time when this timer will run again, next.
+ (next-time (timer-relative-time
+ (list (aref timer 1) (aref timer 2) (aref timer 3))
+ (* 5 (aref timer 4)) 0)))
+ ;; If the activation time is far in the past,
+ ;; skip executions until we reach a time in the future.
+ ;; This avoids a long pause if Emacs has been suspended for hours.
+ (or (> (nth 0 next-time) (nth 0 current))
+ (and (= (nth 0 next-time) (nth 0 current))
+ (> (nth 1 next-time) (nth 1 current)))
+ (and (= (nth 0 next-time) (nth 0 current))
+ (= (nth 1 next-time) (nth 1 current))
+ (> (nth 2 next-time) (nth 2 current)))