annotate lisp/type-break.el @ 8313:589abdc989e1

(add-log-current-defun): Skip doc string correctly even if it ends with line that starts space.
author Richard M. Stallman <rms@gnu.org>
date Sun, 24 Jul 1994 02:50:50 +0000
parents d7bb8587fdf0
children 97cacab659d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
1 ;;; type-break.el --- encourage rests from typing at appropriate intervals
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
2
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 ;;; Setting type-break-good-rest-interval makes emacs cons like a maniac
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
46 ;;; because of repeated calls to `current-time'. There's not really any
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
47 ;;; good way to avoid this without disabling the variable. In fact, this
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
48 ;;; package makes emacs somewhat cycle intensive because a small amount of
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
49 ;;; extra lisp code gets evaluated on every keystroke anyway. But what's
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
50 ;;; more important, a few computer cycles or reducing your risk of
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
51 ;;; repetitive strain injury?
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
52
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
53 ;;; This package was inspired by Roland McGrath's hanoi-break.el.
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
54 ;;; Thanks to Mark Ashton <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
55
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
56 ;;; Code:
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
57
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
58
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
59 (require 'timer)
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
60
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
61 ;; 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
62 ;; will cause scheduling and so forth to happen.
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
63 ;;;###autoload
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
64 (defvar type-break-mode nil
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
65 "*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
66 See the docstring for the `type-break-mode' command for more information.")
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
67
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
68 ;;;###autoload
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
69 (defvar type-break-interval (* 60 60)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
70 "*Number of seconds between scheduled typing breaks.")
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
71
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
72 ;;;###autoload
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
73 (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
74 "*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
75
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
76 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
77 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
78 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
79
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
80 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
81 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
82
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
83 ;;;###autoload
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
84 (defvar type-break-query-interval 60
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
85 "*Number of seconds between queries to take a break, if put off.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
86 The user will continue to be prompted at this interval until he or she
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
87 finally submits to taking a typing break.")
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
88
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
89 ;;;###autoload
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
90 (defvar type-break-keystroke-threshold
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
91 ;; 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
92 ;; 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
93 ;; 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
94 ;; 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
95 ;; 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
96 ;; 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
97 ;; 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
98 ;; 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
99 (let* ((wpm 35)
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
100 (avg-word-length 5)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
101 (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
102 (lower (/ upper 5)))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
103 (cons lower upper))
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
104 "*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
105 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
106
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
107 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
108 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
109 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
110 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
111 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
112 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
113
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
114 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
115 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
116 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
117 will occur; only scheduled ones will.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
118
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
119 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
120 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
121
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
122 ;;;###autoload
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
123 (defvar type-break-query-function 'yes-or-no-p
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
124 "*Function to use for making query for a typing break.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
125 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
126 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
127
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
128 (defvar type-break-demo-functions
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
129 '(type-break-demo-life type-break-demo-hanoi)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
130 "*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
131 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
132 to have emacs do something interesting.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
133
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
134 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
135 key is pressed.")
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
136
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
137 ;; 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
138
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
139 (defvar type-break-alarm-p nil) ; Non-nil when a scheduled typing break is due.
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
140 (defvar type-break-keystroke-count 0)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
141 (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
142 (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
143 (defvar type-break-time-last-command (current-time))
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
144
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
145
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
146 ;; Compute the difference, in seconds, between a and b, two structures
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
147 ;; similar to those returned by `current-time'.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
148 ;; Use addition rather than logand since I found it convenient to add
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
149 ;; seconds to the cdr of some of my stored time values, which may throw off
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
150 ;; the number of bits in the cdr.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
151 (defsubst type-break-time-difference (a b)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
152 (abs (+ (lsh (- (car b) (car a)) 16)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
153 (- (car (cdr b)) (car (cdr a))))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
154
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
155 (defsubst type-break-format-time (secs)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
156 (let ((mins (/ secs 60)))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
157 (cond
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
158 ((> mins 0)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
159 (format "%d minutes" mins))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
160 (t
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
161 (format "%d seconds" secs)))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
162
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
163
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
164 ;;;###autoload
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
165 (defun type-break-mode (&optional prefix)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
166 "Enable or disable typing-break mode.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
167 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
168
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
177 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
178 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
179
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
180 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
181 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
182 reset the keystroke counter.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
183
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
184 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
185 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
186 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
187 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
188
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
189 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
190 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
191 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
192 `type-break-schedule' command.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
193
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
194 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
195 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
196 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
197 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
198 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
199 or not to continue.
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
200
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
201 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
202 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
203 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
204 approximate good values for this.
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
205
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
206 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
207 (interactive "P")
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
208 ;; make sure it's there.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
209 (add-hook 'post-command-hook 'type-break-check 'append)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
210
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
211 (let ((already-enabled type-break-mode))
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
212 (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
213
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
214 (cond
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
215 ((and already-enabled type-break-mode)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
216 (and (interactive-p)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
217 (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
218 (type-break-mode
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
219 (setq type-break-keystroke-count 0)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
220 (type-break-schedule)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
221 (and (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 enabled and reset")))
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
223 ((interactive-p)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
224 (message "type-break-mode is disabled"))))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
225 type-break-mode)
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
226
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
227 ;;;###autoload
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
228 (defun type-break ()
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
229 "Take a typing break.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
230
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
231 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
232 `type-break-demo-functions' is run.
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
233
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
234 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
235 as per the function `type-break-schedule'."
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
236 (interactive)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
237 (let ((continue t)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
238 (start-time (current-time)))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
239 (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
240 (while continue
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
241 (save-window-excursion
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
242 ;; Eat the screen.
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
243 (and (eq (selected-window) (minibuffer-window))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
244 (other-window 1))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
245 (delete-other-windows)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
246 (scroll-right (window-width))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
247 (message "Press any key to resume from typing break.")
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
248
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
249 (random t)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
250 (let* ((len (length type-break-demo-functions))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
251 (idx (random len))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
252 (fn (nth idx type-break-demo-functions)))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
253 (condition-case ()
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
254 (funcall fn)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
255 (error nil))))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
256
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
257 (cond
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
258 (type-break-good-rest-interval
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
259 (let ((break-secs (type-break-time-difference
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
260 start-time (current-time))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
261 (cond
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
262 ((>= break-secs type-break-good-rest-interval)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
263 (setq continue nil))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
264 ;; Don't be pedantic; if user's rest was only a minute or two
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
265 ;; short, why bother?
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
266 ((> 120 (abs (- break-secs type-break-good-rest-interval)))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
267 (setq continue nil))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
268 ((funcall
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
269 type-break-query-function
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
270 (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
271 (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
272 break-secs)))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
273 (t
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
274 (setq continue nil)))))
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
275 (t (setq continue nil)))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
277 (setq type-break-keystroke-count 0)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
278 (type-break-schedule))
8248
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
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
281 (defun type-break-schedule (&optional time)
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
282 "Schedule a typing break for TIME seconds from now.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
283 If time is not specified, default to `type-break-interval'."
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
284 (interactive (list (and current-prefix-arg
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
285 (prefix-numeric-value current-prefix-arg))))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
286 (or time (setq time type-break-interval))
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
287 ;; Remove any old scheduled break
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
288 (type-break-cancel-schedule)
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
289 (run-at-time time nil 'type-break-alarm)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
290
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
291 (setq type-break-time-next-break (current-time))
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
292 (setcar (cdr type-break-time-next-break)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
293 (+ time (car (cdr type-break-time-next-break)))))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
294
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
295 (defun type-break-cancel-schedule ()
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
296 "Cancel scheduled typing breaks.
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
297 This does not prevent queries for typing breaks when the keystroke
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
298 threshold has been reached; to turn off typing breaks altogether, turn off
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
299 type-break-mode."
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
300 (interactive)
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
301 (let ((timer-dont-exit t))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
302 (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
303 (setq type-break-alarm-p nil)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
304 (setq type-break-time-next-break nil))
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
305
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
306 (defun type-break-alarm ()
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
307 "This function is run when a scheduled typing break is due."
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
308 (setq type-break-alarm-p t))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
309
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
310 (defun type-break-check ()
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
311 "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
312 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
313 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
314 keystroke threshold has been exceeded."
8305
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
315 (and type-break-mode
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
316 (let* ((min-threshold (car type-break-keystroke-threshold))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
317 (max-threshold (cdr type-break-keystroke-threshold)))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
318 (and type-break-good-rest-interval
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
319 (progn
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
320 (and (> (type-break-time-difference
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
321 type-break-time-last-command (current-time))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
322 type-break-good-rest-interval)
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
323 (progn
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
324 (setq type-break-keystroke-count 0)
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
325 (setq type-break-time-last-break (current-time))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
326 (type-break-schedule)))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
327 (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
328
8305
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
329 (and type-break-keystroke-threshold
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
330 (setq type-break-keystroke-count
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
331 (+ 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
332
8305
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
333 ;; This has been optimized for speed; calls to input-pending-p and
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
334 ;; checking for the minibuffer window are only done if it would
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
335 ;; matter for the sake of querying user.
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
336 (cond
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
337 (type-break-alarm-p
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
338 (cond
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
339 ((input-pending-p))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
340 ((eq (selected-window) (minibuffer-window)))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
341 ((and min-threshold
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
342 (< type-break-keystroke-count min-threshold))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
343 (type-break-schedule))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
344 (t
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
345 ;; If keystroke count is within min-threshold of
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
346 ;; max-threshold, lower it to reduce the liklihood of an
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
347 ;; immediate subsequent query.
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
348 (and max-threshold
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
349 min-threshold
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
350 (< (- max-threshold type-break-keystroke-count) min-threshold)
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
351 (setq type-break-keystroke-count min-threshold))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
352 (type-break-query))))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
353 ((and max-threshold
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
354 (> type-break-keystroke-count max-threshold)
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
355 (not (input-pending-p))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
356 (not (eq (selected-window) (minibuffer-window))))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
357 (setq type-break-keystroke-count (or min-threshold 0))
d7bb8587fdf0 type-break-schedule: Remove autoload cookie.
Noah Friedman <friedman@splode.com>
parents: 8304
diff changeset
358 (type-break-query))))))
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
359
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
360 (defun type-break-query ()
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
361 (condition-case ()
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
362 (cond
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
363 ((funcall type-break-query-function "Take a break from typing now? ")
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
364 (type-break))
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
365 (t
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
366 (type-break-schedule type-break-query-interval)))
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
367 (quit
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
368 (type-break-schedule type-break-query-interval))))
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
369
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
370
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
371 ;; 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
372 ;; 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
373 ;; 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
374 (defun type-break-demo-hanoi ()
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
375 "Take a hanoiing typing break."
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
376 (and (get-buffer "*Hanoi*")
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
377 (kill-buffer "*Hanoi*"))
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
378 (condition-case ()
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
379 (progn
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
380 (hanoi (/ (window-width) 8))
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
381 ;; Wait for user to come back.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
382 (read-char)
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
383 (kill-buffer "*Hanoi*"))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
384 (quit
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
385 ;; eat char
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
386 (read-char)
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
387 (and (get-buffer "*Hanoi*")
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
388 (kill-buffer "*Hanoi*")))))
5939
454dc146502d Initial revision
Roland McGrath <roland@gnu.org>
parents:
diff changeset
389
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
390 ;; 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
391 ;; it run a little more leisurely.
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
392 ;; 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
393 (defun type-break-demo-life ()
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
394 "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
395 (let ((continue t))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
396 (while continue
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
397 (setq continue nil)
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
398 (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
399 (kill-buffer "*Life*"))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
400 (condition-case ()
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
401 (progn
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
402 (life 3)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
403 ;; wait for user to return
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
404 (read-char)
8282
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
405 (kill-buffer "*Life*"))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
406 (life-extinct
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
407 (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
408 (sit-for 3)
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
409 ;; restart demo
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
410 (setq continue t))
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
411 (quit
206451cdd48a type-break-keystroke-threshold: Change default wpm to 30 and lower
Noah Friedman <friedman@splode.com>
parents: 8281
diff changeset
412 (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
413 (kill-buffer "*Life*")))))))
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
414
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
415
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
416 ;;;###autoload
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
417 (defun type-break-statistics ()
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
418 "Print statistics about typing breaks in a temporary buffer.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
419 This includes the last time a typing break was taken, when the next one is
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
420 scheduled, the keystroke thresholds and the current keystroke count, etc."
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
421 (interactive)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
422 (with-output-to-temp-buffer "*Typing Break Statistics*"
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
423 (princ (format "Typing break statistics\n-----------------------\n
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
424 Last typing break : %s
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
425 Next scheduled typing break : %s\n
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
426 Minimum keystroke threshold : %s
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
427 Maximum keystroke threshold : %s
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
428 Current keystroke count : %s"
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
429 (if type-break-time-last-break
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
430 (current-time-string type-break-time-last-break)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
431 "never")
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
432 (if (and type-break-mode type-break-time-next-break)
8281
e41f372e0ea3 type-break-check: Shrink keystroke count if it is less than min-threshold
Noah Friedman <friedman@splode.com>
parents: 8276
diff changeset
433 (format "%s\t(%s from now)"
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
434 (current-time-string type-break-time-next-break)
8304
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
435 (type-break-format-time
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
436 (type-break-time-difference
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
437 (current-time)
6c34e249d217 type-break-good-rest-interval: Doc fix.
Noah Friedman <friedman@splode.com>
parents: 8282
diff changeset
438 type-break-time-next-break)))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
439 "none scheduled")
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
440 (or (car type-break-keystroke-threshold) "none")
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
441 (or (cdr type-break-keystroke-threshold) "none")
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
442 type-break-keystroke-count))))
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
443
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
444 ;;;###autoload
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
445 (defun type-break-guestimate-keystroke-threshold (wpm &optional wordlen frac)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
446 "Guess values for the minimum/maximum keystroke threshold for typing breaks.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
447 If called interactively, the user is prompted for their guess as to how
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
448 many words per minute they usually type. From that, the command sets the
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
449 values in `type-break-keystroke-threshold' based on a fairly simple
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
450 algorithm involving assumptions about the average length of words (5).
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
451 For the minimum threshold, it uses about a quarter of the computed maximum
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
452 threshold.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
453
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
454 When called from lisp programs, the optional args WORDLEN and FRAC can be
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
455 used to override the default assumption about average word length and the
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
456 fraction of the maximum threshold to which to set the minimum threshold.
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
457 FRAC should be the inverse of the fractional value; for example, a value of
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
458 2 would mean to use one half, a value of 4 would mean to use one quarter, etc."
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
459 (interactive "nHow many words per minute do you type? ")
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
460 (let* ((upper (* wpm (or wordlen 5) (/ 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
461 (lower (/ upper (or frac 5))))
8276
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
462 (or type-break-keystroke-threshold
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
463 (setq type-break-keystroke-threshold (cons nil nil)))
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
464 (setcar type-break-keystroke-threshold lower)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
465 (setcdr type-break-keystroke-threshold upper)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
466 (if (interactive-p)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
467 (message "min threshold: %d\tmax threshold: %d" lower upper)
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
468 type-break-keystroke-threshold)))
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
469
73b85998c868 type-break-mode: Make variable `nil' by default.
Noah Friedman <friedman@splode.com>
parents: 8275
diff changeset
470
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
471 (provide 'type-break)
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
472
8275
4fdf77f4e45c type-break-mode: New variable and function.
Noah Friedman <friedman@splode.com>
parents: 8248
diff changeset
473 (type-break-mode t)
8248
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
474
5ecef3b02f2d Real initial revision. (rewrite from hanoi-break.)
Noah Friedman <friedman@splode.com>
parents: 5939
diff changeset
475 ;;; type-break.el ends here