The following is a simple example of using Emacs hooks. It logs all buffer saves to a log file. The log file is currently written to saves in [[.emacs.d?]]--a location where the ‘auto-save-list’ data is also stored.
The save log is generated when Emacs quits. That behavior could obviously be modified.
(defvar save-log-log-file "~/.emacs.d/saves") (defvar save-log-alist nil) (defvar save-log-date-format "%Y-%m-%d %H:%M:%S")
(defun save-log-add-file (file)
"Add the file FILE to the log."
(let ((date-time (format-time-string save-log-date-format)))
(setq save-log-alist (append save-log-alist
(list (list file date-time)))))) (defun save-log-write-log-file (file)
"Write save log file to FILE."
(with-temp-file file
(if (file-exists-p file)
(insert-file-contents file))
;; Assumed: (goto-char (point-max))
(mapcar (lambda (file-and-date)
(insert (cadr file-and-date) " "
(car file-and-date) "\n"))
save-log-alist))
(message (format "Save log saved: %s" file))) (defun save-log-after-save-hook ()
(save-log-add-file buffer-file-truename))(add-hook 'after-save-hook 'save-log-after-save-hook)
(defun save-log-kill-emacs-hook ()
(save-log-write-log-file save-log-log-file))(add-hook 'kill-emacs-hook 'save-log-kill-emacs-hook)
Here is an example ~/.emacs.d/saves file:
[Insert the file contents of ~/.emacs.d/saves here]