@@ -1007,8 +1007,8 @@ was written will be preserved even if the file is copied or transformed
10071007in a way that loses the file system's modification time.
10081008
10091009There 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.
10121012The template looks like this:
10131013
10141014@example
@@ -1022,59 +1022,81 @@ or (your choice) like this:
10221022Time-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
10521058To 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+
10571066As 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}).
10961118See the built-in documentation for the variable @code {time-stamp-format }
10971119for 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
0 commit comments