Home > emacs, Linux > eMarch 3 : Time-stamps

eMarch 3 : Time-stamps

Keeping a track of changes in your source code is always a good idea. I generally use two ways to know when I’ve done my last change of a file.


This function is generally useful for small scripts or projects. First you have to insert the following lines in your .emacs

 time-stamp-active t          ; Set  time-stamp
 time-stamp-line-limit 20     ; Indicate within how many lines a time-stamp should be seek (here the 20th first lines)
 time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; Format date
 (add-hook 'write-file-hooks 'time-stamp) ; ask for automatic update

Second, just add within the first line of your file (20 in the latter code); the keyword:

Time-stamp: <>

Any time you ‘ll save your file, the Time-stamp will be updated. A nice feature here is that emacs is looking for a pattern, so we can play a bit with is. As instance, if you want to keep a track in a log file of which version of a script was used, just add :

T="Time-stamp: <>"
echo "Running "$0 "Version "$T

Likewise, you can add some similar kind of code to your FORTRAN, C etc…  source code to know which version of the source was used to create your executable as already mentioned in a later post.

SVN ID version

The last comment lead us directly to the second time-stamping option. When I first start using svn I had trouble with the Time-stamp tags in my files since any small change in a file under svn generate at least two lines of changes (the actual change and the Time-stamp change). In this case the correct way to proceed is to use the
VC-dir tool.

Either, with C-x v h, or Tools, Version Control,  Insert Header, or click-1 on major mode keyword in baseline  and then Insert Header.

This will add the tag $Id$ preceded by an appropriate comment sign. Every time you commit your source the tag will be updated (and won’t be considered as an actual changes in the code).

Categories: emacs, Linux
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: