Path: utzoo!attcan!uunet!mcvax!ukc!eagle!icdoc!qmc-cs!harlqn!jcgs
From: jcgs@harlqn.UUCP (John Sturdy)
Newsgroups: comp.emacs
Subject: Re: insert time/date and signature
Summary: Here's my version
Keywords: timestamping signing
Message-ID: <1043@harlqn.UUCP>
Date: 20 Sep 88 11:01:29 GMT
References: <29477@bbn.COM> <7243@haddock.ima.isc.com> <14107@agate.BERKELEY.EDU>
Reply-To: jcgs@uucp (John Sturdy)
Organization: Harlequin (Cambridge, UK) Ltd.
Lines: 69

Here is the code I've been using to do this for the last year or so:

;;; date.el
;;; Last edited: Tue Sep 20 11:58:42 1988 by jcgs (John Sturdy) on harlqn

;;; This code maintains dates and signatures in files, removing the old
;;; date each time.

(defvar last-edited-pattern
  "Last edited: "
  "*The regexp after which the time-stamp is written by the
function \"time-stamp\". See also \"last-edited-end-pattern\".")

(defvar last-edited-end-pattern
  "$"
  "*The function \"time-stamp\" deletes the text between the first match of
\"last-edited-pattern\" (which see) and the following match of
\"last-edited-end-pattern\", then writes the time-stamp between them.
This pattern normally marks the end of the current line."
)

(defvar by-line
  (concat
   " by "
   (user-login-name)
   " ("
   (user-full-name)
   (if (boundp 'nick-name)
       (concat " - " nick-name ")")
     ")")
   " on "
   (system-name))
  "The user-id and name of the user, and the name of the host machine,
in a form suitable for time-stamping.  If the user has defined the
variable \"nick-name\" before loading \"date\", it is included after
the real name, separated from it by a dash.")

(defun time-stamp ()
  "Update the \"Last edited:\" field in a buffer. Can be used on
\"write-file-hook\" for automatic time-stamping. The time-stamp
includes the date and time, the user's user-id and real name, and a
nick-name if the variable \"nick-name\" was already defined when the
\"date\" package was loaded. The \"Last edited:\" marker string must
occur in the first 3000 characters of the buffer."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (if
        (re-search-forward last-edited-pattern 3000 t)
        (let
            ((start-of-date (point)))
          (re-search-forward last-edited-end-pattern)
          (delete-region (point) start-of-date)
          (insert (current-time-string))
          (insert by-line)))))

(defun date-line ()
  "Insert a date marker line, in outline-mode's top-level format."
  (interactive)
  (beginning-of-line 2)
  (insert "* ")
  (insert (current-time-string))
  (insert by-line)
  (insert "\n"))

(setq write-file-hook 'time-stamp)      ; mark time, date on all files
                                        ; containing "Last edited:" as
                                        ; they are saved
;;; end of date.el