diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi index a81c7134a70..d8ca41d737e 100644 --- a/doc/emacs/emacs.texi +++ b/doc/emacs/emacs.texi @@ -486,6 +486,11 @@ Backup Files * Backup Deletion:: Emacs deletes excess numbered backups. * Backup Copying:: Backups can be made by copying or renaming. +Updating Time Stamps Automatically + +* Time Stamp Customization:: How to customize with time-stamp-pattern. +* Time Stamps for One File:: Ensure automatic time-stamp of a specific file. + @ifnottex Auto Reverting Non-File Buffers diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index c04ac685ee0..2a7017779f6 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -411,7 +411,7 @@ that was visited in the buffer. * Interlocking:: How Emacs protects against simultaneous editing of one file by two users. * Shadowing: File Shadowing. Copying files to ``shadows'' automatically. -* Time Stamps:: Emacs can update time stamps on saved files. +* Time Stamps:: Emacs can update time stamps when a file is saved. @end menu @node Save Commands @@ -992,35 +992,152 @@ File Shadowing is not available on MS Windows. @node Time Stamps @subsection Updating Time Stamps Automatically -@cindex time stamps +@cindex time stamps, automatic file timestamps @cindex modification dates -@cindex locale, date format +@cindex last modified time -You can arrange to put a time stamp in a file, so that it is updated -automatically each time you edit and save the file. The time stamp -must be in the first eight lines of the file, and you should insert it -like this: +You can arrange to have a time stamp in a file be updated +automatically each time you save the file. +(A time stamp may also be called a date stamp or a last modified time.) +Having a time stamp in the text of a file ensures that the time the file +was written will be preserved even if the file is copied or transformed +in a way that loses the file system's modification time. + +There are two steps to setting up automatic time stamping. +First, the file needs a time stamp template +somewhere in the first eight lines. +The template looks like this: @example Time-stamp: <> @end example @noindent -or like this: +or (your choice) like this: @example Time-stamp: " " @end example @findex time-stamp - Then add the function @code{time-stamp} to the hook -@code{before-save-hook} (@pxref{Hooks}). When you save the file, this -function then automatically updates the time stamp with the current -date and time. You can also use the command @kbd{M-x time-stamp} to -update the time stamp manually. By default the time stamp is +With that template in place, you can update the current buffer's time +stamp once immediately with the command @kbd{M-x time-stamp}. +Emacs will check for a template; if a template is found, +Emacs will write the current date, time, author, and/or +other info between the brackets or quotes. +(If the buffer has no template, @code{time-stamp} does nothing.) +After the first time stamp, the line might look like this: + +@example +Time-stamp: <1993-07-06 11:05:14 terryg> +@end example + +Second, configure Emacs to run @code{time-stamp} any time it saves a +file, by adding @code{time-stamp} +to @code{before-save-hook} (@pxref{Hooks}). +You can either customize the option @code{before-save-hook} +(with @kbd{M-x customize-option}, @pxref{Specific Customization}), +or you can edit your init file adding this line: + +@example +(add-hook 'before-save-hook 'time-stamp) +@end example + +@menu +* Time Stamp Customization:: How to customize with time-stamp-pattern. +* Time Stamps for One File:: Ensure automatic time-stamp of a specific file. +@end menu + +@node Time Stamp Customization +@subsubsection Customizing the Time Stamp + +@vindex time-stamp-pattern +To customize the time stamp in a particular file, set the +variable @code{time-stamp-pattern} in that file's local variables +list (@pxref{Specifying File Variables}). +You can change what pattern @code{time-stamp} will match against to +identify a template and where in the file to look for the pattern using +@code{time-stamp-pattern}; for details, see the variable's built-in +documentation (with @kbd{C-h v}, @pxref{Name Help}). + +As a simple example, if this line occurs near the top of a file: + +@example +publishing_year_and_city = "Published nnnn in Boston, Mass."; +@end example + +@noindent +then the following comment at the end of the same file tells +@code{time-stamp} how to identify and update that custom template: + +@example +@group +// Local variables: +// time-stamp-pattern: "Published %Y in Boston" +// End: +@end group +@end example + +This pattern says that the text before the start of the time stamp is +``Published '', and the text after the end is `` in Boston''. +If @code{time-stamp} finds both in one of the first eight lines, +what is between will be replaced by the current year, as requested by +the @code{%Y} format. + +After any change to file-local variables, +type @kbd{M-x normal-mode} to re-read them. + +Here is another example, with the time stamp inserted into +the last paragraph of an HTML document. +Since this template is at the end of the document, not in the first +eight lines, @code{time-stamp-format} starts with @code{-10/} to tell +@code{time-stamp} to look at the last 10 lines. +The @code{%%} asks for the default format +(specified by @code{time-stamp-format}). + +@example +@r{@dots{}} +
Last modified:
+