]> code.delx.au - gnu-emacs/blobdiff - lisp/time-stamp.el
*** empty log message ***
[gnu-emacs] / lisp / time-stamp.el
index 5ac4d49f2621c743c04e6dc5ce99a31a508d604d..577faf80715e61ee0a780947e6fd1e0e5185b4fb 100644 (file)
@@ -1,9 +1,12 @@
 ;;; time-stamp.el --- Maintain last change time stamps in files edited by Emacs
 
-;; Copyright 1989, 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
+;; Copyright 1989, 1993, 1994, 1995, 1997, 2000, 2001
+;;;    Free Software Foundation, Inc.
 
-;; Maintainer's Time-stamp: <1999-06-26 15:12:53 gildea>
-;; Maintainer: Stephen Gildea <gildea@alum.mit.edu>
+;; This file is part of GNU Emacs.
+
+;; Maintainer's Time-stamp: <2001-09-20 11:57:46 gildea>
+;; Maintainer: Stephen Gildea <gildea@stop.mail-abuse.org>
 ;; Keywords: tools
 
 ;; This file is free software; you can redistribute it and/or modify
 The value may be a string or a list.  Lists are supported only for
 backward compatibility; see variable `time-stamp-old-format-warn'.
 
-A string is used verbatim except for character sequences beginning with %:
+A string is used verbatim except for character sequences beginning
+with %, as follows.  The values of non-numeric formatted items depend
+on the locale setting recorded in `system-time-locale' and
+`locale-coding-system'.  The examples here are for the default
+(`C') locale.
 
 %:a  weekday name: `Monday'.           %#A gives uppercase: `MONDAY'
 %3a  abbreviated weekday: `Mon'.       %3A gives uppercase: `MON'
@@ -94,20 +101,22 @@ See also the variable `time-stamp-warn-inactive'."
   :group 'time-stamp)
 
 (defcustom time-stamp-warn-inactive t
-  "Non-nil to have \\[time-stamp] warn if a buffer did not get time-stamped.
-A warning is printed if `time-stamp-active' disables time stamping and the
-buffer contains a template that would otherwise have been updated."
+  "Have \\[time-stamp] warn if a buffer did not get time-stamped.
+If non-nil, a warning is displayed if `time-stamp-active' disables time
+stamping and the buffer contains a template that would otherwise have
+been updated."
   :type 'boolean
   :group 'time-stamp)
 
 (defcustom time-stamp-old-format-warn 'ask
-  "Action to take if `time-stamp-format' is an old-style list.
+  "Action if `time-stamp-format' is an old-style list.
 If `error', the format is not used.  If `ask', the user is queried about
 using the time-stamp-format.  If `warn', a warning is displayed.
 If nil, no notification is given."
-  :type '(choice (const :tag "No notification" nil)
-                 (const :tag "Don't use the format" error)
-                 (const ask) (const warn))
+  :type '(choice (const :tag "Don't use the format" error)
+                 (const ask)
+                 (const warn)
+                (const :tag "No notification" nil))
   :group 'time-stamp)
 
 (defcustom time-stamp-time-zone nil
@@ -182,7 +191,7 @@ variables section of the time-stamped file itself.")
 
 
 (defvar time-stamp-count 1             ;Do not change!
-  "How many time stamp templates \\[time-stamp] will look for in a buffer.
+  "How many templates \\[time-stamp] will look for in a buffer.
 The same time-stamp will be written in each case.
 
 Do not change `time-stamp-count' for yourself or you will be
@@ -275,9 +284,10 @@ template."
           ;; to output any warnings about time-stamp not being active.
           (setq ts-count 1)))
     ;; Figure out what lines the end should be on.
-    (let ((nl-start 0))
-      (while (string-match "\n" ts-format nl-start)
-       (setq format-lines (1+ format-lines) nl-start (match-end 0))))
+    (if (stringp ts-format)
+       (let ((nl-start 0))
+         (while (string-match "\n" ts-format nl-start)
+           (setq format-lines (1+ format-lines) nl-start (match-end 0)))))
     (let ((nl-start 0))
       (while (string-match "\n" ts-end nl-start)
        (setq end-lines (1+ end-lines) nl-start (match-end 0))))
@@ -385,7 +395,8 @@ With arg, turn time stamping on if and only if arg is positive."
 
 (defun time-stamp-string (&optional ts-format)
   "Generate the new string to be inserted by \\[time-stamp].
-Optionally use FORMAT."
+Optionally use format TS-FORMAT instead of `time-stamp-format' to
+format the string."
   (or ts-format
       (setq ts-format time-stamp-format))
   (if (stringp ts-format)
@@ -428,10 +439,10 @@ Optionally use FORMAT."
 ;;;      The : modifier is a temporary conversion feature used to resolve
 ;;; ambiguous formats--formats that are changing (over time) incompatibly.
 (defun time-stamp-string-preprocess (format &optional time)
-  ;; Use a FORMAT to format date, time, file, and user information.
-  ;; Optional second argument TIME is only for testing.
-  ;; Implements non-time extensions to format-time-string
-  ;; and all time-stamp-format compatibility.
+  "Use a FORMAT to format date, time, file, and user information.
+Optional second argument TIME is only for testing.
+Implements non-time extensions to `format-time-string'
+and all time-stamp-format compatibility."
   (let ((fmt-len (length format))
        (ind 0)
        cur-char
@@ -457,7 +468,7 @@ Optionally use FORMAT."
                                  ?\0))
                 (or (eq ?. cur-char)
                     (eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char)
-                    (eq ?- cur-char) (eq ?+ cur-char) (eq ?_ cur-char) 
+                    (eq ?- cur-char) (eq ?+ cur-char) (eq ?_ cur-char)
                     (eq ?\  cur-char) (eq ?# cur-char) (eq ?^ cur-char)
                     (and (eq ?\( cur-char)
                          (not (eq prev-char ?\\))
@@ -492,7 +503,7 @@ Optionally use FORMAT."
          "%%")
         ((eq cur-char ?a)              ;day of week
          (if change-case
-             (format-time-string "%#A" time)
+             (format-time-string "%#a" time)
            (or alt-form (not (string-equal field-width ""))
                (time-stamp-conv-warn "%a" "%:a"))
            (if (and alt-form (not (string-equal field-width "")))
@@ -506,7 +517,7 @@ Optionally use FORMAT."
            (format-time-string "%#A" time)))
         ((eq cur-char ?b)              ;month name
          (if change-case
-             (format-time-string "%#B" time)
+             (format-time-string "%#b" time)
            (or alt-form (not (string-equal field-width ""))
                (time-stamp-conv-warn "%b" "%:b"))
            (if (and alt-form (not (string-equal field-width "")))
@@ -572,33 +583,32 @@ Optionally use FORMAT."
         ((eq cur-char ?h)              ;mail host name
          (time-stamp-mail-host-name))
         ))
-       (if (string-equal field-width "")
-           field-result
-         (let ((padded-result
-                (format (format "%%%s%c"
-                                field-width
-                                (if (numberp field-result) ?d ?s))
-                        (or field-result ""))))
-           (let ((initial-length (length padded-result))
-                 (desired-length (string-to-int field-width)))
-             (if (> initial-length desired-length)
-                 ;; truncate strings on right, years on left
-                 (if (stringp field-result)
-                     (substring padded-result 0 desired-length)
-                   (if (eq cur-char ?y)
-                       (substring padded-result (- desired-length))
-                     padded-result))   ;non-year numbers don't truncate
-               padded-result)))))
+       (let ((padded-result
+              (format (format "%%%s%c"
+                              field-width
+                              (if (numberp field-result) ?d ?s))
+                      (or field-result ""))))
+         (let* ((initial-length (length padded-result))
+                (desired-length (if (string-equal field-width "")
+                                    initial-length
+                                  (string-to-int field-width))))
+           (if (> initial-length desired-length)
+               ;; truncate strings on right, years on left
+               (if (stringp field-result)
+                   (substring padded-result 0 desired-length)
+                 (if (eq cur-char ?y)
+                     (substring padded-result (- desired-length))
+                   padded-result))     ;non-year numbers don't truncate
+             padded-result))))
        (t
        (char-to-string cur-char)))))
       (setq ind (1+ ind)))
     result))
 
 (defun time-stamp-do-number (format-char alt-form field-width time)
-  ;; Handle a compatible FORMAT-CHAR where only
-  ;; the default width/padding will change.
-  ;; ALT-FORM is whether `#' specified.  FIELD-WIDTH is the string
-  ;; width specification or "".  TIME is the time to convert.
+  "Handle compatible FORMAT-CHAR where only default width/padding will change.
+ALT-FORM is whether `#' specified.  FIELD-WIDTH is the string
+width specification or \"\".  TIME is the time to convert."
   (let ((format-string (concat "%" (char-to-string format-char))))
     (and (not alt-form) (string-equal field-width "")
         (time-stamp-conv-warn format-string
@@ -608,8 +618,8 @@ Optionally use FORMAT."
       (string-to-int (format-time-string format-string time)))))
 
 (defvar time-stamp-conversion-warn t
-  "Non-nil to warn about soon-to-be-unsupported forms in `time-stamp-format'.
-In would be a bad idea to disable these warnings!
+  "Warn about soon-to-be-unsupported forms in `time-stamp-format'.
+If nil, these warnings are disabled, which would be a bad idea!
 You really need to update your files instead.
 
 The new formats will work with old versions of Emacs.
@@ -619,7 +629,7 @@ The new forms being recommended now will continue to work then.")
 
 
 (defun time-stamp-conv-warn (old-form new-form)
-  ;; Display a warning about a soon-to-be-obsolete format.
+  "Display a warning about a soon-to-be-obsolete format."
   (cond
    (time-stamp-conversion-warn
     (save-excursion