annotate lisp/time-stamp.el @ 11946:581775d8ec7a

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