aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-07-31 22:49:46 +0000
committerRichard M. Stallman1994-07-31 22:49:46 +0000
commit823d86f380b46a01b96c5c7aa9f8b6eb2fa79d6d (patch)
tree9713b11ba5b69c3c5729a500b6fa5ded70414619
parent370b6149a40b7ca4f006483166602b61236858ad (diff)
downloademacs-823d86f380b46a01b96c5c7aa9f8b6eb2fa79d6d.tar.gz
emacs-823d86f380b46a01b96c5c7aa9f8b6eb2fa79d6d.zip
(display-time-string-forms): New variable.
(display-time-filter): Simplify to use it.
-rw-r--r--lisp/time.el109
1 files changed, 62 insertions, 47 deletions
diff --git a/lisp/time.el b/lisp/time.el
index 413783d516a..901f00d9d3f 100644
--- a/lisp/time.el
+++ b/lisp/time.el
@@ -91,55 +91,70 @@ After each update, `display-time-hook' is run with `run-hooks'."
91 (set-buffer-modified-p (buffer-modified-p)) 91 (set-buffer-modified-p (buffer-modified-p))
92 (sit-for 0)) 92 (sit-for 0))
93 93
94(defvar display-time-string-forms
95 '((if display-time-day-and-date
96 (format "%s %s %s " dayname monthname day)
97 "")
98 (format "%s:%s%s"
99 (if display-time-24hr-format 24-hours 12-hours)
100 minutes
101 (if display-time-24hr-format "" am-pm))
102 load
103 (if mail " Mail" ""))
104 "*A list of expressions governing display of the time in the mode line.
105This expression is a list of expressions that can involve the keywords
106`load', `day', `month', and `year', `12-hours', `24-hours', `minutes',
107`seconds', all numbers in string form, and `monthname', `dayname', `am-pm',
108and `time-zone' all alphabetic strings, and `mail' a true/nil value.
109
110For example, the form
111
112 '((substring year -2) \"/\" month \"/\" day
113 " " 24-hours \":\" minutes \":\" seconds
114 (if time-zone \" (\") time-zone (if time-zone \")\")
115 (if mail \" Mail\" \"\"))
116
117would give mode line times like `94/12/30 21:07:48 (UTC)'.")
118
94(defun display-time-filter (proc string) 119(defun display-time-filter (proc string)
95 (let ((time (current-time-string)) 120 (let* ((time (current-time-string))
96 (load (condition-case () 121 (load (condition-case ()
97 (if (zerop (car (load-average))) "" 122 (if (zerop (car (load-average))) ""
98 (let ((str (format " %03d" (car (load-average))))) 123 (let ((str (format " %03d" (car (load-average)))))
99 (concat (substring str 0 -2) "." (substring str -2)))) 124 (concat (substring str 0 -2) "." (substring str -2))))
100 (error ""))) 125 (error "")))
101 (mail-spool-file (or display-time-mail-file 126 (mail-spool-file (or display-time-mail-file
102 (getenv "MAIL") 127 (getenv "MAIL")
103 (concat rmail-spool-directory 128 (concat rmail-spool-directory
104 (user-login-name)))) 129 (or (getenv "LOGNAME")
105 hour am-pm-flag mail-flag) 130 (getenv "USER")
106 (setq hour (read (substring time 11 13))) 131 (user-login-name)))))
107 (if (not display-time-24hr-format) 132 (mail (and (file-exists-p mail-spool-file)
108 (progn 133 (display-time-file-nonempty-p mail-spool-file)))
109 (setq am-pm-flag (if (>= hour 12) "pm" "am")) 134 (24-hours (substring time 11 13))
110 (if (> hour 12) 135 (hour (string-to-int 24-hours))
111 (setq hour (- hour 12)) 136 (12-hours (int-to-string (if (> hour 12)
112 (if (= hour 0) 137 (- hour 12)
113 (setq hour 12)))) 138 (if (= hour 0)
114 (setq am-pm-flag "")) 139 12
115 (setq mail-flag 140 hour))))
116 (if (and (or (null display-time-server-down-time) 141 (am-pm (if (> hour 12) "pm" "am"))
117 ;; If have been down for 20 min, try again. 142 (minutes (substring time 14 16))
118 (> (- (nth 1 (current-time)) 143 (seconds (substring time 17 19))
119 display-time-server-down-time) 144 (time-zone (car (cdr (current-time-zone))))
120 1200)) 145 (day (substring time 8 10))
121 (let ((start-time (current-time))) 146 (year (substring time 20 24))
122 (prog1 147 (monthname (substring time 4 7))
123 (display-time-file-nonempty-p mail-spool-file) 148 (month
124 (if (> (- (nth 1 (current-time)) (nth 1 start-time)) 149 (cdr
125 20) 150 (assoc
126 ;; Record that mail file is not accessible. 151 monthname
127 (setq display-time-server-down-time 152 '(("Jan" . "1") ("Feb" . "2") ("Mar" . "3") ("Apr" . "4")
128 (nth 1 (current-time))) 153 ("May" . "5") ("Jun" . "6") ("Jul" . "7") ("Aug" . "8")
129 ;; Record that mail file is accessible. 154 ("Sep" . "9") ("Oct" . "10") ("Nov" . "11") ("Dec" . "12")))))
130 (setq display-time-server-down-time nil)) 155 (dayname (substring time 0 3)))
131 )))
132 " Mail"
133 ""))
134 (setq display-time-string 156 (setq display-time-string
135 (concat (format "%d" hour) (substring time 13 16) 157 (mapconcat 'eval display-time-string-forms "")))
136 am-pm-flag
137 load
138 mail-flag))
139 ;; Append the date if desired.
140 (if display-time-day-and-date
141 (setq display-time-string
142 (concat (substring time 0 11) display-time-string))))
143 (run-hooks 'display-time-hook) 158 (run-hooks 'display-time-hook)
144 ;; Force redisplay of all buffers' mode lines to be considered. 159 ;; Force redisplay of all buffers' mode lines to be considered.
145 (save-excursion (set-buffer (other-buffer))) 160 (save-excursion (set-buffer (other-buffer)))