Skip to content

Commit 7527e39

Browse files
author
Stephen Gildea
committed
; Time Stamps doc: expand the explanation of the examples
* doc/emacs/files.texi (Time Stamps): Divide into three sections. * doc/emacs/emacs.texi: Add new nodes to menu. * lisp/time-stamp.el: Change reference to new node.
1 parent 638ec3c commit 7527e39

File tree

3 files changed

+87
-36
lines changed

3 files changed

+87
-36
lines changed

doc/emacs/emacs.texi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ Backup Files
486486
* Backup Deletion:: Emacs deletes excess numbered backups.
487487
* Backup Copying:: Backups can be made by copying or renaming.
488488
489+
Updating Time Stamps Automatically
490+
491+
* Time Stamp Customization:: How to customize with time-stamp-pattern.
492+
* Time Stamps for One File:: Ensure automatic time-stamp of a specific file.
493+
489494
@ifnottex
490495
Auto Reverting Non-File Buffers
491496

doc/emacs/files.texi

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ was written will be preserved even if the file is copied or transformed
10071007
in a way that loses the file system's modification time.
10081008

10091009
There are two steps to setting up automatic time stamping.
1010-
First, you need to have a time stamp template
1011-
somewhere in the first eight lines of the file.
1010+
First, the file needs a time stamp template
1011+
somewhere in the first eight lines.
10121012
The template looks like this:
10131013

10141014
@example
@@ -1022,59 +1022,81 @@ or (your choice) like this:
10221022
Time-stamp: " "
10231023
@end example
10241024

1025-
@noindent
1026-
When time-stamping, Emacs will write the current time, date, and/or
1027-
other info between the brackets or quotes.
1028-
10291025
@findex time-stamp
1030-
Second, add the function @code{time-stamp}
1031-
to @code{before-save-hook} (@pxref{Hooks}).
1032-
To do this, either customize the option @code{before-save-hook}
1033-
(with @kbd{M-x customize-option}, @pxref{Specific Customization})
1034-
or edit your init file adding this line:
1026+
With that template in place, you can update the current buffer's time
1027+
stamp once immediately with the command @kbd{M-x time-stamp}.
1028+
Emacs will check for a template; if a template is found,
1029+
Emacs will write the current date, time, author, and/or
1030+
other info between the brackets or quotes.
1031+
(If the buffer has no template, @code{time-stamp} does nothing.)
1032+
After the first time stamp, the line might look like this:
10351033

10361034
@example
1037-
(add-hook 'before-save-hook 'time-stamp)
1035+
Time-stamp: <1993-07-06 11:05:14 terryg>
10381036
@end example
10391037

1040-
To enable automatic time-stamping for only a specific file, add the
1041-
following line to a local variables list
1042-
(@pxref{Specifying File Variables}) near the end of the file:
1038+
Second, configure Emacs to run @code{time-stamp} any time it saves a
1039+
file, by adding @code{time-stamp}
1040+
to @code{before-save-hook} (@pxref{Hooks}).
1041+
You can either customize the option @code{before-save-hook}
1042+
(with @kbd{M-x customize-option}, @pxref{Specific Customization}),
1043+
or you can edit your init file adding this line:
10431044

10441045
@example
1045-
eval: (add-hook 'before-save-hook 'time-stamp nil t)
1046+
(add-hook 'before-save-hook 'time-stamp)
10461047
@end example
10471048

1048-
To update the current buffer's time stamp once
1049-
immediately, use the command @kbd{M-x time-stamp}.
1049+
@menu
1050+
* Time Stamp Customization:: How to customize with time-stamp-pattern.
1051+
* Time Stamps for One File:: Ensure automatic time-stamp of a specific file.
1052+
@end menu
1053+
1054+
@node Time Stamp Customization
1055+
@subsubsection Customizing the Time Stamp
10501056

10511057
@vindex time-stamp-pattern
10521058
To customize the time stamp in a particular file, set the
1053-
variable @code{time-stamp-pattern} in that file's local variables list.
1054-
You can change where the time stamp starts and ends and how the dynamic
1055-
information is to be formatted; see the variable's built-in
1056-
documentation for details.
1059+
variable @code{time-stamp-pattern} in that file's local variables
1060+
list (@pxref{Specifying File Variables}).
1061+
You can change what pattern @code{time-stamp} will match against to
1062+
identify a template and where in the file to look for the pattern using
1063+
@code{time-stamp-pattern}; for details, see the variable's built-in
1064+
documentation (with @kbd{C-h v}, @pxref{Name Help}).
1065+
10571066
As a simple example, if this line occurs near the top of a file:
10581067

10591068
@example
1060-
\newcommand@{\yearpublished@}@{@}
1069+
publishing_year_and_city = "Published nnnn in Boston, Mass.";
10611070
@end example
10621071

10631072
@noindent
1064-
then the following at the end of the file tells @code{time-stamp} how to
1065-
identify and update that custom template:
1073+
then the following comment at the end of the same file tells
1074+
@code{time-stamp} how to identify and update that custom template:
10661075

10671076
@example
10681077
@group
1069-
%% Local variables:
1070-
%% time-stamp-pattern: "@{.yearpublished@}@{%Y@}"
1071-
%% End:
1078+
// Local variables:
1079+
// time-stamp-pattern: "Published %Y in Boston"
1080+
// End:
10721081
@end group
10731082
@end example
10741083

1075-
Here is another example, with the time stamp inserted into the last
1076-
paragraph of an HTML document. The @code{%%} in the pattern asks for
1077-
the default format.
1084+
This pattern says that the text before the start of the time stamp is
1085+
``Published '', and the text after the end is `` in Boston''.
1086+
If @code{time-stamp} finds both in one of the first eight lines,
1087+
what is between will be replaced by the current year, as requested by
1088+
the @code{%Y} format.
1089+
1090+
After any change to file-local variables,
1091+
type @kbd{M-x normal-mode} to re-read them.
1092+
1093+
Here is another example, with the time stamp inserted into
1094+
the last paragraph of an HTML document.
1095+
Since this template is at the end of the document, not in the first
1096+
eight lines, @code{time-stamp-format} starts with @code{-10/} to tell
1097+
@code{time-stamp} to look at the last 10 lines.
1098+
The @code{%%} asks for the default format
1099+
(specified by @code{time-stamp-format}).
10781100

10791101
@example
10801102
@r{@dots{}}
@@ -1096,7 +1118,29 @@ Manual}).
10961118
See the built-in documentation for the variable @code{time-stamp-format}
10971119
for specifics and other variables that affect the formatting.
10981120

1099-
For customizations, see the Custom group @code{time-stamp}.
1121+
@node Time Stamps for One File
1122+
@subsubsection Forcing Time Stamps for One File
1123+
1124+
If you are working on a file with multiple authors, and you cannot
1125+
be sure the other authors have enabled time-stamping globally in
1126+
their Emacs init files, you can force it to be enabled for a
1127+
particular file by adding @code{time-stamp} to that buffer's
1128+
@code{before-save-hook} in that file's local variables list.
1129+
To extend one of the previous examples:
1130+
1131+
@example
1132+
@group
1133+
// Local variables:
1134+
// eval: (add-hook 'before-save-hook 'time-stamp nil t)
1135+
// time-stamp-pattern: "year_published = \"%Y\""
1136+
// End:
1137+
@end group
1138+
@end example
1139+
1140+
@noindent
1141+
Although this example shows them both set together,
1142+
you can use @code{eval} without also setting @code{time-stamp-pattern}
1143+
if you like the default pattern.
11001144

11011145
@node Reverting
11021146
@section Reverting a Buffer

lisp/time-stamp.el

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ This part may be omitted to use the value of `time-stamp-end'.
283283
284284
The pattern does not need to match the entire line of the time stamp.
285285
The pattern will update time stamp information on multiple lines if the
286-
pattern includes newlines, written as \"\\n\".
286+
pattern includes newlines, which can be written as \"\\n\".
287287
288288
These variables are best changed with file-local variables.
289289
If you were to change `time-stamp-pattern', `time-stamp-line-limit',
@@ -307,7 +307,8 @@ Examples:
307307
// time-stamp-pattern: \"10/Author %L\\nRevised %-d %b %Y$\"
308308
(sets all four variables and updates text on two lines)
309309
310-
See Info node `Time Stamps' for more examples.
310+
See Info node `Time Stamp Customization' for more discussion and more
311+
in-depth examples.
311312
312313
313314
See also `time-stamp-count' and `time-stamp-inserts-lines'.")
@@ -318,8 +319,8 @@ See also `time-stamp-count' and `time-stamp-inserts-lines'.")
318319
;;;###autoload
319320
(defun time-stamp ()
320321
"Update any time stamp strings (timestamps) in the buffer.
321-
Look for a time stamp template and update it with the current date,
322-
time, and/or other info.
322+
Look for a time stamp template and update it with the current
323+
date, time, author, and/or other info.
323324
324325
The template, which you manually create on one of the first 8 lines
325326
of the file before running this function, by default can look like
@@ -526,6 +527,7 @@ time is used. The time zone is determined by `time-stamp-time-zone'."
526527
;;; five years.
527528
;;; The : modifier is a temporary conversion feature used to resolve
528529
;;; ambiguous formats--formats that are changing (over time) incompatibly.
530+
529531
(defun time-stamp-string-preprocess (format &optional time)
530532
"Use a FORMAT to format date, time, file, and user information.
531533
Optional second argument TIME is only for testing.

0 commit comments

Comments
 (0)