aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoah Friedman1994-08-09 21:21:28 +0000
committerNoah Friedman1994-08-09 21:21:28 +0000
commitdefa73468e78485a4f4c90f22693dd6458d8053e (patch)
tree0267a292bfce1c4753472ba964b1483c49a8405f
parent9fa6ed8fd4a589cef49163aaf7c3dc581ca05e10 (diff)
downloademacs-defa73468e78485a4f4c90f22693dd6458d8053e.tar.gz
emacs-defa73468e78485a4f4c90f22693dd6458d8053e.zip
type-break-time-sum: New function.
type-break-schedule: Use it. Make interactive again. type-break-guestimate-keystroke-threshold: Use `N' interactive spec, not `n'. type-break-demo-boring: Show elapsed time of break, or number of minutes left for good break. (top level): Do not call type-break-mode.
-rw-r--r--lisp/type-break.el100
1 files changed, 84 insertions, 16 deletions
diff --git a/lisp/type-break.el b/lisp/type-break.el
index 38717856ec0..e839bc3a923 100644
--- a/lisp/type-break.el
+++ b/lisp/type-break.el
@@ -147,7 +147,7 @@ key is pressed.")
147 147
148;; These are internal variables. Do not set them yourself. 148;; These are internal variables. Do not set them yourself.
149 149
150(defvar type-break-alarm-p nil) ; Non-nil when a scheduled typing break is due. 150(defvar type-break-alarm-p nil)
151(defvar type-break-keystroke-count 0) 151(defvar type-break-keystroke-count 0)
152(defvar type-break-time-last-break nil) 152(defvar type-break-time-last-break nil)
153(defvar type-break-time-next-break nil) 153(defvar type-break-time-next-break nil)
@@ -278,13 +278,16 @@ as per the function `type-break-schedule'."
278 278
279 279
280(defun type-break-schedule (&optional time) 280(defun type-break-schedule (&optional time)
281 "Schedule a typing break for TIME seconds from now.
282If time is not specified, default to `type-break-interval'."
283 (interactive (list (and current-prefix-arg
284 (prefix-numeric-value current-prefix-arg))))
281 (or time (setq time type-break-interval)) 285 (or time (setq time type-break-interval))
282 (type-break-cancel-schedule) 286 (type-break-cancel-schedule)
283 (type-break-time-warning-schedule time 'reset) 287 (type-break-time-warning-schedule time 'reset)
284 (run-at-time time nil 'type-break-alarm) 288 (run-at-time time nil 'type-break-alarm)
285 (setq type-break-time-next-break (current-time)) 289 (setq type-break-time-next-break
286 (setcar (cdr type-break-time-next-break) 290 (type-break-time-sum (current-time) time)))
287 (+ time (car (cdr type-break-time-next-break)))))
288 291
289(defun type-break-cancel-schedule () 292(defun type-break-cancel-schedule ()
290 (type-break-cancel-time-warning-schedule) 293 (type-break-cancel-time-warning-schedule)
@@ -505,7 +508,7 @@ used to override the default assumption about average word length and the
505fraction of the maximum threshold to which to set the minimum threshold. 508fraction of the maximum threshold to which to set the minimum threshold.
506FRAC should be the inverse of the fractional value; for example, a value of 509FRAC should be the inverse of the fractional value; for example, a value of
5072 would mean to use one half, a value of 4 would mean to use one quarter, etc." 5102 would mean to use one half, a value of 4 would mean to use one quarter, etc."
508 (interactive "nHow many words per minute do you type? ") 511 (interactive "NHow many words per minute do you type? ")
509 (let* ((upper (* wpm (or wordlen 5) (/ type-break-interval 60))) 512 (let* ((upper (* wpm (or wordlen 5) (/ type-break-interval 60)))
510 (lower (/ upper (or frac 5)))) 513 (lower (/ upper (or frac 5))))
511 (or type-break-keystroke-threshold 514 (or type-break-keystroke-threshold
@@ -521,13 +524,50 @@ FRAC should be the inverse of the fractional value; for example, a value of
521 524
522;; Compute the difference, in seconds, between a and b, two structures 525;; Compute the difference, in seconds, between a and b, two structures
523;; similar to those returned by `current-time'. 526;; similar to those returned by `current-time'.
524;; Use addition rather than logand since I found it convenient to add 527;; Use addition rather than logand since that is more robust; the low 16
525;; seconds to the cdr of some of my stored time values, which may throw off 528;; bits of the seconds might have been incremented, making it more than 16
526;; the number of bits in the cdr. 529;; bits wide.
527(defsubst type-break-time-difference (a b) 530(defsubst type-break-time-difference (a b)
528 (+ (lsh (- (car b) (car a)) 16) 531 (+ (lsh (- (car b) (car a)) 16)
529 (- (car (cdr b)) (car (cdr a))))) 532 (- (car (cdr b)) (car (cdr a)))))
530 533
534;; Return (in a new list the same in structure to that returned by
535;; `current-time') the sum of the arguments. Each argument may be a time
536;; list or a single integer, a number of seconds.
537;; This function keeps the high and low 16 bits of the seconds properly
538;; balanced so that the lower value never exceeds 16 bits. Otherwise, when
539;; the result is passed to `current-time-string' it will toss some of the
540;; "low" bits and return the wrong value.
541(defun type-break-time-sum (&rest tmlist)
542 (let ((high 0)
543 (low 0)
544 (micro 0)
545 tem)
546 (while tmlist
547 (setq tem (car tmlist))
548 (setq tmlist (cdr tmlist))
549 (cond
550 ((numberp tem)
551 (setq low (+ low tem)))
552 (t
553 (setq high (+ high (or (car tem) 0)))
554 (setq low (+ low (or (car (cdr tem)) 0)))
555 (setq micro (+ micro (or (car (cdr (cdr tem))) 0))))))
556
557 (and (>= micro 1000000)
558 (progn
559 (setq tem (/ micro 1000000))
560 (setq low (+ low tem))
561 (setq micro (- micro (* tem 1000000)))))
562
563 (setq tem (lsh low -16))
564 (and (> tem 0)
565 (progn
566 (setq low (logand low 65535))
567 (setq high (+ high tem))))
568
569 (list high low micro)))
570
531(defsubst type-break-format-time (secs) 571(defsubst type-break-format-time (secs)
532 (let ((mins (/ secs 60))) 572 (let ((mins (/ secs 60)))
533 (cond 573 (cond
@@ -590,23 +630,49 @@ FRAC should be the inverse of the fractional value; for example, a value of
590 (and (get-buffer "*Life*") 630 (and (get-buffer "*Life*")
591 (kill-buffer "*Life*"))))))) 631 (kill-buffer "*Life*")))))))
592 632
593;; Boring demo, but doesn't use any cycles 633;; Boring demo, but doesn't use many cycles
594(defun type-break-demo-boring () 634(defun type-break-demo-boring ()
595 "Boring typing break demo." 635 "Boring typing break demo."
596 (let ((msg "Press any key to resume from typing break") 636 (let ((rmsg "Press any key to resume from typing break")
597 (buffer-name "*Typing Break Buffer*") 637 (buffer-name "*Typing Break Buffer*")
598 line col) 638 line col pos
639 elapsed timeleft tmsg)
599 (condition-case () 640 (condition-case ()
600 (progn 641 (progn
601 (switch-to-buffer (get-buffer-create buffer-name)) 642 (switch-to-buffer (get-buffer-create buffer-name))
602 (buffer-disable-undo (current-buffer)) 643 (buffer-disable-undo (current-buffer))
603 (erase-buffer) 644 (erase-buffer)
604 (setq line (/ (window-height) 2)) 645 (setq line (1+ (/ (window-height) 2)))
605 (setq col (/ (- (window-width) (length msg)) 2)) 646 (setq col (/ (- (window-width) (length rmsg)) 2))
606 (insert (make-string line ?\C-j) 647 (insert (make-string line ?\C-j)
607 (make-string col ?\ ) 648 (make-string col ?\ )
608 msg) 649 rmsg)
609 (goto-char (point-min)) 650 (forward-line -1)
651 (beginning-of-line)
652 (setq pos (point))
653 (while (not (input-pending-p))
654 (delete-region pos (progn
655 (goto-char pos)
656 (end-of-line)
657 (point)))
658 (setq elapsed (type-break-time-difference
659 type-break-time-last-break
660 (current-time)))
661 (cond
662 (type-break-good-rest-interval
663 (setq timeleft (- type-break-good-rest-interval elapsed))
664 (if (> timeleft 0)
665 (setq tmsg (format "You should rest for %s more"
666 (type-break-format-time timeleft)))
667 (setq tmsg (format "Typing break has lasted %s"
668 (type-break-format-time elapsed)))))
669 (t
670 (setq tmsg (format "Typing break has lasted %s"
671 (type-break-format-time elapsed)))))
672 (setq col (/ (- (window-width) (length tmsg)) 2))
673 (insert (make-string col ?\ ) tmsg)
674 (goto-char (point-min))
675 (sit-for 60))
610 (read-char) 676 (read-char)
611 (kill-buffer buffer-name)) 677 (kill-buffer buffer-name))
612 (quit 678 (quit
@@ -616,7 +682,9 @@ FRAC should be the inverse of the fractional value; for example, a value of
616 682
617(provide 'type-break) 683(provide 'type-break)
618 684
619(type-break-mode t) 685;; Do not do this at load time because it makes it impossible to load this
686;; file into temacs and then dump it.
687;(type-break-mode t)
620 688
621;; local variables: 689;; local variables:
622;; vc-make-backup-files: t 690;; vc-make-backup-files: t