]> code.delx.au - gnu-emacs/blobdiff - lisp/type-break.el
*** empty log message ***
[gnu-emacs] / lisp / type-break.el
index ec96ab09fe2cd1e7142481e84ef8a924954dc76f..beb7e6f37255ef8111dfccc01d7925bf3bbd6219 100644 (file)
@@ -1,6 +1,7 @@
 ;;; type-break.el --- encourage rests from typing at appropriate intervals
 
-;; Copyright (C) 1994, 95, 97, 2000, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1997, 2000, 2002, 2003,
+;;   2004, 2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: Noah Friedman
 ;; Maintainer: Noah Friedman <friedman@splode.com>
@@ -22,8 +23,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -229,7 +230,8 @@ key is pressed."
   :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)
 
@@ -389,6 +391,10 @@ problems."
       (and (interactive-p)
            (message "Type Break mode is already enabled")))
      (type-break-mode
+      (when type-break-file-name
+       (with-current-buffer (find-file-noselect type-break-file-name 'nowarn)
+         (setq buffer-save-without-query t)))
+
       (or global-mode-string
           (setq global-mode-string '("")))
       (or (assq 'type-break-mode-line-message-mode
@@ -399,11 +405,9 @@ problems."
       (type-break-keystroke-reset)
       (type-break-mode-line-countdown-or-break nil)
 
-      (if (boundp 'save-some-buffers-always)
-          (add-to-list 'save-some-buffers-always
-                       (expand-file-name type-break-file-name)))
-
-      (setq type-break-time-last-break (type-break-get-previous-time))
+      (setq type-break-time-last-break
+            (or (type-break-get-previous-time)
+                (current-time)))
 
       ;; schedule according to break time from session file
       (type-break-schedule
@@ -435,15 +439,12 @@ problems."
       (type-break-mode-line-countdown-or-break nil)
       (type-break-cancel-schedule)
       (do-auto-save)
-      (with-current-buffer (find-file-noselect type-break-file-name
-                                               'nowarn)
-        (set-buffer-modified-p nil)
-        (unlock-buffer)
-        (kill-this-buffer))
-      (if (boundp 'save-some-buffers-always)
-          (setq save-some-buffers-always
-                (remove (expand-file-name type-break-file-name)
-                        save-some-buffers-always)))
+      (when type-break-file-name
+       (with-current-buffer (find-file-noselect type-break-file-name
+                                                'nowarn)
+         (set-buffer-modified-p nil)
+         (unlock-buffer)
+         (kill-this-buffer)))
       (and (interactive-p)
            (message "Type Break mode is disabled")))))
   type-break-mode)
@@ -503,7 +504,8 @@ variable of the same name."
 
 (defun type-break-file-time (&optional time)
   "File break time in `type-break-file-name', unless the file is locked."
-  (if (not (stringp (file-locked-p type-break-file-name)))
+  (if (and type-break-file-name
+           (not (stringp (file-locked-p type-break-file-name))))
       (with-current-buffer (find-file-noselect type-break-file-name
                                                'nowarn)
         (let ((inhibit-read-only t))
@@ -514,17 +516,20 @@ variable of the same name."
 
 (defun type-break-file-keystroke-count ()
   "File keystroke count in `type-break-file-name', unless the file is locked."
-  (if (not (stringp (file-locked-p type-break-file-name)))
-      (with-current-buffer (find-file-noselect type-break-file-name
-                                               'nowarn)
-        (save-excursion
-          (let ((inhibit-read-only t))
-            (goto-char (point-min))
-            (forward-line)
-            (delete-region (point) (save-excursion (end-of-line) (point)))
-            (insert (format "%s" type-break-keystroke-count))
-            ;; file saving is left to auto-save
-            )))))
+  (if (and type-break-file-name
+           (not (stringp (file-locked-p type-break-file-name))))
+      ;; Prevent deactivation of the mark in some other buffer.
+      (let (deactivate-mark)
+       (with-current-buffer (find-file-noselect type-break-file-name
+                                                'nowarn)
+         (save-excursion
+           (let ((inhibit-read-only t))
+             (goto-char (point-min))
+             (forward-line)
+             (delete-region (point) (save-excursion (end-of-line) (point)))
+             (insert (format "%s" type-break-keystroke-count))
+             ;; file saving is left to auto-save
+             ))))))
 
 (defun timep (time)
   "If TIME is in the format returned by `current-time' then
@@ -539,6 +544,8 @@ return TIME, else return nil."
 (defun type-break-choose-file ()
   "Return file to read from."
   (cond
+   ((not type-break-file-name)
+    nil)
    ((and (file-exists-p type-break-auto-save-file-name)
          (file-readable-p type-break-auto-save-file-name))
     type-break-auto-save-file-name)