From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel 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 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1378750035 13015 80.91.229.3 (9 Sep 2013 18:07:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Sep 2013 18:07:15 +0000 (UTC) Cc: emacs-devel@gnu.org To: Glenn Morris Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 09 20:07:17 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VJ5rm-0007ZQ-N5 for ged-emacs-devel@m.gmane.org; Mon, 09 Sep 2013 20:07:14 +0200 Original-Received: from localhost ([::1]:53113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ5rm-0005lJ-77 for ged-emacs-devel@m.gmane.org; Mon, 09 Sep 2013 14:07:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ5rb-0005c4-Us for emacs-devel@gnu.org; Mon, 09 Sep 2013 14:07:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJ5rU-0003fi-Jd for emacs-devel@gnu.org; Mon, 09 Sep 2013 14:07:03 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:24225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ5rU-0003fZ-FK; Mon, 09 Sep 2013 14:06:56 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EABK/CFG4rxBo/2dsb2JhbABEuzWDWRdzgh8BBVYjEBkmBwsUGA0kiCTBLZEKA6R6gV6DEw X-IPAS-Result: Av8EABK/CFG4rxBo/2dsb2JhbABEuzWDWRdzgh8BBVYjEBkmBwsUGA0kiCTBLZEKA6R6gV6DEw X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="26999817" Original-Received: from 184-175-16-104.dsl.teksavvy.com (HELO pastel.home) ([184.175.16.104]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 09 Sep 2013 14:03:35 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id CFA8462F86; Mon, 9 Sep 2013 14:06:54 -0400 (EDT) In-Reply-To: (Glenn Morris's message of "Sun, 08 Sep 2013 23:15:23 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:163269 Archived-At: > + ;; 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.