annotate lisp/time-stamp.el @ 4252:cfee000861f5

entered into RCS
author Richard M. Stallman <rms@gnu.org>
date Fri, 23 Jul 1993 19:31:05 +0000
parents 7e33c0f86cb6
children afdc363a0c9b
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>
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Time-stamp: <93/06/20 17:36:04 gildea>
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: <>
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Time-stamp: ""
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 ;;; (autoload 'time-stamp "time-stamp" "Update the time stamp in a buffer." t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; (if (not (memq 'time-stamp write-file-hooks))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; (setq write-file-hooks
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; (cons 'time-stamp write-file-hooks)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; Change Log:
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 ;;; Originally based on the 19 Dec 88 version of
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; 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
45
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; Code:
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 (defvar time-stamp-active t
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "*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
50
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (defvar time-stamp-format
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 '(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
53 "*A list of functions to call to generate the time stamp string.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 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
55 concatenated together separated by spaces. Elements may also be strings,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 which are included verbatim. Spaces are not inserted around literal strings.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;; Do not change time-stamp-line-limit, time-stamp-start, or
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;; time-stamp-end in your .emacs or you will be incompatible
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; with other people's files! If you must change them,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; do so only in the local variables section of the file itself.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (defvar time-stamp-line-limit 8 ;Do not change! See comment above.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 "Number of lines at the beginning of a file that are searched.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 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
66 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
67 be time-stamped.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (defvar time-stamp-start "Time-stamp: \\\\?[\"<]+" ;Do not change!
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 "Regexp after which the time stamp is written by \\[time-stamp].
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 See also the variables time-stamp-end and time-stamp-line-limit.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 Do not change time-stamp-line-limit, time-stamp-start, or
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 time-stamp-end for yourself or you will be incompatible
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 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
76 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
77
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (defvar time-stamp-end "\\\\?[\">]" ;Do not change! See comment above.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 "Regexp marking the text after the time stamp.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 \\[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
82 \(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
83 then writes the time stamp specified by time-stamp-format between them.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defun time-stamp ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "Update the time stamp string in the buffer.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 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
88 Typically used on write-file-hooks for automatic time-stamping.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 The format of the time stamp is determined by the variable
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 time-stamp-format. The first time-stamp-line-limit lines of the
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 buffer (normally 8) are searched for the time stamp template,
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 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
93 (interactive)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (if time-stamp-active
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (let ((case-fold-search nil))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (if (and (stringp time-stamp-start)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (stringp time-stamp-end))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (save-excursion
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (goto-char (point-min))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (if (re-search-forward time-stamp-start
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 (forward-line time-stamp-line-limit)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (point))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (let ((start (point)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (if (re-search-forward time-stamp-end
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (save-excursion (end-of-line) (point))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (let ((end (match-beginning 0)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (delete-region start end)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (goto-char start)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (insert (time-stamp-string))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (setq end (point))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; remove any tabs used to format the time stamp
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (goto-char start)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (if (search-forward "\t" end t)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (untabify start end)))))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; don't signal an error in a write-file-hook
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (message "time-stamp-start or time-stamp-end is not a string"))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; 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
121 nil)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defun time-stamp-string ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 "Generate the new string to be inserted by \\[time-stamp]."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (time-stamp-fconcat time-stamp-format " "))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defun time-stamp-fconcat (list sep)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "Similar to (mapconcat 'funcall LIST SEP) but LIST can have literals.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 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
130 the separator SEP is used between two strings obtained by funcalling a
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 symbol. Otherwise the element itself is inserted; no separator is used
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 around literals."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (let ((return-string "")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (insert-sep-p nil))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (while list
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (cond ((symbolp (car list))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (if insert-sep-p
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (setq return-string (concat return-string sep)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (setq return-string (concat return-string (funcall (car list))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (setq insert-sep-p t))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (t
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (setq return-string (concat return-string (car list)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq insert-sep-p nil)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (setq list (cdr list)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 return-string))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (defconst time-stamp-month-numbers
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 "Assoc list of months and their number.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (defconst time-stamp-month-full-names
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ["(zero)" "January" "February" "March" "April" "May" "June"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "July" "August" "September" "October" "November" "December"])
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (defvar time-stamp-mail-host nil
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 "Name of the host where the user receives mail.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 See the function time-stamp-mail-host-name.")
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;;; Some useful functions to use in time-stamp-format
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;;; Could generate most of a message-id with
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;;; '(yymmdd "" hhmm "@" mail-host-name)
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 (defun time-stamp-mail-host-name ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 "Return the name of the host where the user receives mail.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 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
169 otherwise the value of the function system-name."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (or (and (boundp 'time-stamp-mail-host)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (stringp time-stamp-mail-host)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 time-stamp-mail-host)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (system-name)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (defun time-stamp-current-year ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 "Return the current year as a four-character string."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (substring (current-time-string) -4))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;;; pretty form, suitable for a title page
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (defun time-stamp-month-dd-yyyy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 "Return the current date as a string in \"Month dd, yyyy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (format "%s %02d, %s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (aref time-stamp-month-full-names
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (substring date -4))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;; same as __DATE__ in ANSI C
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (defun time-stamp-mon-dd-yyyy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 "Return the current date as a string in \"Mon dd yyyy\" form.
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 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
195 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (format "%s %2d %s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (substring date 4 7)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (substring date -4))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ;;; RFC 822 date
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (defun time-stamp-dd-mon-yy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 "Return the current date as a string in \"dd Mon yy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (format "%02d %s %s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (substring date 4 7)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (substring date -2))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;;; RCS 3 date
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun time-stamp-yy/mm/dd ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 "Return the current date as a string in \"yy/mm/dd\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (format "%s/%02d/%02d"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (substring date -2)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (string-to-int (substring date 8 10)))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;;; RCS 5 date
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (defun time-stamp-yyyy/mm/dd ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 "Return the current date as a string in \"yyyy/mm/dd\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (format "%s/%02d/%02d"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (substring date -4)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (string-to-int (substring date 8 10)))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (defun time-stamp-yymmdd ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 "Return the current date as a string in \"yymmdd\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (format "%s%02d%02d"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (substring date -2)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (string-to-int (substring date 8 10)))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (defun time-stamp-dd/mm/yy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 "Return the current date as a string in \"dd/mm/yy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (format "%02d/%02d/%s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (substring date -2))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (defun time-stamp-mm/dd/yy ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 "Return the current date as a string in \"mm/dd/yy\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (format "%02d/%02d/%s"
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (string-to-int (substring date 8 10))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (substring date -2))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (defun time-stamp-hh:mm:ss ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 "Return the current time as a string in \"hh:mm:ss\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (substring (current-time-string) 11 19))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (defun time-stamp-hh:mm ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 "Return the current time as a string in \"hh:mm\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (substring (current-time-string) 11 16))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (defun time-stamp-hhmm ()
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 "Return the current time as a string in \"hhmm\" form."
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (let ((date (current-time-string)))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (concat (substring date 11 13)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (substring date 14 16))))
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (provide 'time-stamp)
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
ae1022bb1578 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 ;;; time-stamp.el ends here