 ;;  kiirogaa.el
 ;;
+(require 'cl)
 
 ; User set variables.
 (defvar kiirogaa-log-base-dir "~/keylog/"

(defun kiirogaa-start-logging (filename)
  (interactive (list
                (read-file-name "Log filename: " kiirogaa-log-base-dir nil nil
                                (concat (buffer-name (current-buffer)) ".keylog"))))
  (setq kiirogaa-log-buffer-alist
        (cons (cons (current-buffer) filename) kiirogaa-log-buffer-alist))
  )

(defun kiirogaa-stop-logging ()
  (interactive)
  (setq kiirogaa-log-buffer-alist
        (assq-delete-all (current-buffer) kiirogaa-log-buffer-alist))
  )

(defun kiirogaa-save-buffer-with-timestamp (filename)
  (interactive "FSave filename: ")
  (let ((chars (make-vector (buffer-size) nil)))
    (let ((i 0))
      (while (< i (length chars))

          (set-buffer (get-buffer-create -kiirogaa-tmp-buffer-name))
          (erase-buffer)
          (insert (kiirogaa-format-entry c time))
          (write-region nil nil (cdr pair) t []))
        ))
    ))

(add-hook 'pre-command-hook (function kiirogaa-pre-command-hook))
(add-hook 'after-save-hook (function kiirogaa-save-buffer-with-timestamp))
(add-hook 'post-self-insert-hook (function kiirogaa-post-self-insert-hook))
