8276
|
1 ;;; type-break.el --- encourage rests from typing at appropriate intervals
|
8248
|
2
|
54322
|
3 ;; Copyright (C) 1994, 95, 97, 2000, 2004 Free Software Foundation, Inc.
|
8248
|
4
|
23240
|
5 ;; Author: Noah Friedman
|
|
6 ;; Maintainer: Noah Friedman <friedman@splode.com>
|
9355
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
|
9355
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
diff
changeset
|
11 ;; This file is part of GNU Emacs.
|
8248
|
12
|
9355
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
diff
changeset
|
13 ;; 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
|
14 ;; 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
|
15 ;; 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
|
16 ;; any later version.
|
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
diff
changeset
|
17
|
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
diff
changeset
|
18 ;; 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
|
19 ;; 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
|
20 ;; 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
|
21 ;; 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
|
22
|
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License
|
18414
|
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
8248
|
27
|
|
28 ;;; Commentary:
|
8276
|
29
|
18414
|
30 ;; The docstring for the function `type-break-mode' summarizes most of the
|
|
31 ;; details of the interface.
|
|
32
|
55189
|
33 ;; This package relies on the assumption that you live entirely in Emacs,
|
18414
|
34 ;; as the author does. If that's not the case for you (e.g. you often
|
55189
|
35 ;; suspend Emacs or work in other windows) then this won't help very much;
|
|
36 ;; it will depend on just how often you switch back to Emacs. At the very
|
18414
|
37 ;; least, you will want to turn off the keystroke thresholds and rest
|
|
38 ;; interval tracking.
|
8276
|
39
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
40 ;; 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
|
41 ;; 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
|
42 ;;
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
43 ;; (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
|
44 ;;
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
45 ;; 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
|
46 ;; argument.
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
47
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
48 ;; 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
|
49 ;; 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
|
50 ;; or set the variable of the same name to `t'.
|
8276
|
51
|
18414
|
52 ;; This program can truly cons up a storm because of all the calls to
|
|
53 ;; `current-time' (which always returns 3 fresh conses). I'm dismayed by
|
|
54 ;; this, but I think the health of my hands is far more important than a
|
|
55 ;; few pages of virtual memory.
|
|
56
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
57 ;; 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
|
58
|
18414
|
59 ;; This package was inspired by Roland McGrath's hanoi-break.el.
|
|
60 ;; Several people contributed feedback and ideas, including
|
25278
|
61 ;; Roland McGrath <roland@gnu.org>
|
30391
|
62 ;; Kleanthes Koniaris <kgk@koniaris.com>
|
25278
|
63 ;; Mark Ashton <mpashton@gnu.org>
|
18414
|
64 ;; 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
|
65 ;; Robert S. Boyer <boyer@cs.utexas.edu>
|
8276
|
66
|
8248
|
67 ;;; Code:
|
|
68
|
|
69
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
70 (defgroup type-break nil
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
71 "Encourage the user to take a rest from typing at suitable intervals."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
72 :prefix "type-break"
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
73 :group 'keyboard)
|
5939
|
74
|
|
75 ;;;###autoload
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
76 (defcustom type-break-mode nil
|
24547
|
77 "Toggle typing break mode.
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
78 See the docstring for the `type-break-mode' command for more information.
|
24648
|
79 Setting this variable directly does not take effect;
|
|
80 use either \\[customize] or the function `type-break-mode'."
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
81 :set (lambda (symbol value)
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
82 (type-break-mode (if value 1 -1)))
|
23239
b88e81176427
(type-break-mode): remove :version field from defcustom declaration.
Noah Friedman <friedman@splode.com>
diff
changeset
|
83 :initialize 'custom-initialize-default
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
84 :type 'boolean
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
85 :group 'type-break
|
23239
b88e81176427
(type-break-mode): remove :version field from defcustom declaration.
Noah Friedman <friedman@splode.com>
diff
changeset
|
86 :require 'type-break)
|
8275
|
87
|
|
88 ;;;###autoload
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
89 (defcustom type-break-interval (* 60 60)
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
90 "*Number of seconds between scheduled typing breaks."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
91 :type 'integer
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
92 :group 'type-break)
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
93
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
94 ;;;###autoload
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
95 (defcustom type-break-good-rest-interval (/ type-break-interval 6)
|
8276
|
96 "*Number of seconds of idle time considered to be an adequate typing rest.
|
|
97
|
55189
|
98 When this variable is non-nil, Emacs checks the idle time between
|
8304
|
99 keystrokes. If this idle time is long enough to be considered a \"good\"
|
8276
|
100 rest from typing, then the next typing break is simply rescheduled for later.
|
|
101
|
8304
|
102 If a break is interrupted before this much time elapses, the user will be
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
103 asked whether or not really to interrupt the break."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
104 :type 'integer
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
105 :group 'type-break)
|
8276
|
106
|
|
107 ;;;###autoload
|
55189
|
108 (defcustom type-break-good-break-interval nil
|
|
109 "*Number of seconds considered to be an adequate explicit typing rest.
|
|
110
|
|
111 When this variable is non-nil, its value is considered to be a \"good\"
|
|
112 length (in seconds) for a break initiated by the command `type-break',
|
|
113 overriding `type-break-good-rest-interval'. This provides querying of
|
|
114 break interruptions when `type-break-good-rest-interval' is nil."
|
|
115 :type 'integer
|
|
116 :group 'type-break)
|
|
117
|
|
118 ;;;###autoload
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
119 (defcustom type-break-keystroke-threshold
|
8304
|
120 ;; 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
|
121 ;; 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
|
122 ;; and simply studying code in buffers) and average word length is
|
8275
|
123 ;; about 5 letters, default upper threshold to the average number of
|
|
124 ;; keystrokes one is likely to type in a break interval. That way if the
|
|
125 ;; user goes through a furious burst of typing activity, cause a typing
|
|
126 ;; 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
|
127 ;; Conversely, the minimum threshold should be about a fifth of this.
|
8304
|
128 (let* ((wpm 35)
|
8275
|
129 (avg-word-length 5)
|
|
130 (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
|
131 (lower (/ upper 5)))
|
8275
|
132 (cons lower upper))
|
|
133 "*Upper and lower bound on number of keystrokes for considering typing break.
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
134 This structure is a pair of numbers (MIN . MAX).
|
8248
|
135
|
8276
|
136 The first number is the minimum number of keystrokes that must have been
|
|
137 entered since the last typing break before considering another one, even if
|
|
138 the scheduled time has elapsed; the break is simply rescheduled until later
|
|
139 if the minimum threshold hasn't been reached. If this first value is nil,
|
|
140 then there is no minimum threshold; as soon as the scheduled time has
|
|
141 elapsed, the user will always be queried.
|
8275
|
142
|
|
143 The second number is the maximum number of keystrokes that can be entered
|
|
144 before a typing break is requested immediately, pre-empting the originally
|
8276
|
145 scheduled break. If this second value is nil, then no pre-emptive breaks
|
|
146 will occur; only scheduled ones will.
|
8275
|
147
|
|
148 Keys with bucky bits (shift, control, meta, etc) are counted as only one
|
18414
|
149 keystroke even though they really require multiple keys to generate them.
|
|
150
|
|
151 The command `type-break-guesstimate-keystroke-threshold' can be used to
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
152 guess a reasonably good pair of values for this variable."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
153 :type 'sexp
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
154 :group 'type-break)
|
18414
|
155
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
156 (defcustom type-break-query-mode t
|
50868
|
157 "*Non-nil means ask whether or not to prompt user for breaks.
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
158 If so, call the function specified in the value of the variable
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
159 `type-break-query-function' to do the asking."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
160 :type 'boolean
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
161 :group 'type-break)
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
162
|
30391
|
163 (defcustom type-break-query-function 'yes-or-no-p
|
|
164 "*Function to use for making query for a typing break.
|
18414
|
165 It should take a string as an argument, the prompt.
|
|
166 Usually this should be set to `yes-or-no-p' or `y-or-n-p'.
|
|
167
|
50868
|
168 To avoid being queried at all, set `type-break-query-mode' to nil."
|
30391
|
169 :type '(radio function
|
|
170 (function-item yes-or-no-p)
|
|
171 (function-item y-or-n-p))
|
|
172 :group 'type-break)
|
18414
|
173
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
174 (defcustom type-break-query-interval 60
|
18414
|
175 "*Number of seconds between queries to take a break, if put off.
|
|
176 The user will continue to be prompted at this interval until he or she
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
177 finally submits to taking a typing break."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
178 :type 'integer
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
179 :group 'type-break)
|
8276
|
180
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
181 (defcustom type-break-time-warning-intervals '(300 120 60 30)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
182 "*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
|
183 At each of the intervals (specified in seconds) away from a scheduled
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
184 typing break, print a warning in the echo area."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
185 :type '(repeat integer)
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
186 :group 'type-break)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
187
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
188 (defcustom type-break-keystroke-warning-intervals '(300 200 100 50)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
189 "*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
|
190 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
|
191 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
|
192 If either this variable or the upper threshold is set, then no warnings
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
193 will occur."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
194 :type '(repeat integer)
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
195 :group 'type-break)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
196
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
197 (defcustom type-break-warning-repeat 40
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
198 "*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
|
199 That is, for each of this many keystrokes the warning is redisplayed
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
200 in the echo area to make sure it's really seen."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
201 :type 'integer
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
202 :group 'type-break)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
203
|
30391
|
204 (defcustom type-break-time-stamp-format "[%H:%M] "
|
|
205 "*Timestamp format used to prefix messages.
|
|
206 Format specifiers are as used by `format-time-string'."
|
|
207 :type 'string
|
|
208 :group 'type-break)
|
|
209
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
210 (defcustom type-break-demo-functions
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
211 '(type-break-demo-boring type-break-demo-life type-break-demo-hanoi)
|
8304
|
212 "*List of functions to consider running as demos during typing breaks.
|
8248
|
213 When a typing break begins, one of these functions is selected randomly
|
55189
|
214 to have Emacs do something interesting.
|
8248
|
215
|
8304
|
216 Any function in this list should start a demo which ceases as soon as a
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
217 key is pressed."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
218 :type '(repeat function)
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
219 :group 'type-break)
|
8248
|
220
|
55189
|
221 (defcustom type-break-demo-boring-stats nil
|
|
222 "*Show word per minute and keystroke figures in the Boring demo."
|
|
223 :type 'boolean
|
|
224 :group 'type-break)
|
|
225
|
|
226 (defcustom type-break-terse-messages nil
|
|
227 "*Use slightly terser messages."
|
|
228 :type 'boolean
|
|
229 :group 'type-break)
|
|
230
|
|
231 (defcustom type-break-file-name (convert-standard-filename "~/.type-break")
|
|
232 "*Name of file used to save state across sessions."
|
|
233 :type 'file
|
|
234 :group 'type-break)
|
|
235
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
236 (defvar type-break-post-command-hook '(type-break-check)
|
55189
|
237 "Hook run indirectly by `post-command-hook' for typing break functions.
|
18414
|
238 This is not really intended to be set by the user, but it's probably
|
|
239 harmless to do so. Mainly it is used by various parts of the typing break
|
|
240 program to delay actions until after the user has completed some command.
|
|
241 It exists because `post-command-hook' itself is inaccessible while its
|
|
242 functions are being run, and some type-break--related functions want to
|
|
243 remove themselves after running.")
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
244
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
245
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
246 ;; Mode line frobs
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
247
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
248 (defcustom type-break-mode-line-message-mode nil
|
50868
|
249 "*Non-nil means put type-break related messages in the mode line.
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
250 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
|
251
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
252 See also `type-break-mode-line-format' and its members."
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
253 :type 'boolean
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
254 :group 'type-break)
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
255
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
256 (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
|
257 '(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
|
258 (""
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
259 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
|
260 type-break-mode-line-warning))
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
261 "*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
|
262
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
263 (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
|
264 '(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
|
265 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
|
266
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
267 (defvar type-break-mode-line-break-message-p nil)
|
30391
|
268 (defvar type-break-mode-line-break-string " *** TAKE A TYPING BREAK NOW ***")
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
269
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
270 (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
|
271 '(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
|
272 ("")
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
273 (type-break-warning-countdown-string
|
30391
|
274 (" *** "
|
|
275 "Break in "
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
276 type-break-warning-countdown-string
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
277 " "
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
278 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
|
279 "***"))))
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
280
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
281 (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
|
282 "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
|
283
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
284 This variable, in conjunction with `type-break-warning-countdown-string-type'
|
50551
f51ff6ca84ca
(type-break-warning-countdown-string): Doc fix; escape open paren at col 0.
John Paul Wallington <jpw@pobox.com>
diff
changeset
|
285 \(which indicates whether this value is a number of keystrokes or seconds)
|
55189
|
286 is installed in `mode-line-format' to notify of imminent typing breaks.")
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
287
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
288 (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
|
289 "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
|
290 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
|
291
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
292
|
8275
|
293 ;; These are internal variables. Do not set them yourself.
|
8248
|
294
|
8497
|
295 (defvar type-break-alarm-p nil)
|
8276
|
296 (defvar type-break-keystroke-count 0)
|
|
297 (defvar type-break-time-last-break nil)
|
|
298 (defvar type-break-time-next-break nil)
|
|
299 (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
|
300 (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
|
301 (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
|
302 (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
|
303 (defvar type-break-keystroke-warning-count 0)
|
55189
|
304 (defvar type-break-interval-start nil)
|
|
305
|
8304
|
306
|
8248
|
307 ;;;###autoload
|
8275
|
308 (defun type-break-mode (&optional prefix)
|
|
309 "Enable or disable typing-break mode.
|
|
310 This is a minor mode, but it is global to all buffers by default.
|
|
311
|
|
312 When this mode is enabled, the user is encouraged to take typing breaks at
|
|
313 appropriate intervals; either after a specified amount of time or when the
|
|
314 user has exceeded a keystroke threshold. When the time arrives, the user
|
55189
|
315 is asked to take a break. If the user refuses at that time, Emacs will ask
|
8275
|
316 again in a short period of time. The idea is to give the user enough time
|
|
317 to find a good breaking point in his or her work, but be sufficiently
|
|
318 annoying to discourage putting typing breaks off indefinitely.
|
|
319
|
|
320 A negative prefix argument disables this mode.
|
8304
|
321 No argument or any non-negative argument enables it.
|
8275
|
322
|
|
323 The user may enable or disable this mode by setting the variable of the
|
|
324 same name, though setting it in that way doesn't reschedule a break or
|
|
325 reset the keystroke counter.
|
|
326
|
8276
|
327 If the mode was previously disabled and is enabled as a consequence of
|
|
328 calling this function, it schedules a break with `type-break-schedule' to
|
|
329 make sure one occurs (the user can call that command to reschedule the
|
|
330 break at any time). It also initializes the keystroke counter.
|
8275
|
331
|
|
332 The variable `type-break-interval' specifies the number of seconds to
|
|
333 schedule between regular typing breaks. This variable doesn't directly
|
|
334 affect the time schedule; it simply provides a default for the
|
|
335 `type-break-schedule' command.
|
|
336
|
8304
|
337 If set, the variable `type-break-good-rest-interval' specifies the minimum
|
|
338 amount of time which is considered a reasonable typing break. Whenever
|
|
339 that time has elapsed, typing breaks are automatically rescheduled for
|
55189
|
340 later even if Emacs didn't prompt you to take one first. Also, if a break
|
8304
|
341 is ended before this much time has elapsed, the user will be asked whether
|
55189
|
342 or not to continue. A nil value for this variable prevents automatic
|
|
343 break rescheduling, making `type-break-interval' an upper bound on the time
|
|
344 between breaks. In this case breaks will be prompted for as usual before
|
|
345 the upper bound if the keystroke threshold is reached.
|
|
346
|
|
347 If `type-break-good-rest-interval' is nil and
|
|
348 `type-break-good-break-interval' is set, then confirmation is required to
|
|
349 interrupt a break before `type-break-good-break-interval' seconds
|
|
350 have passed. This provides for an upper bound on the time between breaks
|
|
351 together with confirmation of interruptions to these breaks.
|
8276
|
352
|
|
353 The variable `type-break-keystroke-threshold' is used to determine the
|
|
354 thresholds at which typing breaks should be considered. You can use
|
18414
|
355 the command `type-break-guesstimate-keystroke-threshold' to try to
|
8276
|
356 approximate good values for this.
|
8275
|
357
|
18414
|
358 There are several variables that affect how or when warning messages about
|
|
359 imminent typing breaks are displayed. They include:
|
|
360
|
22049
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
361 `type-break-mode-line-message-mode'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
362 `type-break-time-warning-intervals'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
363 `type-break-keystroke-warning-intervals'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
364 `type-break-warning-repeat'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
365 `type-break-warning-countdown-string'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
366 `type-break-warning-countdown-string-type'
|
18414
|
367
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
368 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
|
369 a typing break occur. They include:
|
18414
|
370
|
22049
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
371 `type-break-query-mode'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
372 `type-break-query-function'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
373 `type-break-query-interval'
|
18414
|
374
|
55189
|
375 The command `type-break-statistics' prints interesting things.
|
|
376
|
|
377 Finally, a file (named `type-break-file-name') is used to store information
|
|
378 across Emacs sessions. This provides recovery of the break status between
|
|
379 sessions and after a crash. Manual changes to the file may result in
|
|
380 problems."
|
8275
|
381 (interactive "P")
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
382 (type-break-check-post-command-hook)
|
8275
|
383
|
8276
|
384 (let ((already-enabled type-break-mode))
|
8304
|
385 (setq type-break-mode (>= (prefix-numeric-value prefix) 0))
|
8275
|
386
|
8276
|
387 (cond
|
|
388 ((and already-enabled type-break-mode)
|
|
389 (and (interactive-p)
|
22049
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
390 (message "Type Break mode is already enabled")))
|
8276
|
391 (type-break-mode
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
392 (or global-mode-string
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
393 (setq global-mode-string '("")))
|
22069
|
394 (or (assq 'type-break-mode-line-message-mode
|
|
395 minor-mode-alist)
|
|
396 (setq minor-mode-alist
|
|
397 (cons type-break-mode-line-format
|
|
398 minor-mode-alist)))
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
399 (type-break-keystroke-reset)
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
400 (type-break-mode-line-countdown-or-break nil)
|
55189
|
401
|
|
402 (if (boundp 'save-some-buffers-always)
|
|
403 (add-to-list 'save-some-buffers-always
|
|
404 (expand-file-name type-break-file-name)))
|
|
405
|
|
406 (setq type-break-time-last-break (type-break-get-previous-time))
|
|
407
|
|
408 ;; schedule according to break time from session file
|
|
409 (type-break-schedule
|
|
410 (let (diff)
|
|
411 (if (and type-break-time-last-break
|
|
412 (< (setq diff (type-break-time-difference
|
|
413 type-break-time-last-break
|
|
414 (current-time)))
|
|
415 type-break-interval))
|
|
416 ;; use the file's value
|
|
417 (progn
|
|
418 (setq type-break-keystroke-count
|
|
419 (type-break-get-previous-count))
|
|
420 ;; file the time, in case it was read from the auto-save file
|
|
421 (type-break-file-time type-break-interval-start)
|
|
422 (setq type-break-interval-start type-break-time-last-break)
|
|
423 (- type-break-interval diff))
|
|
424 ;; schedule from now
|
|
425 (setq type-break-interval-start (current-time))
|
|
426 (type-break-file-time type-break-interval-start)
|
|
427 type-break-interval))
|
|
428 type-break-interval-start
|
|
429 type-break-interval)
|
|
430
|
8276
|
431 (and (interactive-p)
|
55189
|
432 (message "Type Break mode is enabled and set")))
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
433 (t
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
434 (type-break-keystroke-reset)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
435 (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
|
436 (type-break-cancel-schedule)
|
55189
|
437 (do-auto-save)
|
|
438 (with-current-buffer (find-file-noselect type-break-file-name
|
|
439 'nowarn)
|
|
440 (set-buffer-modified-p nil)
|
|
441 (unlock-buffer)
|
|
442 (kill-this-buffer))
|
|
443 (if (boundp 'save-some-buffers-always)
|
|
444 (setq save-some-buffers-always
|
|
445 (remove (expand-file-name type-break-file-name)
|
|
446 save-some-buffers-always)))
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
447 (and (interactive-p)
|
22049
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
448 (message "Type Break mode is disabled")))))
|
8275
|
449 type-break-mode)
|
|
450
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
451 (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
|
452 "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
|
453
|
55189
|
454 A negative PREFIX argument disables this mode.
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
455 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
|
456
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
457 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
|
458 variable of the same name.
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
459
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
460 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
|
461
|
22049
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
462 `mode-line-format'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
463 `global-mode-string'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
464 `type-break-mode-line-break-message'
|
247682b1da6b
(type-break-mode-line-message-mode): Doc fix. Fix some messages.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
465 `type-break-mode-line-warning'"
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
466 (interactive "P")
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
467 (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
|
468 (>= (prefix-numeric-value prefix) 0))
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
469 (and (interactive-p)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
470 (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
|
471 (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
|
472 (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
|
473 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
|
474
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
475 (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
|
476 "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
|
477
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
478 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
|
479 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
|
480 specified by the variable `type-break-query-function'.
|
18414
|
481
|
55189
|
482 A negative PREFIX argument disables this mode.
|
18414
|
483 No argument or any non-negative argument enables it.
|
|
484
|
|
485 The user may also enable or disable this mode simply by setting the
|
|
486 variable of the same name."
|
|
487 (interactive "P")
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
488 (setq type-break-query-mode
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
489 (>= (prefix-numeric-value prefix) 0))
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
490 (and (interactive-p)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
491 (if type-break-query-mode
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
492 (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
|
493 (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
|
494 type-break-query-mode)
|
18414
|
495
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
496
|
55189
|
497 ;;; session file functions
|
|
498
|
|
499 (defvar type-break-auto-save-file-name
|
|
500 (let ((buffer-file-name type-break-file-name))
|
|
501 (make-auto-save-file-name))
|
|
502 "Auto-save name of `type-break-file-name'.")
|
|
503
|
|
504 (defun type-break-file-time (&optional time)
|
|
505 "File break time in `type-break-file-name', unless the file is locked."
|
|
506 (if (not (stringp (file-locked-p type-break-file-name)))
|
|
507 (with-current-buffer (find-file-noselect type-break-file-name
|
|
508 'nowarn)
|
|
509 (let ((inhibit-read-only t))
|
|
510 (erase-buffer)
|
|
511 (insert (format "%s\n\n" (or time type-break-interval-start)))
|
|
512 ;; file saving is left to auto-save
|
|
513 ))))
|
|
514
|
|
515 (defun type-break-file-keystroke-count ()
|
|
516 "File keystroke count in `type-break-file-name', unless the file is locked."
|
|
517 (if (not (stringp (file-locked-p type-break-file-name)))
|
|
518 (with-current-buffer (find-file-noselect type-break-file-name
|
|
519 'nowarn)
|
|
520 (save-excursion
|
|
521 (let ((inhibit-read-only t))
|
|
522 (goto-char (point-min))
|
|
523 (forward-line)
|
|
524 (delete-region (point) (save-excursion (end-of-line) (point)))
|
|
525 (insert (format "%s" type-break-keystroke-count))
|
|
526 ;; file saving is left to auto-save
|
|
527 )))))
|
|
528
|
|
529 (defun timep (time)
|
|
530 "If TIME is in the format returned by `current-time' then
|
|
531 return TIME, else return nil."
|
|
532 (and (listp time)
|
|
533 (eq (length time) 3)
|
|
534 (integerp (car time))
|
|
535 (integerp (nth 1 time))
|
|
536 (integerp (nth 2 time))
|
|
537 time))
|
|
538
|
|
539 (defun type-break-choose-file ()
|
|
540 "Return file to read from."
|
|
541 (cond
|
|
542 ((and (file-exists-p type-break-auto-save-file-name)
|
|
543 (file-readable-p type-break-auto-save-file-name))
|
|
544 type-break-auto-save-file-name)
|
|
545 ((and (file-exists-p type-break-file-name)
|
|
546 (file-readable-p type-break-file-name))
|
|
547 type-break-file-name)
|
|
548 (t nil)))
|
|
549
|
|
550 (defun type-break-get-previous-time ()
|
|
551 "Get previous break time from `type-break-file-name'.
|
|
552 Returns nil if the file is missing or if the time breaks with the
|
|
553 `current-time' format."
|
|
554 (let ((file (type-break-choose-file)))
|
|
555 (if file
|
|
556 (timep ;; returns expected format, else nil
|
|
557 (with-current-buffer (find-file-noselect file 'nowarn)
|
|
558 (save-excursion
|
|
559 (goto-char (point-min))
|
|
560 (read (current-buffer))))))))
|
|
561
|
|
562 (defun type-break-get-previous-count ()
|
|
563 "Get previous keystroke count from `type-break-file-name'.
|
|
564 Return 0 if the file is missing or if the form read is not an
|
|
565 integer."
|
|
566 (let ((file (type-break-choose-file)))
|
|
567 (if (and file
|
|
568 (integerp
|
|
569 (setq file
|
|
570 (with-current-buffer
|
|
571 (find-file-noselect file 'nowarn)
|
|
572 (save-excursion
|
|
573 (goto-char (point-min))
|
|
574 (forward-line 1)
|
|
575 (read (current-buffer)))))))
|
|
576 file
|
|
577 0)))
|
|
578
|
|
579
|
8275
|
580 ;;;###autoload
|
8248
|
581 (defun type-break ()
|
|
582 "Take a typing break.
|
|
583
|
8275
|
584 During the break, a demo selected from the functions listed in
|
8304
|
585 `type-break-demo-functions' is run.
|
8248
|
586
|
8275
|
587 After the typing break is finished, the next break is scheduled
|
8304
|
588 as per the function `type-break-schedule'."
|
5939
|
589 (interactive)
|
30391
|
590 (do-auto-save)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
591 (type-break-cancel-schedule)
|
55189
|
592 ;; remove any query scheduled during interactive invocation
|
|
593 (remove-hook 'type-break-post-command-hook 'type-break-do-query)
|
8304
|
594 (let ((continue t)
|
|
595 (start-time (current-time)))
|
|
596 (setq type-break-time-last-break start-time)
|
|
597 (while continue
|
|
598 (save-window-excursion
|
|
599 ;; Eat the screen.
|
|
600 (and (eq (selected-window) (minibuffer-window))
|
|
601 (other-window 1))
|
|
602 (delete-other-windows)
|
|
603 (scroll-right (window-width))
|
55189
|
604 (unless type-break-terse-messages
|
|
605 (message "Press any key to resume from typing break."))
|
5939
|
606
|
8304
|
607 (random t)
|
|
608 (let* ((len (length type-break-demo-functions))
|
|
609 (idx (random len))
|
|
610 (fn (nth idx type-break-demo-functions)))
|
|
611 (condition-case ()
|
|
612 (funcall fn)
|
|
613 (error nil))))
|
8275
|
614
|
55189
|
615 (let ((good-interval (or type-break-good-rest-interval
|
|
616 type-break-good-break-interval)))
|
|
617 (cond
|
|
618 (good-interval
|
|
619 (let ((break-secs (type-break-time-difference
|
|
620 start-time (current-time))))
|
|
621 (cond
|
|
622 ((>= break-secs good-interval)
|
|
623 (setq continue nil))
|
|
624 ;; 60 seconds may be too much leeway if the break is only 3
|
|
625 ;; minutes to begin with. You can just say "no" to the query
|
|
626 ;; below if you're in that much of a hurry.
|
|
627 ;;((> 60 (abs (- break-secs good-interval)))
|
|
628 ;; (setq continue nil))
|
|
629 ((funcall
|
|
630 type-break-query-function
|
|
631 (format
|
|
632 (if type-break-terse-messages
|
|
633 "%s%s remaining. Continue break? "
|
|
634 "%sYou really ought to rest %s more. Continue break? ")
|
|
635 (type-break-time-stamp)
|
|
636 (type-break-format-time (- good-interval
|
|
637 break-secs)))))
|
|
638 (t
|
|
639 (setq continue nil)))))
|
|
640 (t (setq continue nil))))))
|
8276
|
641
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
642 (type-break-keystroke-reset)
|
55189
|
643 (type-break-file-time)
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
644 (type-break-mode-line-countdown-or-break nil)
|
8276
|
645 (type-break-schedule))
|
8248
|
646
|
|
647
|
55189
|
648 (defun type-break-schedule (&optional time start interval)
|
8497
|
649 "Schedule a typing break for TIME seconds from now.
|
55189
|
650 If time is not specified it defaults to `type-break-interval'.
|
|
651 START and INTERVAL are used when recovering a break.
|
|
652 START is the start of the break (defaults to now).
|
|
653 INTERVAL is the full length of an interval (defaults to TIME)."
|
8497
|
654 (interactive (list (and current-prefix-arg
|
|
655 (prefix-numeric-value current-prefix-arg))))
|
8248
|
656 (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
|
657 (type-break-check-post-command-hook)
|
8275
|
658 (type-break-cancel-schedule)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
659 (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
|
660 (type-break-run-at-time (max 1 time) nil 'type-break-alarm)
|
8497
|
661 (setq type-break-time-next-break
|
55189
|
662 (type-break-time-sum (or start (current-time))
|
|
663 (or interval time))))
|
8248
|
664
|
8275
|
665 (defun type-break-cancel-schedule ()
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
666 (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
|
667 (type-break-cancel-function-timers 'type-break-alarm)
|
8276
|
668 (setq type-break-alarm-p nil)
|
|
669 (setq type-break-time-next-break nil))
|
5939
|
670
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
671 (defun type-break-time-warning-schedule (&optional time resetp)
|
18414
|
672 (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
|
673 (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
|
674 (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
|
675 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
676 (type-break-time-warning-intervals
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
677 (and resetp
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
678 (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
|
679 type-break-time-warning-intervals))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
680
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
681 (or time
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
682 (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
|
683 type-break-time-next-break)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
684
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
685 (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
|
686 (> (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
|
687 (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
|
688 (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
|
689
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
690 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
691 (type-break-current-time-warning-interval
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
692 (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
|
693 (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
|
694 (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
|
695
|
18414
|
696 ;(let (type-break-current-time-warning-interval)
|
|
697 ; (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
|
698 (type-break-run-at-time (max 1 time) nil 'type-break-time-warning-alarm)
|
18414
|
699
|
|
700 (cond
|
|
701 (resetp
|
|
702 (setq type-break-warning-countdown-string nil))
|
|
703 (t
|
|
704 (setq type-break-warning-countdown-string (number-to-string time))
|
|
705 (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
|
706
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
707 (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
|
708 (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
|
709 (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
|
710 (setq type-break-current-time-warning-interval
|
18414
|
711 type-break-time-warning-intervals)
|
55189
|
712 (setq type-break-time-warning-count 0) ; avoid warnings after break
|
18414
|
713 (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
|
714
|
8275
|
715 (defun type-break-alarm ()
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
716 (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
|
717 (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
|
718 (type-break-mode-line-countdown-or-break 'break))
|
8248
|
719
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
720 (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
|
721 (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
|
722 (type-break-time-warning-schedule)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
723 (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
|
724 (type-break-time-warning)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
725 (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
|
726
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
727
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
728 (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
|
729 (and type-break-mode
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
730 (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
|
731
|
8248
|
732 (defun type-break-check ()
|
8275
|
733 "Ask to take a typing break if appropriate.
|
|
734 This may be the case either because the scheduled time has come \(and the
|
|
735 minimum keystroke threshold has been reached\) or because the maximum
|
|
736 keystroke threshold has been exceeded."
|
55189
|
737 (type-break-file-keystroke-count)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
738 (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
|
739 (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
|
740 (and type-break-good-rest-interval
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
741 (progn
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
742 (and (> (type-break-time-difference
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
743 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
|
744 type-break-good-rest-interval)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
745 (progn
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
746 (type-break-keystroke-reset)
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
747 (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
|
748 (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
|
749 (type-break-schedule)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
750 (setq type-break-time-last-command (current-time))))
|
8276
|
751
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
752 (and type-break-keystroke-threshold
|
18414
|
753 (let ((keys (this-command-keys)))
|
|
754 (cond
|
|
755 ;; Ignore mouse motion
|
|
756 ((and (vectorp keys)
|
|
757 (consp (aref keys 0))
|
|
758 (memq (car (aref keys 0)) '(mouse-movement))))
|
|
759 (t
|
|
760 (setq type-break-keystroke-count
|
|
761 (+ type-break-keystroke-count (length keys)))))))
|
8276
|
762
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
763 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
764 (type-break-alarm-p
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
765 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
766 ((input-pending-p))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
767 ((eq (selected-window) (minibuffer-window)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
768 ((and min-threshold
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
769 (< type-break-keystroke-count min-threshold))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
770 (type-break-schedule))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
771 (t
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
772 ;; If keystroke count is within min-threshold of
|
18414
|
773 ;; 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
|
774 ;; immediate subsequent query.
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
775 (and max-threshold
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
776 min-threshold
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
777 (< (- 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
|
778 (progn
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
779 (type-break-keystroke-reset)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
780 (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
|
781 (type-break-query))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
782 ((and type-break-keystroke-warning-intervals
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
783 max-threshold
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
784 (= type-break-keystroke-warning-count 0)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
785 (type-break-check-keystroke-warning)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
786 ((and max-threshold
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
787 (> type-break-keystroke-count max-threshold)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
788 (not (input-pending-p))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
789 (not (eq (selected-window) (minibuffer-window))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
790 (type-break-keystroke-reset)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
791 (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
|
792 (type-break-query)))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
793
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
794 ;; 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
|
795 (defun type-break-check-keystroke-warning ()
|
18414
|
796 ;; This is safe because the caller should have checked that the cdr was
|
|
797 ;; non-nil already.
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
798 (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
|
799 type-break-keystroke-count)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
800 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
801 ((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
|
802 nil)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
803 ((> 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
|
804 nil)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
805 (t
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
806 (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
|
807 (< 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
|
808 (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
|
809 (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
|
810 (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
|
811 (add-hook 'type-break-post-command-hook 'type-break-keystroke-warning)
|
18414
|
812 (setq type-break-warning-countdown-string (number-to-string left))
|
|
813 (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
|
814 (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
|
815 t))))
|
8275
|
816
|
18414
|
817 ;; Arrange for a break query to be made, when the user stops typing furiously.
|
8275
|
818 (defun type-break-query ()
|
18414
|
819 (add-hook 'type-break-post-command-hook 'type-break-do-query))
|
|
820
|
|
821 (defun type-break-do-query ()
|
|
822 (cond
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
823 ((not type-break-query-mode)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
824 (type-break-noninteractive-query)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
825 (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
|
826 (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
|
827 ((sit-for 2)
|
18414
|
828 (condition-case ()
|
|
829 (cond
|
|
830 ((let ((type-break-mode nil)
|
|
831 ;; yes-or-no-p sets this-command to exit-minibuffer,
|
|
832 ;; which hoses undo or yank-pop (if you happened to be
|
|
833 ;; yanking just when the query occurred).
|
|
834 (this-command this-command))
|
30391
|
835 ;; Cancel schedule to prevent possibility of a second query
|
|
836 ;; from taking place before this one has even returned.
|
|
837 ;; The condition-case wrapper will reschedule on quit.
|
|
838 (type-break-cancel-schedule)
|
55189
|
839 ;; Also prevent a second query when the break is interrupted.
|
|
840 (remove-hook 'type-break-post-command-hook 'type-break-do-query)
|
18414
|
841 (funcall type-break-query-function
|
30391
|
842 (format "%s%s"
|
|
843 (type-break-time-stamp)
|
55189
|
844 (if type-break-terse-messages
|
|
845 "Break now? "
|
|
846 "Take a break from typing now? "))))
|
18414
|
847 (type-break))
|
|
848 (t
|
|
849 (type-break-schedule type-break-query-interval)))
|
|
850 (quit
|
55189
|
851 (type-break-schedule type-break-query-interval))))))
|
5939
|
852
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
853 (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
|
854 "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
|
855 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
|
856 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
|
857 (cond
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
858 (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
|
859 (t
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
860 (beep t)
|
30391
|
861 (message "%sYou should take a typing break now. Do `M-x type-break'."
|
|
862 (type-break-time-stamp))
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
863 (sit-for 1)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
864 (beep t)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
865 ;; 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
|
866 ;; 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
|
867 nil)))
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
868
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
869 (defun type-break-time-warning ()
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
870 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
871 ((and (car type-break-keystroke-threshold)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
872 (< 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
|
873 ((> type-break-time-warning-count 0)
|
18414
|
874 (let ((timeleft (type-break-time-difference (current-time)
|
|
875 type-break-time-next-break)))
|
|
876 (setq type-break-warning-countdown-string (number-to-string timeleft))
|
|
877 (cond
|
|
878 ((eq (selected-window) (minibuffer-window)))
|
|
879 ;; Do nothing if the command was just a prefix arg, since that will
|
|
880 ;; 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
|
881 ;; 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
|
882 ;; delay redisplay when one types sequences like `C-u -1 C-l'.
|
18414
|
883 ((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
|
884 ((not type-break-mode-line-message-mode)
|
18414
|
885 ;; Pause for a moment so any previous message can be seen.
|
|
886 (sit-for 2)
|
30391
|
887 (message "%sWarning: typing break due in %s."
|
|
888 (type-break-time-stamp)
|
18414
|
889 (type-break-format-time timeleft))
|
|
890 (setq type-break-time-warning-count
|
|
891 (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
|
892 (t
|
18414
|
893 (remove-hook 'type-break-post-command-hook 'type-break-time-warning)
|
|
894 (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
|
895
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
896 (defun type-break-keystroke-warning ()
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
897 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
898 ((> type-break-keystroke-warning-count 0)
|
18414
|
899 (setq type-break-warning-countdown-string
|
|
900 (number-to-string (- (cdr type-break-keystroke-threshold)
|
|
901 type-break-keystroke-count)))
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
902 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
903 ((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
|
904 ;; 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
|
905 ;; 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
|
906 ;; 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
|
907 ;; 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
|
908 ((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
|
909 ((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
|
910 (sit-for 2)
|
30391
|
911 (message "%sWarning: typing break due in %s keystrokes."
|
|
912 (type-break-time-stamp)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
913 (- (cdr type-break-keystroke-threshold)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
914 type-break-keystroke-count))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
915 (setq type-break-keystroke-warning-count
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
916 (1- type-break-keystroke-warning-count)))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
917 (t
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
918 (remove-hook 'type-break-post-command-hook
|
18414
|
919 'type-break-keystroke-warning)
|
|
920 (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
|
921
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
922 (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
|
923 (cond
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
924 ((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
|
925 ((eq type 'countdown)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
926 ;(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
|
927 (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
|
928 '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
|
929 ((eq type 'break)
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
930 ;; Alternate
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
931 (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
|
932 (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
|
933 (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
|
934 '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
|
935 (t
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
936 (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
|
937 (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
|
938 (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
|
939 '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
|
940 (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
|
941
|
8248
|
942
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
943 ;;;###autoload
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
944 (defun type-break-statistics ()
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
945 "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
|
946 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
|
947 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
|
948 (interactive)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
949 (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
|
950 (princ (format "Typing break statistics\n-----------------------\n
|
18414
|
951 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
|
952 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
|
953 Warnings of imminent typing breaks in mode line is %s.
|
18414
|
954
|
|
955 Last typing break ended : %s
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
956 Next scheduled typing break : %s\n
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
957 Minimum keystroke threshold : %s
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
958 Maximum keystroke threshold : %s
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
959 Current keystroke count : %s"
|
18414
|
960 (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
|
961 (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
|
962 (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
|
963 (if type-break-time-last-break
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
964 (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
|
965 "never")
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
966 (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
|
967 (format "%s\t(%s from now)"
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
968 (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
|
969 (type-break-format-time
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
970 (type-break-time-difference
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
971 (current-time)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
972 type-break-time-next-break)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
973 "none scheduled")
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
974 (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
|
975 (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
|
976 type-break-keystroke-count))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
977
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
978 ;;;###autoload
|
18414
|
979 (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
|
980 "Guess values for the minimum/maximum keystroke threshold for typing breaks.
|
18414
|
981
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
982 If called interactively, the user is prompted for their guess as to how
|
18414
|
983 many words per minute they usually type. This value should not be your
|
|
984 maximum WPM, but your average. Of course, this is harder to gauge since it
|
|
985 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
|
986 tends to type less when debugging a program as opposed to writing
|
18414
|
987 documentation. (Perhaps a separate program should be written to estimate
|
|
988 average typing speed.)
|
|
989
|
|
990 From that, this command sets the values in `type-break-keystroke-threshold'
|
|
991 based on a fairly simple algorithm involving assumptions about the average
|
|
992 length of words (5). For the minimum threshold, it uses about a fifth of
|
|
993 the computed maximum threshold.
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
994
|
55189
|
995 When called from Lisp programs, the optional args WORDLEN and FRAC can be
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 2 would mean to use one half, a value of 4 would mean to use one quarter, etc."
|
18414
|
1000 (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
|
1001 (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
|
1002 (lower (/ upper (or frac 5))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1003 (or type-break-keystroke-threshold
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1004 (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
|
1005 (setcar type-break-keystroke-threshold lower)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1006 (setcdr type-break-keystroke-threshold upper)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1007 (if (interactive-p)
|
57744
a14f0e52fd5e
(type-break-run-at-time): Always use run-at-time; forget the alternatives.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1008 (message "min threshold: %d\tmax threshold: %d" lower upper))
|
a14f0e52fd5e
(type-break-run-at-time): Always use run-at-time; forget the alternatives.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1009 type-break-keystroke-threshold))
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1010
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1011
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1012 ;;; misc functions
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1013
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1014 ;; 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
|
1015 ;; similar to those returned by `current-time'.
|
8497
|
1016 ;; Use addition rather than logand since that is more robust; the low 16
|
|
1017 ;; bits of the seconds might have been incremented, making it more than 16
|
|
1018 ;; bits wide.
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1019 (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
|
1020 (+ (lsh (- (car b) (car a)) 16)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1021 (- (car (cdr b)) (car (cdr a)))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1022
|
8497
|
1023 ;; Return (in a new list the same in structure to that returned by
|
|
1024 ;; `current-time') the sum of the arguments. Each argument may be a time
|
|
1025 ;; list or a single integer, a number of seconds.
|
|
1026 ;; This function keeps the high and low 16 bits of the seconds properly
|
|
1027 ;; balanced so that the lower value never exceeds 16 bits. Otherwise, when
|
|
1028 ;; 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
|
1029 ;; "low" bits and format the time incorrectly.
|
8497
|
1030 (defun type-break-time-sum (&rest tmlist)
|
|
1031 (let ((high 0)
|
|
1032 (low 0)
|
|
1033 (micro 0)
|
|
1034 tem)
|
|
1035 (while tmlist
|
|
1036 (setq tem (car tmlist))
|
|
1037 (setq tmlist (cdr tmlist))
|
|
1038 (cond
|
|
1039 ((numberp tem)
|
|
1040 (setq low (+ low tem)))
|
|
1041 (t
|
|
1042 (setq high (+ high (or (car tem) 0)))
|
|
1043 (setq low (+ low (or (car (cdr tem)) 0)))
|
|
1044 (setq micro (+ micro (or (car (cdr (cdr tem))) 0))))))
|
|
1045
|
|
1046 (and (>= micro 1000000)
|
|
1047 (progn
|
|
1048 (setq tem (/ micro 1000000))
|
|
1049 (setq low (+ low tem))
|
|
1050 (setq micro (- micro (* tem 1000000)))))
|
|
1051
|
|
1052 (setq tem (lsh low -16))
|
|
1053 (and (> tem 0)
|
|
1054 (progn
|
|
1055 (setq low (logand low 65535))
|
|
1056 (setq high (+ high tem))))
|
|
1057
|
|
1058 (list high low micro)))
|
|
1059
|
30391
|
1060 (defun type-break-time-stamp (&optional when)
|
|
1061 (if (fboundp 'format-time-string)
|
|
1062 (format-time-string type-break-time-stamp-format when)
|
|
1063 ;; Emacs 19.28 and prior do not have format-time-string.
|
|
1064 ;; In that case, result is not customizable. Upgrade today!
|
|
1065 (format "[%s] " (substring (current-time-string when) 11 16))))
|
|
1066
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1067 (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
|
1068 (let ((mins (/ secs 60)))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1069 (cond
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1070 ((= mins 1) (format "%d minute" mins))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1071 ((> mins 0) (format "%d minutes" mins))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1072 ((= secs 1) (format "%d second" secs))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1073 (t (format "%d seconds" secs)))))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1074
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1075 (defun type-break-keystroke-reset ()
|
55189
|
1076 (setq type-break-interval-start (current-time)) ; not a keystroke
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1077 (setq type-break-keystroke-count 0)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1078 (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
|
1079 (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
|
1080 type-break-keystroke-warning-intervals)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1081 (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
|
1082
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1083 (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
|
1084 "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
|
1085 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
|
1086 (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
|
1087 (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
|
1088
|
55189
|
1089 ;; If an exception occurs in Emacs while running the post command hook, the
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1090 ;; 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
|
1091 ;; 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
|
1092 ;; 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
|
1093 ;; 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
|
1094 ;; just in case.
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1095 (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
|
1096 (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
|
1097
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1098
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1099 ;;; Timer wrapper functions
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1100 ;;;
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1101 ;;; These shield type-break from variations in the interval timer packages
|
55189
|
1102 ;;; for different versions of Emacs.
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1103
|
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1104 (defun type-break-run-at-time (time repeat function)
|
54322
|
1105 (condition-case nil (or (require 'timer) (require 'itimer)) (error nil))
|
57744
a14f0e52fd5e
(type-break-run-at-time): Always use run-at-time; forget the alternatives.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1106 (run-at-time time repeat function))
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1107
|
54322
|
1108 (defvar timer-dont-exit)
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1109 (defun type-break-cancel-function-timers (function)
|
57744
a14f0e52fd5e
(type-break-run-at-time): Always use run-at-time; forget the alternatives.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1110 (let ((timer-dont-exit t))
|
a14f0e52fd5e
(type-break-run-at-time): Always use run-at-time; forget the alternatives.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1111 (cancel-function-timers function)))
|
18416
2ec71bb15f86
Don't require timer; use autoloaded functions from Emacs or XEmacs,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1112
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1113
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1114 ;;; Demo wrappers
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1115
|
8248
|
1116 ;; This is a wrapper around hanoi that calls it with an arg large enough to
|
|
1117 ;; make the largest discs possible that will fit in the window.
|
|
1118 ;; Also, clean up the *Hanoi* buffer after we're done.
|
8275
|
1119 (defun type-break-demo-hanoi ()
|
8248
|
1120 "Take a hanoiing typing break."
|
|
1121 (and (get-buffer "*Hanoi*")
|
|
1122 (kill-buffer "*Hanoi*"))
|
|
1123 (condition-case ()
|
|
1124 (progn
|
|
1125 (hanoi (/ (window-width) 8))
|
|
1126 ;; Wait for user to come back.
|
|
1127 (read-char)
|
|
1128 (kill-buffer "*Hanoi*"))
|
8276
|
1129 (quit
|
|
1130 ;; eat char
|
|
1131 (read-char)
|
8248
|
1132 (and (get-buffer "*Hanoi*")
|
|
1133 (kill-buffer "*Hanoi*")))))
|
5939
|
1134
|
8248
|
1135 ;; This is a wrapper around life that calls it with a `sleep' arg to make
|
|
1136 ;; it run a little more leisurely.
|
|
1137 ;; Also, clean up the *Life* buffer after we're done.
|
8275
|
1138 (defun type-break-demo-life ()
|
8248
|
1139 "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
|
1140 (let ((continue t))
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1141 (while continue
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1142 (setq continue nil)
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1143 (and (get-buffer "*Life*")
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1144 (kill-buffer "*Life*"))
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1145 (condition-case ()
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1146 (progn
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1147 (life 3)
|
8304
|
1148 ;; wait for user to return
|
|
1149 (read-char)
|
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1150 (kill-buffer "*Life*"))
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1151 (life-extinct
|
18414
|
1152 (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
|
1153 (sit-for 3)
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1154 ;; restart demo
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1155 (setq continue t))
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1156 (quit
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1157 (and (get-buffer "*Life*")
|
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
diff
changeset
|
1158 (kill-buffer "*Life*")))))))
|
8248
|
1159
|
8497
|
1160 ;; 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
|
1161 (defun type-break-demo-boring ()
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1162 "Boring typing break demo."
|
55189
|
1163 (let ((rmsg (if type-break-terse-messages
|
|
1164 ""
|
|
1165 "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
|
1166 (buffer-name "*Typing Break Buffer*")
|
55189
|
1167 lines elapsed timeleft tmsg)
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1168 (condition-case ()
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1169 (progn
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1170 (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
|
1171 (buffer-disable-undo (current-buffer))
|
55189
|
1172 (setq lines (/ (window-body-height) 2))
|
|
1173 (unless type-break-terse-messages (setq lines (1- lines)))
|
|
1174 (if type-break-demo-boring-stats
|
|
1175 (setq lines (- lines 2)))
|
|
1176 (setq lines (make-string lines ?\C-j))
|
8497
|
1177 (while (not (input-pending-p))
|
55189
|
1178 (erase-buffer)
|
8497
|
1179 (setq elapsed (type-break-time-difference
|
|
1180 type-break-time-last-break
|
|
1181 (current-time)))
|
55189
|
1182 (let ((good-interval (or type-break-good-rest-interval
|
|
1183 type-break-good-break-interval)))
|
|
1184 (cond
|
|
1185 (good-interval
|
|
1186 (setq timeleft (- good-interval elapsed))
|
|
1187 (if (> timeleft 0)
|
|
1188 (setq tmsg
|
|
1189 (format (if type-break-terse-messages
|
|
1190 "Break remaining: %s"
|
|
1191 "You should rest for %s more")
|
|
1192 (type-break-format-time timeleft)))
|
|
1193 (setq tmsg
|
|
1194 (format (if type-break-terse-messages
|
|
1195 "Break complete (%s elapsed in total)"
|
|
1196 "Typing break has lasted %s")
|
|
1197 (type-break-format-time elapsed)))))
|
|
1198 (t
|
|
1199 (setq tmsg
|
|
1200 (format (if type-break-terse-messages
|
|
1201 "Break has lasted %s"
|
|
1202 "Typing break has lasted %s")
|
|
1203 (type-break-format-time elapsed))))))
|
|
1204 (insert lines
|
|
1205 (make-string (/ (- (window-width) (length tmsg)) 2) ?\ )
|
|
1206 tmsg)
|
|
1207 (if (> (length rmsg) 0)
|
|
1208 (insert "\n"
|
|
1209 (make-string (/ (- (window-width) (length rmsg)) 2)
|
|
1210 ?\ )
|
|
1211 rmsg))
|
|
1212 (if type-break-demo-boring-stats
|
|
1213 (let*
|
|
1214 ((message
|
|
1215 (format
|
|
1216 (if type-break-terse-messages
|
|
1217 "Since last break: %s keystrokes\n"
|
|
1218 "Since your last break you've typed %s keystrokes\n")
|
|
1219 type-break-keystroke-count))
|
|
1220 (column-spaces
|
|
1221 (make-string (/ (- (window-width) (length message)) 2)
|
|
1222 ?\ ))
|
|
1223 (wpm (/ (/ (float type-break-keystroke-count) 5)
|
|
1224 (/ (type-break-time-difference
|
|
1225 type-break-interval-start
|
|
1226 type-break-time-last-break)
|
|
1227 60.0))))
|
|
1228 (insert "\n\n" column-spaces message)
|
|
1229 (if type-break-terse-messages
|
|
1230 (insert (format " %s%.2f wpm"
|
|
1231 column-spaces
|
|
1232 wpm))
|
|
1233 (setq message
|
|
1234 (format "at an average of %.2f words per minute"
|
|
1235 wpm))
|
|
1236 (insert
|
|
1237 (make-string (/ (- (window-width) (length message)) 2)
|
|
1238 ?\ )
|
|
1239 message))))
|
8497
|
1240 (goto-char (point-min))
|
|
1241 (sit-for 60))
|
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1242 (read-char)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1243 (kill-buffer buffer-name))
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1244 (quit
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1245 (and (get-buffer buffer-name)
|
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
diff
changeset
|
1246 (kill-buffer buffer-name))))))
|
8276
|
1247
|
|
1248
|
8248
|
1249 (provide 'type-break)
|
|
1250
|
20800
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
1251 (if type-break-mode
|
43c77517a76c
(type-break-mode): New customize variable to automatically load the package.
Stephen Eglen <stephen@gnu.org>
diff
changeset
|
1252 (type-break-mode 1))
|
30391
|
1253
|
52401
|
1254 ;;; arch-tag: 943a2eb3-07e6-420b-993f-96e4796f5fd0
|
8248
|
1255 ;;; type-break.el ends here
|