diff options
| author | Karl Heuer | 1996-01-06 01:03:24 +0000 |
|---|---|---|
| committer | Karl Heuer | 1996-01-06 01:03:24 +0000 |
| commit | c7c4ddd481b7c3edfcdda55888b50345f97c309f (patch) | |
| tree | e56d1e6d9579ce47a720bea7689a9660450190b6 | |
| parent | c7f493fd9f9d669713a394e6f35c35cc6eb72bf0 (diff) | |
| download | emacs-c7c4ddd481b7c3edfcdda55888b50345f97c309f.tar.gz emacs-c7c4ddd481b7c3edfcdda55888b50345f97c309f.zip | |
(time-stamp-line-limit): negative value counts
from end of file.
| -rw-r--r-- | lisp/time-stamp.el | 92 |
1 files changed, 51 insertions, 41 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index b9bf1ed1e04..c509a04ee45 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/09/21 12:32:56 gildea> | 3 | ;;; Maintainer's Time-stamp: <95/12/28 19:48:49 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 |
| @@ -28,7 +28,7 @@ | |||
| 28 | ;;; Time-stamp: " " | 28 | ;;; Time-stamp: " " |
| 29 | ;;; The time stamp is written between the brackets or quotes, resulting in | 29 | ;;; The time stamp is written between the brackets or quotes, resulting in |
| 30 | ;;; Time-stamp: <95/01/18 10:20:51 gildea> | 30 | ;;; Time-stamp: <95/01/18 10:20:51 gildea> |
| 31 | ;;; Here is an example which puts the file name and time stamp in the binary: | 31 | ;;; Here is an example that puts the file name and time stamp in the binary: |
| 32 | ;;; static char *time_stamp = "sdmain.c Time-stamp: <>"; | 32 | ;;; static char *time_stamp = "sdmain.c Time-stamp: <>"; |
| 33 | 33 | ||
| 34 | ;;; To activate automatic time stamping in GNU Emacs 19, add this code | 34 | ;;; To activate automatic time stamping in GNU Emacs 19, add this code |
| @@ -48,7 +48,7 @@ | |||
| 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.14 1995/05/31 20:00:40 kwzh Exp kwzh $ | 51 | ;;; $Id: time-stamp.el,v 1.15 1995/10/31 00:01:15 kwzh Exp kwzh $ |
| 52 | 52 | ||
| 53 | ;;; Code: | 53 | ;;; Code: |
| 54 | 54 | ||
| @@ -102,10 +102,10 @@ use \"%3a %3b %2d %02H:%02M:%02S %Z %y\"") | |||
| 102 | ;;; do so only in the local variables section of the file itself. | 102 | ;;; do so only in the local variables section of the file itself. |
| 103 | 103 | ||
| 104 | (defvar time-stamp-line-limit 8 ;Do not change! | 104 | (defvar time-stamp-line-limit 8 ;Do not change! |
| 105 | "Number of lines at the beginning of a file that are searched. | 105 | "Lines of a file searched; positive counts from start, negative from end. |
| 106 | The patterns `time-stamp-start' and `time-stamp-end' must be found on one | 106 | The patterns `time-stamp-start' and `time-stamp-end' must be found on one |
| 107 | of the first `time-stamp-line-limit' lines of the file for the file to | 107 | of the first (last) `time-stamp-line-limit' lines of the file for the |
| 108 | be time-stamped by \\[time-stamp]. | 108 | file to be time-stamped by \\[time-stamp]. |
| 109 | 109 | ||
| 110 | Do not change `time-stamp-line-limit', `time-stamp-start', or | 110 | Do not change `time-stamp-line-limit', `time-stamp-start', or |
| 111 | `time-stamp-end' for yourself or you will be incompatible | 111 | `time-stamp-end' for yourself or you will be incompatible |
| @@ -152,40 +152,45 @@ The variables time-stamp-line-limit, time-stamp-start, and time-stamp-end | |||
| 152 | control finding the template." | 152 | control finding the template." |
| 153 | (interactive) | 153 | (interactive) |
| 154 | (let ((case-fold-search nil) | 154 | (let ((case-fold-search nil) |
| 155 | (need-to-warn nil)) | 155 | (need-to-warn nil) |
| 156 | start search-end) | ||
| 156 | (if (and (stringp time-stamp-start) | 157 | (if (and (stringp time-stamp-start) |
| 157 | (stringp time-stamp-end)) | 158 | (stringp time-stamp-end)) |
| 158 | (save-excursion | 159 | (save-excursion |
| 159 | (save-restriction | 160 | (save-restriction |
| 160 | (widen) | 161 | (widen) |
| 161 | (goto-char (point-min)) | 162 | (if (> time-stamp-line-limit 0) |
| 162 | (forward-line time-stamp-line-limit) | 163 | (progn |
| 163 | (let ((start (point-min)) | 164 | (goto-char (setq start (point-min))) |
| 164 | (search-end (point))) | 165 | (forward-line time-stamp-line-limit) |
| 165 | (goto-char start) | 166 | (setq search-end (point))) |
| 166 | (while | 167 | (goto-char (setq search-end (point-max))) |
| 167 | (and (< (point) search-end) | 168 | (forward-line time-stamp-line-limit) |
| 168 | (re-search-forward time-stamp-start search-end 'move)) | 169 | (setq start (point))) |
| 169 | (setq start (point)) | 170 | (goto-char start) |
| 170 | (end-of-line) | 171 | (while |
| 171 | (let ((line-end (point))) | 172 | (and (< (point) search-end) |
| 172 | (goto-char start) | 173 | (re-search-forward time-stamp-start search-end 'move)) |
| 173 | (if (re-search-forward time-stamp-end line-end 'move) | 174 | (setq start (point)) |
| 174 | (progn | 175 | (end-of-line) |
| 175 | (if time-stamp-active | 176 | (let ((line-end (point))) |
| 176 | (let ((end (match-beginning 0))) | 177 | (goto-char start) |
| 177 | (delete-region start end) | 178 | (if (re-search-forward time-stamp-end line-end 'move) |
| 178 | (goto-char start) | 179 | (progn |
| 179 | (insert (time-stamp-string)) | 180 | (if time-stamp-active |
| 180 | (setq end (point)) | 181 | (let ((end (match-beginning 0))) |
| 181 | ;; remove any tabs used to format time stamp | 182 | (delete-region start end) |
| 182 | (goto-char start) | 183 | (goto-char start) |
| 183 | (if (search-forward "\t" end t) | 184 | (insert (time-stamp-string)) |
| 184 | (untabify start end))) | 185 | (setq end (point)) |
| 185 | (if time-stamp-warn-inactive | 186 | ;; remove any tabs used to format time stamp |
| 186 | ;; do warning outside save-excursion | 187 | (goto-char start) |
| 187 | (setq need-to-warn t))) | 188 | (if (search-forward "\t" end t) |
| 188 | (setq search-end (point))))))))) | 189 | (untabify start end))) |
| 190 | (if time-stamp-warn-inactive | ||
| 191 | ;; do warning outside save-excursion | ||
| 192 | (setq need-to-warn t))) | ||
| 193 | (setq search-end (point)))))))) | ||
| 189 | ;; don't signal an error in a write-file-hook | 194 | ;; don't signal an error in a write-file-hook |
| 190 | (message "time-stamp-start or time-stamp-end is not a string") | 195 | (message "time-stamp-start or time-stamp-end is not a string") |
| 191 | (sit-for 1)) | 196 | (sit-for 1)) |
| @@ -231,6 +236,12 @@ With arg, turn time stamping on if and only if arg is positive." | |||
| 231 | (defconst time-stamp-weekday-full-names | 236 | (defconst time-stamp-weekday-full-names |
| 232 | ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]) | 237 | ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]) |
| 233 | 238 | ||
| 239 | (defconst time-stamp-am-pm '("am" "pm") | ||
| 240 | "List of strings used to denote morning and afternoon.") | ||
| 241 | |||
| 242 | (defconst time-stamp-no-file "(no file)" | ||
| 243 | "String to use when the buffer is not associated with a file.") | ||
| 244 | |||
| 234 | (defun time-stamp-strftime (format &optional time) | 245 | (defun time-stamp-strftime (format &optional time) |
| 235 | "Uses a FORMAT to format date, time, file, and user information. | 246 | "Uses a FORMAT to format date, time, file, and user information. |
| 236 | Optional second argument TIME will be used instead of the current time. | 247 | Optional second argument TIME will be used instead of the current time. |
| @@ -328,8 +339,8 @@ of the format string." | |||
| 328 | (eq cur-char ?P)) | 339 | (eq cur-char ?P)) |
| 329 | (let ((name | 340 | (let ((name |
| 330 | (if (> 12 (string-to-int (substring time-string 11 13))) | 341 | (if (> 12 (string-to-int (substring time-string 11 13))) |
| 331 | "am" | 342 | (car time-stamp-am-pm) |
| 332 | "pm"))) | 343 | (car (cdr time-stamp-am-pm))))) |
| 333 | (if (eq cur-char ?p) | 344 | (if (eq cur-char ?p) |
| 334 | name | 345 | name |
| 335 | (upcase name)))) | 346 | (upcase name)))) |
| @@ -351,10 +362,10 @@ of the format string." | |||
| 351 | ((eq cur-char ?f) ;buffer-file-name, base name only | 362 | ((eq cur-char ?f) ;buffer-file-name, base name only |
| 352 | (if buffer-file-name | 363 | (if buffer-file-name |
| 353 | (file-name-nondirectory buffer-file-name) | 364 | (file-name-nondirectory buffer-file-name) |
| 354 | "(no file)")) | 365 | time-stamp-no-file)) |
| 355 | ((eq cur-char ?F) ;buffer-file-name, full path | 366 | ((eq cur-char ?F) ;buffer-file-name, full path |
| 356 | (or buffer-file-name | 367 | (or buffer-file-name |
| 357 | "(no file)")) | 368 | time-stamp-no-file)) |
| 358 | ((eq cur-char ?s) ;system name | 369 | ((eq cur-char ?s) ;system name |
| 359 | (system-name)) | 370 | (system-name)) |
| 360 | ((eq cur-char ?u) ;user name | 371 | ((eq cur-char ?u) ;user name |
| @@ -386,8 +397,7 @@ of the format string." | |||
| 386 | "Return the name of the host where the user receives mail. | 397 | "Return the name of the host where the user receives mail. |
| 387 | This is the value of `mail-host-address' if bound and a string, | 398 | This is the value of `mail-host-address' if bound and a string, |
| 388 | otherwise the value of `time-stamp-mail-host' (for versions of Emacs | 399 | otherwise the value of `time-stamp-mail-host' (for versions of Emacs |
| 389 | before 19.29) otherwise the value of the function system-name. | 400 | before 19.29) otherwise the value of the function system-name." |
| 390 | This function may be usefully referenced by `time-stamp-format'." | ||
| 391 | (or (and (boundp 'mail-host-address) | 401 | (or (and (boundp 'mail-host-address) |
| 392 | (stringp mail-host-address) | 402 | (stringp mail-host-address) |
| 393 | mail-host-address) | 403 | mail-host-address) |