Emacs Time Stamp

Enabling automatic time-stamping in Emacs

I do almost all my text editing in Emacs, and it would be worth to store the last modified date/time of a file — org/plain text/source code/whatever — in the file, without consulting the file system.

Fortunately, that is Emacs, and it always extends a helping hand. In our case this is the time-stamp Emacs built-in function that provides automatic time-stamping for a file.

All you need to do is to place a time-stamp template near the beginning of the file, and enable automatic time-stamping in your config.

;; When there is a "Time-stamp: <>" string in the first 10 lines of the file,
;; Emacs will write time-stamp information there when saving the file.
;; (Borrowed from http://home.thep.lu.se/~karlf/emacs.html)
(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 "Last changed %Y-%02m-%02d %02H:%02M:%02S by %u")
(add-hook 'write-file-hooks 'time-stamp) ; Update when saving.

See more about the time-stamp-format variable in Emacs built-in Help (M-x describe-variable).

Examples

ELisp

;;; package --- .emacs
;; Time-stamp: <Last changed 2025-04-18 12:54:28 by magnolia>
;;; Commentary:
;; Emacs startup file (macOS, Linux, Windows).

(defvar os-windows (string-equal system-type "windows-nt") "OMG, that's Windows!")
(defvar os-linux (string-equal system-type "gnu/linux") "I'm on Linux")
(defvar os-macos (string-equal system-type "darwin") "Oh, I'm on macOS")

(defvar my/home (getenv "HOME"))

Org Mode

:PROPERTIES:
:ID:       a483c173-162d-44fb-8c10-fec0f24eafc9
:END:
#+TITLE: Hugo
#+DATE: Time-stamp: <Last changed 2025-04-22 14:40:44 by magnolia>
#+FILETAGS: :blog:web:

* Issues
** 2025-04-01 Newest Hugo version publishes local links
   Fixed: Rolled back to v.0.123.7 from Ubuntu 24.04 repository.

C++ source code

// Time-stamp: <Last changed 2025-03-31 15:36:04 by magnolia>

#pragma once

#include <queue>
#include <mutex>
#include <condition_variable>

class SafeQueue {

Happy emacsing!

— The Emacs Cat.