打开time-stamp可以记录最后运行time-stamp的时间, 所以一般将 time-stamp 加入 write-file-hooks 中, 记录文件的最后修改时间, ~/.emacs 配置如下:
(add-hook 'write-file-hooks 'time-stamp) (setq time-stamp-format "%:u %02m/%02d/%04y %02H:%02M:%02S")
上面设置写入文件时执行time-stamp, 并设置时间格式为"%:u %02m/%02d/%04y %02H:%02M:%02S", 缺省的情况下, 在所编辑文件的前八行内插入如下标记
Time-stamp: <>
或者
Time-stamp: " "
Emacs在保存时就会运行write-file-hooks中的time-stamp, 从而加 入修改时间, 结果类似下面所示
Time-stamp: <jerry 12/17/2003 12:00:54 (unidevel.com)>
或者
Time-stamp: "jerry 12/17/2003 12:00:54 (unidevel.com)"
要使用中文表示, 可以这样设置
(setq time-stamp-start "最后更新时间:[ ]+\\\\?") (setq time-stamp-end: "\n") (setq time-stamp-format: "%:y年%:m月%:d日")
上面设置了如果碰到"最后更新时间:"的字样, time-stamp就将其后 面的字符替换为当前时间的"XXXX年XX月XX日", 注意, time-stamp-end的结束符 为换行符, 所以"最后更新时间:"行后所有字符都将无条件被替换为"XXXX年XX月XX日" 格式的时间, 本文首页上的更新时间就是这样做出来的