help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Timestamped command-history and post-command-hook


From: Michael T Decerbo
Subject: Timestamped command-history and post-command-hook
Date: 06 Apr 2006 04:22:33 GMT

I wrote:
>The command M-x command-history-mode puts you in a buffer with the
>current command history, one command to a line.
>
>I would like to create a similar command that creates such a history
>with a timestamp at which each command was performed, perhaps as a
>comment.

So far, the best I have come up with is the following:

(defun history-timestamp ()
 "Append a timestamp to the most recent event"
 (interactive)
  (setq command-history (cons (append (car command-history) (list 
(format-time-string "%H:%M:%S %d.%m.%Y"))) (cdr command-history))))
(add-hook 'post-command-hook 'history-timestamp)

... which gives me results like the following.


(kill-buffer "foo3" "00:13:52 06.04.2006" "00:13:53 06.04.2006" "00:13:53 
06.04.2006" "00:13:53 06.04.2006" "00:13:53 06.04.2006" "00:13:53 06.04.2006" 
"00:13:53 06.04.2006" "00:13:53 06.04.2006" "00:13:53 06.04.2006" "00:13:54 
06.04.2006" "00:13:54 06.04.2006" "00:13:54 06.04.2006")
(switch-to-buffer "foo3" "00:13:51 06.04.2006" "00:13:52 06.04.2006")
(find-file "/tmp/foo8" 1 "00:13:48 06.04.2006" "00:13:49 06.04.2006" "00:13:49 
06.04.2006" "00:13:50 06.04.2006" "00:13:50 06.04.2006" "00:13:51 06.04.2006")
(kill-buffer "foo2" "00:12:41 06.04.2006" "00:12:42 06.04.2006" "00:12:42 
06.04.2006" "00:12:42 06.04.2006" "00:12:43 06.04.2006" "00:12:43 06.04.2006" 
"00:12:43 06.04.2006" "00:12:43 06.04.2006" "00:12:43 06.04.2006" "00:12:43 
06.04.2006" "00:12:43 06.04.2006" "00:12:43 06.04.2006")

Curiously, post-command-hook seems to be getting called multiple times
for each command, which is not at all what I had expected! Can anyone
shed any light on this?

I'm sure this breaks compatibility with packages that use the command-history;
is there a better way to do this?


-- 
Mike --- mike@mit.edu


reply via email to

[Prev in Thread] Current Thread [Next in Thread]