]> code.delx.au - gnu-emacs/blobdiff - lisp/type-break.el
(find-file, find-file-other-window, find-file-other-frame, find-file-existing)
[gnu-emacs] / lisp / type-break.el
index 3a0b8b5adccc4da9d1481d63c8ff193ba4578185..59b49f7092ca61b9e5ac305727e7a0a48478b5c1 100644 (file)
@@ -1,6 +1,7 @@
 ;;; 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>
@@ -12,7 +13,7 @@
 
 ;; 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,
@@ -22,8 +23,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -390,8 +391,9 @@ problems."
       (and (interactive-p)
            (message "Type Break mode is already enabled")))
      (type-break-mode
-      (with-current-buffer (find-file-noselect type-break-file-name 'nowarn)
-        (setq buffer-save-without-query t))
+      (when type-break-file-name
+       (with-current-buffer (find-file-noselect type-break-file-name 'nowarn)
+         (setq buffer-save-without-query t)))
 
       (or global-mode-string
           (setq global-mode-string '("")))
@@ -560,9 +562,12 @@ Returns nil if the file is missing or if the time breaks with the
     (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'.
@@ -574,10 +579,13 @@ integer."
               (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)))
 
@@ -1118,6 +1126,13 @@ With optional non-nil ALL, force redisplay of all mode-lines."
 \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.
@@ -1129,11 +1144,12 @@ With optional non-nil ALL, force redisplay of all mode-lines."
       (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*")))))
 
@@ -1151,14 +1167,15 @@ With optional non-nil ALL, force redisplay of all mode-lines."
           (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*")))))))
 
@@ -1244,7 +1261,8 @@ With optional non-nil ALL, force redisplay of all mode-lines."
                      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)