annotate lisp/packages/time-stamp.el @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents 34a5b81f86ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; time-stamp.el --- Maintain last change time stamps in files edited by Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3 ;; Copyright 1989, 1993, 1994, 1995 Free Software Foundation, Inc.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
4
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
5 ;; Maintainer's Time-stamp: <95/12/28 19:48:49 gildea>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: Stephen Gildea <gildea@lcs.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
10 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
17 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
22 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
24 ;;; Synched up with: 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
28 ;; If you put a time stamp template anywhere in the first 8 lines of a file,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
29 ;; it can be updated every time you save the file. See the top of
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
30 ;; time-stamp.el for a sample. The template looks like one of the following:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
31 ;; Time-stamp: <>
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
32 ;; Time-stamp: " "
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
33 ;; The time stamp is written between the brackets or quotes, resulting in
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
34 ;; Time-stamp: <95/01/18 10:20:51 gildea>
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
35 ;; Here is an example that puts the file name and time stamp in the binary:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
36 ;; static char *time_stamp = "sdmain.c Time-stamp: <>";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
38 ;; To activate automatic time stamping in GNU Emacs 19, add this code
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
39 ;; to your .emacs file:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
40 ;; (add-hook 'write-file-hooks 'time-stamp)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
41 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
42 ;; In Emacs 18 you will need to do this instead:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
43 ;; (if (not (memq 'time-stamp write-file-hooks))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
44 ;; (setq write-file-hooks
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
45 ;; (cons 'time-stamp write-file-hooks)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
46 ;; (autoload 'time-stamp "time-stamp" "Update the time stamp in a buffer." t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
47
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
48 ;; See the documentation for the function `time-stamp' for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; Change Log:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
52 ;; Originally based on the 19 Dec 88 version of
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
53 ;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net>
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
54 ;; version 2, January 1995: replaced functions with %-escapes
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
55 ;; $Id: time-stamp.el,v 1.2 1997/04/19 23:21:12 steve Exp $
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
59 (defgroup time-stamp nil
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
60 "Maintain last change time stamps in files edited by Emacs."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
61 :group 'data
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
62 :group 'extensions)
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
63
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
64
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
65 (defcustom time-stamp-active t
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
66 "*Non-nil to enable time-stamping of buffers by \\[time-stamp].
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
67 Can be toggled by \\[time-stamp-toggle-active].
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
68 See also the variable time-stamp-warn-inactive."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
69 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
70 :group 'time-stamp)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
71
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
72 (defcustom time-stamp-warn-inactive t
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
73 "*Non-nil to have \\[time-stamp] warn if a buffer did not get time-stamped.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
74 A warning is printed if time-stamp-active is nil and the buffer contains
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
75 a time stamp template that would otherwise have been updated."
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
76 :type 'boolean
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
77 :group 'time-stamp)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
78
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
79 (defcustom time-stamp-format "%02y/%02m/%02d %02H:%02M:%02S %u"
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
80 "*Template for the string inserted by \\[time-stamp].
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
81 Value may be a string or a list. (Lists are supported only for
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
82 backward compatibility.) A string is used verbatim except
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
83 for character sequences beginning with %:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
85 %a weekday name: `Monday'. %A gives uppercase: `MONDAY'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
86 %b month name: `January'. %B gives uppercase: `JANUARY'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
87 %d day of month
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
88 %H 24-hour clock hour
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
89 %I 12-hour clock hour
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
90 %m month number
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
91 %M minute
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
92 %p `am' or `pm'. %P gives uppercase: `AM' or `PM'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
93 %S seconds
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
94 %w day number of week, Sunday is 0
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
95 %y year: `1995'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
96 %z time zone name: `est'. %Z gives uppercase: `EST'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
97
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
98 Non-date items:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
99 %% a literal percent character: `%'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
100 %f file name without directory %F gives absolute pathname
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
101 %s system name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
102 %u user's login name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
103 %h mail host name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
104
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
105 Decimal digits between the % and the type character specify the
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
106 field width. Strings are truncated on the right; numbers on the left.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
107 A leading zero causes numbers to be zero-filled.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
108
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
109 For example, to get the format used by the `date' command,
134
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
110 use \"%3a %3b %2d %02H:%02M:%02S %Z %y\""
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
111 :type 'string
34a5b81f86ba Import from CVS: tag r20-2b1
cvs
parents: 72
diff changeset
112 :group 'time-stamp)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
113
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; Do not change time-stamp-line-limit, time-stamp-start, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; time-stamp-end in your .emacs or you will be incompatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; with other people's files! If you must change them,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; do so only in the local variables section of the file itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
120 (defvar time-stamp-line-limit 8 ;Do not change!
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
121 "Lines of a file searched; positive counts from start, negative from end.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
122 The patterns `time-stamp-start' and `time-stamp-end' must be found on one
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
123 of the first (last) `time-stamp-line-limit' lines of the file for the
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
124 file to be time-stamped by \\[time-stamp].
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
126 Do not change `time-stamp-line-limit', `time-stamp-start', or
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
127 `time-stamp-end' for yourself or you will be incompatible
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 with other people's files! If you must change them for some application,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 do so in the local variables section of the time-stamped file itself.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
132 (defvar time-stamp-start "Time-stamp:[ \t]+\\\\?[\"<]+" ;Do not change!
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
133 "Regexp after which the time stamp is written by \\[time-stamp].
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
134 See also the variables `time-stamp-end' and `time-stamp-line-limit'.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
135
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
136 Do not change `time-stamp-line-limit', `time-stamp-start', or
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
137 `time-stamp-end' for yourself or you will be incompatible
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
138 with other people's files! If you must change them for some application,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
139 do so in the local variables section of the time-stamped file itself.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
140
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
141
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
142 (defvar time-stamp-end "\\\\?[\">]" ;Do not change!
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "Regexp marking the text after the time stamp.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
144 \\[time-stamp] deletes the text between the first match of `time-stamp-start'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
145 and the following match of `time-stamp-end' on the same line,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
146 then writes the time stamp specified by `time-stamp-format' between them.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
147
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
148 Do not change `time-stamp-line-limit', `time-stamp-start', or
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
149 `time-stamp-end' for yourself or you will be incompatible
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
150 with other people's files! If you must change them for some application,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
151 do so in the local variables section of the time-stamped file itself.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
152
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun time-stamp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Update the time stamp string in the buffer.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
157 If you put a time stamp template anywhere in the first 8 lines of a file,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
158 it can be updated every time you save the file. See the top of
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
159 `time-stamp.el' for a sample. The template looks like one of the following:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
160 Time-stamp: <>
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
161 Time-stamp: \" \"
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
162 The time stamp is written between the brackets or quotes, resulting in
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
163 Time-stamp: <95/01/18 10:20:51 gildea>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 Only does its thing if the variable time-stamp-active is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Typically used on write-file-hooks for automatic time-stamping.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
166 The format of the time stamp is determined by the variable time-stamp-format.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
167 The variables time-stamp-line-limit, time-stamp-start, and time-stamp-end
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
168 control finding the template."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (interactive)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
170 (let ((case-fold-search nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
171 (need-to-warn nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
172 start search-end)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
173 (if (and (stringp time-stamp-start)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
174 (stringp time-stamp-end))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
175 (save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
176 (save-restriction
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
177 (widen)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
178 (if (> time-stamp-line-limit 0)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
179 (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
180 (goto-char (setq start (point-min)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
181 (forward-line time-stamp-line-limit)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
182 (setq search-end (point)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
183 (goto-char (setq search-end (point-max)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
184 (forward-line time-stamp-line-limit)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
185 (setq start (point)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
186 (goto-char start)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
187 (while
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
188 (and (< (point) search-end)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
189 (re-search-forward time-stamp-start search-end 'move))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
190 (setq start (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
191 (end-of-line)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
192 (let ((line-end (point)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
193 (goto-char start)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
194 (if (re-search-forward time-stamp-end line-end 'move)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
195 (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
196 (if time-stamp-active
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
197 (let ((end (match-beginning 0)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
198 (delete-region start end)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
199 (goto-char start)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
200 (insert (time-stamp-string))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
201 (setq end (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
202 ;; remove any tabs used to format time stamp
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
203 (goto-char start)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
204 (if (search-forward "\t" end t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
205 (untabify start end)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
206 (if time-stamp-warn-inactive
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
207 ;; do warning outside save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
208 (setq need-to-warn t)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
209 (setq search-end (point))))))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
210 ;; don't signal an error in a write-file-hook
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
211 (message "time-stamp-start or time-stamp-end is not a string")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
212 (sit-for 1))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
213 (if need-to-warn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
214 (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
215 (message "Warning: time-stamp-active is off; did not time-stamp buffer.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
216 (sit-for 1))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; be sure to return nil so can be used on write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
220 ;;;###autoload
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
221 (defun time-stamp-toggle-active (&optional arg)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
222 "Toggle time-stamp-active, setting whether \\[time-stamp] updates a buffer.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
223 With arg, turn time stamping on if and only if arg is positive."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
224 (interactive "P")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
225 (setq time-stamp-active
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
226 (if (null arg)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
227 (not time-stamp-active)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
228 (> (prefix-numeric-value arg) 0)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
229 (message "time-stamp is now %s." (if time-stamp-active "active" "off")))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
230
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
231
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defun time-stamp-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 "Generate the new string to be inserted by \\[time-stamp]."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
234 (if (stringp time-stamp-format)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
235 (time-stamp-strftime time-stamp-format)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
236 (time-stamp-fconcat time-stamp-format " "))) ;version 1 compatibility
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
237
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
238 (defconst time-stamp-month-numbers
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
239 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
240 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
241 "Alist of months and their number.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
242
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
243 (defconst time-stamp-month-full-names
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
244 ["(zero)" "January" "February" "March" "April" "May" "June"
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
245 "July" "August" "September" "October" "November" "December"])
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
246
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
247 (defconst time-stamp-weekday-numbers
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
248 '(("Sun" . 0) ("Mon" . 1) ("Tue" . 2) ("Wed" . 3)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
249 ("Thu" . 4) ("Fri" . 5) ("Sat" . 6))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
250 "Alist of weekdays and their number.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
251
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
252 (defconst time-stamp-weekday-full-names
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
253 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"])
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
254
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
255 (defconst time-stamp-am-pm '("am" "pm")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
256 "List of strings used to denote morning and afternoon.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
257
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
258 (defconst time-stamp-no-file "(no file)"
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
259 "String to use when the buffer is not associated with a file.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
260
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
261 (defun time-stamp-strftime (format &optional time)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
262 "Uses a FORMAT to format date, time, file, and user information.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
263 Optional second argument TIME will be used instead of the current time.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
264 See the description of the variable `time-stamp-format' for a description
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
265 of the format string."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
266 (let ((time-string (cond ((stringp time)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
267 time)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
268 (time
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
269 (current-time-string time))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
270 (t
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
271 (current-time-string))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
272 (fmt-len (length format))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
273 (ind 0)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
274 cur-char
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
275 (prev-char nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
276 (result "")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
277 field-index
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
278 field-width
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
279 field-result
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
280 (paren-level 0))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
281 (while (< ind fmt-len)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
282 (setq cur-char (aref format ind))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
283 (setq
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
284 result
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
285 (concat result
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
286 (cond
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
287 ((eq cur-char ?%)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
288 (setq field-index (1+ ind))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
289 (while (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
290 (setq ind (1+ ind))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
291 (setq cur-char (if (< ind fmt-len)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
292 (aref format ind)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
293 ?\0))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
294 (and (<= ?0 cur-char) (>= ?9 cur-char))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
295 (setq field-width (substring format field-index ind))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
296 ;; eat any additional args to allow for future expansion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
297 (while (or (and (<= ?0 cur-char) (>= ?9 cur-char)) (eq ?. cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
298 (eq ?, cur-char) (eq ?: cur-char) (eq ?@ cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
299 (eq ?- cur-char) (eq ?+ cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
300 (eq ?\ cur-char) (eq ?# cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
301 (and (eq ?\( cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
302 (not (eq prev-char ?\\))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
303 (setq paren-level (1+ paren-level)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
304 (if (and (eq ?\) cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
305 (not (eq prev-char ?\\))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
306 (> paren-level 0))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
307 (setq paren-level (1- paren-level))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
308 (and (> paren-level 0)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
309 (< ind fmt-len))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
310 (setq ind (1+ ind))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
311 (setq prev-char cur-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
312 (setq cur-char (if (< ind fmt-len)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
313 (aref format ind)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
314 ?\0)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
315 (setq field-result
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
316 (cond
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
317 ((eq cur-char ?%)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
318 "%")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
319 ((or (eq cur-char ?a) ;weekday name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
320 (eq cur-char ?A))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
321 (let ((name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
322 (aref time-stamp-weekday-full-names
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
323 (cdr (assoc (substring time-string 0 3)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
324 time-stamp-weekday-numbers)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
325 (if (eq cur-char ?a)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
326 name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
327 (upcase name))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
328 ((or (eq cur-char ?b) ;month name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
329 (eq cur-char ?B))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
330 (let ((name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
331 (aref time-stamp-month-full-names
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
332 (cdr (assoc (substring time-string 4 7)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
333 time-stamp-month-numbers)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
334 (if (eq cur-char ?b)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
335 name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
336 (upcase name))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
337 ((eq cur-char ?d) ;day of month, 1-31
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
338 (string-to-int (substring time-string 8 10)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
339 ((eq cur-char ?H) ;hour, 0-23
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
340 (string-to-int (substring time-string 11 13)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
341 ((eq cur-char ?I) ;hour, 1-12
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
342 (let ((hour (string-to-int (substring time-string 11 13))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
343 (cond ((< hour 1)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
344 (+ hour 12))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
345 ((> hour 12)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
346 (- hour 12))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
347 (t
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
348 hour))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
349 ((eq cur-char ?m) ;month number, 1-12
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
350 (cdr (assoc (substring time-string 4 7)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
351 time-stamp-month-numbers)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
352 ((eq cur-char ?M) ;minute, 0-59
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
353 (string-to-int (substring time-string 14 16)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
354 ((or (eq cur-char ?p) ;am or pm
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
355 (eq cur-char ?P))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
356 (let ((name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
357 (if (> 12 (string-to-int (substring time-string 11 13)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
358 (car time-stamp-am-pm)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
359 (car (cdr time-stamp-am-pm)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
360 (if (eq cur-char ?p)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
361 name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
362 (upcase name))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
363 ((eq cur-char ?S) ;seconds, 00-60
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
364 (string-to-int (substring time-string 17 19)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
365 ((eq cur-char ?w) ;weekday number, Sunday is 0
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
366 (cdr (assoc (substring time-string 0 3) time-stamp-weekday-numbers)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
367 ((eq cur-char ?y) ;year
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
368 (string-to-int (substring time-string -4)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
369 ((or (eq cur-char ?z) ;time zone
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
370 (eq cur-char ?Z))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
371 (let ((name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
372 (if (fboundp 'current-time-zone)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
373 (car (cdr (current-time-zone time))))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
374 (or name (setq name ""))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
375 (if (eq cur-char ?z)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
376 (downcase name)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
377 (upcase name))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
378 ((eq cur-char ?f) ;buffer-file-name, base name only
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
379 (if buffer-file-name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
380 (file-name-nondirectory buffer-file-name)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
381 time-stamp-no-file))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
382 ((eq cur-char ?F) ;buffer-file-name, full path
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
383 (or buffer-file-name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
384 time-stamp-no-file))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
385 ((eq cur-char ?s) ;system name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
386 (system-name))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
387 ((eq cur-char ?u) ;user name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
388 (user-login-name))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
389 ((eq cur-char ?h) ;mail host name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
390 (time-stamp-mail-host-name))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
391 ))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
392 (if (string-equal field-width "")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
393 field-result
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
394 (let ((padded-result
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
395 (format (format "%%%s%c"
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
396 field-width
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
397 (if (numberp field-result) ?d ?s))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
398 (or field-result ""))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
399 (let ((initial-length (length padded-result))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
400 (desired-length (string-to-int field-width)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
401 (if (> initial-length desired-length)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
402 ;; truncate strings on right, numbers on left
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
403 (if (stringp field-result)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
404 (substring padded-result 0 desired-length)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
405 (substring padded-result (- desired-length)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
406 padded-result)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
407 (t
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
408 (char-to-string cur-char)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
409 (setq ind (1+ ind)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
410 result))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
411
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
412 (defun time-stamp-mail-host-name ()
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
413 "Return the name of the host where the user receives mail.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
414 This is the value of `mail-host-address' if bound and a string,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
415 otherwise the value of `time-stamp-mail-host' (for versions of Emacs
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
416 before 19.29) otherwise the value of the function system-name."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
417 (or (and (boundp 'mail-host-address)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
418 (stringp mail-host-address)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
419 mail-host-address)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
420 (and (boundp 'time-stamp-mail-host) ;for backward compatibility
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
421 (stringp time-stamp-mail-host)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
422 time-stamp-mail-host)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
423 (system-name)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
424
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
425 ;;; the rest of this file is for version 1 compatibility
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (defun time-stamp-fconcat (list sep)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
428 "Similar to (mapconcat 'funcall LIST SEP) but LIST allows literals.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 If an element of LIST is a symbol, it is funcalled to get the string to use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 the separator SEP is used between two strings obtained by funcalling a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 symbol. Otherwise the element itself is inserted; no separator is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 around literals."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (let ((return-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (insert-sep-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (cond ((symbolp (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (if insert-sep-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq return-string (concat return-string sep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (setq return-string (concat return-string (funcall (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (setq insert-sep-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq return-string (concat return-string (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (setq insert-sep-p nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 return-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;;; Some useful functions to use in time-stamp-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;;; Could generate most of a message-id with
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
451 ;;; '(time-stamp-yymmdd "" time-stamp-hhmm "@" time-stamp-mail-host-name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;;; pretty form, suitable for a title page
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (defun time-stamp-month-dd-yyyy ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
456 "Return the current date as a string in \"Month DD, YYYY\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (let ((date (current-time-string)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
458 (format "%s %d, %s"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (aref time-stamp-month-full-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (cdr (assoc (substring date 4 7) time-stamp-month-numbers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (string-to-int (substring date 8 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (substring date -4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;;; same as __DATE__ in ANSI C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defun time-stamp-mon-dd-yyyy ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
467 "Return the current date as a string in \"Mon DD YYYY\" form.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
468 The first character of DD is space if the value is less than 10."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (let ((date (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (format "%s %2d %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (substring date 4 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (string-to-int (substring date 8 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (substring date -4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;;; RFC 822 date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (defun time-stamp-dd-mon-yy ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
478 "Return the current date as a string in \"DD Mon YY\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (let ((date (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (format "%02d %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (string-to-int (substring date 8 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (substring date 4 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (substring date -2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;;; RCS 3 date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun time-stamp-yy/mm/dd ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
488 "Return the current date as a string in \"YY/MM/DD\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (let ((date (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (format "%s/%02d/%02d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (substring date -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (string-to-int (substring date 8 10)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;;; RCS 5 date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (defun time-stamp-yyyy/mm/dd ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
498 "Return the current date as a string in \"YYYY/MM/DD\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (let ((date (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (format "%s/%02d/%02d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (substring date -4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (string-to-int (substring date 8 10)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
505 ;;; ISO 8601 date
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
506
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
507 (defun time-stamp-yyyy-mm-dd ()
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
508 "Return the current date as a string in \"YYYY-MM-DD\" form."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
509 (let ((date (current-time-string)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
510 (format "%s-%02d-%02d"
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
511 (substring date -4)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
512 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
513 (string-to-int (substring date 8 10)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
514
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (defun time-stamp-yymmdd ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
516 "Return the current date as a string in \"YYMMDD\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (let ((date (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (format "%s%02d%02d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (substring date -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (cdr (assoc (substring date 4 7) time-stamp-month-numbers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (string-to-int (substring date 8 10)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defun time-stamp-hh:mm:ss ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
524 "Return the current time as a string in \"HH:MM:SS\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (substring (current-time-string) 11 19))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (defun time-stamp-hhmm ()
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
528 "Return the current time as a string in \"HHMM\" form."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (let ((date (current-time-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (concat (substring date 11 13)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (substring date 14 16))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (provide 'time-stamp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;;; time-stamp.el ends here