aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-04-30 01:12:24 +0000
committerRichard M. Stallman1997-04-30 01:12:24 +0000
commit622b7ede1cb1fc2174e8c63c283296f71bfb30e8 (patch)
tree6007c78b9f25f929d86f556475cf01885b97c490
parenta06e220dd65db7f9b0b29cf9d4f557b4021275f0 (diff)
downloademacs-622b7ede1cb1fc2174e8c63c283296f71bfb30e8.tar.gz
emacs-622b7ede1cb1fc2174e8c63c283296f71bfb30e8.zip
(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.
-rw-r--r--lisp/time-stamp.el90
1 files changed, 46 insertions, 44 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index 77b1a64646a..0944a73d611 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -2,8 +2,8 @@
2 2
3;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc. 3;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc.
4 4
5;; Maintainer's Time-stamp: <1996-08-13 14:03:17 gildea> 5;; Maintainer's Time-stamp: <1997-04-28 11:51:22 gildea>
6;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu> 6;; Maintainer: Stephen Gildea <gildea@alum.mit.edu>
7;; Keywords: tools 7;; Keywords: tools
8 8
9;; This file is free software; you can redistribute it and/or modify 9;; This file is free software; you can redistribute it and/or modify
@@ -35,13 +35,6 @@
35;; See the documentation for the functions `time-stamp' 35;; See the documentation for the functions `time-stamp'
36;; and `time-stamp-toggle-active' for details. 36;; and `time-stamp-toggle-active' for details.
37 37
38;;; Change Log:
39
40;; Originally based on the 19 Dec 88 version of
41;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
42;; Version 2, January 1995: replaced functions with %-escapes
43;; $Id: time-stamp.el,v 1.24 1996/12/18 02:45:09 rms Exp rms $
44
45;;; Code: 38;;; Code:
46 39
47(defgroup time-stamp nil 40(defgroup time-stamp nil
@@ -68,20 +61,17 @@ a time stamp template that would otherwise have been updated."
68If `error', the format is not used. If `ask', the user is queried about 61If `error', the format is not used. If `ask', the user is queried about
69using the time-stamp-format. If `warn', a warning is displayed. 62using the time-stamp-format. If `warn', a warning is displayed.
70If nil, no notification is given." 63If nil, no notification is given."
71 :type '(choice (const :tag "No modification" nil) 64 :type '(choice (const :tag "No notification" nil)
72 (const :tag "Don't use the format" error) 65 (const :tag "Don't use the format" error)
73 (const ask) (const warn)) 66 (const ask) (const warn))
74 :group 'time-stamp) 67 :group 'time-stamp)
75 68
76(defcustom time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u" 69(defcustom time-stamp-format "%Y-%02m-%02d %02H:%02M:%02S %u"
77 "*Format of the string inserted by \\[time-stamp]. 70 "*Format of the string inserted by \\[time-stamp].
78The value may be a string or a list. Lists are supported only for 71The value may be a string or a list. Lists are supported only for
79backward compatibility; see variable `time-stamp-old-format-warn'. 72backward compatibility; see variable `time-stamp-old-format-warn'.
80 73
81A string is used with `format-time-string'. 74A string is used with `format-time-string'.
82For example, to get the format used by the `date' command,
83use \"%3a %3b %2d %H:%M:%S %Z %y\".
84
85In addition to the features of `format-time-string', 75In addition to the features of `format-time-string',
86you can use the following %-constructs: 76you can use the following %-constructs:
87 77
@@ -89,10 +79,15 @@ you can use the following %-constructs:
89%F full file name 79%F full file name
90%h mail host name 80%h mail host name
91%s system name 81%s system name
92%u user's login name" 82%u user's login name
83
84For example, to get the format used by the `date' command,
85use \"%3a %3b %2d %02H:%02M:%02S %Z %Y\"."
93 :type 'string 86 :type 'string
94 :group 'time-stamp) 87 :group 'time-stamp)
95 88
89
90
96;;; Do not change time-stamp-line-limit, time-stamp-start, or 91;;; Do not change time-stamp-line-limit, time-stamp-start, or
97;;; time-stamp-end in your .emacs or you will be incompatible 92;;; time-stamp-end in your .emacs or you will be incompatible
98;;; with other people's files! If you must change them, 93;;; with other people's files! If you must change them,
@@ -146,7 +141,7 @@ look like one of the following:
146 Time-stamp: \" \" 141 Time-stamp: \" \"
147The time stamp is written between the brackets or quotes: 142The time stamp is written between the brackets or quotes:
148 Time-stamp: <1996-07-18 10:20:51 gildea> 143 Time-stamp: <1996-07-18 10:20:51 gildea>
149Only updates the time stamp if the variable `time-stamp-active' is non-nil. 144The time stamp is updated only if the variable `time-stamp-active' is non-nil.
150The format of the time stamp is set by the variable `time-stamp-format'. 145The format of the time stamp is set by the variable `time-stamp-format'.
151The variables `time-stamp-line-limit', `time-stamp-start', 146The variables `time-stamp-line-limit', `time-stamp-start',
152and `time-stamp-end' control finding the template." 147and `time-stamp-end' control finding the template."
@@ -154,28 +149,33 @@ and `time-stamp-end' control finding the template."
154 (let ((case-fold-search nil) 149 (let ((case-fold-search nil)
155 (start nil) 150 (start nil)
156 (end nil) 151 (end nil)
157 search-limit) 152 search-limit
158 (save-excursion 153 (line-limit time-stamp-line-limit))
159 (save-restriction 154 (cond ((not (integerp line-limit))
160 (widen) 155 (setq line-limit 8)
161 (cond ((> time-stamp-line-limit 0) 156 (message "time-stamp-line-limit is not a number")
162 (goto-char (setq start (point-min))) 157 (sit-for 1)))
163 (forward-line time-stamp-line-limit) 158 (save-excursion
164 (setq search-limit (point))) 159 (save-restriction
165 (t 160 (widen)
166 (goto-char (setq search-limit (point-max))) 161 (cond ((> line-limit 0)
167 (forward-line time-stamp-line-limit) 162 (goto-char (setq start (point-min)))
168 (setq start (point)))) 163 (forward-line line-limit)
164 (setq search-limit (point)))
165 (t
166 (goto-char (setq search-limit (point-max)))
167 (forward-line line-limit)
168 (setq start (point))))
169 (goto-char start)
170 (while (and (< (point) search-limit)
171 (not end)
172 (re-search-forward time-stamp-start search-limit 'move))
173 (setq start (point))
174 (end-of-line)
175 (let ((line-end (point)))
169 (goto-char start) 176 (goto-char start)
170 (while (and (< (point) search-limit) 177 (if (re-search-forward time-stamp-end line-end 'move)
171 (not end) 178 (setq end (match-beginning 0)))))))
172 (re-search-forward time-stamp-start search-limit 'move))
173 (setq start (point))
174 (end-of-line)
175 (let ((line-end (point)))
176 (goto-char start)
177 (if (re-search-forward time-stamp-end line-end 'move)
178 (setq end (match-beginning 0)))))))
179 (if end 179 (if end
180 (progn 180 (progn
181 ;; do all warnings outside save-excursion 181 ;; do all warnings outside save-excursion
@@ -226,8 +226,7 @@ With arg, turn time stamping on if and only if arg is positive."
226These are replaced with the file name (nondirectory part), 226These are replaced with the file name (nondirectory part),
227full file name, host name for mail, system name, and user name. 227full file name, host name for mail, system name, and user name.
228Do not alter other %-combinations, and do detect %%." 228Do not alter other %-combinations, and do detect %%."
229 (let ((result "") (pos 0) (case-fold-search nil) 229 (let ((result "") (pos 0) (case-fold-search nil))
230 (file (or buffer-file-name "(no file)")))
231 (while (string-match "%[%uhfFs]" format pos) 230 (while (string-match "%[%uhfFs]" format pos)
232 (setq result (concat result (substring format pos (match-beginning 0)))) 231 (setq result (concat result (substring format pos (match-beginning 0))))
233 (let ((char (aref format (1+ (match-beginning 0))))) 232 (let ((char (aref format (1+ (match-beginning 0)))))
@@ -236,9 +235,13 @@ Do not alter other %-combinations, and do detect %%."
236 ((= char ?u) 235 ((= char ?u)
237 (setq result (concat result (user-login-name)))) 236 (setq result (concat result (user-login-name))))
238 ((= char ?f) 237 ((= char ?f)
239 (setq result (concat result (file-name-nondirectory file)))) 238 (setq result (concat result
240 ((= char ?f) 239 (if buffer-file-name
241 (setq result (concat result file))) 240 (file-name-nondirectory buffer-file-name)
241 time-stamp-no-file))))
242 ((= char ?F)
243 (setq result (concat result
244 (or buffer-file-name time-stamp-no-file))))
242 ((= char ?s) 245 ((= char ?s)
243 (setq result (concat result (system-name)))) 246 (setq result (concat result (system-name))))
244 ((= char ?h) 247 ((= char ?h)
@@ -249,8 +252,7 @@ Do not alter other %-combinations, and do detect %%."
249(defun time-stamp-string () 252(defun time-stamp-string ()
250 "Generate the new string to be inserted by \\[time-stamp]." 253 "Generate the new string to be inserted by \\[time-stamp]."
251 (if (stringp time-stamp-format) 254 (if (stringp time-stamp-format)
252 (format-time-string (time-stamp-string-preprocess time-stamp-format) 255 (format-time-string (time-stamp-string-preprocess time-stamp-format))
253 (current-time))
254 ;; handle version 1 compatibility 256 ;; handle version 1 compatibility
255 (cond ((or (eq time-stamp-old-format-warn 'error) 257 (cond ((or (eq time-stamp-old-format-warn 'error)
256 (and (eq time-stamp-old-format-warn 'ask) 258 (and (eq time-stamp-old-format-warn 'ask)