aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-01-19 13:57:16 +0000
committerRichard M. Stallman1994-01-19 13:57:16 +0000
commite1f40b2841d36ba1c61e2343e04717c65677415d (patch)
tree80eaf0ab350923eb6505b760bea3f7a13732217d
parent2ae4152014eb954ba6335448b819fd6522a55040 (diff)
downloademacs-e1f40b2841d36ba1c61e2343e04717c65677415d.tar.gz
emacs-e1f40b2841d36ba1c61e2343e04717c65677415d.zip
Better, more user-oriented doc strings.
(time-stamp-mail-host): Now a user option. (time-stamp-current-year, time-stamp-hh:mm): Removed. (time-stamp-mm/dd/yy, time-stamp-dd/mm/yy): Removed. (time-stamp-yyyy-mm-dd): New function, ISO 8601 format.
-rw-r--r--lisp/time-stamp.el118
1 files changed, 61 insertions, 57 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index af529c93cee..b7e9b022238 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -2,7 +2,7 @@
2;;; Copyright 1989, 1993 Free Software Foundation, Inc. 2;;; Copyright 1989, 1993 Free Software Foundation, Inc.
3 3
4;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu> 4;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
5;; Time-stamp: <93/12/07 07:38:54 gildea> 5;; Time-stamp: <93/12/19 14:50:59 gildea>
6;; Keywords: tools 6;; Keywords: tools
7 7
8;; This file is free software; you can redistribute it and/or modify 8;; This file is free software; you can redistribute it and/or modify
@@ -62,37 +62,55 @@ which are included verbatim. Spaces are not inserted around literal strings.")
62;;; with other people's files! If you must change them, 62;;; with other people's files! If you must change them,
63;;; do so only in the local variables section of the file itself. 63;;; do so only in the local variables section of the file itself.
64 64
65(defvar time-stamp-line-limit 8 ;Do not change! See comment above. 65(defvar time-stamp-line-limit 8 ;Do not change!
66 "Number of lines at the beginning of a file that are searched. 66 "Number of lines at the beginning of a file that are searched.
67The patterns time-stamp-start and time-stamp-end must be found on one 67The patterns `time-stamp-start' and `time-stamp-end' must be found on one
68of the first time-stamp-line-limit lines of the file for the file to 68of the first `time-stamp-line-limit' lines of the file for the file to
69be time-stamped.") 69be time-stamped by \\[time-stamp].
70
71Do not change `time-stamp-line-limit', `time-stamp-start', or
72`time-stamp-end' for yourself or you will be incompatible
73with other people's files! If you must change them for some application,
74do so in the local variables section of the time-stamped file itself.")
75
70 76
71(defvar time-stamp-start "Time-stamp: \\\\?[\"<]+" ;Do not change! 77(defvar time-stamp-start "Time-stamp: \\\\?[\"<]+" ;Do not change!
72 "Regexp after which the time stamp is written by \\[time-stamp]. 78 "Regexp after which the time stamp is written by \\[time-stamp].
73See also the variables time-stamp-end and time-stamp-line-limit. 79See also the variables `time-stamp-end' and `time-stamp-line-limit'.
74 80
75Do not change time-stamp-line-limit, time-stamp-start, or 81Do not change `time-stamp-line-limit', `time-stamp-start', or
76time-stamp-end for yourself or you will be incompatible 82`time-stamp-end' for yourself or you will be incompatible
77with other people's files! If you must change them for some application, 83with other people's files! If you must change them for some application,
78do so in the local variables section of the time-stamped file itself.") 84do so in the local variables section of the time-stamped file itself.")
79 85
80 86
81(defvar time-stamp-end "\\\\?[\">]" ;Do not change! See comment above. 87(defvar time-stamp-end "\\\\?[\">]" ;Do not change!
82 "Regexp marking the text after the time stamp. 88 "Regexp marking the text after the time stamp.
83\\[time-stamp] deletes the text between the first match of time-stamp-start 89\\[time-stamp] deletes the text between the first match of `time-stamp-start'
84\(which see) and the following match of time-stamp-end on the same line, 90and the following match of `time-stamp-end' on the same line,
85then writes the time stamp specified by time-stamp-format between them.") 91then writes the time stamp specified by `time-stamp-format' between them.
92
93Do not change `time-stamp-line-limit', `time-stamp-start', or
94`time-stamp-end' for yourself or you will be incompatible
95with other people's files! If you must change them for some application,
96do so in the local variables section of the time-stamped file itself.")
97
86 98
87;;;###autoload 99;;;###autoload
88(defun time-stamp () 100(defun time-stamp ()
89 "Update the time stamp string in the buffer. 101 "Update the time stamp string in the buffer.
102If you put a time stamp template anywhere in the first 8 lines of a file,
103it can be updated every time you save the file. See the top of
104`time-stamp.el' for a sample. The template looks like one of the following:
105 Time-stamp: <>
106 Time-stamp: \" \"
107The time stamp is written between the brackets or quotes, resulting in
108 Time-stamp: <93/06/18 10:26:51 gildea>
90Only does its thing if the variable time-stamp-active is non-nil. 109Only does its thing if the variable time-stamp-active is non-nil.
91Typically used on write-file-hooks for automatic time-stamping. 110Typically used on write-file-hooks for automatic time-stamping.
92The format of the time stamp is determined by the variable 111The format of the time stamp is determined by the variable time-stamp-format.
93time-stamp-format. The first time-stamp-line-limit lines of the 112The variables time-stamp-line-limit, time-stamp-start, and time-stamp-end
94buffer (normally 8) are searched for the time stamp template, 113control finding the template."
95and if it is found, a new time stamp is written into it."
96 (interactive) 114 (interactive)
97 (if time-stamp-active 115 (if time-stamp-active
98 (let ((case-fold-search nil)) 116 (let ((case-fold-search nil))
@@ -128,7 +146,7 @@ and if it is found, a new time stamp is written into it."
128 (time-stamp-fconcat time-stamp-format " ")) 146 (time-stamp-fconcat time-stamp-format " "))
129 147
130(defun time-stamp-fconcat (list sep) 148(defun time-stamp-fconcat (list sep)
131 "Similar to (mapconcat 'funcall LIST SEP) but LIST can have literals. 149 "Similar to (mapconcat 'funcall LIST SEP) but LIST allows literals.
132If an element of LIST is a symbol, it is funcalled to get the string to use; 150If an element of LIST is a symbol, it is funcalled to get the string to use;
133the separator SEP is used between two strings obtained by funcalling a 151the separator SEP is used between two strings obtained by funcalling a
134symbol. Otherwise the element itself is inserted; no separator is used 152symbol. Otherwise the element itself is inserted; no separator is used
@@ -151,38 +169,35 @@ around literals."
151(defconst time-stamp-month-numbers 169(defconst time-stamp-month-numbers
152 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6) 170 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
153 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12)) 171 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
154 "Assoc list of months and their number.") 172 "Alist of months and their number.")
155 173
156(defconst time-stamp-month-full-names 174(defconst time-stamp-month-full-names
157 ["(zero)" "January" "February" "March" "April" "May" "June" 175 ["(zero)" "January" "February" "March" "April" "May" "June"
158 "July" "August" "September" "October" "November" "December"]) 176 "July" "August" "September" "October" "November" "December"])
159 177
160(defvar time-stamp-mail-host nil 178(defvar time-stamp-mail-host nil
161 "Name of the host where the user receives mail. 179 "*Name of the host where the user receives mail.
162See the function time-stamp-mail-host-name.") 180See the function `time-stamp-mail-host-name'.")
163 181
164;;; Some useful functions to use in time-stamp-format 182;;; Some useful functions to use in time-stamp-format
165 183
166;;; Could generate most of a message-id with 184;;; Could generate most of a message-id with
167;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" mail-host-name) 185;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" time-stamp-mail-host-name)
168 186
169(defun time-stamp-mail-host-name () 187(defun time-stamp-mail-host-name ()
170 "Return the name of the host where the user receives mail. 188 "Return the name of the host where the user receives mail.
171This is the value of time-stamp-mail-host if bound and a string, 189This is the value of `time-stamp-mail-host' if bound and a string,
172otherwise the value of the function system-name." 190otherwise the value of the function system-name.
191This function may be usefully referenced by `time-stamp-format'."
173 (or (and (boundp 'time-stamp-mail-host) 192 (or (and (boundp 'time-stamp-mail-host)
174 (stringp time-stamp-mail-host) 193 (stringp time-stamp-mail-host)
175 time-stamp-mail-host) 194 time-stamp-mail-host)
176 (system-name))) 195 (system-name)))
177 196
178(defun time-stamp-current-year ()
179 "Return the current year as a four-character string."
180 (substring (current-time-string) -4))
181
182;;; pretty form, suitable for a title page 197;;; pretty form, suitable for a title page
183 198
184(defun time-stamp-month-dd-yyyy () 199(defun time-stamp-month-dd-yyyy ()
185 "Return the current date as a string in \"Month dd, yyyy\" form." 200 "Return the current date as a string in \"Month DD, YYYY\" form."
186 (let ((date (current-time-string))) 201 (let ((date (current-time-string)))
187 (format "%s %d, %s" 202 (format "%s %d, %s"
188 (aref time-stamp-month-full-names 203 (aref time-stamp-month-full-names
@@ -193,8 +208,8 @@ otherwise the value of the function system-name."
193;;; same as __DATE__ in ANSI C 208;;; same as __DATE__ in ANSI C
194 209
195(defun time-stamp-mon-dd-yyyy () 210(defun time-stamp-mon-dd-yyyy ()
196 "Return the current date as a string in \"Mon dd yyyy\" form. 211 "Return the current date as a string in \"Mon DD YYYY\" form.
197The first character of dd is Space if the value is less than 10." 212The first character of DD is space if the value is less than 10."
198 (let ((date (current-time-string))) 213 (let ((date (current-time-string)))
199 (format "%s %2d %s" 214 (format "%s %2d %s"
200 (substring date 4 7) 215 (substring date 4 7)
@@ -204,7 +219,7 @@ The first character of dd is Space if the value is less than 10."
204;;; RFC 822 date 219;;; RFC 822 date
205 220
206(defun time-stamp-dd-mon-yy () 221(defun time-stamp-dd-mon-yy ()
207 "Return the current date as a string in \"dd Mon yy\" form." 222 "Return the current date as a string in \"DD Mon YY\" form."
208 (let ((date (current-time-string))) 223 (let ((date (current-time-string)))
209 (format "%02d %s %s" 224 (format "%02d %s %s"
210 (string-to-int (substring date 8 10)) 225 (string-to-int (substring date 8 10))
@@ -214,7 +229,7 @@ The first character of dd is Space if the value is less than 10."
214;;; RCS 3 date 229;;; RCS 3 date
215 230
216(defun time-stamp-yy/mm/dd () 231(defun time-stamp-yy/mm/dd ()
217 "Return the current date as a string in \"yy/mm/dd\" form." 232 "Return the current date as a string in \"YY/MM/DD\" form."
218 (let ((date (current-time-string))) 233 (let ((date (current-time-string)))
219 (format "%s/%02d/%02d" 234 (format "%s/%02d/%02d"
220 (substring date -2) 235 (substring date -2)
@@ -224,47 +239,37 @@ The first character of dd is Space if the value is less than 10."
224;;; RCS 5 date 239;;; RCS 5 date
225 240
226(defun time-stamp-yyyy/mm/dd () 241(defun time-stamp-yyyy/mm/dd ()
227 "Return the current date as a string in \"yyyy/mm/dd\" form." 242 "Return the current date as a string in \"YYYY/MM/DD\" form."
228 (let ((date (current-time-string))) 243 (let ((date (current-time-string)))
229 (format "%s/%02d/%02d" 244 (format "%s/%02d/%02d"
230 (substring date -4) 245 (substring date -4)
231 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)) 246 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
232 (string-to-int (substring date 8 10))))) 247 (string-to-int (substring date 8 10)))))
233 248
234(defun time-stamp-yymmdd () 249;;; ISO 8601 date
235 "Return the current date as a string in \"yymmdd\" form."
236 (let ((date (current-time-string)))
237 (format "%s%02d%02d"
238 (substring date -2)
239 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
240 (string-to-int (substring date 8 10)))))
241 250
242(defun time-stamp-dd/mm/yy () 251(defun time-stamp-yyyy-mm-dd ()
243 "Return the current date as a string in \"dd/mm/yy\" form." 252 "Return the current date as a string in \"YYYY-MM-DD\" form."
244 (let ((date (current-time-string))) 253 (let ((date (current-time-string)))
245 (format "%02d/%02d/%s" 254 (format "%s-%02d-%02d"
246 (string-to-int (substring date 8 10)) 255 (substring date -4)
247 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)) 256 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
248 (substring date -2)))) 257 (string-to-int (substring date 8 10)))))
249 258
250(defun time-stamp-mm/dd/yy () 259(defun time-stamp-yymmdd ()
251 "Return the current date as a string in \"mm/dd/yy\" form." 260 "Return the current date as a string in \"YYMMDD\" form."
252 (let ((date (current-time-string))) 261 (let ((date (current-time-string)))
253 (format "%02d/%02d/%s" 262 (format "%s%02d%02d"
263 (substring date -2)
254 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)) 264 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
255 (string-to-int (substring date 8 10)) 265 (string-to-int (substring date 8 10)))))
256 (substring date -2))))
257 266
258(defun time-stamp-hh:mm:ss () 267(defun time-stamp-hh:mm:ss ()
259 "Return the current time as a string in \"hh:mm:ss\" form." 268 "Return the current time as a string in \"HH:MM:SS\" form."
260 (substring (current-time-string) 11 19)) 269 (substring (current-time-string) 11 19))
261 270
262(defun time-stamp-hh:mm ()
263 "Return the current time as a string in \"hh:mm\" form."
264 (substring (current-time-string) 11 16))
265
266(defun time-stamp-hhmm () 271(defun time-stamp-hhmm ()
267 "Return the current time as a string in \"hhmm\" form." 272 "Return the current time as a string in \"HHMM\" form."
268 (let ((date (current-time-string))) 273 (let ((date (current-time-string)))
269 (concat (substring date 11 13) 274 (concat (substring date 11 13)
270 (substring date 14 16)))) 275 (substring date 14 16))))
@@ -272,4 +277,3 @@ The first character of dd is Space if the value is less than 10."
272(provide 'time-stamp) 277(provide 'time-stamp)
273 278
274;;; time-stamp.el ends here 279;;; time-stamp.el ends here
275