annotate lisp/time-stamp.el @ 5287:6811f9d90b62

(time-stamp-month-dd-yyyy): no leading zero on day.
author Richard M. Stallman <rms@gnu.org>
date Thu, 23 Dec 1993 03:43:13 +0000
parents 16da133809dd
children 63d80d94e0d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; time-stamp.el --- Maintain last change time stamps in files edited by Emacs
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;;; Copyright 1989, 1993 Free Software Foundation, Inc.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
5287
6811f9d90b62 (time-stamp-month-dd-yyyy): no leading zero on day.
Richard M. Stallman <rms@gnu.org>
parents: 5072
diff changeset
5 ;; Time-stamp: <93/12/07 07:38:54 gildea>
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: tools
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is free software; you can redistribute it and/or modify
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; any later version.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; This file is distributed in the hope that it will be useful,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;; Commentary:
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; If you put a time stamp template anywhere in the first 8 lines of a file,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; it can be updated every time you save the file. See the top of
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; time-stamp.el for a sample. The template looks like one of the following:
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Time-stamp: <>
4325
afdc363a0c9b Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 3855
diff changeset
28 ;;; Time-stamp: " "
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; The time stamp is written between the brackets or quotes, resulting in
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Time-stamp: <93/06/18 10:26:51 gildea>
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; Here is an example which puts the file name and time stamp in the binary:
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; static char *time_stamp = "sdmain.c Time-stamp: <>";
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; To activate automatic time stamping, add this code to your .emacs file:
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;;
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; (if (not (memq 'time-stamp write-file-hooks))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; (setq write-file-hooks
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; (cons 'time-stamp write-file-hooks)))
5072
16da133809dd Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 4327
diff changeset
39 ;;;
16da133809dd Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 4327
diff changeset
40 ;;; In Emacs 18 you will also need
16da133809dd Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 4327
diff changeset
41 ;;; (autoload 'time-stamp "time-stamp" "Update the time stamp in a buffer." t)
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; Change Log:
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; Originally based on the 19 Dec 88 version of
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; Code:
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defvar time-stamp-active t
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 "*Non-nil to enable time-stamping of files. See the function time-stamp.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defvar time-stamp-format
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 '(time-stamp-yy/mm/dd time-stamp-hh:mm:ss user-login-name)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 "*A list of functions to call to generate the time stamp string.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 Each element of the list is called as a function and the results are
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 concatenated together separated by spaces. Elements may also be strings,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 which are included verbatim. Spaces are not inserted around literal strings.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; Do not change time-stamp-line-limit, time-stamp-start, or
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; time-stamp-end in your .emacs or you will be incompatible
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;; with other people's files! If you must change them,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; do so only in the local variables section of the file itself.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defvar time-stamp-line-limit 8 ;Do not change! See comment above.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "Number of lines at the beginning of a file that are searched.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 The patterns time-stamp-start and time-stamp-end must be found on one
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 of the first time-stamp-line-limit lines of the file for the file to
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 be time-stamped.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (defvar time-stamp-start "Time-stamp: \\\\?[\"<]+" ;Do not change!
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 "Regexp after which the time stamp is written by \\[time-stamp].
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 See also the variables time-stamp-end and time-stamp-line-limit.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 Do not change time-stamp-line-limit, time-stamp-start, or
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 time-stamp-end for yourself or you will be incompatible
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 with other people's files! If you must change them for some application,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 do so in the local variables section of the time-stamped file itself.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (defvar time-stamp-end "\\\\?[\">]" ;Do not change! See comment above.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 "Regexp marking the text after the time stamp.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 \\[time-stamp] deletes the text between the first match of time-stamp-start
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 \(which see) and the following match of time-stamp-end on the same line,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 then writes the time stamp specified by time-stamp-format between them.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
4327
771786f5d8c2 (time-stamp): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 4325
diff changeset
87 ;;;###autoload
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (defun time-stamp ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 "Update the time stamp string in the buffer.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 Only does its thing if the variable time-stamp-active is non-nil.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 Typically used on write-file-hooks for automatic time-stamping.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 The format of the time stamp is determined by the variable
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 time-stamp-format. The first time-stamp-line-limit lines of the
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 buffer (normally 8) are searched for the time stamp template,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 and if it is found, a new time stamp is written into it."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (interactive)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (if time-stamp-active
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (let ((case-fold-search nil))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (if (and (stringp time-stamp-start)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (stringp time-stamp-end))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (save-excursion
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (goto-char (point-min))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (if (re-search-forward time-stamp-start
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (save-excursion
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (forward-line time-stamp-line-limit)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (point))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (let ((start (point)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (if (re-search-forward time-stamp-end
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (save-excursion (end-of-line) (point))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (let ((end (match-beginning 0)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (delete-region start end)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (goto-char start)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (insert (time-stamp-string))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (setq end (point))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; remove any tabs used to format the time stamp
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (goto-char start)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (if (search-forward "\t" end t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (untabify start end)))))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; don't signal an error in a write-file-hook
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (message "time-stamp-start or time-stamp-end is not a string"))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;; be sure to return nil so can be used on write-file-hooks
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 nil)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defun time-stamp-string ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "Generate the new string to be inserted by \\[time-stamp]."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (time-stamp-fconcat time-stamp-format " "))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (defun time-stamp-fconcat (list sep)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 "Similar to (mapconcat 'funcall LIST SEP) but LIST can have literals.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 If an element of LIST is a symbol, it is funcalled to get the string to use;
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 the separator SEP is used between two strings obtained by funcalling a
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 symbol. Otherwise the element itself is inserted; no separator is used
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 around literals."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (let ((return-string "")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (insert-sep-p nil))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (while list
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (cond ((symbolp (car list))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (if insert-sep-p
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (setq return-string (concat return-string sep)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (setq return-string (concat return-string (funcall (car list))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq insert-sep-p t))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (t
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (setq return-string (concat return-string (car list)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (setq insert-sep-p nil)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (setq list (cdr list)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 return-string))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defconst time-stamp-month-numbers
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 "Assoc list of months and their number.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defconst time-stamp-month-full-names
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ["(zero)" "January" "February" "March" "April" "May" "June"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 "July" "August" "September" "October" "November" "December"])
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defvar time-stamp-mail-host nil
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 "Name of the host where the user receives mail.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 See the function time-stamp-mail-host-name.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;;; Some useful functions to use in time-stamp-format
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;;; Could generate most of a message-id with
5072
16da133809dd Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 4327
diff changeset
167 ;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" mail-host-name)
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (defun time-stamp-mail-host-name ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 "Return the name of the host where the user receives mail.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 This is the value of time-stamp-mail-host if bound and a string,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 otherwise the value of the function system-name."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (or (and (boundp 'time-stamp-mail-host)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (stringp time-stamp-mail-host)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 time-stamp-mail-host)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (system-name)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (defun time-stamp-current-year ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 "Return the current year as a four-character string."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (substring (current-time-string) -4))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;;; pretty form, suitable for a title page
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (defun time-stamp-month-dd-yyyy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 "Return the current date as a string in \"Month dd, yyyy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (let ((date (current-time-string)))
5287
6811f9d90b62 (time-stamp-month-dd-yyyy): no leading zero on day.
Richard M. Stallman <rms@gnu.org>
parents: 5072
diff changeset
187 (format "%s %d, %s"
3854
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (aref time-stamp-month-full-names
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (substring date -4))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;;; same as __DATE__ in ANSI C
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (defun time-stamp-mon-dd-yyyy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 "Return the current date as a string in \"Mon dd yyyy\" form.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 The first character of dd is Space if the value is less than 10."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (format "%s %2d %s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (substring date 4 7)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (substring date -4))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ;;; RFC 822 date
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (defun time-stamp-dd-mon-yy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 "Return the current date as a string in \"dd Mon yy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (format "%02d %s %s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (substring date 4 7)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (substring date -2))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;;; RCS 3 date
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defun time-stamp-yy/mm/dd ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 "Return the current date as a string in \"yy/mm/dd\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (format "%s/%02d/%02d"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (substring date -2)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (string-to-int (substring date 8 10)))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;;; RCS 5 date
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (defun time-stamp-yyyy/mm/dd ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 "Return the current date as a string in \"yyyy/mm/dd\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (format "%s/%02d/%02d"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (substring date -4)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (string-to-int (substring date 8 10)))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (defun time-stamp-yymmdd ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 "Return the current date as a string in \"yymmdd\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (format "%s%02d%02d"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (substring date -2)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (string-to-int (substring date 8 10)))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (defun time-stamp-dd/mm/yy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 "Return the current date as a string in \"dd/mm/yy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (format "%02d/%02d/%s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (substring date -2))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (defun time-stamp-mm/dd/yy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 "Return the current date as a string in \"mm/dd/yy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (format "%02d/%02d/%s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (substring date -2))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun time-stamp-hh:mm:ss ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "Return the current time as a string in \"hh:mm:ss\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (substring (current-time-string) 11 19))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun time-stamp-hh:mm ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 "Return the current time as a string in \"hh:mm\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (substring (current-time-string) 11 16))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (defun time-stamp-hhmm ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 "Return the current time as a string in \"hhmm\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (concat (substring date 11 13)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (substring date 14 16))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (provide 'time-stamp)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 ;;; time-stamp.el ends here
5072
16da133809dd Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 4327
diff changeset
275