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