| perldiver ( @ 2009-06-24 00:19:00 |
| Entry tags: | emacs, programming |
How to make Emacs automatically update timestamps in your files
It's basically not possible to know all the nifty ways that Emacs can make your life easier; learning it is part of the fun. So, the next time you want automatically updated timestamps in your files, just add the following to your .emacs file:
(setq
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
(add-hook 'write-file-hooks 'time-stamp) ;; update when saving
Then, in your file, you put: Time-stamp: <>
The "Time-stamp" *is* case-sensitive, but may be embedded in other text. It must appear in the first 10 lines (or whatever you set "time-stamp-line-limit" to). Note that there cannot be spaces between the '<' and the '>'.
The resulting timestamp will be updated every time you save, and it will look something like this:
Time-stamp: <2009-06-24 00:21:45 (dstorrs)>
Given that this is my machine and I'm the only one using it, I removed the "(%u)" at the end of the format so that I didn't have the username cluttering things up.
The above is courtesy of: http://emacs-fu.blogspot.com/2008/12/aut