 (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))
-  )
+                                (concat (buffer-name) ".keylog"))))
+  (let ((pair (cons (buffer-name) filename)))
+    (setq kiirogaa-log-buffer-alist
+          (cons pair kiirogaa-log-buffer-alist))
+    ))
 
 (defun kiirogaa-stop-logging ()
   (interactive)
-  (setq kiirogaa-log-buffer-alist
-        (assq-delete-all (current-buffer) kiirogaa-log-buffer-alist))
-  )
+  (let ((name (buffer-name)))
+    (setq kiirogaa-log-buffer-alist
+          (remove-if (lambda (pair) (string= name (car pair)))
+                     kiirogaa-log-buffer-alist))
+    ))
 
-(defun kiirogaa-save-buffer-with-timestamp (filename)
-  (interactive "FSave filename: ")
+(defun kiirogaa-write-buffer-with-timestamp (filename &optional visit)
+  (interactive "FWrite filename: ")
   (let ((chars (make-vector (buffer-size) nil)))
     (let ((i 0))
       (while (< i (length chars))

          (let ((e (aref chars i)))
            (insert (kiirogaa-format-entry (car e) (cadr e))))
          (setq i (1+ i))))
      (write-file filename t))
    ))

(defun kiirogaa-pre-command-hook ()
  (setq -kiirogaa-tmp-last-point (point)))

(defun kiirogaa-post-self-insert-hook ()
  (let* ((alist (assq (current-buffer) kiirogaa-log-buffer-alist)))
    (when alist
      (let ((time (float-time))
            (p -kiirogaa-tmp-last-point)
            (c last-command-event))

;;  kiirogaa.el
;;
(require 'cl)

; User set variables.
(defvar kiirogaa-log-base-dir "~/keylog/"
