annotate lisp/type-break.el @ 22344:2ec50b4767ed

Handle the new convention that `position' values in a string's intervals start from zero. (validate_interval_range, interval_of, Fnext_property_change) (property_change_between_p, Fnext_single_property_change) (Fprevious_property_change, Fprevious_single_property_change): (Ftext_property_any, Ftext_property_not_all): Implement that. Undo previous change.
author Karl Heuer <kwzh@gnu.org>
date Wed, 03 Jun 1998 14:45:03 +0000
parents 3df130425e5e
children b88e81176427
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
1 ;;; type-break.el --- encourage rests from typing at appropriate intervals
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
2
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
3 ;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
4
9355
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
6 ;; Maintainer: friedman@prep.ai.mit.edu
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
7 ;; Keywords: extensions, timers
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
8 ;; Status: Works in GNU Emacs 19.25 or later, some versions of XEmacs
9355
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
9 ;; Created: 1994-07-13
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
10
22069
3df130425e5e (type-break-mode): Don't alter global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents: 22049
diff changeset
11 ;; $Id: type-break.el,v 1.16 1998/05/13 01:46:28 rms Exp rms $
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
12
9355
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
13 ;; This file is part of GNU Emacs.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
14
9355
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
16 ;; it under the terms of the GNU General Public License as published by
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
18 ;; any later version.
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
19
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
23 ;; GNU General Public License for more details.
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
24
8ac258bc59ef Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents: 8497
diff changeset
25 ;; You should have received a copy of the GNU General Public License
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
28 ;; Boston, MA 02111-1307, USA.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
29
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
30 ;;; Commentary:
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
31
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
32 ;; The docstring for the function `type-break-mode' summarizes most of the
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
33 ;; details of the interface.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
34
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
35 ;; This package relies on the assumption that you live entirely in emacs,
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
36 ;; as the author does. If that's not the case for you (e.g. you often
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
37 ;; suspend emacs or work in other windows) then this won't help very much;
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
38 ;; it will depend on just how often you switch back to emacs. At the very
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
39 ;; least, you will want to turn off the keystroke thresholds and rest
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
40 ;; interval tracking.
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
41
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
42 ;; If you prefer not to be queried about taking breaks, but instead just
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
43 ;; want to be reminded, do the following:
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
44 ;;
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
45 ;; (setq type-break-query-mode nil)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
46 ;;
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
47 ;; Or call the command `type-break-query-mode' with a negative prefix
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
48 ;; argument.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
49
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
50 ;; If you find echo area messages annoying and would prefer to see messages
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
51 ;; in the mode line instead, do M-x type-break-mode-line-message-mode
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
52 ;; or set the variable of the same name to `t'.
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
53
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
54 ;; This program can truly cons up a storm because of all the calls to
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
55 ;; `current-time' (which always returns 3 fresh conses). I'm dismayed by
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
56 ;; this, but I think the health of my hands is far more important than a
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
57 ;; few pages of virtual memory.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
58
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
59 ;; This program has no hope of working in Emacs 18.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
60
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
61 ;; This package was inspired by Roland McGrath's hanoi-break.el.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
62 ;; Several people contributed feedback and ideas, including
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
63 ;; Roland McGrath <roland@gnu.ai.mit.edu>
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
64 ;; Kleanthes Koniaris <kgk@martigny.ai.mit.edu>
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
65 ;; Mark Ashton <mpashton@gnu.ai.mit.edu>
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
66 ;; Matt Wilding <wilding@cli.com>
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
67 ;; Robert S. Boyer <boyer@cs.utexas.edu>
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
68
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
69 ;;; Code:
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
70
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
71
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
72 (defgroup type-break nil
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
73 "Encourage the user to take a rest from typing at suitable intervals."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
74 :prefix "type-break"
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
75 :group 'keyboard)
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
76
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
77 ;;;###autoload
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
78 (defcustom type-break-mode nil
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
79 "*Non-nil means typing break mode is enabled.
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
80 See the docstring for the `type-break-mode' command for more information.
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
81 You must modify via \\[customize] for this variable to have an effect."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
82 :set (lambda (symbol value)
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
83 (type-break-mode (if value 1 -1)))
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
84 :initialize 'custom-initialize-default
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
85 :type 'boolean
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
86 :group 'type-break
21670
808ecc2eaa84 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21159
diff changeset
87 :require 'type-break
808ecc2eaa84 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21159
diff changeset
88 :version "20.3")
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
89
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
90 ;;;###autoload
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
91 (defcustom type-break-interval (* 60 60)
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
92 "*Number of seconds between scheduled typing breaks."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
93 :type 'integer
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
94 :group 'type-break)
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
95
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
96 ;;;###autoload
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
97 (defcustom type-break-good-rest-interval (/ type-break-interval 6)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
98 "*Number of seconds of idle time considered to be an adequate typing rest.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
99
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
100 When this variable is non-`nil', emacs checks the idle time between
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
101 keystrokes. If this idle time is long enough to be considered a \"good\"
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
102 rest from typing, then the next typing break is simply rescheduled for later.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
103
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
104 If a break is interrupted before this much time elapses, the user will be
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
105 asked whether or not really to interrupt the break."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
106 :type 'integer
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
107 :group 'type-break)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
108
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
109 ;;;###autoload
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
110 (defcustom type-break-keystroke-threshold
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
111 ;; Assuming typing speed is 35wpm (on the average, do you really
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
112 ;; type more than that in a minute? I spend a lot of time reading mail
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
113 ;; and simply studying code in buffers) and average word length is
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
114 ;; about 5 letters, default upper threshold to the average number of
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
115 ;; keystrokes one is likely to type in a break interval. That way if the
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
116 ;; user goes through a furious burst of typing activity, cause a typing
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
117 ;; break to be required sooner than originally scheduled.
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
118 ;; Conversely, the minimum threshold should be about a fifth of this.
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
119 (let* ((wpm 35)
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
120 (avg-word-length 5)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
121 (upper (* wpm avg-word-length (/ type-break-interval 60)))
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
122 (lower (/ upper 5)))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
123 (cons lower upper))
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
124 "*Upper and lower bound on number of keystrokes for considering typing break.
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
125 This structure is a pair of numbers (MIN . MAX).
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
126
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
127 The first number is the minimum number of keystrokes that must have been
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
128 entered since the last typing break before considering another one, even if
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
129 the scheduled time has elapsed; the break is simply rescheduled until later
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
130 if the minimum threshold hasn't been reached. If this first value is nil,
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
131 then there is no minimum threshold; as soon as the scheduled time has
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
132 elapsed, the user will always be queried.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
133
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
134 The second number is the maximum number of keystrokes that can be entered
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
135 before a typing break is requested immediately, pre-empting the originally
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
136 scheduled break. If this second value is nil, then no pre-emptive breaks
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
137 will occur; only scheduled ones will.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
138
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
139 Keys with bucky bits (shift, control, meta, etc) are counted as only one
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
140 keystroke even though they really require multiple keys to generate them.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
141
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
142 The command `type-break-guesstimate-keystroke-threshold' can be used to
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
143 guess a reasonably good pair of values for this variable."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
144 :type 'sexp
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
145 :group 'type-break)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
146
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
147 (defcustom type-break-query-mode t
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
148 "*Non-`nil' means ask whether or not to prompt user for breaks.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
149 If so, call the function specified in the value of the variable
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
150 `type-break-query-function' to do the asking."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
151 :type 'boolean
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
152 :group 'type-break)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
153
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
154 (defvar type-break-query-function 'yes-or-no-p
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
155 "Function to use for making query for a typing break.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
156 It should take a string as an argument, the prompt.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
157 Usually this should be set to `yes-or-no-p' or `y-or-n-p'.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
158
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
159 To avoid being queried at all, set `type-break-query-mode' to `nil'.")
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
160
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
161 (defcustom type-break-query-interval 60
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
162 "*Number of seconds between queries to take a break, if put off.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
163 The user will continue to be prompted at this interval until he or she
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
164 finally submits to taking a typing break."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
165 :type 'integer
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
166 :group 'type-break)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
167
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
168 (defcustom type-break-time-warning-intervals '(300 120 60 30)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
169 "*List of time intervals for warnings about upcoming typing break.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
170 At each of the intervals (specified in seconds) away from a scheduled
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
171 typing break, print a warning in the echo area."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
172 :type '(repeat integer)
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
173 :group 'type-break)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
174
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
175 (defcustom type-break-keystroke-warning-intervals '(300 200 100 50)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
176 "*List of keystroke measurements for warnings about upcoming typing break.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
177 At each of the intervals (specified in keystrokes) away from the upper
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
178 keystroke threshold, print a warning in the echo area.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
179 If either this variable or the upper threshold is set, then no warnings
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
180 will occur."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
181 :type '(repeat integer)
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
182 :group 'type-break)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
183
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
184
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
185 (defcustom type-break-warning-repeat 40
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
186 "*Number of keystrokes for which warnings should be repeated.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
187 That is, for each of this many keystrokes the warning is redisplayed
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
188 in the echo area to make sure it's really seen."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
189 :type 'integer
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
190 :group 'type-break)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
191
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
192 (defcustom type-break-demo-functions
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
193 '(type-break-demo-boring type-break-demo-life type-break-demo-hanoi)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
194 "*List of functions to consider running as demos during typing breaks.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
195 When a typing break begins, one of these functions is selected randomly
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
196 to have emacs do something interesting.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
197
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
198 Any function in this list should start a demo which ceases as soon as a
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
199 key is pressed."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
200 :type '(repeat function)
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
201 :group 'type-break)
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
202
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
203 (defvar type-break-post-command-hook '(type-break-check)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
204 "Hook run indirectly by post-command-hook for typing break functions.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
205 This is not really intended to be set by the user, but it's probably
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
206 harmless to do so. Mainly it is used by various parts of the typing break
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
207 program to delay actions until after the user has completed some command.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
208 It exists because `post-command-hook' itself is inaccessible while its
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
209 functions are being run, and some type-break--related functions want to
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
210 remove themselves after running.")
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
211
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
212
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
213 ;; Mode line frobs
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
214
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
215 (defcustom type-break-mode-line-message-mode nil
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
216 "*Non-`nil' means put type-break related messages in the mode line.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
217 Otherwise, messages typically go in the echo area.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
218
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
219 See also `type-break-mode-line-format' and its members."
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
220 :type 'boolean
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
221 :group 'type-break)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
222
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
223 (defvar type-break-mode-line-format
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
224 '(type-break-mode-line-message-mode
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
225 (""
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
226 type-break-mode-line-break-message
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
227 type-break-mode-line-warning))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
228 "*Format of messages in the mode line concerning typing breaks.")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
229
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
230 (defvar type-break-mode-line-break-message
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
231 '(type-break-mode-line-break-message-p
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
232 type-break-mode-line-break-string))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
233
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
234 (defvar type-break-mode-line-break-message-p nil)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
235 (defvar type-break-mode-line-break-string " *** TAKE A TYPING BREAK ***")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
236
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
237 (defvar type-break-mode-line-warning
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
238 '(type-break-mode-line-break-message-p
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
239 ("")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
240 (type-break-warning-countdown-string
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
241 (" ***Break in "
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
242 type-break-warning-countdown-string
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
243 " "
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
244 type-break-warning-countdown-string-type
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
245 "***"))))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
246
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
247 (defvar type-break-warning-countdown-string nil
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
248 "If non-nil, this is a countdown for the next typing break.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
249
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
250 This variable, in conjunction with `type-break-warning-countdown-string-type'
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
251 (which indicates whether this value is a number of keystrokes or seconds)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
252 is installed in mode-line-format to notify of imminent typing breaks.")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
253
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
254 (defvar type-break-warning-countdown-string-type nil
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
255 "Indicates the unit type of `type-break-warning-countdown-string'.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
256 It will be either \"seconds\" or \"keystrokes\".")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
257
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
258
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
259 ;; These are internal variables. Do not set them yourself.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
260
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
261 (defvar type-break-alarm-p nil)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
262 (defvar type-break-keystroke-count 0)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
263 (defvar type-break-time-last-break nil)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
264 (defvar type-break-time-next-break nil)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
265 (defvar type-break-time-last-command (current-time))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
266 (defvar type-break-current-time-warning-interval nil)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
267 (defvar type-break-current-keystroke-warning-interval nil)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
268 (defvar type-break-time-warning-count 0)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
269 (defvar type-break-keystroke-warning-count 0)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
270
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
271 ;; Constant indicating emacs variant.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
272 ;; This can be one of `xemacs', `lucid', `epoch', `mule', etc.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
273 (defconst type-break-emacs-variant
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
274 (let ((data (match-data))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
275 (version (cond
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
276 ((fboundp 'nemacs-version)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
277 (nemacs-version))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
278 (t
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
279 (emacs-version))))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
280 (alist '(("\\bXEmacs\\b" . xemacs)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
281 ("\\bLucid\\b" . lucid)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
282 ("^Nemacs\\b" . nemacs)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
283 ("^GNU Emacs 19" . standard19)
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
284 ("^GNU Emacs 20" . standard19)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
285 ("^GNU Emacs 18" . emacs18)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
286 result)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
287 (while alist
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
288 (cond
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
289 ((string-match (car (car alist)) version)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
290 (setq result (cdr (car alist)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
291 (setq alist nil))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
292 (t
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
293 (setq alist (cdr alist)))))
21159
32a849d62a3f (type-break-emacs-variant): store-match-data => set-match-data.
Richard M. Stallman <rms@gnu.org>
parents: 20800
diff changeset
294 (set-match-data data)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
295 (cond ((eq result 'lucid)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
296 (and (string= emacs-version "19.8 Lucid")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
297 (setq result 'lucid-19-8)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
298 ((memq result '(nemacs emacs18))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
299 (signal 'error
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
300 "type-break not supported in this version of emacs.")))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
301 result))
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
302
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
303
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
304 ;;;###autoload
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
305 (defun type-break-mode (&optional prefix)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
306 "Enable or disable typing-break mode.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
307 This is a minor mode, but it is global to all buffers by default.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
308
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
309 When this mode is enabled, the user is encouraged to take typing breaks at
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
310 appropriate intervals; either after a specified amount of time or when the
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
311 user has exceeded a keystroke threshold. When the time arrives, the user
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
312 is asked to take a break. If the user refuses at that time, emacs will ask
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
313 again in a short period of time. The idea is to give the user enough time
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
314 to find a good breaking point in his or her work, but be sufficiently
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
315 annoying to discourage putting typing breaks off indefinitely.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
316
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
317 A negative prefix argument disables this mode.
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
318 No argument or any non-negative argument enables it.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
319
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
320 The user may enable or disable this mode by setting the variable of the
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
321 same name, though setting it in that way doesn't reschedule a break or
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
322 reset the keystroke counter.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
323
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
324 If the mode was previously disabled and is enabled as a consequence of
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
325 calling this function, it schedules a break with `type-break-schedule' to
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
326 make sure one occurs (the user can call that command to reschedule the
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
327 break at any time). It also initializes the keystroke counter.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
328
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
329 The variable `type-break-interval' specifies the number of seconds to
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
330 schedule between regular typing breaks. This variable doesn't directly
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
331 affect the time schedule; it simply provides a default for the
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
332 `type-break-schedule' command.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
333
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
334 If set, the variable `type-break-good-rest-interval' specifies the minimum
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
335 amount of time which is considered a reasonable typing break. Whenever
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
336 that time has elapsed, typing breaks are automatically rescheduled for
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
337 later even if emacs didn't prompt you to take one first. Also, if a break
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
338 is ended before this much time has elapsed, the user will be asked whether
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
339 or not to continue.
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
340
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
341 The variable `type-break-keystroke-threshold' is used to determine the
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
342 thresholds at which typing breaks should be considered. You can use
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
343 the command `type-break-guesstimate-keystroke-threshold' to try to
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
344 approximate good values for this.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
345
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
346 There are several variables that affect how or when warning messages about
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
347 imminent typing breaks are displayed. They include:
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
348
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
349 `type-break-mode-line-message-mode'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
350 `type-break-time-warning-intervals'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
351 `type-break-keystroke-warning-intervals'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
352 `type-break-warning-repeat'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
353 `type-break-warning-countdown-string'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
354 `type-break-warning-countdown-string-type'
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
355
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
356 There are several variables that affect if, how, and when queries to begin
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
357 a typing break occur. They include:
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
358
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
359 `type-break-query-mode'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
360 `type-break-query-function'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
361 `type-break-query-interval'
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
362
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
363 Finally, the command `type-break-statistics' prints interesting things."
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
364 (interactive "P")
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
365 (type-break-check-post-command-hook)
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
366
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
367 (let ((already-enabled type-break-mode))
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
368 (setq type-break-mode (>= (prefix-numeric-value prefix) 0))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
369
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
370 (cond
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
371 ((and already-enabled type-break-mode)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
372 (and (interactive-p)
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
373 (message "Type Break mode is already enabled")))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
374 (type-break-mode
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
375 (or global-mode-string
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
376 (setq global-mode-string '("")))
22069
3df130425e5e (type-break-mode): Don't alter global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents: 22049
diff changeset
377 (or (assq 'type-break-mode-line-message-mode
3df130425e5e (type-break-mode): Don't alter global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents: 22049
diff changeset
378 minor-mode-alist)
3df130425e5e (type-break-mode): Don't alter global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents: 22049
diff changeset
379 (setq minor-mode-alist
3df130425e5e (type-break-mode): Don't alter global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents: 22049
diff changeset
380 (cons type-break-mode-line-format
3df130425e5e (type-break-mode): Don't alter global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents: 22049
diff changeset
381 minor-mode-alist)))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
382 (type-break-keystroke-reset)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
383 (type-break-mode-line-countdown-or-break nil)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
384 (type-break-schedule)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
385 (and (interactive-p)
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
386 (message "Type Break mode is enabled and reset")))
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
387 (t
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
388 (type-break-keystroke-reset)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
389 (type-break-mode-line-countdown-or-break nil)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
390 (type-break-cancel-schedule)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
391 (and (interactive-p)
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
392 (message "Type Break mode is disabled")))))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
393 type-break-mode)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
394
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
395 (defun type-break-mode-line-message-mode (&optional prefix)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
396 "Enable or disable warnings in the mode line about typing breaks.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
397
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
398 A negative prefix argument disables this mode.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
399 No argument or any non-negative argument enables it.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
400
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
401 The user may also enable or disable this mode simply by setting the
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
402 variable of the same name.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
403
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
404 Variables controlling the display of messages in the mode line include:
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
405
22049
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
406 `mode-line-format'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
407 `global-mode-string'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
408 `type-break-mode-line-break-message'
247682b1da6b (type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
parents: 21670
diff changeset
409 `type-break-mode-line-warning'"
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
410 (interactive "P")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
411 (setq type-break-mode-line-message-mode
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
412 (>= (prefix-numeric-value prefix) 0))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
413 (and (interactive-p)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
414 (if type-break-mode-line-message-mode
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
415 (message "type-break-mode-line-message-mode is enabled")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
416 (message "type-break-mode-line-message-mode is disabled")))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
417 type-break-mode-line-message-mode)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
418
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
419 (defun type-break-query-mode (&optional prefix)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
420 "Enable or disable warnings in the mode line about typing breaks.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
421
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
422 When enabled, the user is periodically queried about whether to take a
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
423 typing break at that moment. The function which does this query is
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
424 specified by the variable `type-break-query-function'.
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
425
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
426 A negative prefix argument disables this mode.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
427 No argument or any non-negative argument enables it.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
428
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
429 The user may also enable or disable this mode simply by setting the
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
430 variable of the same name."
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
431 (interactive "P")
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
432 (setq type-break-query-mode
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
433 (>= (prefix-numeric-value prefix) 0))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
434 (and (interactive-p)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
435 (if type-break-query-mode
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
436 (message "type-break-query-mode is enabled")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
437 (message "type-break-query-mode is disabled")))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
438 type-break-query-mode)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
439
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
440
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
441 ;;;###autoload
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
442 (defun type-break ()
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
443 "Take a typing break.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
444
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
445 During the break, a demo selected from the functions listed in
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
446 `type-break-demo-functions' is run.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
447
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
448 After the typing break is finished, the next break is scheduled
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
449 as per the function `type-break-schedule'."
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
450 (interactive)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
451 (type-break-cancel-schedule)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
452 (let ((continue t)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
453 (start-time (current-time)))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
454 (setq type-break-time-last-break start-time)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
455 (while continue
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
456 (save-window-excursion
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
457 ;; Eat the screen.
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
458 (and (eq (selected-window) (minibuffer-window))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
459 (other-window 1))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
460 (delete-other-windows)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
461 (scroll-right (window-width))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
462 (message "Press any key to resume from typing break.")
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
463
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
464 (random t)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
465 (let* ((len (length type-break-demo-functions))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
466 (idx (random len))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
467 (fn (nth idx type-break-demo-functions)))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
468 (condition-case ()
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
469 (funcall fn)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
470 (error nil))))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
471
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
472 (cond
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
473 (type-break-good-rest-interval
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
474 (let ((break-secs (type-break-time-difference
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
475 start-time (current-time))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
476 (cond
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
477 ((>= break-secs type-break-good-rest-interval)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
478 (setq continue nil))
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
479 ;; 60 seconds may be too much leeway if the break is only 3
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
480 ;; minutes to begin with. You can just say "no" to the query
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
481 ;; below if you're in that much of a hurry.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
482 ;((> 60 (abs (- break-secs type-break-good-rest-interval)))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
483 ; (setq continue nil))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
484 ((funcall
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
485 type-break-query-function
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
486 (format "You really ought to rest %s more. Continue break? "
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
487 (type-break-format-time (- type-break-good-rest-interval
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
488 break-secs)))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
489 (t
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
490 (setq continue nil)))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
491 (t (setq continue nil)))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
492
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
493 (type-break-keystroke-reset)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
494 (type-break-mode-line-countdown-or-break nil)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
495 (type-break-schedule))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
496
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
497
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
498 (defun type-break-schedule (&optional time)
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
499 "Schedule a typing break for TIME seconds from now.
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
500 If time is not specified, default to `type-break-interval'."
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
501 (interactive (list (and current-prefix-arg
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
502 (prefix-numeric-value current-prefix-arg))))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
503 (or time (setq time type-break-interval))
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
504 (type-break-check-post-command-hook)
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
505 (type-break-cancel-schedule)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
506 (type-break-time-warning-schedule time 'reset)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
507 (type-break-run-at-time (max 1 time) nil 'type-break-alarm)
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
508 (setq type-break-time-next-break
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
509 (type-break-time-sum (current-time) time)))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
510
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
511 (defun type-break-cancel-schedule ()
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
512 (type-break-cancel-time-warning-schedule)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
513 (type-break-cancel-function-timers 'type-break-alarm)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
514 (setq type-break-alarm-p nil)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
515 (setq type-break-time-next-break nil))
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
516
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
517 (defun type-break-time-warning-schedule (&optional time resetp)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
518 (let ((type-break-current-time-warning-interval nil))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
519 (type-break-cancel-time-warning-schedule))
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
520 (add-hook 'type-break-post-command-hook 'type-break-time-warning 'append)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
521 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
522 (type-break-time-warning-intervals
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
523 (and resetp
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
524 (setq type-break-current-time-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
525 type-break-time-warning-intervals))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
526
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
527 (or time
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
528 (setq time (type-break-time-difference (current-time)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
529 type-break-time-next-break)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
530
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
531 (while (and type-break-current-time-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
532 (> (car type-break-current-time-warning-interval) time))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
533 (setq type-break-current-time-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
534 (cdr type-break-current-time-warning-interval)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
535
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
536 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
537 (type-break-current-time-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
538 (setq time (- time (car type-break-current-time-warning-interval)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
539 (setq type-break-current-time-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
540 (cdr type-break-current-time-warning-interval))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
541
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
542 ;(let (type-break-current-time-warning-interval)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
543 ; (type-break-cancel-time-warning-schedule))
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
544 (type-break-run-at-time (max 1 time) nil 'type-break-time-warning-alarm)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
545
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
546 (cond
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
547 (resetp
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
548 (setq type-break-warning-countdown-string nil))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
549 (t
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
550 (setq type-break-warning-countdown-string (number-to-string time))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
551 (setq type-break-warning-countdown-string-type "seconds"))))))))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
552
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
553 (defun type-break-cancel-time-warning-schedule ()
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
554 (type-break-cancel-function-timers 'type-break-time-warning-alarm)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
555 (remove-hook 'type-break-post-command-hook 'type-break-time-warning)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
556 (setq type-break-current-time-warning-interval
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
557 type-break-time-warning-intervals)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
558 (setq type-break-warning-countdown-string nil))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
559
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
560 (defun type-break-alarm ()
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
561 (type-break-check-post-command-hook)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
562 (setq type-break-alarm-p t)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
563 (type-break-mode-line-countdown-or-break 'break))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
564
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
565 (defun type-break-time-warning-alarm ()
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
566 (type-break-check-post-command-hook)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
567 (type-break-time-warning-schedule)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
568 (setq type-break-time-warning-count type-break-warning-repeat)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
569 (type-break-time-warning)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
570 (type-break-mode-line-countdown-or-break 'countdown))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
571
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
572
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
573 (defun type-break-run-tb-post-command-hook ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
574 (and type-break-mode
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
575 (run-hooks 'type-break-post-command-hook)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
576
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
577 (defun type-break-check ()
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
578 "Ask to take a typing break if appropriate.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
579 This may be the case either because the scheduled time has come \(and the
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
580 minimum keystroke threshold has been reached\) or because the maximum
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
581 keystroke threshold has been exceeded."
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
582 (let* ((min-threshold (car type-break-keystroke-threshold))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
583 (max-threshold (cdr type-break-keystroke-threshold)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
584 (and type-break-good-rest-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
585 (progn
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
586 (and (> (type-break-time-difference
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
587 type-break-time-last-command (current-time))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
588 type-break-good-rest-interval)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
589 (progn
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
590 (type-break-keystroke-reset)
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
591 (type-break-mode-line-countdown-or-break nil)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
592 (setq type-break-time-last-break (current-time))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
593 (type-break-schedule)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
594 (setq type-break-time-last-command (current-time))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
595
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
596 (and type-break-keystroke-threshold
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
597 ;; next line is test for 20.2 that can be deleted
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
598 ;;(setq type-break-keystroke-count (1+ type-break-keystroke-count))
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
599 (let ((keys (this-command-keys)))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
600 (cond
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
601 ;; Ignore mouse motion
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
602 ((and (vectorp keys)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
603 (consp (aref keys 0))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
604 (memq (car (aref keys 0)) '(mouse-movement))))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
605 (t
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
606 (setq type-break-keystroke-count
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
607 (+ type-break-keystroke-count (length keys)))))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
608
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
609 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
610 (type-break-alarm-p
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
611 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
612 ((input-pending-p))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
613 ((eq (selected-window) (minibuffer-window)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
614 ((and min-threshold
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
615 (< type-break-keystroke-count min-threshold))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
616 (type-break-schedule))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
617 (t
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
618 ;; If keystroke count is within min-threshold of
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
619 ;; max-threshold, lower it to reduce the likelihood of an
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
620 ;; immediate subsequent query.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
621 (and max-threshold
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
622 min-threshold
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
623 (< (- max-threshold type-break-keystroke-count) min-threshold)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
624 (progn
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
625 (type-break-keystroke-reset)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
626 (setq type-break-keystroke-count min-threshold)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
627 (type-break-query))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
628 ((and type-break-keystroke-warning-intervals
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
629 max-threshold
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
630 (= type-break-keystroke-warning-count 0)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
631 (type-break-check-keystroke-warning)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
632 ((and max-threshold
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
633 (> type-break-keystroke-count max-threshold)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
634 (not (input-pending-p))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
635 (not (eq (selected-window) (minibuffer-window))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
636 (type-break-keystroke-reset)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
637 (setq type-break-keystroke-count (or min-threshold 0))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
638 (type-break-query)))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
639
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
640 ;; This should return t if warnings were enabled, nil otherwise.
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
641 (defun type-break-check-keystroke-warning ()
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
642 ;; This is safe because the caller should have checked that the cdr was
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
643 ;; non-nil already.
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
644 (let ((left (- (cdr type-break-keystroke-threshold)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
645 type-break-keystroke-count)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
646 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
647 ((null (car type-break-current-keystroke-warning-interval))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
648 nil)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
649 ((> left (car type-break-current-keystroke-warning-interval))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
650 nil)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
651 (t
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
652 (while (and (car type-break-current-keystroke-warning-interval)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
653 (< left (car type-break-current-keystroke-warning-interval)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
654 (setq type-break-current-keystroke-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
655 (cdr type-break-current-keystroke-warning-interval)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
656 (setq type-break-keystroke-warning-count type-break-warning-repeat)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
657 (add-hook 'type-break-post-command-hook 'type-break-keystroke-warning)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
658 (setq type-break-warning-countdown-string (number-to-string left))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
659 (setq type-break-warning-countdown-string-type "keystrokes")
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
660 (type-break-mode-line-countdown-or-break 'countdown)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
661 t))))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
662
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
663 ;; Arrange for a break query to be made, when the user stops typing furiously.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
664 (defun type-break-query ()
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
665 (add-hook 'type-break-post-command-hook 'type-break-do-query))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
666
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
667 (defun type-break-do-query ()
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
668 (cond
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
669 ((not type-break-query-mode)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
670 (type-break-noninteractive-query)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
671 (type-break-schedule type-break-query-interval)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
672 (remove-hook 'type-break-post-command-hook 'type-break-do-query))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
673 ((sit-for 2)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
674 (condition-case ()
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
675 (cond
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
676 ((let ((type-break-mode nil)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
677 ;; yes-or-no-p sets this-command to exit-minibuffer,
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
678 ;; which hoses undo or yank-pop (if you happened to be
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
679 ;; yanking just when the query occurred).
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
680 (this-command this-command))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
681 (funcall type-break-query-function
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
682 "Take a break from typing now? "))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
683 (type-break))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
684 (t
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
685 (type-break-schedule type-break-query-interval)))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
686 (quit
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
687 (type-break-schedule type-break-query-interval)))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
688 (remove-hook 'type-break-post-command-hook 'type-break-do-query))))
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
689
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
690 (defun type-break-noninteractive-query (&optional ignored-args)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
691 "Null query function which doesn't interrupt user and assumes `no'.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
692 It prints a reminder in the echo area to take a break, but doesn't enforce
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
693 this or ask the user to start one right now."
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
694 (cond
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
695 (type-break-mode-line-message-mode)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
696 (t
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
697 (beep t)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
698 (message "You should take a typing break now. Do `M-x type-break'.")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
699 (sit-for 1)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
700 (beep t)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
701 ;; return nil so query caller knows to reset reminder, as if user
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
702 ;; said "no" in response to yes-or-no-p.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
703 nil)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
704
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
705 (defun type-break-time-warning ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
706 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
707 ((and (car type-break-keystroke-threshold)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
708 (< type-break-keystroke-count (car type-break-keystroke-threshold))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
709 ((> type-break-time-warning-count 0)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
710 (let ((timeleft (type-break-time-difference (current-time)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
711 type-break-time-next-break)))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
712 (setq type-break-warning-countdown-string (number-to-string timeleft))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
713 (cond
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
714 ((eq (selected-window) (minibuffer-window)))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
715 ;; Do nothing if the command was just a prefix arg, since that will
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
716 ;; immediately be followed by some other interactive command.
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
717 ;; Otherwise, it is particularly annoying for the sit-for below to
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
718 ;; delay redisplay when one types sequences like `C-u -1 C-l'.
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
719 ((memq this-command '(digit-argument universal-argument)))
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
720 ((not type-break-mode-line-message-mode)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
721 ;; Pause for a moment so any previous message can be seen.
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
722 (sit-for 2)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
723 (message "Warning: typing break due in %s."
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
724 (type-break-format-time timeleft))
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
725 (setq type-break-time-warning-count
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
726 (1- type-break-time-warning-count))))))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
727 (t
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
728 (remove-hook 'type-break-post-command-hook 'type-break-time-warning)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
729 (setq type-break-warning-countdown-string nil))))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
730
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
731 (defun type-break-keystroke-warning ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
732 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
733 ((> type-break-keystroke-warning-count 0)
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
734 (setq type-break-warning-countdown-string
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
735 (number-to-string (- (cdr type-break-keystroke-threshold)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
736 type-break-keystroke-count)))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
737 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
738 ((eq (selected-window) (minibuffer-window)))
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
739 ;; Do nothing if the command was just a prefix arg, since that will
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
740 ;; immediately be followed by some other interactive command.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
741 ;; Otherwise, it is particularly annoying for the sit-for below to
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
742 ;; delay redisplay when one types sequences like `C-u -1 C-l'.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
743 ((memq this-command '(digit-argument universal-argument)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
744 ((not type-break-mode-line-message-mode)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
745 (sit-for 2)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
746 (message "Warning: typing break due in %s keystrokes."
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
747 (- (cdr type-break-keystroke-threshold)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
748 type-break-keystroke-count))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
749 (setq type-break-keystroke-warning-count
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
750 (1- type-break-keystroke-warning-count)))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
751 (t
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
752 (remove-hook 'type-break-post-command-hook
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
753 'type-break-keystroke-warning)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
754 (setq type-break-warning-countdown-string nil))))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
755
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
756 (defun type-break-mode-line-countdown-or-break (&optional type)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
757 (cond
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
758 ((not type-break-mode-line-message-mode))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
759 ((eq type 'countdown)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
760 ;(setq type-break-mode-line-break-message-p nil)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
761 (add-hook 'type-break-post-command-hook
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
762 'type-break-force-mode-line-update 'append))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
763 ((eq type 'break)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
764 ;; Alternate
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
765 (setq type-break-mode-line-break-message-p
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
766 (not type-break-mode-line-break-message-p))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
767 (remove-hook 'type-break-post-command-hook
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
768 'type-break-force-mode-line-update))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
769 (t
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
770 (setq type-break-mode-line-break-message-p nil)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
771 (setq type-break-warning-countdown-string nil)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
772 (remove-hook 'type-break-post-command-hook
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
773 'type-break-force-mode-line-update)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
774 (type-break-force-mode-line-update))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
775
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
776
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
777 ;;;###autoload
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
778 (defun type-break-statistics ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
779 "Print statistics about typing breaks in a temporary buffer.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
780 This includes the last time a typing break was taken, when the next one is
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
781 scheduled, the keystroke thresholds and the current keystroke count, etc."
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
782 (interactive)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
783 (with-output-to-temp-buffer "*Typing Break Statistics*"
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
784 (princ (format "Typing break statistics\n-----------------------\n
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
785 Typing break mode is currently %s.
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
786 Interactive query for breaks is %s.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
787 Warnings of imminent typing breaks in mode line is %s.
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
788
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
789 Last typing break ended : %s
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
790 Next scheduled typing break : %s\n
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
791 Minimum keystroke threshold : %s
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
792 Maximum keystroke threshold : %s
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
793 Current keystroke count : %s"
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
794 (if type-break-mode "enabled" "disabled")
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
795 (if type-break-query-mode "enabled" "disabled")
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
796 (if type-break-mode-line-message-mode "enabled" "disabled")
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
797 (if type-break-time-last-break
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
798 (current-time-string type-break-time-last-break)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
799 "never")
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
800 (if (and type-break-mode type-break-time-next-break)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
801 (format "%s\t(%s from now)"
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
802 (current-time-string type-break-time-next-break)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
803 (type-break-format-time
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
804 (type-break-time-difference
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
805 (current-time)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
806 type-break-time-next-break)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
807 "none scheduled")
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
808 (or (car type-break-keystroke-threshold) "none")
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
809 (or (cdr type-break-keystroke-threshold) "none")
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
810 type-break-keystroke-count))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
811
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
812 ;;;###autoload
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
813 (defun type-break-guesstimate-keystroke-threshold (wpm &optional wordlen frac)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
814 "Guess values for the minimum/maximum keystroke threshold for typing breaks.
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
815
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
816 If called interactively, the user is prompted for their guess as to how
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
817 many words per minute they usually type. This value should not be your
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
818 maximum WPM, but your average. Of course, this is harder to gauge since it
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
819 can vary considerably depending on what you are doing. For example, one
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
820 tends to type less when debugging a program as opposed to writing
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
821 documentation. (Perhaps a separate program should be written to estimate
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
822 average typing speed.)
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
823
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
824 From that, this command sets the values in `type-break-keystroke-threshold'
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
825 based on a fairly simple algorithm involving assumptions about the average
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
826 length of words (5). For the minimum threshold, it uses about a fifth of
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
827 the computed maximum threshold.
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
828
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
829 When called from lisp programs, the optional args WORDLEN and FRAC can be
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
830 used to override the default assumption about average word length and the
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
831 fraction of the maximum threshold to which to set the minimum threshold.
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
832 FRAC should be the inverse of the fractional value; for example, a value of
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
833 2 would mean to use one half, a value of 4 would mean to use one quarter, etc."
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
834 (interactive "NOn average, how many words per minute do you type? ")
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
835 (let* ((upper (* wpm (or wordlen 5) (/ type-break-interval 60)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
836 (lower (/ upper (or frac 5))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
837 (or type-break-keystroke-threshold
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
838 (setq type-break-keystroke-threshold (cons nil nil)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
839 (setcar type-break-keystroke-threshold lower)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
840 (setcdr type-break-keystroke-threshold upper)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
841 (if (interactive-p)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
842 (message "min threshold: %d\tmax threshold: %d" lower upper)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
843 type-break-keystroke-threshold)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
844
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
845
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
846 ;;; misc functions
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
847
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
848 ;; Compute the difference, in seconds, between a and b, two structures
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
849 ;; similar to those returned by `current-time'.
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
850 ;; Use addition rather than logand since that is more robust; the low 16
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
851 ;; bits of the seconds might have been incremented, making it more than 16
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
852 ;; bits wide.
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
853 (defun type-break-time-difference (a b)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
854 (+ (lsh (- (car b) (car a)) 16)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
855 (- (car (cdr b)) (car (cdr a)))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
856
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
857 ;; Return (in a new list the same in structure to that returned by
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
858 ;; `current-time') the sum of the arguments. Each argument may be a time
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
859 ;; list or a single integer, a number of seconds.
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
860 ;; This function keeps the high and low 16 bits of the seconds properly
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
861 ;; balanced so that the lower value never exceeds 16 bits. Otherwise, when
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
862 ;; the result is passed to `current-time-string' it will toss some of the
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
863 ;; "low" bits and format the time incorrectly.
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
864 (defun type-break-time-sum (&rest tmlist)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
865 (let ((high 0)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
866 (low 0)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
867 (micro 0)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
868 tem)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
869 (while tmlist
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
870 (setq tem (car tmlist))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
871 (setq tmlist (cdr tmlist))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
872 (cond
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
873 ((numberp tem)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
874 (setq low (+ low tem)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
875 (t
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
876 (setq high (+ high (or (car tem) 0)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
877 (setq low (+ low (or (car (cdr tem)) 0)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
878 (setq micro (+ micro (or (car (cdr (cdr tem))) 0))))))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
879
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
880 (and (>= micro 1000000)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
881 (progn
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
882 (setq tem (/ micro 1000000))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
883 (setq low (+ low tem))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
884 (setq micro (- micro (* tem 1000000)))))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
885
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
886 (setq tem (lsh low -16))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
887 (and (> tem 0)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
888 (progn
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
889 (setq low (logand low 65535))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
890 (setq high (+ high tem))))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
891
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
892 (list high low micro)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
893
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
894 (defun type-break-format-time (secs)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
895 (let ((mins (/ secs 60)))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
896 (cond
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
897 ((= mins 1) (format "%d minute" mins))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
898 ((> mins 0) (format "%d minutes" mins))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
899 ((= secs 1) (format "%d second" secs))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
900 (t (format "%d seconds" secs)))))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
901
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
902 (defun type-break-keystroke-reset ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
903 (setq type-break-keystroke-count 0)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
904 (setq type-break-keystroke-warning-count 0)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
905 (setq type-break-current-keystroke-warning-interval
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
906 type-break-keystroke-warning-intervals)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
907 (remove-hook 'type-break-post-command-hook 'type-break-keystroke-warning))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
908
18416
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
909 (defun type-break-force-mode-line-update (&optional all)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
910 "Force the mode-line of the current buffer to be redisplayed.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
911 With optional non-nil ALL, force redisplay of all mode-lines."
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
912 (and all (save-excursion (set-buffer (other-buffer))))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
913 (set-buffer-modified-p (buffer-modified-p)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
914
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
915 ;; If an exception occurs in emacs while running the post command hook, the
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
916 ;; value of that hook is clobbered. This is because the value of the
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
917 ;; variable is temporarily set to nil while it's running to prevent
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
918 ;; recursive application, but it also means an exception aborts the routine
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
919 ;; of restoring it. This function is called from the timers to restore it,
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
920 ;; just in case.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
921 (defun type-break-check-post-command-hook ()
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
922 (add-hook 'post-command-hook 'type-break-run-tb-post-command-hook 'append))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
923
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
924
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
925 ;;; Timer wrapper functions
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
926 ;;;
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
927 ;;; These shield type-break from variations in the interval timer packages
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
928 ;;; for different versions of emacs.
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
929
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
930 (defun type-break-run-at-time (time repeat function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
931 (cond ((eq type-break-emacs-variant 'standard19)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
932 (require 'timer)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
933 (funcall 'run-at-time time repeat function))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
934 ((eq type-break-emacs-variant 'lucid-19-8)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
935 (let ((name (if (symbolp function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
936 (symbol-name function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
937 "type-break")))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
938 (require 'timer)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
939 (funcall 'start-timer name function time repeat)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
940 ((memq type-break-emacs-variant '(xemacs lucid))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
941 (let ((name (if (symbolp function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
942 (symbol-name function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
943 "type-break")))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
944 (require 'itimer)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
945 (funcall 'start-itimer name function time repeat)))))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
946
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
947 (defun type-break-cancel-function-timers (function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
948 (cond ((eq type-break-emacs-variant 'standard19)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
949 (let ((timer-dont-exit t))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
950 (funcall 'cancel-function-timers function)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
951 ((eq type-break-emacs-variant 'lucid-19-8)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
952 (let ((list timer-list))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
953 (while list
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
954 (and (eq (funcall 'timer-function (car list)) function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
955 (funcall 'delete-timer (car list)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
956 (setq list (cdr list)))))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
957 ((memq type-break-emacs-variant '(xemacs lucid))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
958 (let ((list itimer-list))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
959 (while list
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
960 (and (eq (funcall 'itimer-function (car list)) function)
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
961 (funcall 'delete-itimer (car list)))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
962 (setq list (cdr list)))))))
2ec71bb15f86 Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
parents: 18414
diff changeset
963
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
964
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
965 ;;; Demo wrappers
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
966
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
967 ;; This is a wrapper around hanoi that calls it with an arg large enough to
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
968 ;; make the largest discs possible that will fit in the window.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
969 ;; Also, clean up the *Hanoi* buffer after we're done.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
970 (defun type-break-demo-hanoi ()
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
971 "Take a hanoiing typing break."
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
972 (and (get-buffer "*Hanoi*")
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
973 (kill-buffer "*Hanoi*"))
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
974 (condition-case ()
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
975 (progn
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
976 (hanoi (/ (window-width) 8))
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
977 ;; Wait for user to come back.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
978 (read-char)
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
979 (kill-buffer "*Hanoi*"))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
980 (quit
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
981 ;; eat char
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
982 (read-char)
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
983 (and (get-buffer "*Hanoi*")
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
984 (kill-buffer "*Hanoi*")))))
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
985
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
986 ;; This is a wrapper around life that calls it with a `sleep' arg to make
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
987 ;; it run a little more leisurely.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
988 ;; Also, clean up the *Life* buffer after we're done.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
989 (defun type-break-demo-life ()
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
990 "Take a typing break and get a life."
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
991 (let ((continue t))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
992 (while continue
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
993 (setq continue nil)
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
994 (and (get-buffer "*Life*")
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
995 (kill-buffer "*Life*"))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
996 (condition-case ()
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
997 (progn
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
998 (life 3)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
999 ;; wait for user to return
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
1000 (read-char)
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1001 (kill-buffer "*Life*"))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1002 (life-extinct
18414
8d2051b79879 Changes which are not mine:
Noah Friedman <friedman@splode.com>
parents: 9355
diff changeset
1003 (message "%s" (get 'life-extinct 'error-message))
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1004 (sit-for 3)
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1005 ;; restart demo
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1006 (setq continue t))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1007 (quit
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1008 (and (get-buffer "*Life*")
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
1009 (kill-buffer "*Life*")))))))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
1010
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1011 ;; Boring demo, but doesn't use many cycles
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1012 (defun type-break-demo-boring ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1013 "Boring typing break demo."
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1014 (let ((rmsg "Press any key to resume from typing break")
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1015 (buffer-name "*Typing Break Buffer*")
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1016 line col pos
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1017 elapsed timeleft tmsg)
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1018 (condition-case ()
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1019 (progn
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1020 (switch-to-buffer (get-buffer-create buffer-name))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1021 (buffer-disable-undo (current-buffer))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1022 (erase-buffer)
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1023 (setq line (1+ (/ (window-height) 2)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1024 (setq col (/ (- (window-width) (length rmsg)) 2))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1025 (insert (make-string line ?\C-j)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1026 (make-string col ?\ )
8497
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1027 rmsg)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1028 (forward-line -1)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1029 (beginning-of-line)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1030 (setq pos (point))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1031 (while (not (input-pending-p))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1032 (delete-region pos (progn
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1033 (goto-char pos)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1034 (end-of-line)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1035 (point)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1036 (setq elapsed (type-break-time-difference
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1037 type-break-time-last-break
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1038 (current-time)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1039 (cond
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1040 (type-break-good-rest-interval
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1041 (setq timeleft (- type-break-good-rest-interval elapsed))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1042 (if (> timeleft 0)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1043 (setq tmsg (format "You should rest for %s more"
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1044 (type-break-format-time timeleft)))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1045 (setq tmsg (format "Typing break has lasted %s"
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1046 (type-break-format-time elapsed)))))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1047 (t
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1048 (setq tmsg (format "Typing break has lasted %s"
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1049 (type-break-format-time elapsed)))))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1050 (setq col (/ (- (window-width) (length tmsg)) 2))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1051 (insert (make-string col ?\ ) tmsg)
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1052 (goto-char (point-min))
3d566eab9870 type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents: 8370
diff changeset
1053 (sit-for 60))
8370
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1054 (read-char)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1055 (kill-buffer buffer-name))
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1056 (quit
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1057 (and (get-buffer buffer-name)
97cacab659d3 type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents: 8305
diff changeset
1058 (kill-buffer buffer-name))))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
1059
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
1060
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
1061 (provide 'type-break)
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
1062
20800
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
1063 (if type-break-mode
43c77517a76c (type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
parents: 18416
diff changeset
1064 (type-break-mode 1))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
1065 ;;; type-break.el ends here