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