;;; 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>
;; 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:
: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)
(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
(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
(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)
(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))
(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
(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)