all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Saving info from inside of error handling
@ 2008-03-28 16:38 B. T. Raven
  2008-03-29 15:09 ` Kevin Rodgers
       [not found] ` <mailman.9576.1206803413.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: B. T. Raven @ 2008-03-28 16:38 UTC (permalink / raw)
  To: help-gnu-emacs

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))

Thanks,

Ed


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Saving info from inside of error handling
  2008-03-28 16:38 Saving info from inside of error handling B. T. Raven
@ 2008-03-29 15:09 ` Kevin Rodgers
       [not found] ` <mailman.9576.1206803413.18990.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2008-03-29 15:09 UTC (permalink / raw)
  To: help-gnu-emacs

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)))
  ...
)

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Saving info from inside of error handling
       [not found] ` <mailman.9576.1206803413.18990.help-gnu-emacs@gnu.org>
@ 2008-03-30 13:03   ` B. T. Raven
  0 siblings, 0 replies; 3+ messages in thread
From: B. T. Raven @ 2008-03-30 13:03 UTC (permalink / raw)
  To: help-gnu-emacs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-30 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-28 16:38 Saving info from inside of error handling B. T. Raven
2008-03-29 15:09 ` Kevin Rodgers
     [not found] ` <mailman.9576.1206803413.18990.help-gnu-emacs@gnu.org>
2008-03-30 13:03   ` B. T. Raven

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.