help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: how to make the "file has auto save data..." message unskippable?


From: Colin S. Miller
Subject: Re: how to make the "file has auto save data..." message unskippable?
Date: Sun, 05 Jul 2009 22:49:20 +0100
User-agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)

Nobuko Three wrote:
I open a file foo.txt and then my emacs displays the message:

foo.txt has auto save data; consider M-x recover-this-file


Is there a hook I can use for this idea?

Nobuko,
A slightly more drastic way of doing this is
to force you to make a choice when you open the file.

Adding the following code to your .emacs
will make emacs ask you if you want to recover the file
when the file is opened, emacs will beep at you until you answer.

This asks via a Y/N prompt.
If you want Yes/No prompt, change the y-or-n-p
to  yes-or-no-p

This is probably not the neatest elisp, but it does the job.

HTH,
Colin S. Miller




(if (not (fboundp 'time-less-p))
; definition from xemacs21
(defun time-less-p (t1 t2)
  "Say whether time value T1 is less than time value T2."
  (or (< (car t1) (car t2))
      (and (= (car t1) (car t2))
           (< (nth 1 t1) (nth 1 t2))))))

(defun csm-check-recover ()
  (interactive)
  (let ((buffer-mtime) (autosave-mtime))
    (progn
      (setq buffer-mtime (nth 5 (file-attributes (buffer-file-name))))
      (setq autosave-mtime (nth 5 (file-attributes (make-auto-save-file-name))))
      (if (time-less-p buffer-mtime autosave-mtime)
          (if (file-exists-p (make-auto-save-file-name))
              (if (not (local-variable-p 'csm-check-recover-loop-block 
(current-buffer)))
                (progn
                  (make-local-variable 'csm-check-recover-loop-block)
                  (if (y-or-n-p (concat "file " (buffer-file-name) " has autosave 
data. Recover? "))
                            (recover-file (buffer-file-name))
                    (kill-local-variable 'csm-check-recover-loop-block)))))))))

(add-hook 'find-file-hooks 'csm-check-recover)



--
Replace the obvious in my email address with the first three letters of the 
hostname to reply.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]