[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.
From: |
Stefan Monnier |
Subject: |
with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) |
Date: |
Mon, 09 Sep 2013 14:06:54 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> + ;; This is with-demoted-errors, but we want to
> + ;; mention save-place in any error message.
> + (condition-case err
> + (car (read-from-string
> + (buffer-substring (point-min) (point-max))))
> + (error (message "Error reading save-place-file: %S"
> err)
> + nil)))
I remember having similar desires in other places. Should we add
a "format" argument to with-demoted-errors?
Stefan
=== modified file 'lisp/subr.el'
--- lisp/subr.el 2013-09-05 03:46:34 +0000
+++ lisp/subr.el 2013-09-09 17:58:01 +0000
@@ -3350,16 +3350,22 @@
(define-obsolete-function-alias 'condition-case-no-debug
'condition-case-unless-debug "24.1")
-(defmacro with-demoted-errors (&rest body)
+(defmacro with-demoted-errors (format &rest body)
"Run BODY and demote any errors to simple messages.
If `debug-on-error' is non-nil, run BODY without catching its errors.
This is to be used around code which is not expected to signal an error
-but which should be robust in the unexpected case that an error is signaled."
- (declare (debug t) (indent 0))
- (let ((err (make-symbol "err")))
+but which should be robust in the unexpected case that an error is signaled.
+For backward compatibility, if FORMAT is not a constant string, it
+is assumed to be part of BODY, in which case the message format
+used is \"Error: %S\"."
+ (declare (debug t) (indent 1))
+ (let ((err (make-symbol "err"))
+ (format (if (and (stringp format) body) format
+ (prog1 "Error: %S"
+ (if format (push format body))))))
`(condition-case-unless-debug ,err
- (progn ,@body)
- (error (message "Error: %S" ,err) nil))))
+ ,(macroexp-progn body)
+ (error (message ,format ,err) nil))))
(defmacro combine-after-change-calls (&rest body)
"Execute BODY, but don't call the after-change functions till the end.
- with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.),
Stefan Monnier <=