mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
; 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.
This commit is contained in:
parent
638ec3cd66
commit
7527e39549
3 changed files with 88 additions and 37 deletions
|
|
@ -486,6 +486,11 @@ Backup Files
|
||||||
* Backup Deletion:: Emacs deletes excess numbered backups.
|
* Backup Deletion:: Emacs deletes excess numbered backups.
|
||||||
* Backup Copying:: Backups can be made by copying or renaming.
|
* 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
|
@ifnottex
|
||||||
Auto Reverting Non-File Buffers
|
Auto Reverting Non-File Buffers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1007,8 +1007,8 @@ was written will be preserved even if the file is copied or transformed
|
||||||
in a way that loses the file system's modification time.
|
in a way that loses the file system's modification time.
|
||||||
|
|
||||||
There are two steps to setting up automatic time stamping.
|
There are two steps to setting up automatic time stamping.
|
||||||
First, you need to have a time stamp template
|
First, the file needs a time stamp template
|
||||||
somewhere in the first eight lines of the file.
|
somewhere in the first eight lines.
|
||||||
The template looks like this:
|
The template looks like this:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
|
|
@ -1022,59 +1022,81 @@ or (your choice) like this:
|
||||||
Time-stamp: " "
|
Time-stamp: " "
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@noindent
|
|
||||||
When time-stamping, Emacs will write the current time, date, and/or
|
|
||||||
other info between the brackets or quotes.
|
|
||||||
|
|
||||||
@findex time-stamp
|
@findex time-stamp
|
||||||
Second, add the function @code{time-stamp}
|
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}).
|
to @code{before-save-hook} (@pxref{Hooks}).
|
||||||
To do this, either customize the option @code{before-save-hook}
|
You can either customize the option @code{before-save-hook}
|
||||||
(with @kbd{M-x customize-option}, @pxref{Specific Customization})
|
(with @kbd{M-x customize-option}, @pxref{Specific Customization}),
|
||||||
or edit your init file adding this line:
|
or you can edit your init file adding this line:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
(add-hook 'before-save-hook 'time-stamp)
|
(add-hook 'before-save-hook 'time-stamp)
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
To enable automatic time-stamping for only a specific file, add the
|
@menu
|
||||||
following line to a local variables list
|
* Time Stamp Customization:: How to customize with time-stamp-pattern.
|
||||||
(@pxref{Specifying File Variables}) near the end of the file:
|
* Time Stamps for One File:: Ensure automatic time-stamp of a specific file.
|
||||||
|
@end menu
|
||||||
|
|
||||||
@example
|
@node Time Stamp Customization
|
||||||
eval: (add-hook 'before-save-hook 'time-stamp nil t)
|
@subsubsection Customizing the Time Stamp
|
||||||
@end example
|
|
||||||
|
|
||||||
To update the current buffer's time stamp once
|
|
||||||
immediately, use the command @kbd{M-x time-stamp}.
|
|
||||||
|
|
||||||
@vindex time-stamp-pattern
|
@vindex time-stamp-pattern
|
||||||
To customize the time stamp in a particular file, set the
|
To customize the time stamp in a particular file, set the
|
||||||
variable @code{time-stamp-pattern} in that file's local variables list.
|
variable @code{time-stamp-pattern} in that file's local variables
|
||||||
You can change where the time stamp starts and ends and how the dynamic
|
list (@pxref{Specifying File Variables}).
|
||||||
information is to be formatted; see the variable's built-in
|
You can change what pattern @code{time-stamp} will match against to
|
||||||
documentation for details.
|
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:
|
As a simple example, if this line occurs near the top of a file:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
\newcommand@{\yearpublished@}@{@}
|
publishing_year_and_city = "Published nnnn in Boston, Mass.";
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
then the following at the end of the file tells @code{time-stamp} how to
|
then the following comment at the end of the same file tells
|
||||||
identify and update that custom template:
|
@code{time-stamp} how to identify and update that custom template:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
%% Local variables:
|
// Local variables:
|
||||||
%% time-stamp-pattern: "@{.yearpublished@}@{%Y@}"
|
// time-stamp-pattern: "Published %Y in Boston"
|
||||||
%% End:
|
// End:
|
||||||
@end group
|
@end group
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
Here is another example, with the time stamp inserted into the last
|
This pattern says that the text before the start of the time stamp is
|
||||||
paragraph of an HTML document. The @code{%%} in the pattern asks for
|
``Published '', and the text after the end is `` in Boston''.
|
||||||
the default format.
|
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
|
@example
|
||||||
@r{@dots{}}
|
@r{@dots{}}
|
||||||
|
|
@ -1096,7 +1118,29 @@ Manual}).
|
||||||
See the built-in documentation for the variable @code{time-stamp-format}
|
See the built-in documentation for the variable @code{time-stamp-format}
|
||||||
for specifics and other variables that affect the formatting.
|
for specifics and other variables that affect the formatting.
|
||||||
|
|
||||||
For customizations, see the Custom group @code{time-stamp}.
|
@node Time Stamps for One File
|
||||||
|
@subsubsection Forcing Time Stamps for One File
|
||||||
|
|
||||||
|
If you are working on a file with multiple authors, and you cannot
|
||||||
|
be sure the other authors have enabled time-stamping globally in
|
||||||
|
their Emacs init files, you can force it to be enabled for a
|
||||||
|
particular file by adding @code{time-stamp} to that buffer's
|
||||||
|
@code{before-save-hook} in that file's local variables list.
|
||||||
|
To extend one of the previous examples:
|
||||||
|
|
||||||
|
@example
|
||||||
|
@group
|
||||||
|
// Local variables:
|
||||||
|
// eval: (add-hook 'before-save-hook 'time-stamp nil t)
|
||||||
|
// time-stamp-pattern: "year_published = \"%Y\""
|
||||||
|
// End:
|
||||||
|
@end group
|
||||||
|
@end example
|
||||||
|
|
||||||
|
@noindent
|
||||||
|
Although this example shows them both set together,
|
||||||
|
you can use @code{eval} without also setting @code{time-stamp-pattern}
|
||||||
|
if you like the default pattern.
|
||||||
|
|
||||||
@node Reverting
|
@node Reverting
|
||||||
@section Reverting a Buffer
|
@section Reverting a Buffer
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,7 @@ This part may be omitted to use the value of `time-stamp-end'.
|
||||||
|
|
||||||
The pattern does not need to match the entire line of the time stamp.
|
The pattern does not need to match the entire line of the time stamp.
|
||||||
The pattern will update time stamp information on multiple lines if the
|
The pattern will update time stamp information on multiple lines if the
|
||||||
pattern includes newlines, written as \"\\n\".
|
pattern includes newlines, which can be written as \"\\n\".
|
||||||
|
|
||||||
These variables are best changed with file-local variables.
|
These variables are best changed with file-local variables.
|
||||||
If you were to change `time-stamp-pattern', `time-stamp-line-limit',
|
If you were to change `time-stamp-pattern', `time-stamp-line-limit',
|
||||||
|
|
@ -307,7 +307,8 @@ Examples:
|
||||||
// time-stamp-pattern: \"10/Author %L\\nRevised %-d %b %Y$\"
|
// time-stamp-pattern: \"10/Author %L\\nRevised %-d %b %Y$\"
|
||||||
(sets all four variables and updates text on two lines)
|
(sets all four variables and updates text on two lines)
|
||||||
|
|
||||||
See Info node `Time Stamps' for more examples.
|
See Info node `Time Stamp Customization' for more discussion and more
|
||||||
|
in-depth examples.
|
||||||
|
|
||||||
|
|
||||||
See also `time-stamp-count' and `time-stamp-inserts-lines'.")
|
See also `time-stamp-count' and `time-stamp-inserts-lines'.")
|
||||||
|
|
@ -318,8 +319,8 @@ See also `time-stamp-count' and `time-stamp-inserts-lines'.")
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun time-stamp ()
|
(defun time-stamp ()
|
||||||
"Update any time stamp strings (timestamps) in the buffer.
|
"Update any time stamp strings (timestamps) in the buffer.
|
||||||
Look for a time stamp template and update it with the current date,
|
Look for a time stamp template and update it with the current
|
||||||
time, and/or other info.
|
date, time, author, and/or other info.
|
||||||
|
|
||||||
The template, which you manually create on one of the first 8 lines
|
The template, which you manually create on one of the first 8 lines
|
||||||
of the file before running this function, by default can look like
|
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'."
|
||||||
;;; five years.
|
;;; five years.
|
||||||
;;; The : modifier is a temporary conversion feature used to resolve
|
;;; The : modifier is a temporary conversion feature used to resolve
|
||||||
;;; ambiguous formats--formats that are changing (over time) incompatibly.
|
;;; ambiguous formats--formats that are changing (over time) incompatibly.
|
||||||
|
|
||||||
(defun time-stamp-string-preprocess (format &optional time)
|
(defun time-stamp-string-preprocess (format &optional time)
|
||||||
"Use a FORMAT to format date, time, file, and user information.
|
"Use a FORMAT to format date, time, file, and user information.
|
||||||
Optional second argument TIME is only for testing.
|
Optional second argument TIME is only for testing.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue