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