From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "B. T. Raven" Newsgroups: gmane.emacs.help Subject: Re: Saving info from inside of error handling Date: Sun, 30 Mar 2008 07:03:52 -0600 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1206884503 3642 80.91.229.12 (30 Mar 2008 13:41:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 30 Mar 2008 13:41:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 30 15:42:15 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JfxnZ-0004x6-9g for geh-help-gnu-emacs@m.gmane.org; Sun, 30 Mar 2008 15:42:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jfxmx-0008TX-GP for geh-help-gnu-emacs@m.gmane.org; Sun, 30 Mar 2008 09:41:35 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.sysmatrix.net!news.sysmatrix.net.POSTED!not-for-mail Original-NNTP-Posting-Date: Sun, 30 Mar 2008 08:03:49 -0500 User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) Original-Newsgroups: gnu.emacs.help In-Reply-To: Original-Lines: 50 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 65.45.140.32 Original-X-Trace: sv3-9DGpS0eV7J0ekDZpCp/ok7IqV8GEVguXHtiS2gW8AAafskqPw9xTHEwyqYoqKVtfd7iz6QZM3cEAUch!8PVcTioNi1LSQnbX2GsHTdlslYoL0l0IbSvvr9pTwsSR/NmFg1gMKG8+JIOVoCOmWVFbH7dbhLGr!VoIDwCdjrLYGF86BFnOMKOBPuuJhkw== Original-X-Complaints-To: abuse@sysmatrix.net X-DMCA-Complaints-To: abuse@sysmatrix.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.37 Original-Xref: shelby.stanford.edu gnu.emacs.help:157466 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:52835 Archived-At: 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.