comparison lisp/type-break.el @ 8282:206451cdd48a

type-break-keystroke-threshold: Change default wpm to 30 and lower threshold to 1/5, rather than 1/4, of upper. type-break-guestimate-keystroke-threshold: Change threshold fraction here too. type-break-demo-life: Restart when all life perishes.
author Noah Friedman <friedman@splode.com>
date Tue, 19 Jul 1994 04:41:50 +0000
parents e41f372e0ea3
children 6c34e249d217
comparison
equal deleted inserted replaced
8281:e41f372e0ea3 8282:206451cdd48a
42 ;;; least, you will want to turn off the keystroke thresholds and rest 42 ;;; least, you will want to turn off the keystroke thresholds and rest
43 ;;; interval tracking. 43 ;;; interval tracking.
44 44
45 ;;; Setting type-break-good-rest-interval makes emacs cons like a maniac 45 ;;; Setting type-break-good-rest-interval makes emacs cons like a maniac
46 ;;; because of repeated calls to `current-time'. There's not really any 46 ;;; because of repeated calls to `current-time'. There's not really any
47 ;;; good way to avoid this without disabling the variable. 47 ;;; good way to avoid this without disabling the variable. In fact, this
48 ;;; package makes emacs somewhat cycle intensive because a small amount of
49 ;;; extra lisp code gets evaluated on every keystroke anyway. But what's
50 ;;; more important, a few computer cycles or reducing your risk of
51 ;;; repetitive strain injury?
48 52
49 ;;; This package was inspired by Roland McGrath's hanoi-break.el. 53 ;;; This package was inspired by Roland McGrath's hanoi-break.el.
50 54
51 ;;; Code: 55 ;;; Code:
52 56
81 The user will continue to be prompted at this interval until he or she 85 The user will continue to be prompted at this interval until he or she
82 finally submits to taking a typing break.") 86 finally submits to taking a typing break.")
83 87
84 ;;;###autoload 88 ;;;###autoload
85 (defvar type-break-keystroke-threshold 89 (defvar type-break-keystroke-threshold
86 ;; Assuming average typing speed is 45wpm and the average word length is 90 ;; Assuming typing speed is 30wpm (on the average, do you really
91 ;; type more than that in a minute? I spend a lot of time reading mail
92 ;; and simply studying code in buffers) and average word length is
87 ;; about 5 letters, default upper threshold to the average number of 93 ;; about 5 letters, default upper threshold to the average number of
88 ;; keystrokes one is likely to type in a break interval. That way if the 94 ;; keystrokes one is likely to type in a break interval. That way if the
89 ;; user goes through a furious burst of typing activity, cause a typing 95 ;; user goes through a furious burst of typing activity, cause a typing
90 ;; break to be required sooner than originally scheduled. 96 ;; break to be required sooner than originally scheduled.
91 ;; Conversely, the minimum threshold should be about a quarter of this. 97 ;; Conversely, the minimum threshold should be about a fifth of this.
92 (let* ((wpm 45) 98 (let* ((wpm 30)
93 (avg-word-length 5) 99 (avg-word-length 5)
94 (upper (* wpm avg-word-length (/ type-break-interval 60))) 100 (upper (* wpm avg-word-length (/ type-break-interval 60)))
95 (lower (/ upper 4))) 101 (lower (/ upper 5)))
96 (cons lower upper)) 102 (cons lower upper))
97 "*Upper and lower bound on number of keystrokes for considering typing break. 103 "*Upper and lower bound on number of keystrokes for considering typing break.
98 This structure is a pair of numbers. 104 This structure is a pair of numbers.
99 105
100 The first number is the minimum number of keystrokes that must have been 106 The first number is the minimum number of keystrokes that must have been
385 ;; This is a wrapper around life that calls it with a `sleep' arg to make 391 ;; This is a wrapper around life that calls it with a `sleep' arg to make
386 ;; it run a little more leisurely. 392 ;; it run a little more leisurely.
387 ;; Also, clean up the *Life* buffer after we're done. 393 ;; Also, clean up the *Life* buffer after we're done.
388 (defun type-break-demo-life () 394 (defun type-break-demo-life ()
389 "Take a typing break and get a life." 395 "Take a typing break and get a life."
390 (and (get-buffer "*Life*") 396 (let ((continue t))
391 (kill-buffer "*Life*")) 397 (while continue
392 (condition-case () 398 (setq continue nil)
393 (progn 399 (and (get-buffer "*Life*")
394 (life 3) 400 (kill-buffer "*Life*"))
395 ;; Wait for user to come back. 401 (condition-case ()
396 (read-char) 402 (progn
397 (kill-buffer "*Life*")) 403 (life 3)
398 (quit 404 (kill-buffer "*Life*"))
399 (and (get-buffer "*Life*") 405 (life-extinct
400 (kill-buffer "*Life*"))))) 406 (message (get 'life-extinct 'error-message))
407 (sit-for 3)
408 ;; restart demo
409 (setq continue t))
410 (quit
411 (and (get-buffer "*Life*")
412 (kill-buffer "*Life*")))))))
401 413
402 414
403 ;;;###autoload 415 ;;;###autoload
404 (defun type-break-statistics () 416 (defun type-break-statistics ()
405 "Print statistics about typing breaks in a temporary buffer. 417 "Print statistics about typing breaks in a temporary buffer.
446 fraction of the maximum threshold to which to set the minimum threshold. 458 fraction of the maximum threshold to which to set the minimum threshold.
447 FRAC should be the inverse of the fractional value; for example, a value of 459 FRAC should be the inverse of the fractional value; for example, a value of
448 2 would mean to use one half, a value of 4 would mean to use one quarter, etc." 460 2 would mean to use one half, a value of 4 would mean to use one quarter, etc."
449 (interactive "nHow many words per minute do you type? ") 461 (interactive "nHow many words per minute do you type? ")
450 (let* ((upper (* wpm (or wordlen 5) (/ type-break-interval 60))) 462 (let* ((upper (* wpm (or wordlen 5) (/ type-break-interval 60)))
451 (lower (/ upper (or frac 4)))) 463 (lower (/ upper (or frac 5))))
452 (or type-break-keystroke-threshold 464 (or type-break-keystroke-threshold
453 (setq type-break-keystroke-threshold (cons nil nil))) 465 (setq type-break-keystroke-threshold (cons nil nil)))
454 (setcar type-break-keystroke-threshold lower) 466 (setcar type-break-keystroke-threshold lower)
455 (setcdr type-break-keystroke-threshold upper) 467 (setcdr type-break-keystroke-threshold upper)
456 (if (interactive-p) 468 (if (interactive-p)