|
From: | B. T. Raven |
Subject: | Re: Saving info from inside of error handling |
Date: | Sun, 30 Mar 2008 07:03:52 -0600 |
User-agent: | Thunderbird 2.0.0.12 (Windows/20080213) |
Kevin Rodgers wrote:
B. T. Raven wrote:I have the following inside a loop where filename is changed and I want to build a string or list of filenames for which the user has answered that the existing file should be overwritten. Can I test for y-or-n-p return result (write-file defun in files.el) and have the program report in which places the files have been replaced with the contents of the current buffer?(condition-case nil (write-file filename t) (error nil))I don't think you can reliably test the result of that particular call to y-or-n-p (there are 2 calls in basic-save-buffer, plus 1 call to yes-or-no-p). But you can test whether the visited file name has changed: (let ((overwritten-files '()) original-file-name) ... (setq original-file buffer-file-name) (condition-case nil (write-file filename t)(error nil)) (when (not (equal original-file-name buffer-file-name))(setq overwritten-files (cons (cons original-file-name buffer-file-name) overwritten-files))) ... )
Thanks, Kevin. Of course it doesn't make sense that I should have access to any calls within the write-file function but I guess it's enough just to know whether a cancel error occurred or not. It should work if I just initialize a write-file-confirmed variable to nil at the start of the loop through the mounted file systems and then:
(condition-case nil (setq write-file-confirmed (not(write-file filename t))) ;; write-file normally returns nil (error nil))Then, if no error was signaled, the function will know that the buffer was written to that file system. If there was an error, execution won't reach the enclosing (setq write-file-confirmed (not (... and the variable will remain nil. I don't want to change the filename or have to type any long pathnames in this process, so the only thing that will change between saves is the drive letter.
[Prev in Thread] | Current Thread | [Next in Thread] |