mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-12 16:23:57 +00:00
type-break-good-rest-interval: Doc fix.
type-break-keystroke-threshold: Calcuate based on 35wpm, not 30. type-break-demo-function-vector: Variable deleted. type-break-demo-functions: New variable. type-break: Use new variable. type-break-time-difference: Return absolute value. type-break-format-time: New inline function (defsubst). type-break-statistics, type-break: Use it. type-break-mode: Just test prefix-numeric-value >= 0 to to enable mode. The only visible difference is that invocation with no prefix arg the same as if given positive numeric prefix arg now. Do not document type-break-query-interval or type-break-query-function here; make fritterware-happy users read the source. type-break: If type break is much less (at least 2 minutes) than a "good rest interval", ask user whether or not to continue with the break. type-break-check: Do nothing if user is in the minibuffer. When alarm is signaled but min threshold isn't reached, reschedule break. type-break-demo-life: Eat char entered to end life demo.
This commit is contained in:
parent
fcbadd58ad
commit
cc669dd810
@ -51,6 +51,7 @@
|
|||||||
;;; repetitive strain injury?
|
;;; repetitive strain injury?
|
||||||
|
|
||||||
;;; This package was inspired by Roland McGrath's hanoi-break.el.
|
;;; This package was inspired by Roland McGrath's hanoi-break.el.
|
||||||
|
;;; Thanks to Mark Ashton <mpashton@gnu.ai.mit.edu> for feedback and ideas.
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
@ -73,11 +74,11 @@ See the docstring for the `type-break-mode' command for more information.")
|
|||||||
"*Number of seconds of idle time considered to be an adequate typing rest.
|
"*Number of seconds of idle time considered to be an adequate typing rest.
|
||||||
|
|
||||||
When this variable is non-`nil', emacs checks the idle time between
|
When this variable is non-`nil', emacs checks the idle time between
|
||||||
keystrokes. If this idle time is long enough to be considered a "good"
|
keystrokes. If this idle time is long enough to be considered a \"good\"
|
||||||
rest from typing, then the next typing break is simply rescheduled for later.
|
rest from typing, then the next typing break is simply rescheduled for later.
|
||||||
|
|
||||||
The user will also be admonished if a forced break isn't at least as long
|
If a break is interrupted before this much time elapses, the user will be
|
||||||
as this time, to remind them to rest longer next time.")
|
asked whether or not really to interrupt the break.")
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defvar type-break-query-interval 60
|
(defvar type-break-query-interval 60
|
||||||
@ -87,7 +88,7 @@ finally submits to taking a typing break.")
|
|||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defvar type-break-keystroke-threshold
|
(defvar type-break-keystroke-threshold
|
||||||
;; Assuming typing speed is 30wpm (on the average, do you really
|
;; Assuming typing speed is 35wpm (on the average, do you really
|
||||||
;; type more than that in a minute? I spend a lot of time reading mail
|
;; type more than that in a minute? I spend a lot of time reading mail
|
||||||
;; and simply studying code in buffers) and average word length is
|
;; and simply studying code in buffers) and average word length is
|
||||||
;; about 5 letters, default upper threshold to the average number of
|
;; about 5 letters, default upper threshold to the average number of
|
||||||
@ -95,7 +96,7 @@ finally submits to taking a typing break.")
|
|||||||
;; user goes through a furious burst of typing activity, cause a typing
|
;; user goes through a furious burst of typing activity, cause a typing
|
||||||
;; break to be required sooner than originally scheduled.
|
;; break to be required sooner than originally scheduled.
|
||||||
;; Conversely, the minimum threshold should be about a fifth of this.
|
;; Conversely, the minimum threshold should be about a fifth of this.
|
||||||
(let* ((wpm 30)
|
(let* ((wpm 35)
|
||||||
(avg-word-length 5)
|
(avg-word-length 5)
|
||||||
(upper (* wpm avg-word-length (/ type-break-interval 60)))
|
(upper (* wpm avg-word-length (/ type-break-interval 60)))
|
||||||
(lower (/ upper 5)))
|
(lower (/ upper 5)))
|
||||||
@ -124,22 +125,19 @@ keystroke even though they really require multiple keys to generate them.")
|
|||||||
It should take a string as an argument, the prompt.
|
It should take a string as an argument, the prompt.
|
||||||
Usually this should be set to `yes-or-no-p' or `y-or-n-p'.")
|
Usually this should be set to `yes-or-no-p' or `y-or-n-p'.")
|
||||||
|
|
||||||
(defvar type-break-demo-function-vector
|
(defvar type-break-demo-functions
|
||||||
[type-break-demo-life type-break-demo-hanoi]
|
'(type-break-demo-life type-break-demo-hanoi)
|
||||||
"*Vector consisting of functions to run as demos during typing breaks.
|
"*List of functions to consider running as demos during typing breaks.
|
||||||
When a typing break begins, one of these functions is selected randomly
|
When a typing break begins, one of these functions is selected randomly
|
||||||
to have emacs do something interesting.
|
to have emacs do something interesting.
|
||||||
|
|
||||||
Any function in this vector should start a demo which ceases as soon as a
|
Any function in this list should start a demo which ceases as soon as a
|
||||||
key is pressed.")
|
key is pressed.")
|
||||||
|
|
||||||
;; These are internal variables. Do not set them yourself.
|
;; These are internal variables. Do not set them yourself.
|
||||||
|
|
||||||
;; Non-nil when a scheduled typing break is due.
|
(defvar type-break-alarm-p nil) ; Non-nil when a scheduled typing break is due.
|
||||||
(defvar type-break-alarm-p nil)
|
|
||||||
|
|
||||||
(defvar type-break-keystroke-count 0)
|
(defvar type-break-keystroke-count 0)
|
||||||
|
|
||||||
(defvar type-break-time-last-break nil)
|
(defvar type-break-time-last-break nil)
|
||||||
(defvar type-break-time-next-break nil)
|
(defvar type-break-time-next-break nil)
|
||||||
(defvar type-break-time-last-command (current-time))
|
(defvar type-break-time-last-command (current-time))
|
||||||
@ -151,9 +149,18 @@ key is pressed.")
|
|||||||
;; seconds to the cdr of some of my stored time values, which may throw off
|
;; seconds to the cdr of some of my stored time values, which may throw off
|
||||||
;; the number of bits in the cdr.
|
;; the number of bits in the cdr.
|
||||||
(defsubst type-break-time-difference (a b)
|
(defsubst type-break-time-difference (a b)
|
||||||
(+ (lsh (- (car b) (car a)) 16)
|
(abs (+ (lsh (- (car b) (car a)) 16)
|
||||||
(- (car (cdr b)) (car (cdr a)))))
|
(- (car (cdr b)) (car (cdr a))))))
|
||||||
|
|
||||||
|
(defsubst type-break-format-time (secs)
|
||||||
|
(let ((mins (/ secs 60)))
|
||||||
|
(cond
|
||||||
|
((> mins 0)
|
||||||
|
(format "%d minutes" mins))
|
||||||
|
(t
|
||||||
|
(format "%d seconds" secs)))))
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun type-break-mode (&optional prefix)
|
(defun type-break-mode (&optional prefix)
|
||||||
"Enable or disable typing-break mode.
|
"Enable or disable typing-break mode.
|
||||||
@ -167,9 +174,8 @@ again in a short period of time. The idea is to give the user enough time
|
|||||||
to find a good breaking point in his or her work, but be sufficiently
|
to find a good breaking point in his or her work, but be sufficiently
|
||||||
annoying to discourage putting typing breaks off indefinitely.
|
annoying to discourage putting typing breaks off indefinitely.
|
||||||
|
|
||||||
Calling this command with no prefix argument toggles this mode.
|
|
||||||
A negative prefix argument disables this mode.
|
A negative prefix argument disables this mode.
|
||||||
A non-negative prefix argument or any other non-`nil' argument enables it.
|
No argument or any non-negative argument enables it.
|
||||||
|
|
||||||
The user may enable or disable this mode by setting the variable of the
|
The user may enable or disable this mode by setting the variable of the
|
||||||
same name, though setting it in that way doesn't reschedule a break or
|
same name, though setting it in that way doesn't reschedule a break or
|
||||||
@ -185,44 +191,30 @@ schedule between regular typing breaks. This variable doesn't directly
|
|||||||
affect the time schedule; it simply provides a default for the
|
affect the time schedule; it simply provides a default for the
|
||||||
`type-break-schedule' command.
|
`type-break-schedule' command.
|
||||||
|
|
||||||
The variable `type-break-query-interval' specifies the number of seconds to
|
If set, the variable `type-break-good-rest-interval' specifies the minimum
|
||||||
schedule between repeated queries for breaks when the user answers \"no\"
|
amount of time which is considered a reasonable typing break. Whenever
|
||||||
to the previous query.
|
that time has elapsed, typing breaks are automatically rescheduled for
|
||||||
|
later even if emacs didn't prompt you to take one first. Also, if a break
|
||||||
The variable `type-break-good-rest-interval' specifies the minimum amount
|
is ended before this much time has elapsed, the user will be asked whether
|
||||||
of time which is considered a reasonable typing break. Whenever that time
|
or not to continue.
|
||||||
has elapsed, typing breaks are automatically rescheduled for later even if
|
|
||||||
emacs didn't prompt you to take one first. You can disable this behavior.
|
|
||||||
|
|
||||||
The variable `type-break-keystroke-threshold' is used to determine the
|
The variable `type-break-keystroke-threshold' is used to determine the
|
||||||
thresholds at which typing breaks should be considered. You can use
|
thresholds at which typing breaks should be considered. You can use
|
||||||
the command `type-break-guestimate-keystroke-threshold' to try to
|
the command `type-break-guestimate-keystroke-threshold' to try to
|
||||||
approximate good values for this.
|
approximate good values for this.
|
||||||
|
|
||||||
The variable `type-break-query-function' should contain a function (or the
|
|
||||||
symbolic name of a function) to be used to query the user for typing
|
|
||||||
breaks.
|
|
||||||
|
|
||||||
Finally, the command `type-break-statistics' prints interesting things."
|
Finally, the command `type-break-statistics' prints interesting things."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
;; make sure it's there.
|
;; make sure it's there.
|
||||||
(add-hook 'post-command-hook 'type-break-check 'append)
|
(add-hook 'post-command-hook 'type-break-check 'append)
|
||||||
|
|
||||||
(let ((already-enabled type-break-mode))
|
(let ((already-enabled type-break-mode))
|
||||||
(cond
|
(setq type-break-mode (>= (prefix-numeric-value prefix) 0))
|
||||||
((null prefix)
|
|
||||||
(setq type-break-mode (not type-break-mode)))
|
|
||||||
((numberp (prefix-numeric-value prefix))
|
|
||||||
(setq type-break-mode (>= (prefix-numeric-value prefix) 0)))
|
|
||||||
(prefix
|
|
||||||
(setq type-break-mode t))
|
|
||||||
(t
|
|
||||||
(setq type-break-mode nil)))
|
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
((and already-enabled type-break-mode)
|
((and already-enabled type-break-mode)
|
||||||
(and (interactive-p)
|
(and (interactive-p)
|
||||||
(message "type-break-mode was already enabled")))
|
(message "type-break-mode is enabled")))
|
||||||
(type-break-mode
|
(type-break-mode
|
||||||
(setq type-break-keystroke-count 0)
|
(setq type-break-keystroke-count 0)
|
||||||
(type-break-schedule)
|
(type-break-schedule)
|
||||||
@ -237,34 +229,50 @@ Finally, the command `type-break-statistics' prints interesting things."
|
|||||||
"Take a typing break.
|
"Take a typing break.
|
||||||
|
|
||||||
During the break, a demo selected from the functions listed in
|
During the break, a demo selected from the functions listed in
|
||||||
`type-break-demo-function-vector' is run.
|
`type-break-demo-functions' is run.
|
||||||
|
|
||||||
After the typing break is finished, the next break is scheduled
|
After the typing break is finished, the next break is scheduled
|
||||||
as per the function `type-break-schedule', and the keystroke counter is
|
as per the function `type-break-schedule'."
|
||||||
reset."
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(setq type-break-time-last-break (current-time))
|
(let ((continue t)
|
||||||
(save-window-excursion
|
(start-time (current-time)))
|
||||||
;; Eat the screen.
|
(setq type-break-time-last-break start-time)
|
||||||
(and (eq (selected-window) (minibuffer-window))
|
(while continue
|
||||||
(other-window 1))
|
(save-window-excursion
|
||||||
(delete-other-windows)
|
;; Eat the screen.
|
||||||
(scroll-right (window-width))
|
(and (eq (selected-window) (minibuffer-window))
|
||||||
(message "Press any key to resume from typing break.")
|
(other-window 1))
|
||||||
|
(delete-other-windows)
|
||||||
|
(scroll-right (window-width))
|
||||||
|
(message "Press any key to resume from typing break.")
|
||||||
|
|
||||||
(random t)
|
(random t)
|
||||||
(let* ((len (length type-break-demo-function-vector))
|
(let* ((len (length type-break-demo-functions))
|
||||||
(idx (random len))
|
(idx (random len))
|
||||||
(fn (aref type-break-demo-function-vector idx)))
|
(fn (nth idx type-break-demo-functions)))
|
||||||
(condition-case ()
|
(condition-case ()
|
||||||
(funcall fn)
|
(funcall fn)
|
||||||
(error nil))))
|
(error nil))))
|
||||||
|
|
||||||
(and type-break-good-rest-interval
|
(cond
|
||||||
(< (type-break-time-difference type-break-time-last-command
|
(type-break-good-rest-interval
|
||||||
(current-time))
|
(let ((break-secs (type-break-time-difference
|
||||||
type-break-good-rest-interval)
|
start-time (current-time))))
|
||||||
(message "That typing break wasn't really long enough. Rest more next time."))
|
(cond
|
||||||
|
((>= break-secs type-break-good-rest-interval)
|
||||||
|
(setq continue nil))
|
||||||
|
;; Don't be pedantic; if user's rest was only a minute or two
|
||||||
|
;; short, why bother?
|
||||||
|
((> 120 (abs (- break-secs type-break-good-rest-interval)))
|
||||||
|
(setq continue nil))
|
||||||
|
((funcall
|
||||||
|
type-break-query-function
|
||||||
|
(format "You really ought to rest %s more. Continue break? "
|
||||||
|
(type-break-format-time (- type-break-good-rest-interval
|
||||||
|
break-secs)))))
|
||||||
|
(t
|
||||||
|
(setq continue nil)))))
|
||||||
|
(t (setq continue nil)))))
|
||||||
|
|
||||||
(setq type-break-keystroke-count 0)
|
(setq type-break-keystroke-count 0)
|
||||||
(type-break-schedule))
|
(type-break-schedule))
|
||||||
@ -321,6 +329,7 @@ keystroke threshold has been exceeded."
|
|||||||
type-break-good-rest-interval)
|
type-break-good-rest-interval)
|
||||||
(progn
|
(progn
|
||||||
(setq type-break-keystroke-count 0)
|
(setq type-break-keystroke-count 0)
|
||||||
|
(setq type-break-time-last-break (current-time))
|
||||||
(type-break-schedule)))
|
(type-break-schedule)))
|
||||||
(setq type-break-time-last-command (current-time))))
|
(setq type-break-time-last-command (current-time))))
|
||||||
|
|
||||||
@ -330,10 +339,12 @@ keystroke threshold has been exceeded."
|
|||||||
|
|
||||||
(cond
|
(cond
|
||||||
((input-pending-p))
|
((input-pending-p))
|
||||||
|
((eq (selected-window) (minibuffer-window)))
|
||||||
(type-break-alarm-p
|
(type-break-alarm-p
|
||||||
(cond
|
(cond
|
||||||
((and min-threshold
|
((and min-threshold
|
||||||
(< type-break-keystroke-count min-threshold)))
|
(< type-break-keystroke-count min-threshold))
|
||||||
|
(type-break-schedule))
|
||||||
(t
|
(t
|
||||||
;; If the keystroke count is within min-threshold characters of
|
;; If the keystroke count is within min-threshold characters of
|
||||||
;; the maximum threshold, set the count to min-threshold. That
|
;; the maximum threshold, set the count to min-threshold. That
|
||||||
@ -401,6 +412,8 @@ keystroke threshold has been exceeded."
|
|||||||
(condition-case ()
|
(condition-case ()
|
||||||
(progn
|
(progn
|
||||||
(life 3)
|
(life 3)
|
||||||
|
;; wait for user to return
|
||||||
|
(read-char)
|
||||||
(kill-buffer "*Life*"))
|
(kill-buffer "*Life*"))
|
||||||
(life-extinct
|
(life-extinct
|
||||||
(message (get 'life-extinct 'error-message))
|
(message (get 'life-extinct 'error-message))
|
||||||
@ -431,13 +444,10 @@ Current keystroke count : %s"
|
|||||||
(if (and type-break-mode type-break-time-next-break)
|
(if (and type-break-mode type-break-time-next-break)
|
||||||
(format "%s\t(%s from now)"
|
(format "%s\t(%s from now)"
|
||||||
(current-time-string type-break-time-next-break)
|
(current-time-string type-break-time-next-break)
|
||||||
(let* ((secs (type-break-time-difference
|
(type-break-format-time
|
||||||
(current-time)
|
(type-break-time-difference
|
||||||
type-break-time-next-break))
|
(current-time)
|
||||||
(mins (/ secs 60)))
|
type-break-time-next-break)))
|
||||||
(if (> mins 0)
|
|
||||||
(format "%d minutes" mins)
|
|
||||||
(format "%d seconds" secs))))
|
|
||||||
"none scheduled")
|
"none scheduled")
|
||||||
(or (car type-break-keystroke-threshold) "none")
|
(or (car type-break-keystroke-threshold) "none")
|
||||||
(or (cdr type-break-keystroke-threshold) "none")
|
(or (cdr type-break-keystroke-threshold) "none")
|
||||||
|
Loading…
Reference in New Issue
Block a user