;;; type-break.el --- encourage rests from typing at appropriate intervals
-;; Copyright (C) 1994, 95, 97, 2000, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1997, 2000, 2001, 2002, 2003,
+;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
;; Author: Noah Friedman
;; Maintainer: Noah Friedman <friedman@splode.com>
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
(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))))))))
+ (condition-case nil
+ (save-excursion
+ (goto-char (point-min))
+ (read (current-buffer)))
+ (end-of-file
+ (error "End of file in `%s'" file))))))))
(defun type-break-get-previous-count ()
"Get previous keystroke count from `type-break-file-name'.
(setq file
(with-current-buffer
(find-file-noselect file 'nowarn)
- (save-excursion
- (goto-char (point-min))
- (forward-line 1)
- (read (current-buffer)))))))
+ (condition-case nil
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line 1)
+ (read (current-buffer)))
+ (end-of-file
+ (error "End of file in `%s'" file)))))))
file
0)))
\f
;;; Demo wrappers
+(defun type-break-catch-up-event ()
+ ;; If the last input event is a down-event, read and discard the
+ ;; corresponding up-event too, to avoid triggering another prompt.
+ (and (eventp last-input-event)
+ (memq 'down (event-modifiers last-input-event))
+ (read-event)))
+
;; This is a wrapper around hanoi that calls it with an arg large enough to
;; make the largest discs possible that will fit in the window.
;; Also, clean up the *Hanoi* buffer after we're done.
(progn
(hanoi (/ (window-width) 8))
;; Wait for user to come back.
- (read-char)
+ (read-event)
+ (type-break-catch-up-event)
(kill-buffer "*Hanoi*"))
(quit
- ;; eat char
- (read-char)
+ (read-event)
+ (type-break-catch-up-event)
(and (get-buffer "*Hanoi*")
(kill-buffer "*Hanoi*")))))
(progn
(life 3)
;; wait for user to return
- (read-char)
+ (read-event)
+ (type-break-catch-up-event)
(kill-buffer "*Life*"))
(life-extinct
(message "%s" (get 'life-extinct 'error-message))
- (sit-for 3)
;; restart demo
(setq continue t))
(quit
+ (type-break-catch-up-event)
(and (get-buffer "*Life*")
(kill-buffer "*Life*")))))))
message))))
(goto-char (point-min))
(sit-for 60))
- (read-char)
+ (read-event)
+ (type-break-catch-up-event)
(kill-buffer buffer-name))
(quit
(and (get-buffer buffer-name)