comparison lisp/type-break.el @ 30391:246b2f521192

(type-break): perform autosave. Suggested by Stephen Gildea <gildea@intouchsys.com>. (type-break-do-query): Cancel query schedule while performing actual query, to avoid possibility of a second query being made while first one is already in progress. (type-break-time-stamp-format): New variable. (type-break-time-stamp): New function. (type-break-time-warning): Use it. (type-break-keystroke-warning): Use it. (type-break-noninteractive-query): Use it.
author Noah Friedman <friedman@splode.com>
date Mon, 24 Jul 2000 00:49:09 +0000
parents cbe304a26771
children a877c0e4875a
comparison
equal deleted inserted replaced
30390:91ee387fb19e 30391:246b2f521192
1 ;;; type-break.el --- encourage rests from typing at appropriate intervals 1 ;;; type-break.el --- encourage rests from typing at appropriate intervals
2 2
3 ;; Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 95, 97, 2000 Free Software Foundation, Inc.
4 4
5 ;; Author: Noah Friedman 5 ;; Author: Noah Friedman
6 ;; Maintainer: Noah Friedman <friedman@splode.com> 6 ;; Maintainer: Noah Friedman <friedman@splode.com>
7 ;; Keywords: extensions, timers 7 ;; Keywords: extensions, timers
8 ;; Status: Works in GNU Emacs 19.25 or later, some versions of XEmacs 8 ;; Status: Works in GNU Emacs 19.25 or later, some versions of XEmacs
9 ;; Created: 1994-07-13 9 ;; Created: 1994-07-13
10 10
11 ;; $Id: type-break.el,v 1.22 1999/04/27 19:00:42 fx Exp kwzh $ 11 ;; $Id: type-break.el,v 1.23 2000/03/13 11:16:00 friedman Exp $
12 12
13 ;; This file is part of GNU Emacs. 13 ;; This file is part of GNU Emacs.
14 14
15 ;; GNU Emacs is free software; you can redistribute it and/or modify 15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by 16 ;; it under the terms of the GNU General Public License as published by
59 ;; This program has no hope of working in Emacs 18. 59 ;; This program has no hope of working in Emacs 18.
60 60
61 ;; This package was inspired by Roland McGrath's hanoi-break.el. 61 ;; This package was inspired by Roland McGrath's hanoi-break.el.
62 ;; Several people contributed feedback and ideas, including 62 ;; Several people contributed feedback and ideas, including
63 ;; Roland McGrath <roland@gnu.org> 63 ;; Roland McGrath <roland@gnu.org>
64 ;; Kleanthes Koniaris <kgk@martigny.ai.mit.edu> 64 ;; Kleanthes Koniaris <kgk@koniaris.com>
65 ;; Mark Ashton <mpashton@gnu.org> 65 ;; Mark Ashton <mpashton@gnu.org>
66 ;; Matt Wilding <wilding@cli.com> 66 ;; Matt Wilding <wilding@cli.com>
67 ;; Robert S. Boyer <boyer@cs.utexas.edu> 67 ;; Robert S. Boyer <boyer@cs.utexas.edu>
68 68
69 ;;; Code: 69 ;;; Code:
70 70
71 71
72 (defgroup type-break nil 72 (defgroup type-break nil
73 "Encourage the user to take a rest from typing at suitable intervals." 73 "Encourage the user to take a rest from typing at suitable intervals."
74 :prefix "type-break" 74 :prefix "type-break"
75 :group 'type-break
75 :group 'keyboard) 76 :group 'keyboard)
76 77
77 ;;;###autoload 78 ;;;###autoload
78 (defcustom type-break-mode nil 79 (defcustom type-break-mode nil
79 "Toggle typing break mode. 80 "Toggle typing break mode.
149 If so, call the function specified in the value of the variable 150 If so, call the function specified in the value of the variable
150 `type-break-query-function' to do the asking." 151 `type-break-query-function' to do the asking."
151 :type 'boolean 152 :type 'boolean
152 :group 'type-break) 153 :group 'type-break)
153 154
154 (defvar type-break-query-function 'yes-or-no-p 155 (defcustom type-break-query-function 'yes-or-no-p
155 "Function to use for making query for a typing break. 156 "*Function to use for making query for a typing break.
156 It should take a string as an argument, the prompt. 157 It should take a string as an argument, the prompt.
157 Usually this should be set to `yes-or-no-p' or `y-or-n-p'. 158 Usually this should be set to `yes-or-no-p' or `y-or-n-p'.
158 159
159 To avoid being queried at all, set `type-break-query-mode' to `nil'.") 160 To avoid being queried at all, set `type-break-query-mode' to `nil'."
161 :type '(radio function
162 (function-item yes-or-no-p)
163 (function-item y-or-n-p))
164 :group 'type-break)
160 165
161 (defcustom type-break-query-interval 60 166 (defcustom type-break-query-interval 60
162 "*Number of seconds between queries to take a break, if put off. 167 "*Number of seconds between queries to take a break, if put off.
163 The user will continue to be prompted at this interval until he or she 168 The user will continue to be prompted at this interval until he or she
164 finally submits to taking a typing break." 169 finally submits to taking a typing break."
179 If either this variable or the upper threshold is set, then no warnings 184 If either this variable or the upper threshold is set, then no warnings
180 will occur." 185 will occur."
181 :type '(repeat integer) 186 :type '(repeat integer)
182 :group 'type-break) 187 :group 'type-break)
183 188
184
185 (defcustom type-break-warning-repeat 40 189 (defcustom type-break-warning-repeat 40
186 "*Number of keystrokes for which warnings should be repeated. 190 "*Number of keystrokes for which warnings should be repeated.
187 That is, for each of this many keystrokes the warning is redisplayed 191 That is, for each of this many keystrokes the warning is redisplayed
188 in the echo area to make sure it's really seen." 192 in the echo area to make sure it's really seen."
189 :type 'integer 193 :type 'integer
194 :group 'type-break)
195
196 (defcustom type-break-time-stamp-format "[%H:%M] "
197 "*Timestamp format used to prefix messages.
198 Format specifiers are as used by `format-time-string'."
199 :type 'string
190 :group 'type-break) 200 :group 'type-break)
191 201
192 (defcustom type-break-demo-functions 202 (defcustom type-break-demo-functions
193 '(type-break-demo-boring type-break-demo-life type-break-demo-hanoi) 203 '(type-break-demo-boring type-break-demo-life type-break-demo-hanoi)
194 "*List of functions to consider running as demos during typing breaks. 204 "*List of functions to consider running as demos during typing breaks.
230 (defvar type-break-mode-line-break-message 240 (defvar type-break-mode-line-break-message
231 '(type-break-mode-line-break-message-p 241 '(type-break-mode-line-break-message-p
232 type-break-mode-line-break-string)) 242 type-break-mode-line-break-string))
233 243
234 (defvar type-break-mode-line-break-message-p nil) 244 (defvar type-break-mode-line-break-message-p nil)
235 (defvar type-break-mode-line-break-string " *** TAKE A TYPING BREAK ***") 245 (defvar type-break-mode-line-break-string " *** TAKE A TYPING BREAK NOW ***")
236 246
237 (defvar type-break-mode-line-warning 247 (defvar type-break-mode-line-warning
238 '(type-break-mode-line-break-message-p 248 '(type-break-mode-line-break-message-p
239 ("") 249 ("")
240 (type-break-warning-countdown-string 250 (type-break-warning-countdown-string
241 (" ***Break in " 251 (" *** "
252 "Break in "
242 type-break-warning-countdown-string 253 type-break-warning-countdown-string
243 " " 254 " "
244 type-break-warning-countdown-string-type 255 type-break-warning-countdown-string-type
245 "***")))) 256 "***"))))
246 257
446 `type-break-demo-functions' is run. 457 `type-break-demo-functions' is run.
447 458
448 After the typing break is finished, the next break is scheduled 459 After the typing break is finished, the next break is scheduled
449 as per the function `type-break-schedule'." 460 as per the function `type-break-schedule'."
450 (interactive) 461 (interactive)
462 (do-auto-save)
451 (type-break-cancel-schedule) 463 (type-break-cancel-schedule)
452 (let ((continue t) 464 (let ((continue t)
453 (start-time (current-time))) 465 (start-time (current-time)))
454 (setq type-break-time-last-break start-time) 466 (setq type-break-time-last-break start-time)
455 (while continue 467 (while continue
481 ;; below if you're in that much of a hurry. 493 ;; below if you're in that much of a hurry.
482 ;((> 60 (abs (- break-secs type-break-good-rest-interval))) 494 ;((> 60 (abs (- break-secs type-break-good-rest-interval)))
483 ; (setq continue nil)) 495 ; (setq continue nil))
484 ((funcall 496 ((funcall
485 type-break-query-function 497 type-break-query-function
486 (format "You really ought to rest %s more. Continue break? " 498 (format "%sYou really ought to rest %s more. Continue break? "
499 (type-break-time-stamp)
487 (type-break-format-time (- type-break-good-rest-interval 500 (type-break-format-time (- type-break-good-rest-interval
488 break-secs))))) 501 break-secs)))))
489 (t 502 (t
490 (setq continue nil))))) 503 (setq continue nil)))))
491 (t (setq continue nil))))) 504 (t (setq continue nil)))))
592 (setq type-break-time-last-break (current-time)) 605 (setq type-break-time-last-break (current-time))
593 (type-break-schedule))) 606 (type-break-schedule)))
594 (setq type-break-time-last-command (current-time)))) 607 (setq type-break-time-last-command (current-time))))
595 608
596 (and type-break-keystroke-threshold 609 (and type-break-keystroke-threshold
597 ;; next line is test for 20.2 that can be deleted
598 ;;(setq type-break-keystroke-count (1+ type-break-keystroke-count))
599 (let ((keys (this-command-keys))) 610 (let ((keys (this-command-keys)))
600 (cond 611 (cond
601 ;; Ignore mouse motion 612 ;; Ignore mouse motion
602 ((and (vectorp keys) 613 ((and (vectorp keys)
603 (consp (aref keys 0)) 614 (consp (aref keys 0))
676 ((let ((type-break-mode nil) 687 ((let ((type-break-mode nil)
677 ;; yes-or-no-p sets this-command to exit-minibuffer, 688 ;; yes-or-no-p sets this-command to exit-minibuffer,
678 ;; which hoses undo or yank-pop (if you happened to be 689 ;; which hoses undo or yank-pop (if you happened to be
679 ;; yanking just when the query occurred). 690 ;; yanking just when the query occurred).
680 (this-command this-command)) 691 (this-command this-command))
692 ;; Cancel schedule to prevent possibility of a second query
693 ;; from taking place before this one has even returned.
694 ;; The condition-case wrapper will reschedule on quit.
695 (type-break-cancel-schedule)
681 (funcall type-break-query-function 696 (funcall type-break-query-function
682 "Take a break from typing now? ")) 697 (format "%s%s"
698 (type-break-time-stamp)
699 "Take a break from typing now? ")))
683 (type-break)) 700 (type-break))
684 (t 701 (t
685 (type-break-schedule type-break-query-interval))) 702 (type-break-schedule type-break-query-interval)))
686 (quit 703 (quit
687 (type-break-schedule type-break-query-interval))) 704 (type-break-schedule type-break-query-interval)))
693 this or ask the user to start one right now." 710 this or ask the user to start one right now."
694 (cond 711 (cond
695 (type-break-mode-line-message-mode) 712 (type-break-mode-line-message-mode)
696 (t 713 (t
697 (beep t) 714 (beep t)
698 (message "You should take a typing break now. Do `M-x type-break'.") 715 (message "%sYou should take a typing break now. Do `M-x type-break'."
716 (type-break-time-stamp))
699 (sit-for 1) 717 (sit-for 1)
700 (beep t) 718 (beep t)
701 ;; return nil so query caller knows to reset reminder, as if user 719 ;; return nil so query caller knows to reset reminder, as if user
702 ;; said "no" in response to yes-or-no-p. 720 ;; said "no" in response to yes-or-no-p.
703 nil))) 721 nil)))
718 ;; delay redisplay when one types sequences like `C-u -1 C-l'. 736 ;; delay redisplay when one types sequences like `C-u -1 C-l'.
719 ((memq this-command '(digit-argument universal-argument))) 737 ((memq this-command '(digit-argument universal-argument)))
720 ((not type-break-mode-line-message-mode) 738 ((not type-break-mode-line-message-mode)
721 ;; Pause for a moment so any previous message can be seen. 739 ;; Pause for a moment so any previous message can be seen.
722 (sit-for 2) 740 (sit-for 2)
723 (message "Warning: typing break due in %s." 741 (message "%sWarning: typing break due in %s."
742 (type-break-time-stamp)
724 (type-break-format-time timeleft)) 743 (type-break-format-time timeleft))
725 (setq type-break-time-warning-count 744 (setq type-break-time-warning-count
726 (1- type-break-time-warning-count)))))) 745 (1- type-break-time-warning-count))))))
727 (t 746 (t
728 (remove-hook 'type-break-post-command-hook 'type-break-time-warning) 747 (remove-hook 'type-break-post-command-hook 'type-break-time-warning)
741 ;; Otherwise, it is particularly annoying for the sit-for below to 760 ;; Otherwise, it is particularly annoying for the sit-for below to
742 ;; delay redisplay when one types sequences like `C-u -1 C-l'. 761 ;; delay redisplay when one types sequences like `C-u -1 C-l'.
743 ((memq this-command '(digit-argument universal-argument))) 762 ((memq this-command '(digit-argument universal-argument)))
744 ((not type-break-mode-line-message-mode) 763 ((not type-break-mode-line-message-mode)
745 (sit-for 2) 764 (sit-for 2)
746 (message "Warning: typing break due in %s keystrokes." 765 (message "%sWarning: typing break due in %s keystrokes."
766 (type-break-time-stamp)
747 (- (cdr type-break-keystroke-threshold) 767 (- (cdr type-break-keystroke-threshold)
748 type-break-keystroke-count)) 768 type-break-keystroke-count))
749 (setq type-break-keystroke-warning-count 769 (setq type-break-keystroke-warning-count
750 (1- type-break-keystroke-warning-count))))) 770 (1- type-break-keystroke-warning-count)))))
751 (t 771 (t
888 (progn 908 (progn
889 (setq low (logand low 65535)) 909 (setq low (logand low 65535))
890 (setq high (+ high tem)))) 910 (setq high (+ high tem))))
891 911
892 (list high low micro))) 912 (list high low micro)))
913
914 (defun type-break-time-stamp (&optional when)
915 (if (fboundp 'format-time-string)
916 (format-time-string type-break-time-stamp-format when)
917 ;; Emacs 19.28 and prior do not have format-time-string.
918 ;; In that case, result is not customizable. Upgrade today!
919 (format "[%s] " (substring (current-time-string when) 11 16))))
893 920
894 (defun type-break-format-time (secs) 921 (defun type-break-format-time (secs)
895 (let ((mins (/ secs 60))) 922 (let ((mins (/ secs 60)))
896 (cond 923 (cond
897 ((= mins 1) (format "%d minute" mins)) 924 ((= mins 1) (format "%d minute" mins))
1060 1087
1061 (provide 'type-break) 1088 (provide 'type-break)
1062 1089
1063 (if type-break-mode 1090 (if type-break-mode
1064 (type-break-mode 1)) 1091 (type-break-mode 1))
1092
1065 ;;; type-break.el ends here 1093 ;;; type-break.el ends here