annotate lisp/time-stamp.el @ 14685:496342156d13

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