diff options
| author | Richard M. Stallman | 1998-03-06 03:48:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-03-06 03:48:15 +0000 |
| commit | b4b33e0104da8aa94178d78262a8bbafd4b8a44f (patch) | |
| tree | 5e544afa325c0ba6ef30583794ab8299dfc37117 | |
| parent | 3e2c89815d3f967214dd1f58bdb75d9d22d1f570 (diff) | |
| download | emacs-b4b33e0104da8aa94178d78262a8bbafd4b8a44f.tar.gz emacs-b4b33e0104da8aa94178d78262a8bbafd4b8a44f.zip | |
(time-stamp-pattern): New variable.
(time-stamp): Use that new variable.
(time-stamp-string): Take optional format arg.
| -rw-r--r-- | lisp/time-stamp.el | 138 |
1 files changed, 94 insertions, 44 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index 93c4f86af1d..7eab5a7a794 100644 --- a/lisp/time-stamp.el +++ b/lisp/time-stamp.el | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | ;; Copyright 1989, 1993, 1994, 1995, 1997 Free Software Foundation, Inc. | 3 | ;; Copyright 1989, 1993, 1994, 1995, 1997 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Maintainer's Time-stamp: <1997-08-07 14:46:50 gildea> | 5 | ;; Maintainer's Time-stamp: <1998-03-04 14:14:19 gildea> |
| 6 | ;; Maintainer: Stephen Gildea <gildea@alum.mit.edu> | 6 | ;; Maintainer: Stephen Gildea <gildea@alum.mit.edu> |
| 7 | ;; Keywords: tools | 7 | ;; Keywords: tools |
| 8 | 8 | ||
| @@ -117,10 +117,11 @@ Format is the same as that used by the environment variable TZ on your system." | |||
| 117 | :group 'time-stamp) | 117 | :group 'time-stamp) |
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | ;;; Do not change time-stamp-line-limit, time-stamp-start, or | 120 | ;;; Do not change time-stamp-line-limit, time-stamp-start, |
| 121 | ;;; time-stamp-end in your .emacs or you will be incompatible | 121 | ;;; time-stamp-end, or time-stamp-pattern in your .emacs |
| 122 | ;;; with other people's files! If you must change them, | 122 | ;;; or you will be incompatible with other people's files! |
| 123 | ;;; do so only in the local variables section of the file itself. | 123 | ;;; If you must change them, do so only in the local variables |
| 124 | ;;; section of the file itself. | ||
| 124 | 125 | ||
| 125 | 126 | ||
| 126 | (defvar time-stamp-line-limit 8 ;Do not change! | 127 | (defvar time-stamp-line-limit 8 ;Do not change! |
| @@ -157,6 +158,36 @@ with other people's files! If you must change them for some application, | |||
| 157 | do so in the local variables section of the time-stamped file itself.") | 158 | do so in the local variables section of the time-stamped file itself.") |
| 158 | 159 | ||
| 159 | 160 | ||
| 161 | (defvar time-stamp-pattern "%%" ;Do not change! | ||
| 162 | "Convenience variable setting all time-stamp location and format variables. | ||
| 163 | This string has four parts, each of which is optional. | ||
| 164 | These four parts set time-stamp-line-limit, time-stamp-start, | ||
| 165 | time-stamp-format, and time-stamp-end. See the documentation | ||
| 166 | for each of these variables for details. | ||
| 167 | |||
| 168 | The first part is a number followed by a slash; the number sets the number | ||
| 169 | of lines at the beginning (negative counts from end) of the file searched | ||
| 170 | for the time-stamp. The number and the slash may be omitted to use the | ||
| 171 | normal value. | ||
| 172 | |||
| 173 | The second part is a regexp identifying the pattern preceding the time stamp. | ||
| 174 | This part may be omitted to use the normal pattern. | ||
| 175 | |||
| 176 | The third part specifies the format of the time-stamp inserted. See | ||
| 177 | the documentation for time-stamp-format for details. Specify this | ||
| 178 | part as \"%%\" to use the normal format. | ||
| 179 | |||
| 180 | The fourth part is a regexp identifying the pattern following the time stamp. | ||
| 181 | This part may be omitted to use the normal pattern. | ||
| 182 | |||
| 183 | As an example, the default behavior can be specified something like this: | ||
| 184 | \"8/Time-stamp: [\\\"<]%:y-%02m-%02d %02H:%02M:%02S %u[\\\">]\" | ||
| 185 | |||
| 186 | Do not change `time-stamp-pattern' for yourself or you will be incompatible | ||
| 187 | with other people's files! Set it only in the local variables section | ||
| 188 | of the time-stamped file itself.") | ||
| 189 | |||
| 190 | |||
| 160 | 191 | ||
| 161 | ;;;###autoload | 192 | ;;;###autoload |
| 162 | (defun time-stamp () | 193 | (defun time-stamp () |
| @@ -169,7 +200,7 @@ look like one of the following: | |||
| 169 | Time-stamp: <> | 200 | Time-stamp: <> |
| 170 | Time-stamp: \" \" | 201 | Time-stamp: \" \" |
| 171 | The time stamp is written between the brackets or quotes: | 202 | The time stamp is written between the brackets or quotes: |
| 172 | Time-stamp: <1996-07-18 10:20:51 gildea> | 203 | Time-stamp: <1998-02-18 10:20:51 gildea> |
| 173 | The time stamp is updated only if the variable `time-stamp-active' is non-nil. | 204 | The time stamp is updated only if the variable `time-stamp-active' is non-nil. |
| 174 | The format of the time stamp is set by the variable `time-stamp-format'. | 205 | The format of the time stamp is set by the variable `time-stamp-format'. |
| 175 | The variables `time-stamp-line-limit', `time-stamp-start', | 206 | The variables `time-stamp-line-limit', `time-stamp-start', |
| @@ -179,10 +210,26 @@ and `time-stamp-end' control finding the template." | |||
| 179 | (start nil) | 210 | (start nil) |
| 180 | (end nil) | 211 | (end nil) |
| 181 | search-limit | 212 | search-limit |
| 182 | (line-limit time-stamp-line-limit)) | 213 | (line-limit time-stamp-line-limit) |
| 214 | (ts-start time-stamp-start) | ||
| 215 | (ts-format time-stamp-format) | ||
| 216 | (ts-end time-stamp-end)) | ||
| 217 | (if (stringp time-stamp-pattern) | ||
| 218 | (progn | ||
| 219 | (string-match "^\\(\\(-?[0-9]+\\)/\\)?\\([^%]+\\)?\\(.*%[-.,:@+_ #^()0-9]*[A-Za-z%]\\)?\\([^%]+\\)?$" time-stamp-pattern) | ||
| 220 | (and (match-beginning 2) | ||
| 221 | (setq line-limit | ||
| 222 | (string-to-int (match-string 2 time-stamp-pattern)))) | ||
| 223 | (and (match-beginning 3) | ||
| 224 | (setq ts-start (match-string 3 time-stamp-pattern))) | ||
| 225 | (and (match-beginning 4) | ||
| 226 | (not (string-equal (match-string 4 time-stamp-pattern) "%%")) | ||
| 227 | (setq ts-format (match-string 4 time-stamp-pattern))) | ||
| 228 | (and (match-beginning 5) | ||
| 229 | (setq ts-end (match-string 5 time-stamp-pattern))))) | ||
| 183 | (cond ((not (integerp line-limit)) | 230 | (cond ((not (integerp line-limit)) |
| 184 | (setq line-limit 8) | 231 | (setq line-limit 8) |
| 185 | (message "time-stamp-line-limit is not a number") | 232 | (message "time-stamp-line-limit is not an integer") |
| 186 | (sit-for 1))) | 233 | (sit-for 1))) |
| 187 | (save-excursion | 234 | (save-excursion |
| 188 | (save-restriction | 235 | (save-restriction |
| @@ -198,41 +245,41 @@ and `time-stamp-end' control finding the template." | |||
| 198 | (goto-char start) | 245 | (goto-char start) |
| 199 | (while (and (< (point) search-limit) | 246 | (while (and (< (point) search-limit) |
| 200 | (not end) | 247 | (not end) |
| 201 | (re-search-forward time-stamp-start search-limit 'move)) | 248 | (re-search-forward ts-start search-limit 'move)) |
| 202 | (setq start (point)) | 249 | (setq start (point)) |
| 203 | (end-of-line) | 250 | (end-of-line) |
| 204 | (let ((line-end (point))) | 251 | (let ((line-end (point))) |
| 205 | (goto-char start) | 252 | (goto-char start) |
| 206 | (if (re-search-forward time-stamp-end line-end 'move) | 253 | (if (re-search-forward ts-end line-end 'move) |
| 207 | (setq end (match-beginning 0))))))) | 254 | (setq end (match-beginning 0))))))) |
| 208 | (if end | 255 | (if end |
| 209 | (progn | 256 | (progn |
| 210 | ;; do all warnings outside save-excursion | 257 | ;; do all warnings outside save-excursion |
| 211 | (cond | 258 | (cond |
| 212 | ((not time-stamp-active) | 259 | ((not time-stamp-active) |
| 213 | (if time-stamp-warn-inactive | 260 | (if time-stamp-warn-inactive |
| 214 | ;; don't signal an error in a write-file-hook | 261 | ;; don't signal an error in a write-file-hook |
| 215 | (progn | 262 | (progn |
| 216 | (message "Warning: time-stamp-active is off; did not time-stamp buffer.") | 263 | (message "Warning: time-stamp-active is off; did not time-stamp buffer.") |
| 217 | (sit-for 1)))) | 264 | (sit-for 1)))) |
| 218 | ((not (and (stringp time-stamp-start) | 265 | ((not (and (stringp ts-start) |
| 219 | (stringp time-stamp-end))) | 266 | (stringp ts-end))) |
| 220 | (message "time-stamp-start or time-stamp-end is not a string") | 267 | (message "time-stamp-start or time-stamp-end is not a string") |
| 221 | (sit-for 1)) | 268 | (sit-for 1)) |
| 222 | (t | 269 | (t |
| 223 | (let ((new-time-stamp (time-stamp-string))) | 270 | (let ((new-time-stamp (time-stamp-string ts-format))) |
| 224 | (if (stringp new-time-stamp) | 271 | (if (stringp new-time-stamp) |
| 225 | (save-excursion | 272 | (save-excursion |
| 226 | (save-restriction | 273 | (save-restriction |
| 227 | (widen) | 274 | (widen) |
| 228 | (delete-region start end) | 275 | (delete-region start end) |
| 229 | (goto-char start) | 276 | (goto-char start) |
| 230 | (insert-and-inherit new-time-stamp) | 277 | (insert-and-inherit new-time-stamp) |
| 231 | (setq end (point)) | 278 | (setq end (point)) |
| 232 | ;; remove any tabs used to format time stamp | 279 | ;; remove any tabs used to format time stamp |
| 233 | (goto-char start) | 280 | (goto-char start) |
| 234 | (if (search-forward "\t" end t) | 281 | (if (search-forward "\t" end t) |
| 235 | (untabify start end))))))))))) | 282 | (untabify start end))))))))))) |
| 236 | ;; be sure to return nil so can be used on write-file-hooks | 283 | ;; be sure to return nil so can be used on write-file-hooks |
| 237 | nil) | 284 | nil) |
| 238 | 285 | ||
| @@ -464,19 +511,22 @@ The new forms being recommended now will continue to work then.") | |||
| 464 | 511 | ||
| 465 | 512 | ||
| 466 | 513 | ||
| 467 | (defun time-stamp-string () | 514 | (defun time-stamp-string (&optional ts-format) |
| 468 | "Generate the new string to be inserted by \\[time-stamp]." | 515 | "Generate the new string to be inserted by \\[time-stamp]. |
| 469 | (if (stringp time-stamp-format) | 516 | Optionally use FORMAT." |
| 517 | (or ts-format | ||
| 518 | (setq ts-format time-stamp-format)) | ||
| 519 | (if (stringp ts-format) | ||
| 470 | (if (stringp time-stamp-time-zone) | 520 | (if (stringp time-stamp-time-zone) |
| 471 | (let ((real-time-zone (getenv "TZ"))) | 521 | (let ((real-time-zone (getenv "TZ"))) |
| 472 | (unwind-protect | 522 | (unwind-protect |
| 473 | (progn | 523 | (progn |
| 474 | (setenv "TZ" time-stamp-time-zone) | 524 | (setenv "TZ" time-stamp-time-zone) |
| 475 | (format-time-string | 525 | (format-time-string |
| 476 | (time-stamp-string-preprocess time-stamp-format))) | 526 | (time-stamp-string-preprocess ts-format))) |
| 477 | (setenv "TZ" real-time-zone))) | 527 | (setenv "TZ" real-time-zone))) |
| 478 | (format-time-string | 528 | (format-time-string |
| 479 | (time-stamp-string-preprocess time-stamp-format))) | 529 | (time-stamp-string-preprocess ts-format))) |
| 480 | ;; handle version 1 compatibility | 530 | ;; handle version 1 compatibility |
| 481 | (cond ((or (eq time-stamp-old-format-warn 'error) | 531 | (cond ((or (eq time-stamp-old-format-warn 'error) |
| 482 | (and (eq time-stamp-old-format-warn 'ask) | 532 | (and (eq time-stamp-old-format-warn 'ask) |
| @@ -488,7 +538,7 @@ The new forms being recommended now will continue to work then.") | |||
| 488 | (cond ((eq time-stamp-old-format-warn 'warn) | 538 | (cond ((eq time-stamp-old-format-warn 'warn) |
| 489 | (message "Obsolescent time-stamp-format type; should be string") | 539 | (message "Obsolescent time-stamp-format type; should be string") |
| 490 | (sit-for 1))) | 540 | (sit-for 1))) |
| 491 | (time-stamp-fconcat time-stamp-format " "))))) | 541 | (time-stamp-fconcat ts-format " "))))) |
| 492 | 542 | ||
| 493 | (defconst time-stamp-no-file "(no file)" | 543 | (defconst time-stamp-no-file "(no file)" |
| 494 | "String to use when the buffer is not associated with a file.") | 544 | "String to use when the buffer is not associated with a file.") |