Mercurial > emacs
annotate lisp/type-break.el @ 8954:c910dbca1355
(paths-force): Depend on src/paths.h
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 20 Sep 1994 22:16:26 +0000 |
parents | 3d566eab9870 |
children | 8ac258bc59ef |
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 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
3 ;;; Copyright (C) 1994 Noah S. Friedman |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
4 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
5 ;;; Author: Noah Friedman <friedman@prep.ai.mit.edu> |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
6 ;;; Maintainer: friedman@prep.ai.mit.edu |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
7 ;;; Keywords: extensions, timers |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
8 ;;; Status: known to work in GNU Emacs 19.25 or later. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
9 ;;; Created: 1994-07-13 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
10 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
11 ;;; LCD Archive Entry: |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
12 ;;; type-break|Noah Friedman|friedman@prep.ai.mit.edu| |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
13 ;;; encourage rests from typing at appropriate intervals| |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
14 ;;; $Date$|$Revision$|| |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
15 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
16 ;;; $Id$ |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
17 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
18 ;;; This program is free software; you can redistribute it and/or modify |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
19 ;;; it under the terms of the GNU General Public License as published by |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
20 ;;; the Free Software Foundation; either version 2, or (at your option) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
21 ;;; any later version. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
22 ;;; |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
23 ;;; This program is distributed in the hope that it will be useful, |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
24 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
25 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
26 ;;; GNU General Public License for more details. |
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 ;;; You should have received a copy of the GNU General Public License |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
29 ;;; along with this program; if not, you can either send email to this |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
30 ;;; program's maintainer or write to: The Free Software Foundation, |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
31 ;;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
32 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
33 ;;; Commentary: |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
34 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
35 ;;; 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
|
36 ;;; details of the interface. |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
37 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
38 ;;; 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
|
39 ;;; 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
|
40 ;;; 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
|
41 ;;; 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
|
42 ;;; 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
|
43 ;;; interval tracking. |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
44 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
45 ;;; 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
|
46 ;;; 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
|
47 ;;; <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
|
48 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
49 ;;; Code: |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
50 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
51 |
5939 | 52 (require 'timer) |
53 | |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
54 ;; 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
|
55 ;; will cause scheduling and so forth to happen. |
5939 | 56 ;;;###autoload |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
57 (defvar type-break-mode nil |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
58 "*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
|
59 See the docstring for the `type-break-mode' command for more information.") |
5939 | 60 |
61 ;;;###autoload | |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
62 (defvar type-break-interval (* 60 60) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
63 "*Number of seconds between scheduled typing breaks.") |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
64 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
65 ;;;###autoload |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
66 (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
|
67 "*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
|
68 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
73 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
|
74 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
|
75 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
76 ;;;###autoload |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
77 (defvar type-break-keystroke-threshold |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
78 ;; 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
|
79 ;; 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
|
80 ;; 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
|
81 ;; 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
|
82 ;; 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
|
83 ;; 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
|
84 ;; 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
|
85 ;; 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
|
86 (let* ((wpm 35) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
87 (avg-word-length 5) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
88 (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
|
89 (lower (/ upper 5))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
90 (cons lower upper)) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
91 "*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
|
92 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
|
93 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 will occur; only scheduled ones will. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
105 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
106 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
|
107 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
|
108 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
109 (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
|
110 "*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
|
111 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
|
112 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
|
113 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
114 (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
|
115 "*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
|
116 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
|
117 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
|
118 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
|
119 Will occur.") |
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-query-interval 60 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
122 "*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
|
123 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
|
124 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
|
125 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
126 (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
|
127 "*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
|
128 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
|
129 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
|
130 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
131 (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
|
132 "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
|
133 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
|
134 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
|
135 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
136 (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
|
137 '(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
|
138 "*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
|
139 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
|
140 to have emacs do something interesting. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
141 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
142 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
|
143 key is pressed.") |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
144 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
145 (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
|
146 "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
|
147 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
148 ;; 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
|
149 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
150 (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
|
151 (defvar type-break-keystroke-count 0) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
152 (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
|
153 (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
|
154 (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
|
155 (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
|
156 (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
|
157 (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
|
158 (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
|
159 |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
160 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
161 ;;;###autoload |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
162 (defun type-break-mode (&optional prefix) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
163 "Enable or disable typing-break mode. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
164 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
|
165 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
174 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
|
175 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
|
176 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
177 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
|
178 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
|
179 reset the keystroke counter. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
180 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 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
|
185 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 `type-break-schedule' command. |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
190 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 or not to continue. |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
197 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 approximate good values for this. |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
202 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
203 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
|
204 (interactive "P") |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
205 ;; 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
|
206 (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
|
207 (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
|
208 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
209 (let ((already-enabled type-break-mode)) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
210 (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
|
211 |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
212 (cond |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
213 ((and already-enabled type-break-mode) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
214 (and (interactive-p) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
215 (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
|
216 (type-break-mode |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
217 (type-break-keystroke-reset) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
218 (type-break-schedule) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
219 (and (interactive-p) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
220 (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
|
221 ((interactive-p) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
222 (message "type-break-mode is disabled")))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
223 type-break-mode) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
224 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
225 ;;;###autoload |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
226 (defun type-break () |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
227 "Take a typing break. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
228 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
229 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
|
230 `type-break-demo-functions' is run. |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
231 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
232 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
|
233 as per the function `type-break-schedule'." |
5939 | 234 (interactive) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
235 (type-break-cancel-schedule) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
236 (let ((continue t) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
237 (start-time (current-time))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
238 (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
|
239 (while continue |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
240 (save-window-excursion |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
241 ;; Eat the screen. |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
242 (and (eq (selected-window) (minibuffer-window)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
243 (other-window 1)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
244 (delete-other-windows) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
245 (scroll-right (window-width)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
246 (message "Press any key to resume from typing break.") |
5939 | 247 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
248 (random t) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
249 (let* ((len (length type-break-demo-functions)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
250 (idx (random len)) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
251 (fn (nth idx type-break-demo-functions))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
252 (condition-case () |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
253 (funcall fn) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
254 (error nil)))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
255 |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
256 (cond |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
257 (type-break-good-rest-interval |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
258 (let ((break-secs (type-break-time-difference |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
259 start-time (current-time)))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
260 (cond |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
261 ((>= break-secs type-break-good-rest-interval) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
262 (setq continue nil)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
263 ;; 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
|
264 ;; why bother? |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
265 ((> 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
|
266 (setq continue nil)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
267 ((funcall |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
268 type-break-query-function |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
269 (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
|
270 (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
|
271 break-secs))))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
272 (t |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
273 (setq continue nil))))) |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
274 (t (setq continue nil))))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
275 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
276 (type-break-keystroke-reset) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
277 (type-break-schedule)) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
278 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
279 |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
280 (defun type-break-schedule (&optional time) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
281 "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
|
282 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
|
283 (interactive (list (and current-prefix-arg |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
284 (prefix-numeric-value current-prefix-arg)))) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
285 (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
|
286 (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
|
287 (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
|
288 (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
|
289 (setq type-break-time-next-break |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
290 (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
|
291 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
292 (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
|
293 (type-break-cancel-time-warning-schedule) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
294 (let ((timer-dont-exit t)) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
295 (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
|
296 (setq type-break-alarm-p nil) |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
297 (setq type-break-time-next-break nil)) |
5939 | 298 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
299 (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
|
300 (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
|
301 (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
|
302 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
303 (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
|
304 (and resetp |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
305 (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
|
306 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
|
307 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
308 (or time |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
309 (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
|
310 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
|
311 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
312 (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
|
313 (> (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
|
314 (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
|
315 (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
|
316 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
317 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
318 (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 (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
|
320 (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
|
321 (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
|
322 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
323 (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
|
324 (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
|
325 (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
|
326 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
327 (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
|
328 (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
|
329 (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
|
330 (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
|
331 (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
|
332 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
|
333 |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
334 (defun type-break-alarm () |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
335 (setq type-break-alarm-p t)) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
336 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
337 (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
|
338 (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
|
339 (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
|
340 (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
|
341 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
342 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
343 (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
|
344 (and type-break-mode |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
345 (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
|
346 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
347 (defun type-break-check () |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
348 "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
|
349 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
|
350 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
|
351 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
|
352 (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
|
353 (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
|
354 (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
|
355 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
356 (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
|
357 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
|
358 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
|
359 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
360 (type-break-keystroke-reset) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
361 (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
|
362 (type-break-schedule))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
363 (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
|
364 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
365 (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
|
366 (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
|
367 (+ 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
|
368 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
369 ;; 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
|
370 ;; 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
|
371 ;; 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
|
372 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
373 (type-break-alarm-p |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
374 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
375 ((input-pending-p)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
376 ((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
|
377 ((and min-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
378 (< 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
|
379 (type-break-schedule)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
380 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
381 ;; 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
|
382 ;; 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
|
383 ;; immediate subsequent query. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
384 (and max-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
385 min-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
386 (< (- 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
|
387 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
388 (type-break-keystroke-reset) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
389 (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
|
390 (type-break-query)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
391 ((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
|
392 max-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
393 (= 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
|
394 (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
|
395 ((and max-threshold |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
396 (> 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
|
397 (not (input-pending-p)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
398 (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
|
399 (type-break-keystroke-reset) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
400 (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
|
401 (type-break-query))))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
402 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
403 ;; 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
|
404 (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
|
405 (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
|
406 type-break-keystroke-count))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
407 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
408 ((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
|
409 nil) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
410 ((> 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
|
411 nil) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
412 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
413 (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
|
414 (< 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
|
415 (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
|
416 (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
|
417 (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
|
418 (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
|
419 t)))) |
8275
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
420 |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
421 (defun type-break-query () |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
422 (condition-case () |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
423 (cond |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
424 ((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
|
425 (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
|
426 (type-break)) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
427 (t |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
428 (type-break-schedule type-break-query-interval))) |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
429 (quit |
4fdf77f4e45c
type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents:
8248
diff
changeset
|
430 (type-break-schedule type-break-query-interval)))) |
5939 | 431 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
432 (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
|
433 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
434 ((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
|
435 (< 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
|
436 ((> 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
|
437 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
438 ((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
|
439 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
440 ;; 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
|
441 (sit-for 2) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
442 (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
|
443 (type-break-format-time |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
444 (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
|
445 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
|
446 (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
|
447 (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
|
448 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
449 (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
|
450 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
451 (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
|
452 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
453 ((> 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
|
454 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
455 ((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
|
456 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
457 (sit-for 2) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
458 (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
|
459 (- (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
|
460 type-break-keystroke-count)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
461 (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
|
462 (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
|
463 (t |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
464 (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
|
465 'type-break-keystroke-warning)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
466 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
467 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
468 ;;;###autoload |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
469 (defun type-break-statistics () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
470 "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
|
471 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
|
472 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
|
473 (interactive) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
474 (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
|
475 (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
|
476 Last typing break : %s |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
477 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
|
478 Minimum keystroke threshold : %s |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
479 Maximum keystroke threshold : %s |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
480 Current keystroke count : %s" |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
481 (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
|
482 (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
|
483 "never") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
484 (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
|
485 (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
|
486 (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
|
487 (type-break-format-time |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
488 (type-break-time-difference |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
489 (current-time) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
490 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
|
491 "none scheduled") |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
492 (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
|
493 (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
|
494 type-break-keystroke-count)))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
495 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
496 ;;;###autoload |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
497 (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
|
498 "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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 threshold. |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
505 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 (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
|
512 (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
|
513 (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
|
514 (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
|
515 (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
|
516 (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
|
517 (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
|
518 (if (interactive-p) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
519 (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
|
520 type-break-keystroke-threshold))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
521 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
522 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
523 ;;; misc functions |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
524 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
525 ;; 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
|
526 ;; similar to those returned by `current-time'. |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
527 ;; 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
|
528 ;; 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
|
529 ;; bits wide. |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
530 (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
|
531 (+ (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
|
532 (- (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
|
533 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
534 ;; 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
|
535 ;; `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
|
536 ;; 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
|
537 ;; 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
|
538 ;; 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
|
539 ;; 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
|
540 ;; "low" bits and return the wrong value. |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
541 (defun type-break-time-sum (&rest tmlist) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
542 (let ((high 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
543 (low 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
544 (micro 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
545 tem) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
546 (while tmlist |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
547 (setq tem (car tmlist)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
548 (setq tmlist (cdr tmlist)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
549 (cond |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
550 ((numberp tem) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
551 (setq low (+ low tem))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
552 (t |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
553 (setq high (+ high (or (car tem) 0))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
554 (setq low (+ low (or (car (cdr tem)) 0))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
555 (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
|
556 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
557 (and (>= micro 1000000) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
558 (progn |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
559 (setq tem (/ micro 1000000)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
560 (setq low (+ low tem)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
561 (setq micro (- micro (* tem 1000000))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
562 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
563 (setq tem (lsh low -16)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
564 (and (> tem 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
565 (progn |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
566 (setq low (logand low 65535)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
567 (setq high (+ high tem)))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
568 |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
569 (list high low micro))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
570 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
571 (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
|
572 (let ((mins (/ secs 60))) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
573 (cond |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
574 ((= 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
|
575 ((> 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
|
576 ((= 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
|
577 (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
|
578 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
579 (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
|
580 (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
|
581 (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
|
582 (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
|
583 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
|
584 (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
|
585 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
586 |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
587 ;;; Demo wrappers |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
588 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
589 ;; 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
|
590 ;; 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
|
591 ;; 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
|
592 (defun type-break-demo-hanoi () |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
593 "Take a hanoiing typing break." |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
594 (and (get-buffer "*Hanoi*") |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
595 (kill-buffer "*Hanoi*")) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
596 (condition-case () |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
597 (progn |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
598 (hanoi (/ (window-width) 8)) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
599 ;; Wait for user to come back. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
600 (read-char) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
601 (kill-buffer "*Hanoi*")) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
602 (quit |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
603 ;; eat char |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
604 (read-char) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
605 (and (get-buffer "*Hanoi*") |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
606 (kill-buffer "*Hanoi*"))))) |
5939 | 607 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
608 ;; 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
|
609 ;; it run a little more leisurely. |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
610 ;; 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
|
611 (defun type-break-demo-life () |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
612 "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
|
613 (let ((continue t)) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
614 (while continue |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
615 (setq continue nil) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
616 (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
|
617 (kill-buffer "*Life*")) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
618 (condition-case () |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
619 (progn |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
620 (life 3) |
8304
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
621 ;; wait for user to return |
6c34e249d217
type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents:
8282
diff
changeset
|
622 (read-char) |
8282
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
623 (kill-buffer "*Life*")) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
624 (life-extinct |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
625 (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
|
626 (sit-for 3) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
627 ;; restart demo |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
628 (setq continue t)) |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
629 (quit |
206451cdd48a
type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents:
8281
diff
changeset
|
630 (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
|
631 (kill-buffer "*Life*"))))))) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
632 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
633 ;; 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
|
634 (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
|
635 "Boring typing break demo." |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
636 (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
|
637 (buffer-name "*Typing Break Buffer*") |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
638 line col pos |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
639 elapsed timeleft tmsg) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
640 (condition-case () |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
641 (progn |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
642 (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
|
643 (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
|
644 (erase-buffer) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
645 (setq line (1+ (/ (window-height) 2))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
646 (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
|
647 (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
|
648 (make-string col ?\ ) |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
649 rmsg) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
650 (forward-line -1) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
651 (beginning-of-line) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
652 (setq pos (point)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
653 (while (not (input-pending-p)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
654 (delete-region pos (progn |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
655 (goto-char pos) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
656 (end-of-line) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
657 (point))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
658 (setq elapsed (type-break-time-difference |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
659 type-break-time-last-break |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
660 (current-time))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
661 (cond |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
662 (type-break-good-rest-interval |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
663 (setq timeleft (- type-break-good-rest-interval elapsed)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
664 (if (> timeleft 0) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
665 (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
|
666 (type-break-format-time timeleft))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
667 (setq tmsg (format "Typing break has lasted %s" |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
668 (type-break-format-time elapsed))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
669 (t |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
670 (setq tmsg (format "Typing break has lasted %s" |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
671 (type-break-format-time elapsed))))) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
672 (setq col (/ (- (window-width) (length tmsg)) 2)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
673 (insert (make-string col ?\ ) tmsg) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
674 (goto-char (point-min)) |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
675 (sit-for 60)) |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
676 (read-char) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
677 (kill-buffer buffer-name)) |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
678 (quit |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
679 (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
|
680 (kill-buffer buffer-name)))))) |
8276
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
681 |
73b85998c868
type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents:
8275
diff
changeset
|
682 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
683 (provide 'type-break) |
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
684 |
8497
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
685 ;; 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
|
686 ;; file into temacs and then dump it. |
3d566eab9870
type-break-time-sum: New function.
Noah Friedman <friedman@splode.com>
parents:
8370
diff
changeset
|
687 ;(type-break-mode t) |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
688 |
8370
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
689 ;; local variables: |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
690 ;; 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
|
691 ;; end: |
97cacab659d3
type-break-time-warning-intervals, type-break-keystroke-warning-intervals,
Noah Friedman <friedman@splode.com>
parents:
8305
diff
changeset
|
692 |
8248
5ecef3b02f2d
Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents:
5939
diff
changeset
|
693 ;;; type-break.el ends here |