Mercurial > emacs
annotate lisp/type-break.el @ 10965:1ade2d8b0ae9
(display_text_line): When setting selective_rlen,
ignore whether selective display is on or off.
(display_text_line, try_window): Check `invisible' prop
using TEXT_PROP_MEANS_INVISIBLE.
(display_text_line): Check TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS;
if it says so, use ellipses after invisible text.
(invisible_p, invisible_ellipsis_p): New functions.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 11 Mar 1995 22:34:35 +0000 |
parents | 8ac258bc59ef |
children | 8d2051b79879 |
rev | line source |
---|---|
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
1 ;;; type-break.el --- encourage rests from typing at appropriate intervals |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
2 |
9355
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
3 ;; Copyright (C) 1994 Free Software Foundation, Inc. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
4 |
9355
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu> |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
6 ;; Maintainer: friedman@prep.ai.mit.edu |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
7 ;; Keywords: extensions, timers |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
8 ;; Status: known to work in GNU Emacs 19.25 or later. |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
9 ;; Created: 1994-07-13 |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
10 ;; $Id$ |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
11 |
9355
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
12 ;; This file is part of GNU Emacs. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
13 |
9355
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
14 ;; GNU Emacs is free software; you can redistribute it and/or modify |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
15 ;; it under the terms of the GNU General Public License as published by |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
16 ;; the Free Software Foundation; either version 2, or (at your option) |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
17 ;; any later version. |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
18 |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
19 ;; GNU Emacs is distributed in the hope that it will be useful, |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
22 ;; GNU General Public License for more details. |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
23 |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to |
8ac258bc59ef
Assign copyright to FSF, and change comments to reflect that type-break
Noah Friedman <friedman@splode.com>
parents:
8497
diff
changeset
|
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
27 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
28 ;;; Commentary: |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
29 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
30 ;;; The docstring for the function `type-break-mode' summarizes most of the |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
31 ;;; details of the interface. |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
32 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
33 ;;; This package relies on the assumption that you live entirely in emacs, |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
34 ;;; as the author does. If that's not the case for you (e.g. you often |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
35 ;;; suspend emacs or work in other windows) then this won't help very much; |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
36 ;;; it will depend on just how often you switch back to emacs. At the very |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
37 ;;; least, you will want to turn off the keystroke thresholds and rest |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
38 ;;; interval tracking. |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
39 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
40 ;;; This package was inspired by Roland McGrath's hanoi-break.el. |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
41 ;;; Thanks to both Roland McGrath <roland@gnu.ai.mit.edu> and Mark Ashton |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
42 ;;; <mpashton@gnu.ai.mit.edu> for feedback and ideas. |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
43 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
44 ;;; Code: |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
45 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
46 |
5939 | 47 (require 'timer) |
48 | |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
49 ;; Make this nil initially so that the call to type-break-mode at the end |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
50 ;; will cause scheduling and so forth to happen. |
5939 | 51 ;;;###autoload |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
52 (defvar type-break-mode nil |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
53 "*Non-`nil' means typing break mode is enabled. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
54 See the docstring for the `type-break-mode' command for more information.") |
5939 | 55 |
56 ;;;###autoload | |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
57 (defvar type-break-interval (* 60 60) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
58 "*Number of seconds between scheduled typing breaks.") |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
59 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
60 ;;;###autoload |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
61 (defvar type-break-good-rest-interval (/ type-break-interval 6) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
62 "*Number of seconds of idle time considered to be an adequate typing rest. |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
63 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
64 When this variable is non-`nil', emacs checks the idle time between |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
65 keystrokes. If this idle time is long enough to be considered a \"good\" |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
66 rest from typing, then the next typing break is simply rescheduled for later. |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
67 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
68 If a break is interrupted before this much time elapses, the user will be |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
69 asked whether or not really to interrupt the break.") |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
70 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
71 ;;;###autoload |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
72 (defvar type-break-keystroke-threshold |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
73 ;; Assuming typing speed is 35wpm (on the average, do you really |
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
74 ;; type more than that in a minute? I spend a lot of time reading mail |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
75 ;; and simply studying code in buffers) and average word length is |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
76 ;; about 5 letters, default upper threshold to the average number of |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
77 ;; keystrokes one is likely to type in a break interval. That way if the |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
78 ;; user goes through a furious burst of typing activity, cause a typing |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
79 ;; break to be required sooner than originally scheduled. |
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
80 ;; Conversely, the minimum threshold should be about a fifth of this. |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
81 (let* ((wpm 35) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
82 (avg-word-length 5) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
83 (upper (* wpm avg-word-length (/ type-break-interval 60))) |
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
84 (lower (/ upper 5))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
85 (cons lower upper)) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
86 "*Upper and lower bound on number of keystrokes for considering typing break. |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
87 This structure is a pair of numbers. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
88 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
89 The first number is the minimum number of keystrokes that must have been |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
90 entered since the last typing break before considering another one, even if |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
91 the scheduled time has elapsed; the break is simply rescheduled until later |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
92 if the minimum threshold hasn't been reached. If this first value is nil, |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
93 then there is no minimum threshold; as soon as the scheduled time has |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
94 elapsed, the user will always be queried. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
95 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
96 The second number is the maximum number of keystrokes that can be entered |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
97 before a typing break is requested immediately, pre-empting the originally |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
98 scheduled break. If this second value is nil, then no pre-emptive breaks |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
99 will occur; only scheduled ones will. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
100 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
101 Keys with bucky bits (shift, control, meta, etc) are counted as only one |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
102 keystroke even though they really require multiple keys to generate them.") |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
103 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
104 (defvar type-break-time-warning-intervals '(300 120 60 30) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
105 "*List of time intervals for warnings about upcoming typing break. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
106 At each of the intervals (specified in seconds) away from a scheduled |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
107 typing break, print a warning in the echo area.") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
108 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
109 (defvar type-break-keystroke-warning-intervals '(300 200 100 50) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
110 "*List of keystroke measurements for warnings about upcoming typing break. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
111 At each of the intervals (specified in keystrokes) away from the upper |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
112 keystroke threshold, print a warning in the echo area. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
113 If either this variable or the upper threshold is set, then no warnings |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
114 Will occur.") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
115 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
116 (defvar type-break-query-interval 60 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
117 "*Number of seconds between queries to take a break, if put off. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
118 The user will continue to be prompted at this interval until he or she |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
119 finally submits to taking a typing break.") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
120 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
121 (defvar type-break-warning-repeat 40 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
122 "*Number of keystrokes for which warnings should be repeated. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
123 That is, for each of this many keystrokes the warning is redisplayed |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
124 in the echo area to make sure it's really seen.") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
125 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
126 (defvar type-break-query-function 'yes-or-no-p |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
127 "Function to use for making query for a typing break. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
128 It should take a string as an argument, the prompt. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
129 Usually this should be set to `yes-or-no-p' or `y-or-n-p'.") |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
130 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
131 (defvar type-break-demo-functions |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
132 '(type-break-demo-boring type-break-demo-life type-break-demo-hanoi) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
133 "*List of functions to consider running as demos during typing breaks. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
134 When a typing break begins, one of these functions is selected randomly |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
135 to have emacs do something interesting. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
136 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
137 Any function in this list should start a demo which ceases as soon as a |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
138 key is pressed.") |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
139 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
140 (defvar type-break-post-command-hook nil |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
141 "Hook run indirectly by post-command-hook for typing break functions.") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
142 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
143 ;; These are internal variables. Do not set them yourself. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
144 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
145 (defvar type-break-alarm-p nil) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
146 (defvar type-break-keystroke-count 0) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
147 (defvar type-break-time-last-break nil) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
148 (defvar type-break-time-next-break nil) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
149 (defvar type-break-time-last-command (current-time)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
150 (defvar type-break-current-time-warning-interval nil) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
151 (defvar type-break-current-keystroke-warning-interval nil) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
152 (defvar type-break-time-warning-count 0) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
153 (defvar type-break-keystroke-warning-count 0) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
154 |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
155 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
156 ;;;###autoload |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
157 (defun type-break-mode (&optional prefix) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
158 "Enable or disable typing-break mode. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
159 This is a minor mode, but it is global to all buffers by default. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
160 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
161 When this mode is enabled, the user is encouraged to take typing breaks at |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
162 appropriate intervals; either after a specified amount of time or when the |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
163 user has exceeded a keystroke threshold. When the time arrives, the user |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
164 is asked to take a break. If the user refuses at that time, emacs will ask |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
165 again in a short period of time. The idea is to give the user enough time |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
166 to find a good breaking point in his or her work, but be sufficiently |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
167 annoying to discourage putting typing breaks off indefinitely. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
168 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
169 A negative prefix argument disables this mode. |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
170 No argument or any non-negative argument enables it. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
171 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
172 The user may enable or disable this mode by setting the variable of the |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
173 same name, though setting it in that way doesn't reschedule a break or |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
174 reset the keystroke counter. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
175 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
176 If the mode was previously disabled and is enabled as a consequence of |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
177 calling this function, it schedules a break with `type-break-schedule' to |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
178 make sure one occurs (the user can call that command to reschedule the |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
179 break at any time). It also initializes the keystroke counter. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
180 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
181 The variable `type-break-interval' specifies the number of seconds to |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
182 schedule between regular typing breaks. This variable doesn't directly |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
183 affect the time schedule; it simply provides a default for the |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
184 `type-break-schedule' command. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
185 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
186 If set, the variable `type-break-good-rest-interval' specifies the minimum |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
187 amount of time which is considered a reasonable typing break. Whenever |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
188 that time has elapsed, typing breaks are automatically rescheduled for |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
189 later even if emacs didn't prompt you to take one first. Also, if a break |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
190 is ended before this much time has elapsed, the user will be asked whether |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
191 or not to continue. |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
192 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
193 The variable `type-break-keystroke-threshold' is used to determine the |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
194 thresholds at which typing breaks should be considered. You can use |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
195 the command `type-break-guestimate-keystroke-threshold' to try to |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
196 approximate good values for this. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
197 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
198 Finally, the command `type-break-statistics' prints interesting things." |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
199 (interactive "P") |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
200 ;; make sure it's there. |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
201 (add-hook 'post-command-hook 'type-break-run-tb-post-command-hook 'append) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
202 (add-hook 'type-break-post-command-hook 'type-break-check) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
203 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
204 (let ((already-enabled type-break-mode)) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
205 (setq type-break-mode (>= (prefix-numeric-value prefix) 0)) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
206 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
207 (cond |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
208 ((and already-enabled type-break-mode) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
209 (and (interactive-p) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
210 (message "type-break-mode is enabled"))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
211 (type-break-mode |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
212 (type-break-keystroke-reset) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
213 (type-break-schedule) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
214 (and (interactive-p) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
215 (message "type-break-mode is enabled and reset"))) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
216 ((interactive-p) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
217 (message "type-break-mode is disabled")))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
218 type-break-mode) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
219 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
220 ;;;###autoload |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
221 (defun type-break () |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
222 "Take a typing break. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
223 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
224 During the break, a demo selected from the functions listed in |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
225 `type-break-demo-functions' is run. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
226 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
227 After the typing break is finished, the next break is scheduled |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
228 as per the function `type-break-schedule'." |
5939 | 229 (interactive) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
230 (type-break-cancel-schedule) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
231 (let ((continue t) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
232 (start-time (current-time))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
233 (setq type-break-time-last-break start-time) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
234 (while continue |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
235 (save-window-excursion |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
236 ;; Eat the screen. |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
237 (and (eq (selected-window) (minibuffer-window)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
238 (other-window 1)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
239 (delete-other-windows) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
240 (scroll-right (window-width)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
241 (message "Press any key to resume from typing break.") |
5939 | 242 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
243 (random t) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
244 (let* ((len (length type-break-demo-functions)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
245 (idx (random len)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
246 (fn (nth idx type-break-demo-functions))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
247 (condition-case () |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
248 (funcall fn) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
249 (error nil)))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
250 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
251 (cond |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
252 (type-break-good-rest-interval |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
253 (let ((break-secs (type-break-time-difference |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
254 start-time (current-time)))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
255 (cond |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
256 ((>= break-secs type-break-good-rest-interval) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
257 (setq continue nil)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
258 ;; Don't be pedantic; if user's rest was only a minute short, |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
259 ;; why bother? |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
260 ((> 60 (abs (- break-secs type-break-good-rest-interval))) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
261 (setq continue nil)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
262 ((funcall |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
263 type-break-query-function |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
264 (format "You really ought to rest %s more. Continue break? " |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
265 (type-break-format-time (- type-break-good-rest-interval |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
266 break-secs))))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
267 (t |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
268 (setq continue nil))))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
269 (t (setq continue nil))))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
270 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
271 (type-break-keystroke-reset) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
272 (type-break-schedule)) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
273 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
274 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
275 (defun type-break-schedule (&optional time) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
276 "Schedule a typing break for TIME seconds from now. |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
277 If time is not specified, default to `type-break-interval'." |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
278 (interactive (list (and current-prefix-arg |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
279 (prefix-numeric-value current-prefix-arg)))) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
280 (or time (setq time type-break-interval)) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
281 (type-break-cancel-schedule) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
282 (type-break-time-warning-schedule time 'reset) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
283 (run-at-time time nil 'type-break-alarm) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
284 (setq type-break-time-next-break |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
285 (type-break-time-sum (current-time) time))) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
286 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
287 (defun type-break-cancel-schedule () |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
288 (type-break-cancel-time-warning-schedule) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
289 (let ((timer-dont-exit t)) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
290 (cancel-function-timers 'type-break-alarm)) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
291 (setq type-break-alarm-p nil) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
292 (setq type-break-time-next-break nil)) |
5939 | 293 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
294 (defun type-break-time-warning-schedule (&optional time resetp) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
295 (let (type-break-current-time-warning-interval) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
296 (type-break-cancel-time-warning-schedule)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
297 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
298 (type-break-time-warning-intervals |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
299 (and resetp |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
300 (setq type-break-current-time-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
301 type-break-time-warning-intervals)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
302 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
303 (or time |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
304 (setq time (type-break-time-difference (current-time) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
305 type-break-time-next-break))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
306 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
307 (while (and type-break-current-time-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
308 (> (car type-break-current-time-warning-interval) time)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
309 (setq type-break-current-time-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
310 (cdr type-break-current-time-warning-interval))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
311 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
312 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
313 (type-break-current-time-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
314 (setq time (- time (car type-break-current-time-warning-interval))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
315 (setq type-break-current-time-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
316 (cdr type-break-current-time-warning-interval)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
317 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
318 (let (type-break-current-time-warning-interval) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
319 (type-break-cancel-time-warning-schedule)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
320 (run-at-time time nil 'type-break-time-warning-alarm)))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
321 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
322 (defun type-break-cancel-time-warning-schedule () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
323 (let ((timer-dont-exit t)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
324 (cancel-function-timers 'type-break-time-warning-alarm)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
325 (remove-hook 'type-break-post-command-hook 'type-break-time-warning) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
326 (setq type-break-current-time-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
327 type-break-time-warning-intervals)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
328 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
329 (defun type-break-alarm () |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
330 (setq type-break-alarm-p t)) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
331 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
332 (defun type-break-time-warning-alarm () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
333 (type-break-time-warning-schedule) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
334 (setq type-break-time-warning-count type-break-warning-repeat) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
335 (add-hook 'type-break-post-command-hook 'type-break-time-warning 'append)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
336 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
337 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
338 (defun type-break-run-tb-post-command-hook () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
339 (and type-break-mode |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
340 (run-hooks 'type-break-post-command-hook))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
341 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
342 (defun type-break-check () |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
343 "Ask to take a typing break if appropriate. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
344 This may be the case either because the scheduled time has come \(and the |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
345 minimum keystroke threshold has been reached\) or because the maximum |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
346 keystroke threshold has been exceeded." |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
347 (let* ((min-threshold (car type-break-keystroke-threshold)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
348 (max-threshold (cdr type-break-keystroke-threshold))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
349 (and type-break-good-rest-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
350 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
351 (and (> (type-break-time-difference |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
352 type-break-time-last-command (current-time)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
353 type-break-good-rest-interval) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
354 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
355 (type-break-keystroke-reset) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
356 (setq type-break-time-last-break (current-time)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
357 (type-break-schedule))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
358 (setq type-break-time-last-command (current-time)))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
359 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
360 (and type-break-keystroke-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
361 (setq type-break-keystroke-count |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
362 (+ type-break-keystroke-count (length (this-command-keys))))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
363 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
364 ;; This has been optimized for speed; calls to input-pending-p and |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
365 ;; checking for the minibuffer window are only done if it would |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
366 ;; matter for the sake of querying user. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
367 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
368 (type-break-alarm-p |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
369 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
370 ((input-pending-p)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
371 ((eq (selected-window) (minibuffer-window))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
372 ((and min-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
373 (< type-break-keystroke-count min-threshold)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
374 (type-break-schedule)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
375 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
376 ;; If keystroke count is within min-threshold of |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
377 ;; max-threshold, lower it to reduce the liklihood of an |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
378 ;; immediate subsequent query. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
379 (and max-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
380 min-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
381 (< (- max-threshold type-break-keystroke-count) min-threshold) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
382 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
383 (type-break-keystroke-reset) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
384 (setq type-break-keystroke-count min-threshold))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
385 (type-break-query)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
386 ((and type-break-keystroke-warning-intervals |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
387 max-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
388 (= type-break-keystroke-warning-count 0) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
389 (type-break-check-keystroke-warning))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
390 ((and max-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
391 (> type-break-keystroke-count max-threshold) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
392 (not (input-pending-p)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
393 (not (eq (selected-window) (minibuffer-window)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
394 (type-break-keystroke-reset) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
395 (setq type-break-keystroke-count (or min-threshold 0)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
396 (type-break-query))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
397 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
398 ;; This should return t if warnings were enabled, nil otherwise. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
399 (defsubst type-break-check-keystroke-warning () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
400 (let ((left (- (cdr type-break-keystroke-threshold) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
401 type-break-keystroke-count))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
402 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
403 ((null (car type-break-current-keystroke-warning-interval)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
404 nil) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
405 ((> left (car type-break-current-keystroke-warning-interval)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
406 nil) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
407 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
408 (while (and (car type-break-current-keystroke-warning-interval) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
409 (< left (car type-break-current-keystroke-warning-interval))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
410 (setq type-break-current-keystroke-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
411 (cdr type-break-current-keystroke-warning-interval))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
412 (setq type-break-keystroke-warning-count type-break-warning-repeat) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
413 (add-hook 'type-break-post-command-hook 'type-break-keystroke-warning) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
414 t)))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
415 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
416 (defun type-break-query () |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
417 (condition-case () |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
418 (cond |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
419 ((let ((type-break-mode nil)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
420 (funcall type-break-query-function "Take a break from typing now? ")) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
421 (type-break)) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
422 (t |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
423 (type-break-schedule type-break-query-interval))) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
424 (quit |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
425 (type-break-schedule type-break-query-interval)))) |
5939 | 426 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
427 (defun type-break-time-warning () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
428 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
429 ((and (car type-break-keystroke-threshold) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
430 (< type-break-keystroke-count (car type-break-keystroke-threshold)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
431 ((> type-break-time-warning-count 0) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
432 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
433 ((eq (selected-window) (minibuffer-window))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
434 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
435 ;; Pause for a moment so previous messages can be seen. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
436 (sit-for 2) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
437 (message "Warning: typing break due in %s." |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
438 (type-break-format-time |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
439 (type-break-time-difference (current-time) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
440 type-break-time-next-break))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
441 (setq type-break-time-warning-count |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
442 (1- type-break-time-warning-count))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
443 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
444 (remove-hook 'type-break-post-command-hook 'type-break-time-warning)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
445 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
446 (defun type-break-keystroke-warning () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
447 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
448 ((> type-break-keystroke-warning-count 0) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
449 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
450 ((eq (selected-window) (minibuffer-window))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
451 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
452 (sit-for 2) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
453 (message "Warning: typing break due in %s keystrokes." |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
454 (- (cdr type-break-keystroke-threshold) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
455 type-break-keystroke-count)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
456 (setq type-break-keystroke-warning-count |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
457 (1- type-break-keystroke-warning-count))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
458 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
459 (remove-hook 'type-break-post-command-hook |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
460 'type-break-keystroke-warning)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
461 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
462 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
463 ;;;###autoload |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
464 (defun type-break-statistics () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
465 "Print statistics about typing breaks in a temporary buffer. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
466 This includes the last time a typing break was taken, when the next one is |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
467 scheduled, the keystroke thresholds and the current keystroke count, etc." |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
468 (interactive) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
469 (with-output-to-temp-buffer "*Typing Break Statistics*" |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
470 (princ (format "Typing break statistics\n-----------------------\n |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
471 Last typing break : %s |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
472 Next scheduled typing break : %s\n |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
473 Minimum keystroke threshold : %s |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
474 Maximum keystroke threshold : %s |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
475 Current keystroke count : %s" |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
476 (if type-break-time-last-break |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
477 (current-time-string type-break-time-last-break) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
478 "never") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
479 (if (and type-break-mode type-break-time-next-break) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
480 (format "%s\t(%s from now)" |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
481 (current-time-string type-break-time-next-break) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
482 (type-break-format-time |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
483 (type-break-time-difference |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
484 (current-time) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
485 type-break-time-next-break))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
486 "none scheduled") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
487 (or (car type-break-keystroke-threshold) "none") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
488 (or (cdr type-break-keystroke-threshold) "none") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
489 type-break-keystroke-count)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
490 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
491 ;;;###autoload |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
492 (defun type-break-guestimate-keystroke-threshold (wpm &optional wordlen frac) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
493 "Guess values for the minimum/maximum keystroke threshold for typing breaks. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
494 If called interactively, the user is prompted for their guess as to how |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
495 many words per minute they usually type. From that, the command sets the |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
496 values in `type-break-keystroke-threshold' based on a fairly simple |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
497 algorithm involving assumptions about the average length of words (5). |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
498 For the minimum threshold, it uses about a quarter of the computed maximum |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
499 threshold. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
500 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
501 When called from lisp programs, the optional args WORDLEN and FRAC can be |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
502 used to override the default assumption about average word length and the |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
503 fraction of the maximum threshold to which to set the minimum threshold. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
504 FRAC should be the inverse of the fractional value; for example, a value of |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
505 2 would mean to use one half, a value of 4 would mean to use one quarter, etc." |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
506 (interactive "NHow many words per minute do you type? ") |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
507 (let* ((upper (* wpm (or wordlen 5) (/ type-break-interval 60))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
508 (lower (/ upper (or frac 5)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
509 (or type-break-keystroke-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
510 (setq type-break-keystroke-threshold (cons nil nil))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
511 (setcar type-break-keystroke-threshold lower) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
512 (setcdr type-break-keystroke-threshold upper) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
513 (if (interactive-p) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
514 (message "min threshold: %d\tmax threshold: %d" lower upper) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
515 type-break-keystroke-threshold))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
516 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
517 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
518 ;;; misc functions |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
519 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
520 ;; Compute the difference, in seconds, between a and b, two structures |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
521 ;; similar to those returned by `current-time'. |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
522 ;; Use addition rather than logand since that is more robust; the low 16 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
523 ;; bits of the seconds might have been incremented, making it more than 16 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
524 ;; bits wide. |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
525 (defsubst type-break-time-difference (a b) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
526 (+ (lsh (- (car b) (car a)) 16) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
527 (- (car (cdr b)) (car (cdr a))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
528 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
529 ;; Return (in a new list the same in structure to that returned by |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
530 ;; `current-time') the sum of the arguments. Each argument may be a time |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
531 ;; list or a single integer, a number of seconds. |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
532 ;; This function keeps the high and low 16 bits of the seconds properly |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
533 ;; balanced so that the lower value never exceeds 16 bits. Otherwise, when |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
534 ;; the result is passed to `current-time-string' it will toss some of the |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
535 ;; "low" bits and return the wrong value. |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
536 (defun type-break-time-sum (&rest tmlist) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
537 (let ((high 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
538 (low 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
539 (micro 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
540 tem) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
541 (while tmlist |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
542 (setq tem (car tmlist)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
543 (setq tmlist (cdr tmlist)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
544 (cond |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
545 ((numberp tem) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
546 (setq low (+ low tem))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
547 (t |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
548 (setq high (+ high (or (car tem) 0))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
549 (setq low (+ low (or (car (cdr tem)) 0))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
550 (setq micro (+ micro (or (car (cdr (cdr tem))) 0)))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
551 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
552 (and (>= micro 1000000) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
553 (progn |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
554 (setq tem (/ micro 1000000)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
555 (setq low (+ low tem)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
556 (setq micro (- micro (* tem 1000000))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
557 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
558 (setq tem (lsh low -16)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
559 (and (> tem 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
560 (progn |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
561 (setq low (logand low 65535)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
562 (setq high (+ high tem)))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
563 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
564 (list high low micro))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
565 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
566 (defsubst type-break-format-time (secs) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
567 (let ((mins (/ secs 60))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
568 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
569 ((= mins 1) (format "%d minute" mins)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
570 ((> mins 0) (format "%d minutes" mins)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
571 ((= secs 1) (format "%d second" secs)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
572 (t (format "%d seconds" secs))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
573 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
574 (defun type-break-keystroke-reset () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
575 (setq type-break-keystroke-count 0) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
576 (setq type-break-keystroke-warning-count 0) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
577 (setq type-break-current-keystroke-warning-interval |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
578 type-break-keystroke-warning-intervals) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
579 (remove-hook 'type-break-post-command-hook 'type-break-keystroke-warning)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
580 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
581 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
582 ;;; Demo wrappers |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
583 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
584 ;; This is a wrapper around hanoi that calls it with an arg large enough to |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
585 ;; make the largest discs possible that will fit in the window. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
586 ;; Also, clean up the *Hanoi* buffer after we're done. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
587 (defun type-break-demo-hanoi () |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
588 "Take a hanoiing typing break." |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
589 (and (get-buffer "*Hanoi*") |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
590 (kill-buffer "*Hanoi*")) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
591 (condition-case () |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
592 (progn |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
593 (hanoi (/ (window-width) 8)) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
594 ;; Wait for user to come back. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
595 (read-char) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
596 (kill-buffer "*Hanoi*")) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
597 (quit |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
598 ;; eat char |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
599 (read-char) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
600 (and (get-buffer "*Hanoi*") |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
601 (kill-buffer "*Hanoi*"))))) |
5939 | 602 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
603 ;; This is a wrapper around life that calls it with a `sleep' arg to make |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
604 ;; it run a little more leisurely. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
605 ;; Also, clean up the *Life* buffer after we're done. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
606 (defun type-break-demo-life () |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
607 "Take a typing break and get a life." |
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
608 (let ((continue t)) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
609 (while continue |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
610 (setq continue nil) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
611 (and (get-buffer "*Life*") |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
612 (kill-buffer "*Life*")) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
613 (condition-case () |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
614 (progn |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
615 (life 3) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
616 ;; wait for user to return |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
617 (read-char) |
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
618 (kill-buffer "*Life*")) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
619 (life-extinct |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
620 (message (get 'life-extinct 'error-message)) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
621 (sit-for 3) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
622 ;; restart demo |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
623 (setq continue t)) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
624 (quit |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
625 (and (get-buffer "*Life*") |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
626 (kill-buffer "*Life*"))))))) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
627 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
628 ;; Boring demo, but doesn't use many cycles |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
629 (defun type-break-demo-boring () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
630 "Boring typing break demo." |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
631 (let ((rmsg "Press any key to resume from typing break") |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
632 (buffer-name "*Typing Break Buffer*") |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
633 line col pos |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
634 elapsed timeleft tmsg) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
635 (condition-case () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
636 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
637 (switch-to-buffer (get-buffer-create buffer-name)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
638 (buffer-disable-undo (current-buffer)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
639 (erase-buffer) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
640 (setq line (1+ (/ (window-height) 2))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
641 (setq col (/ (- (window-width) (length rmsg)) 2)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
642 (insert (make-string line ?\C-j) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
643 (make-string col ?\ ) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
644 rmsg) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
645 (forward-line -1) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
646 (beginning-of-line) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
647 (setq pos (point)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
648 (while (not (input-pending-p)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
649 (delete-region pos (progn |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
650 (goto-char pos) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
651 (end-of-line) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
652 (point))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
653 (setq elapsed (type-break-time-difference |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
654 type-break-time-last-break |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
655 (current-time))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
656 (cond |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
657 (type-break-good-rest-interval |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
658 (setq timeleft (- type-break-good-rest-interval elapsed)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
659 (if (> timeleft 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
660 (setq tmsg (format "You should rest for %s more" |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
661 (type-break-format-time timeleft))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
662 (setq tmsg (format "Typing break has lasted %s" |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
663 (type-break-format-time elapsed))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
664 (t |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
665 (setq tmsg (format "Typing break has lasted %s" |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
666 (type-break-format-time elapsed))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
667 (setq col (/ (- (window-width) (length tmsg)) 2)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
668 (insert (make-string col ?\ ) tmsg) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
669 (goto-char (point-min)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
670 (sit-for 60)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
671 (read-char) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
672 (kill-buffer buffer-name)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
673 (quit |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
674 (and (get-buffer buffer-name) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
675 (kill-buffer buffer-name)))))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
676 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
677 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
678 (provide 'type-break) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
679 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
680 ;; Do not do this at load time because it makes it impossible to load this |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
681 ;; file into temacs and then dump it. |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
682 ;(type-break-mode t) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
683 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
684 ;; local variables: |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
685 ;; vc-make-backup-files: t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
686 ;; end: |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
687 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
688 ;;; type-break.el ends here |