[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autosave Feature (and the lack thereof)

   Date: Wed, 26 Jun 91 13:43:06 CDT
   From: flan@informatics.WUstl.EDU (Ian Flanigan)
   To: info-macl@cambridge.apple.com
   Subject: Autosave Feature (and the lack thereof)
       Today I was cruising along in a coding frenzy when that dreaded
   little bomb popped up in middle of my display.  In that instant I lost
   about an hour and a half of work.  True, it's not a dreadful
   catastrophe, but it is terribly frustrating.  And, yes, I know I
   should be in the habit of saving every five minutes or so, but . . .
       So, my question is, is it possible to implement an autosave
   feature in MCL?  If so, does anyone have any idea how it might be
   done?  Could such a beast be incorperated into the final release of
   MCL 2.0?
   Thanks much,
   Ian Flanigan
   Medical Informatics Group
   Washington University in St. Louis	"You can never have too many napkins."
   (314) 362-4320

The following is a simple 15-minute pass at an auto-save.  In 2.0
final, there will be a periodic task queue so you won't need to use
*eventhook* for this kind of thing.


(in-package :ccl)

(export 'set-auto-save-period)

(defvar *next-auto-save-time* nil)
(defvar *auto-save-period* nil)

(defun ticks () (#_TickCount))

; NIL will turn off autosaving
(defun set-auto-save-period (minutes)
  (if minutes
      (setq *auto-save-period* (round (* minutes 3600))) 
       (setq *next-auto-save-time*
             (min (or *next-auto-save-time* most-positive-fixnum)       ; 8 year max
                  (+ (ticks) *auto-save-period*)))))
    (setq *auto-save-period* nil
          *next-auto-save-time* nil)))

; Doesn't try to save windows that don't yet have a file. 
(defun do-auto-save ()
  (with-cursor *watch-cursor*
    (map-windows #'(lambda (win)
                     (when (and (not (typep win 'listener))
                                (slot-value win 'my-file-name))
                       (catch-cancel (window-save win))))
                 :class 'fred-window)))

(defun maybe-do-auto-save ()
  (let ((time *next-auto-save-time*)
    (when (and time (>= (setq ticks (ticks)) time))
        (setq *next-auto-save-time* (+ ticks *auto-save-period*))
  ; NIL tells event-dispatch that we are'nt handling the event

(push 'maybe-do-auto-save *eventhook*)