* with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) [not found] <E1VIoCR-0003nJ-A6@vcs.savannah.gnu.org> @ 2013-09-09 18:06 ` Stefan Monnier 2013-09-09 18:13 ` with-demoted-errors Glenn Morris 2013-09-10 15:54 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Karl Fogel 0 siblings, 2 replies; 6+ messages in thread From: Stefan Monnier @ 2013-09-09 18:06 UTC (permalink / raw) To: Glenn Morris; +Cc: emacs-devel > + ;; 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: with-demoted-errors 2013-09-09 18:06 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Stefan Monnier @ 2013-09-09 18:13 ` Glenn Morris 2013-09-10 15:30 ` with-demoted-errors Stefan Monnier 2013-09-10 15:54 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Karl Fogel 1 sibling, 1 reply; 6+ messages in thread From: Glenn Morris @ 2013-09-09 18:13 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel Stefan Monnier wrote: > I remember having similar desires in other places. Should we add > a "format" argument to with-demoted-errors? Yes please. I've previously needed the same thing in eg dir-locals-read-from-file. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: with-demoted-errors 2013-09-09 18:13 ` with-demoted-errors Glenn Morris @ 2013-09-10 15:30 ` Stefan Monnier 0 siblings, 0 replies; 6+ messages in thread From: Stefan Monnier @ 2013-09-10 15:30 UTC (permalink / raw) To: Glenn Morris; +Cc: emacs-devel >> I remember having similar desires in other places. Should we add >> a "format" argument to with-demoted-errors? > Yes please. I've previously needed the same thing in eg > dir-locals-read-from-file. Installed, Stefan ^ permalink raw reply [flat|nested] 6+ messages in thread
* with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) 2013-09-09 18:06 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Stefan Monnier 2013-09-09 18:13 ` with-demoted-errors Glenn Morris @ 2013-09-10 15:54 ` Karl Fogel 2013-09-10 16:07 ` with-demoted-errors Glenn Morris 1 sibling, 1 reply; 6+ messages in thread From: Karl Fogel @ 2013-09-10 15:54 UTC (permalink / raw) To: Emacs Development From: Stefan Monnier <monnier@iro.umontreal.ca> >> + ;; 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? I'm not sure I understand the original comment in saveplace.el, actually. Does "mention save-place" mean something special there? The error string already says "save-place-file", and it will print `err' too... In other words, why couldn't one just use `with-demoted-errors' in that spot right now? Another way to say it is: the BODY argument to `with-demoted-errors' can format anything in its error messages that it want to, so I don't see why that code in saveplace.el isn't using `with-demoted-errors' already. Not a facetious question; I'm sure I'm just missing something obvious, but having pondered I can't think of what it is, so am asking. -Karl ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: with-demoted-errors 2013-09-10 15:54 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Karl Fogel @ 2013-09-10 16:07 ` Glenn Morris 2013-09-11 20:22 ` with-demoted-errors Karl Fogel 0 siblings, 1 reply; 6+ messages in thread From: Glenn Morris @ 2013-09-10 16:07 UTC (permalink / raw) To: Karl Fogel; +Cc: Emacs Development Karl Fogel wrote: > From: Stefan Monnier <monnier@iro.umontreal.ca> >>> + ;; 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? > > I'm not sure I understand the original comment in saveplace.el, > actually. Does "mention save-place" mean something special there? > > The error string already says "save-place-file", and it will print `err' > too... In other words, why couldn't one just use `with-demoted-errors' > in that spot right now? Another way to say it is: the BODY argument to > `with-demoted-errors' can format anything in its error messages that it > want to, so I don't see why that code in saveplace.el isn't using > `with-demoted-errors' already. Because (with-demoted-errors (car (read-from-string (buffer-substring (point-min) (point-max))))) just prints "end-of-file", which gives you no clue that the error is coming from save-place. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: with-demoted-errors 2013-09-10 16:07 ` with-demoted-errors Glenn Morris @ 2013-09-11 20:22 ` Karl Fogel 0 siblings, 0 replies; 6+ messages in thread From: Karl Fogel @ 2013-09-11 20:22 UTC (permalink / raw) To: Glenn Morris; +Cc: Emacs Development Glenn Morris <rgm@gnu.org> writes: >Karl Fogel wrote: >> From: Stefan Monnier <monnier@iro.umontreal.ca> >>>> + ;; 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? >> >> I'm not sure I understand the original comment in saveplace.el, >> actually. Does "mention save-place" mean something special there? >> >> The error string already says "save-place-file", and it will print `err' >> too... In other words, why couldn't one just use `with-demoted-errors' >> in that spot right now? Another way to say it is: the BODY argument to >> `with-demoted-errors' can format anything in its error messages that it >> want to, so I don't see why that code in saveplace.el isn't using >> `with-demoted-errors' already. > >Because > >(with-demoted-errors > (car (read-from-string > (buffer-substring (point-min) (point-max))))) > >just prints "end-of-file", which gives you no clue that the error is >coming from save-place. Oh I see it now; and the proposed solution obviously makes sense. Thanks. -K ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-09-11 20:22 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <E1VIoCR-0003nJ-A6@vcs.savannah.gnu.org> 2013-09-09 18:06 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Stefan Monnier 2013-09-09 18:13 ` with-demoted-errors Glenn Morris 2013-09-10 15:30 ` with-demoted-errors Stefan Monnier 2013-09-10 15:54 ` with-demoted-errors (was: [Emacs-diffs] trunk r114172: * lisp/saveplace.el (load-save-place-alist-from-file): Demote errors.) Karl Fogel 2013-09-10 16:07 ` with-demoted-errors Glenn Morris 2013-09-11 20:22 ` with-demoted-errors Karl Fogel
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.