+\f
+;;; session file functions
+
+(defvar type-break-auto-save-file-name
+ (let ((buffer-file-name type-break-file-name))
+ (make-auto-save-file-name))
+ "Auto-save name of `type-break-file-name'.")
+
+(defun type-break-file-time (&optional time)
+ "File break time in `type-break-file-name', unless the file is locked."
+ (if (and type-break-file-name
+ (not (stringp (file-locked-p type-break-file-name))))
+ (with-current-buffer (find-file-noselect type-break-file-name
+ 'nowarn)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert (format "%s\n\n" (or time type-break-interval-start)))
+ ;; file saving is left to auto-save
+ ))))
+
+(defun type-break-file-keystroke-count ()
+ "File keystroke count in `type-break-file-name', unless the file is locked."
+ (if (and type-break-file-name
+ (not (stringp (file-locked-p type-break-file-name))))
+ ;; Prevent deactivation of the mark in some other buffer.
+ (let (deactivate-mark)
+ (with-current-buffer (find-file-noselect type-break-file-name
+ 'nowarn)
+ (save-excursion
+ (let ((inhibit-read-only t))
+ (goto-char (point-min))
+ (forward-line)
+ (delete-region (point) (save-excursion (end-of-line) (point)))
+ (insert (format "%s" type-break-keystroke-count))
+ ;; file saving is left to auto-save
+ ))))))
+
+(defun timep (time)
+ "If TIME is in the format returned by `current-time' then
+return TIME, else return nil."
+ (and (listp time)
+ (eq (length time) 3)
+ (integerp (car time))
+ (integerp (nth 1 time))
+ (integerp (nth 2 time))
+ time))
+
+(defun type-break-choose-file ()
+ "Return file to read from."
+ (cond
+ ((not type-break-file-name)
+ nil)
+ ((and (file-exists-p type-break-auto-save-file-name)
+ (file-readable-p type-break-auto-save-file-name))
+ type-break-auto-save-file-name)
+ ((and (file-exists-p type-break-file-name)
+ (file-readable-p type-break-file-name))
+ type-break-file-name)
+ (t nil)))
+
+(defun type-break-get-previous-time ()
+ "Get previous break time from `type-break-file-name'.
+Returns nil if the file is missing or if the time breaks with the
+`current-time' format."
+ (let ((file (type-break-choose-file)))
+ (if file
+ (timep ;; returns expected format, else nil
+ (with-current-buffer (find-file-noselect file 'nowarn)
+ (save-excursion
+ (goto-char (point-min))
+ (read (current-buffer))))))))
+
+(defun type-break-get-previous-count ()
+ "Get previous keystroke count from `type-break-file-name'.
+Return 0 if the file is missing or if the form read is not an
+integer."
+ (let ((file (type-break-choose-file)))
+ (if (and file
+ (integerp
+ (setq file
+ (with-current-buffer
+ (find-file-noselect file 'nowarn)
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line 1)
+ (read (current-buffer)))))))
+ file
+ 0)))
+