aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-12-13 01:49:23 +0000
committerRichard M. Stallman1996-12-13 01:49:23 +0000
commitc9c0e4bb722115161f9eba5db65969c1bcbaa8cc (patch)
tree5fb5e4fa3ee73a8254e62f7136ce325a93b36744
parenta39a6e40e7d93fa7cd06357c4159751712dc55f7 (diff)
downloademacs-c9c0e4bb722115161f9eba5db65969c1bcbaa8cc.tar.gz
emacs-c9c0e4bb722115161f9eba5db65969c1bcbaa8cc.zip
(time-stamp-am-pm): Variable deleted.
(time-stamp-weekday-full-names): Likewise. (time-stamp-weekday-numbers): Likewise. (time-stamp-old-format-warn): Doc fix. (time-stamp-strftime): Function deleted. (time-stamp-string): Use format-time-string. (time-stamp-format): Change default value to work with format-time-string.
-rw-r--r--lisp/time-stamp.el206
1 files changed, 9 insertions, 197 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index 9d4c45037a1..73be7968cc1 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -40,7 +40,7 @@
40;; Originally based on the 19 Dec 88 version of 40;; Originally based on the 19 Dec 88 version of
41;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net> 41;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
42;; Version 2, January 1995: replaced functions with %-escapes 42;; Version 2, January 1995: replaced functions with %-escapes
43;; $Id: time-stamp.el,v 1.19 1996/09/22 22:20:58 kwzh Exp rms $ 43;; $Id: time-stamp.el,v 1.20 1996/11/05 18:27:41 rms Exp rms $
44 44
45;;; Code: 45;;; Code:
46 46
@@ -56,44 +56,18 @@ a time stamp template that would otherwise have been updated.")
56 56
57(defvar time-stamp-old-format-warn 'ask 57(defvar time-stamp-old-format-warn 'ask
58 "Action to take if `time-stamp-format' is an old-style list. 58 "Action to take if `time-stamp-format' is an old-style list.
59If 'error, the format is not used. If 'ask, the user is queried about 59If `error', the format is not used. If `ask', the user is queried about
60using the time-stamp-format. If 'warn, a warning is displayed. 60using the time-stamp-format. If `warn', a warning is displayed.
61If nil, no notification is given.") 61If nil, no notification is given.")
62 62
63(defvar time-stamp-format "%y-%02m-%02d %02H:%02M:%02S %u" 63(defvar time-stamp-format "%y-%m-%d %H:%M:%S %u"
64 "*Format of the string inserted by \\[time-stamp]. 64 "*Format of the string inserted by \\[time-stamp].
65Value may be a string or a list. (Lists are supported only for 65The value may be a string or a list. Lists are supported only for
66backward compatibility; see variable `time-stamp-old-format-warn'.) 66backward compatibility; see variable `time-stamp-old-format-warn'.
67A string is used verbatim except for character sequences beginning with %:
68
69%a weekday name: `Monday'. %A gives uppercase: `MONDAY'
70%b month name: `January'. %B gives uppercase: `JANUARY'
71%d day of month
72%H 24-hour clock hour
73%I 12-hour clock hour
74%m month number
75%M minute
76%p `am' or `pm'. %P gives uppercase: `AM' or `PM'
77%S seconds
78%w day number of week, Sunday is 0
79%y year: `1995'
80%z time zone name: `est'. %Z gives uppercase: `EST'
81
82Non-date items:
83%% a literal percent character: `%'
84%f file name without directory %F gives absolute pathname
85%s system name
86%u user's login name
87%h mail host name
88
89Decimal digits between the % and the type character specify the
90field width. Strings are truncated on the right; numbers on the left.
91A leading zero causes numbers to be zero-filled.
92 67
68A string is used with `format-time-string'.
93For example, to get the format used by the `date' command, 69For example, to get the format used by the `date' command,
94use \"%3a %3b %2d %02H:%02M:%02S %Z %y\"") 70use \"%3a %3b %2d %H:%M:%S %Z %y\"")
95
96
97 71
98;;; Do not change time-stamp-line-limit, time-stamp-start, or 72;;; Do not change time-stamp-line-limit, time-stamp-start, or
99;;; time-stamp-end in your .emacs or you will be incompatible 73;;; time-stamp-end in your .emacs or you will be incompatible
@@ -224,7 +198,7 @@ With arg, turn time stamping on if and only if arg is positive."
224(defun time-stamp-string () 198(defun time-stamp-string ()
225 "Generate the new string to be inserted by \\[time-stamp]." 199 "Generate the new string to be inserted by \\[time-stamp]."
226 (if (stringp time-stamp-format) 200 (if (stringp time-stamp-format)
227 (time-stamp-strftime time-stamp-format) 201 (format-time-string time-stamp-format (current-time))
228 ;; handle version 1 compatibility 202 ;; handle version 1 compatibility
229 (cond ((or (eq time-stamp-old-format-warn 'error) 203 (cond ((or (eq time-stamp-old-format-warn 'error)
230 (and (eq time-stamp-old-format-warn 'ask) 204 (and (eq time-stamp-old-format-warn 'ask)
@@ -247,171 +221,9 @@ With arg, turn time stamping on if and only if arg is positive."
247 ["(zero)" "January" "February" "March" "April" "May" "June" 221 ["(zero)" "January" "February" "March" "April" "May" "June"
248 "July" "August" "September" "October" "November" "December"]) 222 "July" "August" "September" "October" "November" "December"])
249 223
250(defconst time-stamp-weekday-numbers
251 '(("Sun" . 0) ("Mon" . 1) ("Tue" . 2) ("Wed" . 3)
252 ("Thu" . 4) ("Fri" . 5) ("Sat" . 6))
253 "Alist of weekdays and their number.")
254
255(defconst time-stamp-weekday-full-names
256 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
257
258(defconst time-stamp-am-pm '("am" "pm")
259 "List of strings used to denote morning and afternoon.")
260
261(defconst time-stamp-no-file "(no file)" 224(defconst time-stamp-no-file "(no file)"
262 "String to use when the buffer is not associated with a file.") 225 "String to use when the buffer is not associated with a file.")
263 226
264(defun time-stamp-strftime (format &optional time)
265 "Uses a FORMAT to format date, time, file, and user information.
266Optional second argument TIME will be used instead of the current time.
267See the documentation of the variable `time-stamp-format' for a description
268of the format string."
269 (let ((time-string (cond ((stringp time)
270 time)
271 (time
272 (current-time-string time))
273 (t
274 (current-time-string))))
275 (fmt-len (length format))
276 (ind 0)
277 cur-char
278 (prev-char nil)
279 (result "")
280 field-index
281 field-width
282 field-result
283 (paren-level 0))
284 (while (< ind fmt-len)
285 (setq cur-char (aref format ind))
286 (setq
287 result
288 (concat result
289 (cond
290 ((eq cur-char ?%)
291 (setq field-index (1+ ind))
292 (while (progn
293 (setq ind (1+ ind))
294 (setq cur-char (if (< ind fmt-len)
295 (aref format ind)
296 ?\0))
297 (and (<= ?0 cur-char) (>= ?9 cur-char))))
298 (setq field-width (substring format field-index ind))
299 ;; eat any additional args to allow for future expansion
300 (while (or (and (<= ?0 cur-char) (>= ?9 cur-char)) (eq ?. cur-char)
301 (eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char)
302 (eq ?- cur-char) (eq ?+ cur-char)
303 (eq ?\ cur-char) (eq ?# cur-char)
304 (and (eq ?\( cur-char)
305 (not (eq prev-char ?\\))
306 (setq paren-level (1+ paren-level)))
307 (if (and (eq ?\) cur-char)
308 (not (eq prev-char ?\\))
309 (> paren-level 0))
310 (setq paren-level (1- paren-level))
311 (and (> paren-level 0)
312 (< ind fmt-len))))
313 (setq ind (1+ ind))
314 (setq prev-char cur-char)
315 (setq cur-char (if (< ind fmt-len)
316 (aref format ind)
317 ?\0)))
318 (setq field-result
319 (cond
320 ((eq cur-char ?%)
321 "%")
322 ((or (eq cur-char ?a) ;weekday name
323 (eq cur-char ?A))
324 (let ((name
325 (aref time-stamp-weekday-full-names
326 (cdr (assoc (substring time-string 0 3)
327 time-stamp-weekday-numbers)))))
328 (if (eq cur-char ?a)
329 name
330 (upcase name))))
331 ((or (eq cur-char ?b) ;month name
332 (eq cur-char ?B))
333 (let ((name
334 (aref time-stamp-month-full-names
335 (cdr (assoc (substring time-string 4 7)
336 time-stamp-month-numbers)))))
337 (if (eq cur-char ?b)
338 name
339 (upcase name))))
340 ((eq cur-char ?d) ;day of month, 1-31
341 (string-to-int (substring time-string 8 10)))
342 ((eq cur-char ?H) ;hour, 0-23
343 (string-to-int (substring time-string 11 13)))
344 ((eq cur-char ?I) ;hour, 1-12
345 (let ((hour (string-to-int (substring time-string 11 13))))
346 (cond ((< hour 1)
347 (+ hour 12))
348 ((> hour 12)
349 (- hour 12))
350 (t
351 hour))))
352 ((eq cur-char ?m) ;month number, 1-12
353 (cdr (assoc (substring time-string 4 7)
354 time-stamp-month-numbers)))
355 ((eq cur-char ?M) ;minute, 0-59
356 (string-to-int (substring time-string 14 16)))
357 ((or (eq cur-char ?p) ;am or pm
358 (eq cur-char ?P))
359 (let ((name
360 (if (> 12 (string-to-int (substring time-string 11 13)))
361 (car time-stamp-am-pm)
362 (car (cdr time-stamp-am-pm)))))
363 (if (eq cur-char ?p)
364 name
365 (upcase name))))
366 ((eq cur-char ?S) ;seconds, 00-60
367 (string-to-int (substring time-string 17 19)))
368 ((eq cur-char ?w) ;weekday number, Sunday is 0
369 (cdr (assoc (substring time-string 0 3) time-stamp-weekday-numbers)))
370 ((eq cur-char ?y) ;year
371 (string-to-int (substring time-string -4)))
372 ((or (eq cur-char ?z) ;time zone
373 (eq cur-char ?Z))
374 (let ((name
375 (if (fboundp 'current-time-zone)
376 (car (cdr (current-time-zone time))))))
377 (or name (setq name ""))
378 (if (eq cur-char ?z)
379 (downcase name)
380 (upcase name))))
381 ((eq cur-char ?f) ;buffer-file-name, base name only
382 (if buffer-file-name
383 (file-name-nondirectory buffer-file-name)
384 time-stamp-no-file))
385 ((eq cur-char ?F) ;buffer-file-name, full path
386 (or buffer-file-name
387 time-stamp-no-file))
388 ((eq cur-char ?s) ;system name
389 (system-name))
390 ((eq cur-char ?u) ;user name
391 (user-login-name))
392 ((eq cur-char ?h) ;mail host name
393 (time-stamp-mail-host-name))
394 ))
395 (if (string-equal field-width "")
396 field-result
397 (let ((padded-result
398 (format (format "%%%s%c"
399 field-width
400 (if (numberp field-result) ?d ?s))
401 (or field-result ""))))
402 (let ((initial-length (length padded-result))
403 (desired-length (string-to-int field-width)))
404 (if (> initial-length desired-length)
405 ;; truncate strings on right, numbers on left
406 (if (stringp field-result)
407 (substring padded-result 0 desired-length)
408 (substring padded-result (- desired-length)))
409 padded-result)))))
410 (t
411 (char-to-string cur-char)))))
412 (setq ind (1+ ind)))
413 result))
414
415(defun time-stamp-mail-host-name () 227(defun time-stamp-mail-host-name ()
416 "Return the name of the host where the user receives mail. 228 "Return the name of the host where the user receives mail.
417This is the value of `mail-host-address' if bound and a string, 229This is the value of `mail-host-address' if bound and a string,