5 |
|
|
6 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
7 |
|
|
8 |
;; Maintainer's Time-stamp: <2001-09-20 11:57:46 gildea> |
;; Maintainer's Time-stamp: <2003-02-01 09:26:25 gildea> |
9 |
;; Maintainer: Stephen Gildea <gildea@stop.mail-abuse.org> |
;; Maintainer: Stephen Gildea <gildea@stop.mail-abuse.org> |
10 |
;; Keywords: tools |
;; Keywords: tools |
11 |
|
|
28 |
|
|
29 |
;; A template in a file can be updated with a new time stamp when |
;; A template in a file can be updated with a new time stamp when |
30 |
;; you save the file. For example: |
;; you save the file. For example: |
31 |
;; static char *ts = "sdmain.c Time-stamp: <1996-08-13 10:20:51 gildea>"; |
;; static char *ts = "sdmain.c Time-stamp: <2001-08-13 10:20:51 gildea>"; |
32 |
;; See the top of `time-stamp.el' for another example. |
;; See the top of `time-stamp.el' for another example. |
33 |
|
|
34 |
;; To use time-stamping, add this line to your .emacs file: |
;; To use time-stamping, add this line to your .emacs file: |
68 |
%#p `am' or `pm'. %P gives uppercase: `AM' or `PM' |
%#p `am' or `pm'. %P gives uppercase: `AM' or `PM' |
69 |
%02S seconds |
%02S seconds |
70 |
%w day number of week, Sunday is 0 |
%w day number of week, Sunday is 0 |
71 |
%02y 2-digit year: `97' %:y 4-digit year: `1997' |
%02y 2-digit year: `03' %:y 4-digit year: `2003' |
72 |
%z time zone name: `est'. %Z gives uppercase: `EST' |
%z time zone name: `est'. %Z gives uppercase: `EST' |
73 |
|
|
74 |
Non-date items: |
Non-date items: |
91 |
specified, or the : modifier should be used to explicitly request the |
specified, or the : modifier should be used to explicitly request the |
92 |
historical default." |
historical default." |
93 |
:type 'string |
:type 'string |
94 |
:group 'time-stamp) |
:group 'time-stamp |
95 |
|
:version "20.1") |
96 |
|
|
97 |
(defcustom time-stamp-active t |
(defcustom time-stamp-active t |
98 |
"*Non-nil to enable time-stamping of buffers by \\[time-stamp]. |
"*Non-nil to enable time-stamping of buffers by \\[time-stamp]. |
103 |
|
|
104 |
(defcustom time-stamp-warn-inactive t |
(defcustom time-stamp-warn-inactive t |
105 |
"Have \\[time-stamp] warn if a buffer did not get time-stamped. |
"Have \\[time-stamp] warn if a buffer did not get time-stamped. |
106 |
If non-nil, a warning is displayed if `time-stamp-active' disables time |
If non-nil, a warning is displayed if `time-stamp-active' has |
107 |
stamping and the buffer contains a template that would otherwise have |
deactivated time stamping and the buffer contains a template that |
108 |
been updated." |
otherwise would have been updated." |
109 |
:type 'boolean |
:type 'boolean |
110 |
:group 'time-stamp) |
:group 'time-stamp |
111 |
|
:version "19.29") |
112 |
|
|
113 |
(defcustom time-stamp-old-format-warn 'ask |
(defcustom time-stamp-old-format-warn 'ask |
114 |
"Action if `time-stamp-format' is an old-style list. |
"Action if `time-stamp-format' is an old-style list. |
125 |
"If non-nil, a string naming the timezone to be used by \\[time-stamp]. |
"If non-nil, a string naming the timezone to be used by \\[time-stamp]. |
126 |
Format is the same as that used by the environment variable TZ on your system." |
Format is the same as that used by the environment variable TZ on your system." |
127 |
:type '(choice (const nil) string) |
:type '(choice (const nil) string) |
128 |
:group 'time-stamp) |
:group 'time-stamp |
129 |
|
:version "20.1") |
130 |
|
|
131 |
|
|
132 |
;;; Do not change time-stamp-line-limit, time-stamp-start, |
;;; Do not change time-stamp-line-limit, time-stamp-start, |
178 |
|
|
179 |
|
|
180 |
(defvar time-stamp-inserts-lines nil ;Do not change! |
(defvar time-stamp-inserts-lines nil ;Do not change! |
181 |
"Whether time-stamp can change the number of lines in a file. |
"Whether \\[time-stamp] can change the number of lines in a file. |
182 |
If nil, \\[time-stamp] skips as many lines as there are newlines in |
If nil, \\[time-stamp] skips as many lines as there are newlines in |
183 |
`time-stamp-format' before looking for the `time-stamp-end' pattern, |
`time-stamp-format' before looking for the `time-stamp-end' pattern, |
184 |
thus it tries not to change the number of lines in the buffer. |
thus it tries not to change the number of lines in the buffer. |
195 |
|
|
196 |
(defvar time-stamp-count 1 ;Do not change! |
(defvar time-stamp-count 1 ;Do not change! |
197 |
"How many templates \\[time-stamp] will look for in a buffer. |
"How many templates \\[time-stamp] will look for in a buffer. |
198 |
The same time-stamp will be written in each case. |
The same time stamp will be written in each case. |
199 |
|
|
200 |
Do not change `time-stamp-count' for yourself or you will be |
Do not change `time-stamp-count' for yourself or you will be |
201 |
incompatible with other people's files! If you must change it for |
incompatible with other people's files! If you must change it for |
203 |
time-stamped file itself.") |
time-stamped file itself.") |
204 |
|
|
205 |
|
|
206 |
(defvar time-stamp-pattern "%%" ;Do not change! |
(defvar time-stamp-pattern nil ;Do not change! |
207 |
"Convenience variable setting all `time-stamp' location and format values. |
"Convenience variable setting all `time-stamp' location and format values. |
208 |
This string has four parts, each of which is optional. |
This string has four parts, each of which is optional. |
209 |
These four parts set `time-stamp-line-limit', `time-stamp-start', |
These four parts set `time-stamp-line-limit', `time-stamp-start', |
212 |
|
|
213 |
The first part is a number followed by a slash; the number sets the number |
The first part is a number followed by a slash; the number sets the number |
214 |
of lines at the beginning (negative counts from end) of the file searched |
of lines at the beginning (negative counts from end) of the file searched |
215 |
for the time-stamp. The number and the slash may be omitted to use the |
for the time stamp. The number and the slash may be omitted to use the |
216 |
normal value. |
normal value. |
217 |
|
|
218 |
The second part is a regexp identifying the pattern preceding the time stamp. |
The second part is a regexp identifying the pattern preceding the time stamp. |
219 |
This part may be omitted to use the normal pattern. |
This part may be omitted to use the normal pattern. |
220 |
|
|
221 |
The third part specifies the format of the time-stamp inserted. See |
The third part specifies the format of the time stamp inserted. See |
222 |
the documentation for `time-stamp-format' for details. Specify this |
the documentation for `time-stamp-format' for details. Specify this |
223 |
part as \"%%\" to use the normal format. |
part as \"%%\" to use the normal format. |
224 |
|
|
225 |
The fourth part is a regexp identifying the pattern following the time stamp. |
The fourth part is a regexp identifying the pattern following the time stamp. |
226 |
This part may be omitted to use the normal pattern. |
This part may be omitted to use the normal pattern. |
227 |
|
|
228 |
As an example, the default behavior can be specified something like this: |
Examples: |
229 |
\"8/Time-stamp: [\\\"<]%:y-%02m-%02d %02H:%02M:%02S %u[\\\">]\" |
\"-10/\" |
230 |
|
\"-9/^Last modified: %%$\" |
231 |
|
\"@set Time-stamp: %:b %:d, %:y$\" |
232 |
|
\"newcommand{\\\\\\\\timestamp}{%%}\" |
233 |
|
|
234 |
Do not change `time-stamp-pattern' for yourself or you will be incompatible |
Do not change `time-stamp-pattern' for yourself or you will be incompatible |
235 |
with other people's files! Set it only in the local variables section |
with other people's files! Set it only in the local variables section |
248 |
Time-stamp: <> |
Time-stamp: <> |
249 |
Time-stamp: \" \" |
Time-stamp: \" \" |
250 |
The time stamp is written between the brackets or quotes: |
The time stamp is written between the brackets or quotes: |
251 |
Time-stamp: <1998-02-18 10:20:51 gildea> |
Time-stamp: <2001-02-18 10:20:51 gildea> |
252 |
The time stamp is updated only if the variable `time-stamp-active' is non-nil. |
The time stamp is updated only if the variable `time-stamp-active' is non-nil. |
253 |
The format of the time stamp is set by the variable `time-stamp-format'. |
The format of the time stamp is set by the variable `time-stamp-format'. |
254 |
The variables `time-stamp-line-limit', `time-stamp-start', `time-stamp-end', |
The variables `time-stamp-line-limit', `time-stamp-start', `time-stamp-end', |
266 |
search-limit) |
search-limit) |
267 |
(if (stringp time-stamp-pattern) |
(if (stringp time-stamp-pattern) |
268 |
(progn |
(progn |
269 |
(string-match "\\`\\(\\(-?[0-9]+\\)/\\)?\\([^%]+\\)?\\(\\(.\\|\n\\)*%[-.,:@+_ #^()0-9]*[A-Za-z%]\\)?\\([^%]+\\)?\\'" time-stamp-pattern) |
(string-match "\\`\\(\\(-?[0-9]+\\)/\\)?\\([^%]+\\)?\\(\\(%[-.,:@+_ #^()0-9]*[A-Za-z%][^%]*\\)*%[-.,:@+_ #^()0-9]*[A-Za-z%]\\)?\\([^%]+\\)?\\'" time-stamp-pattern) |
270 |
(and (match-beginning 2) |
(and (match-beginning 2) |
271 |
(setq line-limit |
(setq line-limit |
272 |
(string-to-int (match-string 2 time-stamp-pattern)))) |
(string-to-int (match-string 2 time-stamp-pattern)))) |
323 |
|
|
324 |
(defun time-stamp-once (start search-limit ts-start ts-end |
(defun time-stamp-once (start search-limit ts-start ts-end |
325 |
ts-format format-lines end-lines) |
ts-format format-lines end-lines) |
326 |
"Update one time-stamp. Internal routine called by \\[time-stamp]. |
"Update one time stamp. Internal routine called by \\[time-stamp]. |
327 |
Returns the end point, which is where `time-stamp' begins the next search." |
Returns the end point, which is where `time-stamp' begins the next search." |
328 |
(let ((case-fold-search nil) |
(let ((case-fold-search nil) |
329 |
(end nil) |
(end nil) |
390 |
;;;###autoload |
;;;###autoload |
391 |
(defun time-stamp-toggle-active (&optional arg) |
(defun time-stamp-toggle-active (&optional arg) |
392 |
"Toggle `time-stamp-active', setting whether \\[time-stamp] updates a buffer. |
"Toggle `time-stamp-active', setting whether \\[time-stamp] updates a buffer. |
393 |
With arg, turn time stamping on if and only if arg is positive." |
With ARG, turn time stamping on if and only if arg is positive." |
394 |
(interactive "P") |
(interactive "P") |
395 |
(setq time-stamp-active |
(setq time-stamp-active |
396 |
(if (null arg) |
(if (null arg) |
410 |
(let ((ts-real-time-zone (getenv "TZ"))) |
(let ((ts-real-time-zone (getenv "TZ"))) |
411 |
(unwind-protect |
(unwind-protect |
412 |
(progn |
(progn |
413 |
(setenv "TZ" time-stamp-time-zone) |
(set-time-zone-rule time-stamp-time-zone) |
414 |
(format-time-string |
(format-time-string |
415 |
(time-stamp-string-preprocess ts-format))) |
(time-stamp-string-preprocess ts-format))) |
416 |
(setenv "TZ" ts-real-time-zone))) |
(set-time-zone-rule ts-real-time-zone))) |
417 |
(format-time-string |
(format-time-string |
418 |
(time-stamp-string-preprocess ts-format))) |
(time-stamp-string-preprocess ts-format))) |
419 |
;; handle version 1 compatibility |
;; handle version 1 compatibility |
448 |
"Use a FORMAT to format date, time, file, and user information. |
"Use a FORMAT to format date, time, file, and user information. |
449 |
Optional second argument TIME is only for testing. |
Optional second argument TIME is only for testing. |
450 |
Implements non-time extensions to `format-time-string' |
Implements non-time extensions to `format-time-string' |
451 |
and all time-stamp-format compatibility." |
and all `time-stamp-format' compatibility." |
452 |
(let ((fmt-len (length format)) |
(let ((fmt-len (length format)) |
453 |
(ind 0) |
(ind 0) |
454 |
cur-char |
cur-char |
635 |
|
|
636 |
|
|
637 |
(defun time-stamp-conv-warn (old-form new-form) |
(defun time-stamp-conv-warn (old-form new-form) |
638 |
"Display a warning about a soon-to-be-obsolete format." |
"Display a warning about a soon-to-be-obsolete format. |
639 |
|
Suggests replacing OLD-FORM with NEW-FORM." |
640 |
(cond |
(cond |
641 |
(time-stamp-conversion-warn |
(time-stamp-conversion-warn |
642 |
(save-excursion |
(save-excursion |
686 |
|
|
687 |
;;; Some functions used in time-stamp-format |
;;; Some functions used in time-stamp-format |
688 |
|
|
689 |
;;; Could generate most of a message-id with |
;;; These functions have been obsolete since 1995 |
690 |
;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" time-stamp-mail-host-name) |
;;; and will be removed in Emacs 22. |
691 |
|
;;; Meanwhile, discourage other packages from using them. |
692 |
|
(let ((obsolete-functions '(time-stamp-month-dd-yyyy |
693 |
|
time-stamp-dd/mm/yyyy |
694 |
|
time-stamp-mon-dd-yyyy |
695 |
|
time-stamp-dd-mon-yy |
696 |
|
time-stamp-yy/mm/dd |
697 |
|
time-stamp-yyyy/mm/dd |
698 |
|
time-stamp-yyyy-mm-dd |
699 |
|
time-stamp-yymmdd |
700 |
|
time-stamp-hh:mm:ss |
701 |
|
time-stamp-hhmm))) |
702 |
|
(while obsolete-functions |
703 |
|
(make-obsolete (car obsolete-functions) |
704 |
|
"use time-stamp-string or format-time-string instead." |
705 |
|
"20.1") |
706 |
|
(setq obsolete-functions (cdr obsolete-functions)))) |
707 |
|
|
708 |
;;; pretty form, suitable for a title page |
;;; pretty form, suitable for a title page |
709 |
|
|