automatic timestamps

Sometimes, it's nice to have a timestamp in your files; i.e. some date that is automatically updated when you save the file. For this, emacs provides timestamps. They can easily be enable in your .emacs:
  time-stamp-active t          ; do enable time-stamps
  time-stamp-line-limit 10     ; check first 10 buffer lines for Time-stamp: 
  time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; date format
This tells emacs that we'd like to use timestamps, and how they should format the date. By default, to add a timestamp in a file, you'd add
Time-stamp: <>
at the top of your file, which you could then fill by calling M-x file-stamp, which would give us something like:
Time-stamp: <2008-12-02 20:35:47 (djcb)>
With 'djcb' replaced with your username. And probably with a different date....

We might want emacs to update this time stamp automatically whenever we save the file; this can be done by add a hook, ie. specifying a function that will be called when something happens; in this case we can put the following in our .emacs:

(add-hook 'write-file-hooks 'time-stamp) ; update when saving
And emacs will obediently update the time stamp whenever we save the file.

No comments: