diff options
| author | Stephen Gildea | 2024-11-02 09:42:25 -0700 |
|---|---|---|
| committer | Stephen Gildea | 2024-11-02 09:45:09 -0700 |
| commit | d245fb3964dcb404dc35a6f985c473f1ca879b33 (patch) | |
| tree | 34a025777b8a42f081a87fee536f80e170d0e01e /doc | |
| parent | 435d7d4292e6803405c1ea65c73693f20eea2a58 (diff) | |
| download | emacs-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.texi | 83 |
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 | ||
| 1002 | You can arrange to put a time stamp in a file, so that it is updated | 1002 | You can arrange to have a time stamp in a file be updated |
| 1003 | automatically each time you edit and save the file. The time stamp | 1003 | automatically each time you save the file. |
| 1004 | must 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.) |
| 1005 | like this: | 1005 | Having a time stamp in the text of a file ensures that the time the file |
| 1006 | was written will be preserved even if the file is copied or transformed | ||
| 1007 | in a way that loses the file system's modification time. | ||
| 1008 | |||
| 1009 | 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. | ||
| 1012 | The template looks like this: | ||
| 1006 | 1013 | ||
| 1007 | @example | 1014 | @example |
| 1008 | Time-stamp: <> | 1015 | Time-stamp: <> |
| 1009 | @end example | 1016 | @end example |
| 1010 | 1017 | ||
| 1011 | @noindent | 1018 | @noindent |
| 1012 | or like this: | 1019 | or (your choice) like this: |
| 1013 | 1020 | ||
| 1014 | @example | 1021 | @example |
| 1015 | Time-stamp: " " | 1022 | Time-stamp: " " |
| 1016 | @end example | 1023 | @end example |
| 1017 | 1024 | ||
| 1025 | @noindent | ||
| 1026 | When time-stamping, Emacs will write the current time, date, and/or | ||
| 1027 | other 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 | 1030 | Second, add the function @code{time-stamp} |
| 1020 | @code{before-save-hook} (@pxref{Hooks}). When you save the file, this | 1031 | to @code{before-save-hook} (@pxref{Hooks}). |
| 1021 | function then automatically updates the time stamp with the current | 1032 | To do this, either customize the option @code{before-save-hook} |
| 1022 | date and time. You can also use the command @kbd{M-x time-stamp} to | 1033 | (with @kbd{M-x customize-option}, @pxref{Specific Customization}) |
| 1023 | update the time stamp manually. By default the time stamp is | 1034 | or edit your init file adding this line: |
| 1035 | |||
| 1036 | @example | ||
| 1037 | (add-hook 'before-save-hook 'time-stamp) | ||
| 1038 | @end example | ||
| 1039 | |||
| 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: | ||
| 1043 | |||
| 1044 | @example | ||
| 1045 | eval: (add-hook 'before-save-hook 'time-stamp nil t) | ||
| 1046 | @end example | ||
| 1047 | |||
| 1048 | To update the current buffer's time stamp once | ||
| 1049 | immediately, use the command @kbd{M-x time-stamp}. | ||
| 1050 | |||
| 1051 | @vindex time-stamp-pattern | ||
| 1052 | 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. | ||
| 1057 | As 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 | ||
| 1064 | then the following at the end of the file tells @code{time-stamp} how to | ||
| 1065 | identify 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 | ||
| 1076 | By default the time stamp is | ||
| 1024 | formatted according to your locale setting (@pxref{Environment}) and | 1077 | formatted according to your locale setting (@pxref{Environment}) and |
| 1025 | time zone (@pxref{Time of Day,,, elisp, The Emacs Lisp Reference | 1078 | time zone (@pxref{Time of Day,,, elisp, The Emacs Lisp Reference |
| 1026 | Manual}). For customizations, see the Custom group @code{time-stamp}. | 1079 | Manual}). |
| 1080 | See the built-in documentation for the variable @code{time-stamp-format} | ||
| 1081 | for specifics and other variables that affect the formatting. | ||
| 1082 | |||
| 1083 | For 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 |