aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorStephen Gildea2024-11-02 09:42:25 -0700
committerStephen Gildea2024-11-02 09:45:09 -0700
commitd245fb3964dcb404dc35a6f985c473f1ca879b33 (patch)
tree34a025777b8a42f081a87fee536f80e170d0e01e /doc
parent435d7d4292e6803405c1ea65c73693f20eea2a58 (diff)
downloademacs-d245fb3964dcb404dc35a6f985c473f1ca879b33.tar.gz
emacs-d245fb3964dcb404dc35a6f985c473f1ca879b33.zip
Expand manual section on Time Stamps
* doc/emacs/files.texi (Time Stamps): Add examples of enabling time stamping with add-hook and setting time-stamp-pattern as a file-local variable.
Diffstat (limited to 'doc')
-rw-r--r--doc/emacs/files.texi83
1 files changed, 70 insertions, 13 deletions
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 86b85f16d69..e732911b98f 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -411,7 +411,7 @@ that was visited in the buffer.
411* Interlocking:: How Emacs protects against simultaneous editing 411* Interlocking:: How Emacs protects against simultaneous editing
412 of one file by two users. 412 of one file by two users.
413* Shadowing: File Shadowing. Copying files to ``shadows'' automatically. 413* Shadowing: File Shadowing. Copying files to ``shadows'' automatically.
414* Time Stamps:: Emacs can update time stamps on saved files. 414* Time Stamps:: Emacs can update time stamps when a file is saved.
415@end menu 415@end menu
416 416
417@node Save Commands 417@node Save Commands
@@ -997,33 +997,90 @@ File Shadowing is not available on MS Windows.
997@subsection Updating Time Stamps Automatically 997@subsection Updating Time Stamps Automatically
998@cindex time stamps 998@cindex time stamps
999@cindex modification dates 999@cindex modification dates
1000@cindex locale, date format 1000@cindex last modified time
1001 1001
1002You can arrange to put a time stamp in a file, so that it is updated 1002You can arrange to have a time stamp in a file be updated
1003automatically each time you edit and save the file. The time stamp 1003automatically each time you save the file.
1004must be in the first eight lines of the file, and you should insert it 1004(A time stamp may also be called a date stamp or a last modified time.)
1005like this: 1005Having a time stamp in the text of a file ensures that the time the file
1006was written will be preserved even if the file is copied or transformed
1007in a way that loses the file system's modification time.
1008
1009There are two steps to setting up automatic time stamping.
1010First, you need to have a time stamp template
1011somewhere in the first eight lines of the file.
1012The template looks like this:
1006 1013
1007@example 1014@example
1008Time-stamp: <> 1015Time-stamp: <>
1009@end example 1016@end example
1010 1017
1011@noindent 1018@noindent
1012or like this: 1019or (your choice) like this:
1013 1020
1014@example 1021@example
1015Time-stamp: " " 1022Time-stamp: " "
1016@end example 1023@end example
1017 1024
1025@noindent
1026When time-stamping, Emacs will write the current time, date, and/or
1027other info between the brackets or quotes.
1028
1018@findex time-stamp 1029@findex time-stamp
1019 Then add the function @code{time-stamp} to the hook 1030Second, add the function @code{time-stamp}
1020@code{before-save-hook} (@pxref{Hooks}). When you save the file, this 1031to @code{before-save-hook} (@pxref{Hooks}).
1021function then automatically updates the time stamp with the current 1032To do this, either customize the option @code{before-save-hook}
1022date and time. You can also use the command @kbd{M-x time-stamp} to 1033(with @kbd{M-x customize-option}, @pxref{Specific Customization})
1023update the time stamp manually. By default the time stamp is 1034or edit your init file adding this line:
1035
1036@example
1037(add-hook 'before-save-hook 'time-stamp)
1038@end example
1039
1040To enable automatic time-stamping for only a specific file, add the
1041following line to a local variables list
1042(@pxref{Specifying File Variables}) near the end of the file:
1043
1044@example
1045eval: (add-hook 'before-save-hook 'time-stamp nil t)
1046@end example
1047
1048To update the current buffer's time stamp once
1049immediately, use the command @kbd{M-x time-stamp}.
1050
1051@vindex time-stamp-pattern
1052To customize the time stamp in a particular file, set the
1053variable @code{time-stamp-pattern} in that file's local variables list.
1054You can change where the time stamp starts and ends and how the dynamic
1055information is to be formatted; see the variable's built-in
1056documentation for details.
1057As a simple example, if this line occurs near the top of a file:
1058
1059@example
1060\newcommand@{\yearpublished@}@{@}
1061@end example
1062
1063@noindent
1064then the following at the end of the file tells @code{time-stamp} how to
1065identify and update that custom template:
1066
1067@example
1068@group
1069%% Local variables:
1070%% time-stamp-pattern: "@{.yearpublished@}@{%Y@}"
1071%% End:
1072@end group
1073@end example
1074
1075@vindex time-stamp-format
1076By default the time stamp is
1024formatted according to your locale setting (@pxref{Environment}) and 1077formatted according to your locale setting (@pxref{Environment}) and
1025time zone (@pxref{Time of Day,,, elisp, The Emacs Lisp Reference 1078time zone (@pxref{Time of Day,,, elisp, The Emacs Lisp Reference
1026Manual}). For customizations, see the Custom group @code{time-stamp}. 1079Manual}).
1080See the built-in documentation for the variable @code{time-stamp-format}
1081for specifics and other variables that affect the formatting.
1082
1083For customizations, see the Custom group @code{time-stamp}.
1027 1084
1028@node Reverting 1085@node Reverting
1029@section Reverting a Buffer 1086@section Reverting a Buffer