Use line-end-position rather than end-of-line, etc.
[bpt/emacs.git] / lisp / type-break.el
index b8b6f48..83278cb 100644 (file)
@@ -1,7 +1,7 @@
 ;;; type-break.el --- encourage rests from typing at appropriate intervals
 
-;; Copyright (C) 1994, 1995, 1997, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1997, 2000, 2001, 2002, 2003, 2004, 2005,
+;;   2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Noah Friedman
 ;; Maintainer: Noah Friedman <friedman@splode.com>
@@ -86,13 +86,13 @@ use either \\[customize] or the function `type-break-mode'."
 
 ;;;###autoload
 (defcustom type-break-interval (* 60 60)
-  "*Number of seconds between scheduled typing breaks."
+  "Number of seconds between scheduled typing breaks."
   :type 'integer
   :group 'type-break)
 
 ;;;###autoload
 (defcustom type-break-good-rest-interval (/ type-break-interval 6)
-  "*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
 keystrokes.  If this idle time is long enough to be considered a \"good\"
@@ -105,7 +105,7 @@ asked whether or not really to interrupt the break."
 
 ;;;###autoload
 (defcustom type-break-good-break-interval nil
-  "*Number of seconds considered to be an adequate explicit typing rest.
+  "Number of seconds considered to be an adequate explicit typing rest.
 
 When this variable is non-nil, its value is considered to be a \"good\"
 length (in seconds) for a break initiated by the command `type-break',
@@ -129,7 +129,7 @@ break interruptions when `type-break-good-rest-interval' is nil."
          (upper (* wpm avg-word-length (/ type-break-interval 60)))
          (lower (/ upper 5)))
     (cons lower upper))
-  "*Upper and lower bound on number of keystrokes for considering typing break.
+  "Upper and lower bound on number of keystrokes for considering typing break.
 This structure is a pair of numbers (MIN . MAX).
 
 The first number is the minimum number of keystrokes that must have been
@@ -152,15 +152,8 @@ guess a reasonably good pair of values for this variable."
   :type 'sexp
   :group 'type-break)
 
-(defcustom type-break-query-mode t
-  "*Non-nil means ask whether or not to prompt user for breaks.
-If so, call the function specified in the value of the variable
-`type-break-query-function' to do the asking."
-  :type 'boolean
-  :group 'type-break)
-
 (defcustom type-break-query-function 'yes-or-no-p
-  "*Function to use for making query for a typing break.
+  "Function to use for making query for a typing break.
 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'.
 
@@ -171,21 +164,21 @@ To avoid being queried at all, set `type-break-query-mode' to nil."
   :group 'type-break)
 
 (defcustom type-break-query-interval 60
-  "*Number of seconds between queries to take a break, if put off.
+  "Number of seconds between queries to take a break, if put off.
 The user will continue to be prompted at this interval until he or she
 finally submits to taking a typing break."
   :type 'integer
   :group 'type-break)
 
 (defcustom type-break-time-warning-intervals '(300 120 60 30)
-  "*List of time intervals for warnings about upcoming typing break.
+  "List of time intervals for warnings about upcoming typing break.
 At each of the intervals (specified in seconds) away from a scheduled
 typing break, print a warning in the echo area."
   :type '(repeat integer)
   :group 'type-break)
 
 (defcustom type-break-keystroke-warning-intervals '(300 200 100 50)
-  "*List of keystroke measurements for warnings about upcoming typing break.
+  "List of keystroke measurements for warnings about upcoming typing break.
 At each of the intervals (specified in keystrokes) away from the upper
 keystroke threshold, print a warning in the echo area.
 If either this variable or the upper threshold is set, then no warnings
@@ -194,21 +187,21 @@ will occur."
   :group 'type-break)
 
 (defcustom type-break-warning-repeat 40
-  "*Number of keystrokes for which warnings should be repeated.
+  "Number of keystrokes for which warnings should be repeated.
 That is, for each of this many keystrokes the warning is redisplayed
 in the echo area to make sure it's really seen."
   :type 'integer
   :group 'type-break)
 
 (defcustom type-break-time-stamp-format "[%H:%M] "
-  "*Timestamp format used to prefix messages.
+  "Timestamp format used to prefix messages.
 Format specifiers are as used by `format-time-string'."
   :type 'string
   :group 'type-break)
 
 (defcustom type-break-demo-functions
   '(type-break-demo-boring type-break-demo-life type-break-demo-hanoi)
-  "*List of functions to consider running 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
 to have Emacs do something interesting.
 
@@ -218,17 +211,17 @@ key is pressed."
   :group 'type-break)
 
 (defcustom type-break-demo-boring-stats nil
-  "*Show word per minute and keystroke figures in the Boring demo."
+  "Show word per minute and keystroke figures in the Boring demo."
   :type 'boolean
   :group 'type-break)
 
 (defcustom type-break-terse-messages nil
-  "*Use slightly terser messages."
+  "Use slightly terser messages."
   :type 'boolean
   :group 'type-break)
 
 (defcustom type-break-file-name (convert-standard-filename "~/.type-break")
-  "*Name of file used to save state across sessions.
+  "Name of file used to save state across sessions.
 If this is nil, no data will be saved across sessions."
   :type 'file
   :group 'type-break)
@@ -245,14 +238,6 @@ remove themselves after running.")
 \f
 ;; Mode line frobs
 
-(defcustom type-break-mode-line-message-mode nil
-  "*Non-nil means put type-break related messages in the mode line.
-Otherwise, messages typically go in the echo area.
-
-See also `type-break-mode-line-format' and its members."
-  :type 'boolean
-  :group 'type-break)
-
 (defvar type-break-mode-line-format
   '(type-break-mode-line-message-mode
     (""
@@ -386,7 +371,7 @@ problems."
 
     (cond
      ((and already-enabled type-break-mode)
-      (and (interactive-p)
+      (and (called-interactively-p 'interactive)
            (message "Type Break mode is already enabled")))
      (type-break-mode
       (when type-break-file-name
@@ -430,7 +415,7 @@ problems."
        type-break-interval-start
        type-break-interval)
 
-      (and (interactive-p)
+      (and (called-interactively-p 'interactive)
            (message "Type Break mode is enabled and set")))
      (t
       (type-break-keystroke-reset)
@@ -443,11 +428,11 @@ problems."
          (set-buffer-modified-p nil)
          (unlock-buffer)
          (kill-this-buffer)))
-      (and (interactive-p)
+      (and (called-interactively-p 'interactive)
            (message "Type Break mode is disabled")))))
   type-break-mode)
 
-(defun type-break-mode-line-message-mode (&optional prefix)
+(define-minor-mode type-break-mode-line-message-mode
   "Enable or disable warnings in the mode line about typing breaks.
 
 A negative PREFIX argument disables this mode.
@@ -462,16 +447,9 @@ Variables controlling the display of messages in the mode line include:
         `global-mode-string'
         `type-break-mode-line-break-message'
         `type-break-mode-line-warning'"
-  (interactive "P")
-  (setq type-break-mode-line-message-mode
-        (>= (prefix-numeric-value prefix) 0))
-  (and (interactive-p)
-       (if type-break-mode-line-message-mode
-           (message "type-break-mode-line-message-mode is enabled")
-         (message "type-break-mode-line-message-mode is disabled")))
-  type-break-mode-line-message-mode)
-
-(defun type-break-query-mode (&optional prefix)
+  :global t)
+
+(define-minor-mode type-break-query-mode
   "Enable or disable warnings in the mode line about typing breaks.
 
 When enabled, the user is periodically queried about whether to take a
@@ -483,14 +461,7 @@ No argument or any non-negative argument enables it.
 
 The user may also enable or disable this mode simply by setting the
 variable of the same name."
-  (interactive "P")
-  (setq type-break-query-mode
-        (>= (prefix-numeric-value prefix) 0))
-  (and (interactive-p)
-       (if type-break-query-mode
-           (message "type-break-query-mode is enabled")
-         (message "type-break-query-mode is disabled")))
-  type-break-query-mode)
+  :global t)
 
 \f
 ;;; session file functions
@@ -524,7 +495,7 @@ variable of the same name."
            (let ((inhibit-read-only t))
              (goto-char (point-min))
              (forward-line)
-             (delete-region (point) (save-excursion (end-of-line) (point)))
+             (delete-region (point) (line-end-position))
              (insert (format "%s" type-break-keystroke-count))
              ;; file saving is left to auto-save
              ))))))
@@ -1015,7 +986,7 @@ FRAC should be the inverse of the fractional value; for example, a value of
         (setq type-break-keystroke-threshold (cons nil nil)))
     (setcar type-break-keystroke-threshold lower)
     (setcdr type-break-keystroke-threshold upper)
-    (if (interactive-p)
+    (if (called-interactively-p 'interactive)
         (message "min threshold: %d\tmax threshold: %d" lower upper))
     type-break-keystroke-threshold))
 
@@ -1094,7 +1065,7 @@ FRAC should be the inverse of the fractional value; for example, a value of
 (defun type-break-force-mode-line-update (&optional all)
   "Force the mode-line of the current buffer to be redisplayed.
 With optional non-nil ALL, force redisplay of all mode-lines."
-  (and all (save-excursion (set-buffer (other-buffer))))
+  (and all (with-current-buffer (other-buffer)))
   (set-buffer-modified-p (buffer-modified-p)))
 
 ;; If an exception occurs in Emacs while running the post command hook, the
@@ -1108,9 +1079,9 @@ With optional non-nil ALL, force redisplay of all mode-lines."
 
 \f
 ;;; Timer wrapper functions
-;;;
-;;; These shield type-break from variations in the interval timer packages
-;;; for different versions of Emacs.
+;;
+;; These shield type-break from variations in the interval timer packages
+;; for different versions of Emacs.
 
 (defun type-break-run-at-time (time repeat function)
   (condition-case nil (or (require 'timer) (require 'itimer)) (error nil))
@@ -1272,5 +1243,4 @@ With optional non-nil ALL, force redisplay of all mode-lines."
 (if type-break-mode
     (type-break-mode 1))
 
-;; arch-tag: 943a2eb3-07e6-420b-993f-96e4796f5fd0
 ;;; type-break.el ends here