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