aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKarl Heuer1996-09-22 22:20:58 +0000
committerKarl Heuer1996-09-22 22:20:58 +0000
commit03d7856ad1f066ff3711411686f2a2e48b25fe9d (patch)
treea1632a407cf859bd3e4f27ab62bc7a840330ac66 /lisp
parentf21c591e50538246ee58fd4d9b51218a4b4f3147 (diff)
downloademacs-03d7856ad1f066ff3711411686f2a2e48b25fe9d.tar.gz
emacs-03d7856ad1f066ff3711411686f2a2e48b25fe9d.zip
(time-stamp-old-format-warn): new variable.
(time-stamp-format): use ISO 8601 format for date.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/time-stamp.el188
1 files changed, 102 insertions, 86 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index f072dba572e..6c65715f456 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -2,7 +2,7 @@
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: <95/12/28 19:48:49 gildea> 5;; Maintainer's Time-stamp: <1996-08-13 14:03:17 gildea>
6;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu> 6;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
7;; Keywords: tools 7;; Keywords: tools
8 8
@@ -23,52 +23,48 @@
23 23
24;;; Commentary: 24;;; Commentary:
25 25
26;; If you put a time stamp template anywhere in the first 8 lines of a file, 26;; A template in a file can be updated with a new time stamp when
27;; it can be updated every time you save the file. See the top of 27;; you save the file. For example:
28;; time-stamp.el for a sample. The template looks like one of the following: 28;; static char *ts = "sdmain.c Time-stamp: <1996-08-13 10:20:51 gildea>";
29;; Time-stamp: <> 29;; See the top of `time-stamp.el' for another example.
30;; Time-stamp: " " 30
31;; The time stamp is written between the brackets or quotes, resulting in 31;; To use time-stamping, add this line to your .emacs file:
32;; Time-stamp: <95/01/18 10:20:51 gildea> 32;; (add-hook 'write-file-hooks 'time-stamp)
33;; Here is an example that puts the file name and time stamp in the binary: 33;; Now any time-stamp templates in your files will be updated automatically.
34;; static char *time_stamp = "sdmain.c Time-stamp: <>"; 34
35 35;; See the documentation for the functions `time-stamp'
36;; To activate automatic time stamping in GNU Emacs 19, add this code 36;; and `time-stamp-toggle-active' for details.
37;; to your .emacs file:
38;; (add-hook 'write-file-hooks 'time-stamp)
39;;
40;; In Emacs 18 you will need to do this instead:
41;; (if (not (memq 'time-stamp write-file-hooks))
42;; (setq write-file-hooks
43;; (cons 'time-stamp write-file-hooks)))
44;; (autoload 'time-stamp "time-stamp" "Update the time stamp in a buffer." t)
45
46;; See the documentation for the function `time-stamp' for more details.
47 37
48;;; Change Log: 38;;; Change Log:
49 39
50;; Originally based on the 19 Dec 88 version of 40;; Originally based on the 19 Dec 88 version of
51;; 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>
52;; version 2, January 1995: replaced functions with %-escapes 42;; Version 2, January 1995: replaced functions with %-escapes
53;; $Id: time-stamp.el,v 1.16 1996/01/06 01:03:24 kwzh Exp erik $ 43;; $Id: time-stamp.el,v 1.5 1996/08/13 18:03:17 gildea Exp $
54 44
55;;; Code: 45;;; Code:
56 46
57(defvar time-stamp-active t 47(defvar time-stamp-active t
58 "*Non-nil to enable time-stamping of buffers by \\[time-stamp]. 48 "*Non-nil to enable time-stamping of buffers by \\[time-stamp].
59Can be toggled by \\[time-stamp-toggle-active]. 49Can be toggled by \\[time-stamp-toggle-active].
60See also the variable time-stamp-warn-inactive.") 50See also the variable `time-stamp-warn-inactive'.")
61 51
62(defvar time-stamp-warn-inactive t 52(defvar time-stamp-warn-inactive t
63 "*Non-nil to have \\[time-stamp] warn if a buffer did not get time-stamped. 53 "Non-nil to have \\[time-stamp] warn if a buffer did not get time-stamped.
64A warning is printed if time-stamp-active is nil and the buffer contains 54A warning is printed if `time-stamp-active' is nil and the buffer contains
65a time stamp template that would otherwise have been updated.") 55a time stamp template that would otherwise have been updated.")
66 56
67(defvar time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u" 57(defvar time-stamp-old-format-warn 'ask
68 "*Template for the string inserted by \\[time-stamp]. 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
60using the time-stamp-format. If 'warn, a warning is displayed.
61If nil, no notification is given.")
62
63(defvar time-stamp-format "%y-%02m-%02d %02H:%02M:%02S %u"
64 "*Format of the string inserted by \\[time-stamp].
69Value may be a string or a list. (Lists are supported only for 65Value may be a string or a list. (Lists are supported only for
70backward compatibility.) A string is used verbatim except 66backward compatibility; see variable `time-stamp-old-format-warn'.)
71for character sequences beginning with %: 67A string is used verbatim except for character sequences beginning with %:
72 68
73%a weekday name: `Monday'. %A gives uppercase: `MONDAY' 69%a weekday name: `Monday'. %A gives uppercase: `MONDAY'
74%b month name: `January'. %B gives uppercase: `JANUARY' 70%b month name: `January'. %B gives uppercase: `JANUARY'
@@ -98,11 +94,13 @@ For example, to get the format used by the `date' command,
98use \"%3a %3b %2d %02H:%02M:%02S %Z %y\"") 94use \"%3a %3b %2d %02H:%02M:%02S %Z %y\"")
99 95
100 96
97
101;;; Do not change time-stamp-line-limit, time-stamp-start, or 98;;; Do not change time-stamp-line-limit, time-stamp-start, or
102;;; time-stamp-end in your .emacs or you will be incompatible 99;;; time-stamp-end in your .emacs or you will be incompatible
103;;; with other people's files! If you must change them, 100;;; with other people's files! If you must change them,
104;;; do so only in the local variables section of the file itself. 101;;; do so only in the local variables section of the file itself.
105 102
103
106(defvar time-stamp-line-limit 8 ;Do not change! 104(defvar time-stamp-line-limit 8 ;Do not change!
107 "Lines of a file searched; positive counts from start, negative from end. 105 "Lines of a file searched; positive counts from start, negative from end.
108The patterns `time-stamp-start' and `time-stamp-end' must be found on one 106The patterns `time-stamp-start' and `time-stamp-end' must be found on one
@@ -137,75 +135,83 @@ with other people's files! If you must change them for some application,
137do so in the local variables section of the time-stamped file itself.") 135do so in the local variables section of the time-stamped file itself.")
138 136
139 137
138
140;;;###autoload 139;;;###autoload
141(defun time-stamp () 140(defun time-stamp ()
142 "Update the time stamp string in the buffer. 141 "Update the time stamp string in the buffer.
143If you put a time stamp template anywhere in the first 8 lines of a file, 142A template in a file can be automatically updated with a new time stamp
144it can be updated every time you save the file. See the top of 143every time you save the file. Add this line to your .emacs file:
145`time-stamp.el' for a sample. The template looks like one of the following: 144 (add-hook 'write-file-hooks 'time-stamp)
146 Time-stamp: <> 145Normally the template must appear in the first 8 lines of a file and
147 Time-stamp: \" \" 146look like one of the following:
148The time stamp is written between the brackets or quotes, resulting in 147 Time-stamp: <>
149 Time-stamp: <95/01/18 10:20:51 gildea> 148 Time-stamp: \" \"
150Only does its thing if the variable time-stamp-active is non-nil. 149The time stamp is written between the brackets or quotes:
151Typically used on write-file-hooks for automatic time-stamping. 150 Time-stamp: <1996-07-18 10:20:51 gildea>
152The format of the time stamp is determined by the variable time-stamp-format. 151Only updates the time stamp if the variable `time-stamp-active' is non-nil.
153The variables time-stamp-line-limit, time-stamp-start, and time-stamp-end 152The format of the time stamp is set by the variable `time-stamp-format'.
154control finding the template." 153The variables `time-stamp-line-limit', `time-stamp-start',
154and `time-stamp-end' control finding the template."
155 (interactive) 155 (interactive)
156 (let ((case-fold-search nil) 156 (let ((case-fold-search nil)
157 (need-to-warn nil) 157 (start nil)
158 start search-end) 158 (end nil)
159 (if (and (stringp time-stamp-start) 159 search-limit)
160 (stringp time-stamp-end))
161 (save-excursion 160 (save-excursion
162 (save-restriction 161 (save-restriction
163 (widen) 162 (widen)
164 (if (> time-stamp-line-limit 0) 163 (cond ((> time-stamp-line-limit 0)
165 (progn 164 (goto-char (setq start (point-min)))
166 (goto-char (setq start (point-min))) 165 (forward-line time-stamp-line-limit)
167 (forward-line time-stamp-line-limit) 166 (setq search-limit (point)))
168 (setq search-end (point))) 167 (t
169 (goto-char (setq search-end (point-max))) 168 (goto-char (setq search-limit (point-max)))
170 (forward-line time-stamp-line-limit) 169 (forward-line time-stamp-line-limit)
171 (setq start (point))) 170 (setq start (point))))
172 (goto-char start) 171 (goto-char start)
173 (while 172 (while (and (< (point) search-limit)
174 (and (< (point) search-end) 173 (not end)
175 (re-search-forward time-stamp-start search-end 'move)) 174 (re-search-forward time-stamp-start search-limit 'move))
176 (setq start (point)) 175 (setq start (point))
177 (end-of-line) 176 (end-of-line)
178 (let ((line-end (point))) 177 (let ((line-end (point)))
179 (goto-char start) 178 (goto-char start)
180 (if (re-search-forward time-stamp-end line-end 'move) 179 (if (re-search-forward time-stamp-end line-end 'move)
180 (setq end (match-beginning 0)))))))
181 (if end
182 (progn
183 ;; do all warnings outside save-excursion
184 (cond
185 ((not time-stamp-active)
186 (if time-stamp-warn-inactive
187 ;; don't signal an error in a write-file-hook
181 (progn 188 (progn
182 (if time-stamp-active 189 (message "Warning: time-stamp-active is off; did not time-stamp buffer.")
183 (let ((end (match-beginning 0))) 190 (sit-for 1))))
184 (delete-region start end) 191 ((not (and (stringp time-stamp-start)
185 (goto-char start) 192 (stringp time-stamp-end)))
186 (insert (time-stamp-string)) 193 (message "time-stamp-start or time-stamp-end is not a string")
187 (setq end (point)) 194 (sit-for 1))
188 ;; remove any tabs used to format time stamp 195 (t
189 (goto-char start) 196 (let ((new-time-stamp (time-stamp-string)))
190 (if (search-forward "\t" end t) 197 (if (stringp new-time-stamp)
191 (untabify start end))) 198 (save-excursion
192 (if time-stamp-warn-inactive 199 (save-restriction
193 ;; do warning outside save-excursion 200 (widen)
194 (setq need-to-warn t))) 201 (delete-region start end)
195 (setq search-end (point)))))))) 202 (goto-char start)
196 ;; don't signal an error in a write-file-hook 203 (insert new-time-stamp)
197 (message "time-stamp-start or time-stamp-end is not a string") 204 (setq end (point))
198 (sit-for 1)) 205 ;; remove any tabs used to format time stamp
199 (if need-to-warn 206 (goto-char start)
200 (progn 207 (if (search-forward "\t" end t)
201 (message "Warning: time-stamp-active is off; did not time-stamp buffer.") 208 (untabify start end)))))))))))
202 (sit-for 1))))
203 ;; be sure to return nil so can be used on write-file-hooks 209 ;; be sure to return nil so can be used on write-file-hooks
204 nil) 210 nil)
205 211
206;;;###autoload 212;;;###autoload
207(defun time-stamp-toggle-active (&optional arg) 213(defun time-stamp-toggle-active (&optional arg)
208 "Toggle time-stamp-active, setting whether \\[time-stamp] updates a buffer. 214 "Toggle `time-stamp-active', setting whether \\[time-stamp] updates a buffer.
209With arg, turn time stamping on if and only if arg is positive." 215With arg, turn time stamping on if and only if arg is positive."
210 (interactive "P") 216 (interactive "P")
211 (setq time-stamp-active 217 (setq time-stamp-active
@@ -213,13 +219,24 @@ With arg, turn time stamping on if and only if arg is positive."
213 (not time-stamp-active) 219 (not time-stamp-active)
214 (> (prefix-numeric-value arg) 0))) 220 (> (prefix-numeric-value arg) 0)))
215 (message "time-stamp is now %s." (if time-stamp-active "active" "off"))) 221 (message "time-stamp is now %s." (if time-stamp-active "active" "off")))
216 222
217 223
218(defun time-stamp-string () 224(defun time-stamp-string ()
219 "Generate the new string to be inserted by \\[time-stamp]." 225 "Generate the new string to be inserted by \\[time-stamp]."
220 (if (stringp time-stamp-format) 226 (if (stringp time-stamp-format)
221 (time-stamp-strftime time-stamp-format) 227 (time-stamp-strftime time-stamp-format)
222 (time-stamp-fconcat time-stamp-format " "))) ;version 1 compatibility 228 ;; handle version 1 compatibility
229 (cond ((or (eq time-stamp-old-format-warn 'error)
230 (and (eq time-stamp-old-format-warn 'ask)
231 (not (y-or-n-p "Use non-string time-stamp-format? "))))
232 (message "Warning: no time-stamp: time-stamp-format not a string")
233 (sit-for 1)
234 nil)
235 (t
236 (cond ((eq time-stamp-old-format-warn 'warn)
237 (message "Obsolescent time-stamp-format type; should be string")
238 (sit-for 1)))
239 (time-stamp-fconcat time-stamp-format " ")))))
223 240
224(defconst time-stamp-month-numbers 241(defconst time-stamp-month-numbers
225 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6) 242 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
@@ -247,7 +264,7 @@ With arg, turn time stamping on if and only if arg is positive."
247(defun time-stamp-strftime (format &optional time) 264(defun time-stamp-strftime (format &optional time)
248 "Uses a FORMAT to format date, time, file, and user information. 265 "Uses a FORMAT to format date, time, file, and user information.
249Optional second argument TIME will be used instead of the current time. 266Optional second argument TIME will be used instead of the current time.
250See the description of the variable `time-stamp-format' for a description 267See the documentation of the variable `time-stamp-format' for a description
251of the format string." 268of the format string."
252 (let ((time-string (cond ((stringp time) 269 (let ((time-string (cond ((stringp time)
253 time) 270 time)
@@ -268,7 +285,7 @@ of the format string."
268 (setq cur-char (aref format ind)) 285 (setq cur-char (aref format ind))
269 (setq 286 (setq
270 result 287 result
271 (concat result 288 (concat result
272 (cond 289 (cond
273 ((eq cur-char ?%) 290 ((eq cur-char ?%)
274 (setq field-index (1+ ind)) 291 (setq field-index (1+ ind))
@@ -430,8 +447,7 @@ around literals."
430 (setq list (cdr list))) 447 (setq list (cdr list)))
431 return-string)) 448 return-string))
432 449
433 450;;; Some functions used in time-stamp-format
434;;; Some useful functions to use in time-stamp-format
435 451
436;;; Could generate most of a message-id with 452;;; Could generate most of a message-id with
437;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" time-stamp-mail-host-name) 453;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" time-stamp-mail-host-name)