diff options
| author | Richard M. Stallman | 1996-12-17 00:14:41 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-12-17 00:14:41 +0000 |
| commit | 6946129cbe0d00931a668b60f7464b4be89875ee (patch) | |
| tree | 6dd78bfd8e9c08e86c905aedf9c5c8741526eade | |
| parent | d2b7637f7c52aa04be2120fe7b8c712af36d9526 (diff) | |
| download | emacs-6946129cbe0d00931a668b60f7464b4be89875ee.tar.gz emacs-6946129cbe0d00931a668b60f7464b4be89875ee.zip | |
(time-stamp-no-file): Reintroduced.
(time-stamp-string-preprocess): New function.
(time-stamp-string): Use time-stamp-string-preprocess.
(time-stamp-format): Doc fix.
| -rw-r--r-- | lisp/time-stamp.el | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index 73be7968cc1..16da129e2bd 100644 --- a/lisp/time-stamp.el +++ b/lisp/time-stamp.el | |||
| @@ -40,7 +40,7 @@ | |||
| 40 | ;; Originally based on the 19 Dec 88 version of | 40 | ;; Originally based on the 19 Dec 88 version of |
| 41 | ;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net> | 41 | ;; date.el by John Sturdy <mcvax!harlqn.co.uk!jcgs@uunet.uu.net> |
| 42 | ;; Version 2, January 1995: replaced functions with %-escapes | 42 | ;; Version 2, January 1995: replaced functions with %-escapes |
| 43 | ;; $Id: time-stamp.el,v 1.20 1996/11/05 18:27:41 rms Exp rms $ | 43 | ;; $Id: time-stamp.el,v 1.21 1996/12/13 01:49:23 rms Exp rms $ |
| 44 | 44 | ||
| 45 | ;;; Code: | 45 | ;;; Code: |
| 46 | 46 | ||
| @@ -60,14 +60,23 @@ If `error', the format is not used. If `ask', the user is queried about | |||
| 60 | using the time-stamp-format. If `warn', a warning is displayed. | 60 | using the time-stamp-format. If `warn', a warning is displayed. |
| 61 | If nil, no notification is given.") | 61 | If nil, no notification is given.") |
| 62 | 62 | ||
| 63 | (defvar time-stamp-format "%y-%m-%d %H:%M:%S %u" | 63 | (defvar time-stamp-format "%Y-%m-%d %H:%M:%S %u" |
| 64 | "*Format of the string inserted by \\[time-stamp]. | 64 | "*Format of the string inserted by \\[time-stamp]. |
| 65 | The value may be a string or a list. Lists are supported only for | 65 | The value may be a string or a list. Lists are supported only for |
| 66 | backward compatibility; see variable `time-stamp-old-format-warn'. | 66 | backward compatibility; see variable `time-stamp-old-format-warn'. |
| 67 | 67 | ||
| 68 | A string is used with `format-time-string'. | 68 | A string is used with `format-time-string'. |
| 69 | For example, to get the format used by the `date' command, | 69 | For example, to get the format used by the `date' command, |
| 70 | use \"%3a %3b %2d %H:%M:%S %Z %y\"") | 70 | use \"%3a %3b %2d %H:%M:%S %Z %y\". |
| 71 | |||
| 72 | In addition to the features of `format-time-string', | ||
| 73 | you can use the following %-constructs: | ||
| 74 | |||
| 75 | %f file name without directory | ||
| 76 | %F full file name | ||
| 77 | %h mail host name | ||
| 78 | %s system name | ||
| 79 | %u user's login name") | ||
| 71 | 80 | ||
| 72 | ;;; Do not change time-stamp-line-limit, time-stamp-start, or | 81 | ;;; Do not change time-stamp-line-limit, time-stamp-start, or |
| 73 | ;;; time-stamp-end in your .emacs or you will be incompatible | 82 | ;;; time-stamp-end in your .emacs or you will be incompatible |
| @@ -194,11 +203,39 @@ With arg, turn time stamping on if and only if arg is positive." | |||
| 194 | (> (prefix-numeric-value arg) 0))) | 203 | (> (prefix-numeric-value arg) 0))) |
| 195 | (message "time-stamp is now %s." (if time-stamp-active "active" "off"))) | 204 | (message "time-stamp is now %s." (if time-stamp-active "active" "off"))) |
| 196 | 205 | ||
| 206 | (defconst time-stamp-no-file "(no file)" | ||
| 207 | "String to use when the buffer is not associated with a file.") | ||
| 208 | |||
| 209 | (defun time-stamp-string-preprocess (format) | ||
| 210 | "Process occurrences in FORMAT of %f, %F, %h, %s and %u. | ||
| 211 | These are replaced with the file name (nondirectory part), | ||
| 212 | full file name, host name for mail, system name, and user name. | ||
| 213 | Do not alter other %-combinations, and do detect %%." | ||
| 214 | (let ((result "") (pos 0) (case-fold-search nil) | ||
| 215 | (file (or buffer-file-name "(no file)"))) | ||
| 216 | (while (string-match "%[%uhfFs]" format pos) | ||
| 217 | (setq result (concat result (substring format pos (match-beginning 0)))) | ||
| 218 | (let ((char (aref format (1+ (match-beginning 0))))) | ||
| 219 | (cond ((= char ?%) | ||
| 220 | (setq result (concat result "%%"))) | ||
| 221 | ((= char ?u) | ||
| 222 | (setq result (concat result (user-login-name)))) | ||
| 223 | ((= char ?f) | ||
| 224 | (setq result (concat result (file-name-nondirectory file)))) | ||
| 225 | ((= char ?f) | ||
| 226 | (setq result (concat result file))) | ||
| 227 | ((= char ?s) | ||
| 228 | (setq result (concat result (system-name)))) | ||
| 229 | ((= char ?h) | ||
| 230 | (setq result (concat result (time-stamp-mail-host-name)))))) | ||
| 231 | (setq pos (match-end 0))) | ||
| 232 | (concat result (substring format pos)))) | ||
| 197 | 233 | ||
| 198 | (defun time-stamp-string () | 234 | (defun time-stamp-string () |
| 199 | "Generate the new string to be inserted by \\[time-stamp]." | 235 | "Generate the new string to be inserted by \\[time-stamp]." |
| 200 | (if (stringp time-stamp-format) | 236 | (if (stringp time-stamp-format) |
| 201 | (format-time-string time-stamp-format (current-time)) | 237 | (format-time-string (time-stamp-string-preprocess time-stamp-format) |
| 238 | (current-time)) | ||
| 202 | ;; handle version 1 compatibility | 239 | ;; handle version 1 compatibility |
| 203 | (cond ((or (eq time-stamp-old-format-warn 'error) | 240 | (cond ((or (eq time-stamp-old-format-warn 'error) |
| 204 | (and (eq time-stamp-old-format-warn 'ask) | 241 | (and (eq time-stamp-old-format-warn 'ask) |