aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-10-31 00:01:15 +0000
committerKarl Heuer1995-10-31 00:01:15 +0000
commitf8d35bf3d139cdec1776761593dfa243339472c2 (patch)
tree80dd0e71dad5a960523b8b42351b61916e777873
parentf6190d46b72ce0815d4d69a641fc3d472940e0c5 (diff)
downloademacs-f8d35bf3d139cdec1776761593dfa243339472c2.tar.gz
emacs-f8d35bf3d139cdec1776761593dfa243339472c2.zip
update some doc strings.
(time-stamp-strftime): ignore some additional chars we might want to use in the future for additional controls or parameters. (time-stamp): minor optimizations.
-rw-r--r--lisp/time-stamp.el163
1 files changed, 93 insertions, 70 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index 5a8fe4dcb07..b9bf1ed1e04 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -1,6 +1,6 @@
1;;; time-stamp.el --- Maintain last change time stamps in files edited by Emacs 1;;; time-stamp.el --- Maintain last change time stamps in files edited by Emacs
2;;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc. 2;;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc.
3;;; Maintainer's Time-stamp: <95/05/31 10:47:14 gildea> 3;;; Maintainer's Time-stamp: <95/09/21 12:32:56 gildea>
4 4
5;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu> 5;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
6;; Keywords: tools 6;; Keywords: tools
@@ -48,28 +48,52 @@
48;;; Originally based on the 19 Dec 88 version of 48;;; Originally based on the 19 Dec 88 version of
49;;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net> 49;;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
50;;; version 2, January 1995: replaced functions with %-escapes 50;;; version 2, January 1995: replaced functions with %-escapes
51;;; $Id: time-stamp.el,v 1.13 1995/05/30 21:20:09 kwzh Exp kwzh $ 51;;; $Id: time-stamp.el,v 1.14 1995/05/31 20:00:40 kwzh Exp kwzh $
52 52
53;;; Code: 53;;; Code:
54 54
55(defvar time-stamp-active t 55(defvar time-stamp-active t
56 "*Non-nil to enable time-stamping of files. 56 "*Non-nil to enable time-stamping of buffers by \\[time-stamp].
57Can be toggled by \\[time-stamp-toggle-active]. 57Can be toggled by \\[time-stamp-toggle-active].
58See also the variable time-stamp-warn-inactive.") 58See also the variable time-stamp-warn-inactive.")
59 59
60(defvar time-stamp-warn-inactive t 60(defvar time-stamp-warn-inactive t
61 "*Non-nil to have time-stamp warn if time-stamp-active is nil.") 61 "*Non-nil to have \\[time-stamp] warn if a buffer did not get time-stamped.
62A warning is printed if time-stamp-active is nil and the buffer contains
63a time stamp template that would otherwise have been updated.")
62 64
63(defvar time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u" 65(defvar time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u"
64 "*Template for the string inserted by the time-stamp function. 66 "*Template for the string inserted by \\[time-stamp].
65Value may be a string or a list. (Lists are supported only for 67Value may be a string or a list. (Lists are supported only for
66backward compatibility.) A string is used verbatim except for character 68backward compatibility.) A string is used verbatim except
67sequences beginning with %. See the documentation for the function 69for character sequences beginning with %:
68time-stamp-strftime for a list of %-escapes. 70
69 Each element of a list is called as a function and the results are 71%a weekday name: `Monday'. %A gives uppercase: `MONDAY'
70concatenated together separated by spaces. List elements may also be 72%b month name: `January'. %B gives uppercase: `JANUARY'
71strings, which are included verbatim. Spaces are not inserted around 73%d day of month
72literal strings.") 74%H 24-hour clock hour
75%I 12-hour clock hour
76%m month number
77%M minute
78%p `am' or `pm'. %P gives uppercase: `AM' or `PM'
79%S seconds
80%w day number of week, Sunday is 0
81%y year: `1995'
82%z time zone name: `est'. %Z gives uppercase: `EST'
83
84Non-date items:
85%% a literal percent character: `%'
86%f file name without directory %F gives absolute pathname
87%s system name
88%u user's login name
89%h mail host name
90
91Decimal digits between the % and the type character specify the
92field width. Strings are truncated on the right; numbers on the left.
93A leading zero causes numbers to be zero-filled.
94
95For example, to get the format used by the `date' command,
96use \"%3a %3b %2d %02H:%02M:%02S %Z %y\"")
73 97
74 98
75;;; Do not change time-stamp-line-limit, time-stamp-start, or 99;;; Do not change time-stamp-line-limit, time-stamp-start, or
@@ -135,43 +159,46 @@ control finding the template."
135 (save-restriction 159 (save-restriction
136 (widen) 160 (widen)
137 (goto-char (point-min)) 161 (goto-char (point-min))
138 (if (re-search-forward time-stamp-start 162 (forward-line time-stamp-line-limit)
139 (save-excursion 163 (let ((start (point-min))
140 (forward-line time-stamp-line-limit) 164 (search-end (point)))
141 (point)) 165 (goto-char start)
142 t) 166 (while
143 (let ((start (point))) 167 (and (< (point) search-end)
144 (if (re-search-forward time-stamp-end 168 (re-search-forward time-stamp-start search-end 'move))
145 (save-excursion 169 (setq start (point))
146 (end-of-line) 170 (end-of-line)
147 (point)) 171 (let ((line-end (point)))
148 t) 172 (goto-char start)
149 (if time-stamp-active 173 (if (re-search-forward time-stamp-end line-end 'move)
150 (let ((end (match-beginning 0))) 174 (progn
151 (delete-region start end) 175 (if time-stamp-active
152 (goto-char start) 176 (let ((end (match-beginning 0)))
153 (insert (time-stamp-string)) 177 (delete-region start end)
154 (setq end (point)) 178 (goto-char start)
155 ;; remove any tabs used to format the time stamp 179 (insert (time-stamp-string))
156 (goto-char start) 180 (setq end (point))
157 (if (search-forward "\t" end t) 181 ;; remove any tabs used to format time stamp
158 (untabify start end))) 182 (goto-char start)
159 (if time-stamp-warn-inactive 183 (if (search-forward "\t" end t)
160 ;; do the actual warning outside save-excursion 184 (untabify start end)))
161 (setq need-to-warn t)))))))) 185 (if time-stamp-warn-inactive
186 ;; do warning outside save-excursion
187 (setq need-to-warn t)))
188 (setq search-end (point)))))))))
162 ;; don't signal an error in a write-file-hook 189 ;; don't signal an error in a write-file-hook
163 (message "time-stamp-start or time-stamp-end is not a string") 190 (message "time-stamp-start or time-stamp-end is not a string")
164 (sit-for 1)) 191 (sit-for 1))
165 (if need-to-warn 192 (if need-to-warn
166 (progn 193 (progn
167 (message "Warning: did not time-stamp buffer.") 194 (message "Warning: time-stamp-active is off; did not time-stamp buffer.")
168 (sit-for 1)))) 195 (sit-for 1))))
169 ;; be sure to return nil so can be used on write-file-hooks 196 ;; be sure to return nil so can be used on write-file-hooks
170 nil) 197 nil)
171 198
172;;;###autoload 199;;;###autoload
173(defun time-stamp-toggle-active (&optional arg) 200(defun time-stamp-toggle-active (&optional arg)
174 "Toggle time-stamp-active, which enables time stamping of files. 201 "Toggle time-stamp-active, setting whether \\[time-stamp] updates a buffer.
175With arg, turn time stamping on if and only if arg is positive." 202With arg, turn time stamping on if and only if arg is positive."
176 (interactive "P") 203 (interactive "P")
177 (setq time-stamp-active 204 (setq time-stamp-active
@@ -207,34 +234,8 @@ With arg, turn time stamping on if and only if arg is positive."
207(defun time-stamp-strftime (format &optional time) 234(defun time-stamp-strftime (format &optional time)
208 "Uses a FORMAT to format date, time, file, and user information. 235 "Uses a FORMAT to format date, time, file, and user information.
209Optional second argument TIME will be used instead of the current time. 236Optional second argument TIME will be used instead of the current time.
210Characters in the format are copied literally except for %-directives: 237See the description of the variable `time-stamp-format' for a description
211 238of the format string."
212%a weekday name: `Monday'. %A gives uppercase: `MONDAY'
213%b month name: `January'. %B gives uppercase: `JANUARY'
214%d day of month
215%H 24-hour clock hour
216%I 12-hour clock hour
217%m month number
218%M minute
219%p `am' or `pm'. %P gives uppercase: `AM' or `PM'
220%S seconds
221%w day number of week, Sunday is 0
222%y year: `1995'
223%z time zone name: `est'. %Z gives uppercase: `EST'
224
225Non-date items:
226%% a literal percent character: `%'
227%f file name without directory %F gives absolute pathname
228%s system name
229%u user's login name
230%h mail host name
231
232Decimal digits between the % and the type character specify the
233field width. Strings are truncated on the right; numbers on the left.
234A leading zero causes numbers to be zero-filled.
235
236For example, to get the format used by the `date' command,
237use \"%3a %3b %2d %02H:%02M:%02S %Z %y\""
238 (let ((time-string (cond ((stringp time) 239 (let ((time-string (cond ((stringp time)
239 time) 240 time)
240 (time 241 (time
@@ -244,24 +245,46 @@ use \"%3a %3b %2d %02H:%02M:%02S %Z %y\""
244 (fmt-len (length format)) 245 (fmt-len (length format))
245 (ind 0) 246 (ind 0)
246 cur-char 247 cur-char
248 (prev-char nil)
247 (result "") 249 (result "")
248 field-index 250 field-index
249 field-width 251 field-width
250 field-result) 252 field-result
253 (paren-level 0))
251 (while (< ind fmt-len) 254 (while (< ind fmt-len)
252 (setq cur-char (aref format ind)) 255 (setq cur-char (aref format ind))
253 (setq 256 (setq
254 result 257 result
255 (concat result 258 (concat result
256 (cond 259 (cond
257 ((and (eq cur-char ?%) 260 ((eq cur-char ?%)
258 (< (1+ ind) fmt-len))
259 (setq field-index (1+ ind)) 261 (setq field-index (1+ ind))
260 (while (progn 262 (while (progn
261 (setq ind (1+ ind)) 263 (setq ind (1+ ind))
262 (setq cur-char (aref format ind)) 264 (setq cur-char (if (< ind fmt-len)
265 (aref format ind)
266 ?\0))
263 (and (<= ?0 cur-char) (>= ?9 cur-char)))) 267 (and (<= ?0 cur-char) (>= ?9 cur-char))))
264 (setq field-width (substring format field-index ind)) 268 (setq field-width (substring format field-index ind))
269 ;; eat any additional args to allow for future expansion
270 (while (or (and (<= ?0 cur-char) (>= ?9 cur-char)) (eq ?. cur-char)
271 (eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char)
272 (eq ?- cur-char) (eq ?+ cur-char)
273 (eq ?\ cur-char) (eq ?# cur-char)
274 (and (eq ?\( cur-char)
275 (not (eq prev-char ?\\))
276 (setq paren-level (1+ paren-level)))
277 (if (and (eq ?\) cur-char)
278 (not (eq prev-char ?\\))
279 (> paren-level 0))
280 (setq paren-level (1- paren-level))
281 (and (> paren-level 0)
282 (< ind fmt-len))))
283 (setq ind (1+ ind))
284 (setq prev-char cur-char)
285 (setq cur-char (if (< ind fmt-len)
286 (aref format ind)
287 ?\0)))
265 (setq field-result 288 (setq field-result
266 (cond 289 (cond
267 ((eq cur-char ?%) 290 ((eq cur-char ?%)