changeset 17600:0dc8180c2e7a

(time-stamp-old-format-warn): Fix a tag string. (time-stamp-format): Use %Y not %y in default value. (time-stamp): Verify time-stamp-line-limit is a number. (time-stamp-string-preprocess): Handle %F correctly.
author Richard M. Stallman <rms@gnu.org>
date Wed, 30 Apr 1997 01:12:24 +0000
parents dd277f4e6737
children 2dd1c9442974
files lisp/time-stamp.el
diffstat 1 files changed, 46 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/time-stamp.el	Tue Apr 29 21:11:33 1997 +0000
+++ b/lisp/time-stamp.el	Wed Apr 30 01:12:24 1997 +0000
@@ -2,8 +2,8 @@
 
 ;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc.
 
-;; Maintainer's Time-stamp: <1996-08-13 14:03:17 gildea>
-;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
+;; Maintainer's Time-stamp: <1997-04-28 11:51:22 gildea>
+;; Maintainer: Stephen Gildea <gildea@alum.mit.edu>
 ;; Keywords: tools
 
 ;; This file is free software; you can redistribute it and/or modify
@@ -35,13 +35,6 @@
 ;; See the documentation for the functions `time-stamp'
 ;; and `time-stamp-toggle-active' for details.
 
-;;; Change Log:
-
-;; Originally based on the 19 Dec 88 version of
-;;   date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
-;; Version 2, January 1995: replaced functions with %-escapes
-;; $Id: time-stamp.el,v 1.24 1996/12/18 02:45:09 rms Exp rms $
-
 ;;; Code:
 
 (defgroup time-stamp nil
@@ -68,20 +61,17 @@
 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 modification" nil)
+  :type '(choice (const :tag "No notification" nil)
                  (const :tag "Don't use the format" error)
                  (const ask) (const warn))
   :group 'time-stamp)
 
-(defcustom time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u"
+(defcustom time-stamp-format "%Y-%02m-%02d %02H:%02M:%02S %u"
   "*Format of the string inserted by \\[time-stamp].
 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 with `format-time-string'.
-For example, to get the format used by the `date' command,
-use \"%3a %3b %2d %H:%M:%S %Z %y\".
-
 In addition to the features of `format-time-string',
 you can use the following %-constructs:
 
@@ -89,10 +79,15 @@
 %F  full file name
 %h  mail host name
 %s  system name
-%u  user's login name"
+%u  user's login name
+
+For example, to get the format used by the `date' command,
+use \"%3a %3b %2d %02H:%02M:%02S %Z %Y\"."
   :type 'string
   :group 'time-stamp)
 
+
+
 ;;; Do not change time-stamp-line-limit, time-stamp-start, or
 ;;; time-stamp-end in your .emacs or you will be incompatible
 ;;; with other people's files!  If you must change them,
@@ -146,7 +141,7 @@
       Time-stamp: \" \"
 The time stamp is written between the brackets or quotes:
       Time-stamp: <1996-07-18 10:20:51 gildea>
-Only updates the time stamp if the variable `time-stamp-active' is non-nil.
+The time stamp is updated only if the variable `time-stamp-active' is non-nil.
 The format of the time stamp is set by the variable `time-stamp-format'.
 The variables `time-stamp-line-limit', `time-stamp-start',
 and `time-stamp-end' control finding the template."
@@ -154,28 +149,33 @@
   (let ((case-fold-search nil)
 	(start nil)
 	(end nil)
-	search-limit)
-	(save-excursion
-	  (save-restriction
-	    (widen)
-	    (cond ((> time-stamp-line-limit 0)
-		   (goto-char (setq start (point-min)))
-		   (forward-line time-stamp-line-limit)
-		   (setq search-limit (point)))
-		  (t
-		   (goto-char (setq search-limit (point-max)))
-		   (forward-line time-stamp-line-limit)
-		   (setq start (point))))
+	search-limit
+	(line-limit time-stamp-line-limit))
+    (cond ((not (integerp line-limit))
+	   (setq line-limit 8)
+	   (message "time-stamp-line-limit is not a number")
+	   (sit-for 1)))
+    (save-excursion
+      (save-restriction
+	(widen)
+	(cond ((> line-limit 0)
+	       (goto-char (setq start (point-min)))
+	       (forward-line line-limit)
+	       (setq search-limit (point)))
+	      (t
+	       (goto-char (setq search-limit (point-max)))
+	       (forward-line line-limit)
+	       (setq start (point))))
+	(goto-char start)
+	(while (and (< (point) search-limit)
+		    (not end)
+		    (re-search-forward time-stamp-start search-limit 'move))
+	  (setq start (point))
+	  (end-of-line)
+	  (let ((line-end (point)))
 	    (goto-char start)
-	    (while (and (< (point) search-limit)
-			(not end)
-			(re-search-forward time-stamp-start search-limit 'move))
-	      (setq start (point))
-	      (end-of-line)
-	      (let ((line-end (point)))
-		(goto-char start)
-		(if (re-search-forward time-stamp-end line-end 'move)
-		    (setq end (match-beginning 0)))))))
+	    (if (re-search-forward time-stamp-end line-end 'move)
+		(setq end (match-beginning 0)))))))
 	(if end
 	    (progn
 	      ;; do all warnings outside save-excursion
@@ -226,8 +226,7 @@
 These are replaced with the file name (nondirectory part),
 full file name, host name for mail, system name, and user name.
 Do not alter other %-combinations, and do detect %%."
-  (let ((result "") (pos 0) (case-fold-search nil)
-	(file (or buffer-file-name "(no file)")))
+  (let ((result "") (pos 0) (case-fold-search nil))
     (while (string-match "%[%uhfFs]" format pos)
       (setq result (concat result (substring format pos (match-beginning 0))))
       (let ((char (aref format (1+ (match-beginning 0)))))
@@ -236,9 +235,13 @@
 	      ((= char ?u)
 	       (setq result (concat result (user-login-name))))
 	      ((= char ?f)
-	       (setq result (concat result (file-name-nondirectory file))))
-	      ((= char ?f)
-	       (setq result (concat result file)))
+	       (setq result (concat result
+				    (if buffer-file-name
+					(file-name-nondirectory buffer-file-name)
+				      time-stamp-no-file))))
+	      ((= char ?F)
+	       (setq result (concat result
+				    (or buffer-file-name time-stamp-no-file))))
 	      ((= char ?s)
 	       (setq result (concat result (system-name))))
 	      ((= char ?h)
@@ -249,8 +252,7 @@
 (defun time-stamp-string ()
   "Generate the new string to be inserted by \\[time-stamp]."
   (if (stringp time-stamp-format)
-      (format-time-string (time-stamp-string-preprocess time-stamp-format)
-			  (current-time))
+      (format-time-string (time-stamp-string-preprocess time-stamp-format))
     ;; handle version 1 compatibility
     (cond ((or (eq time-stamp-old-format-warn 'error)
 	       (and (eq time-stamp-old-format-warn 'ask)