@end example
@end defmac
+@defmac ignore-error condition body@dots{}
+This macro is like @code{ignore-errors}, but will only ignore the
+specific error condition specified.
+
+@example
+ (ignore-error end-of-file
+ (read ""))
+@end example
+
+@var{condition} can also be a list of error conditions.
+@end defmac
+
@defmac with-demoted-errors format body@dots{}
This macro is like a milder version of @code{ignore-errors}. Rather
than suppressing errors altogether, it converts them into messages.
** The new macro `with-suppressed-warnings' can be used to suppress
specific byte-compile warnings.
++++
+** The new macro `ignore-error' is like `ignore-errors', but takes a
+specific error condition, and will only ignore that condition. (This
+can also be a list of conditions.)
+
---
** The new function `byte-compile-info-message' can be used to output
informational messages that look pleasing during the Emacs build.
(scan-error pos))))
;; t if in function position.
(funpos (eq (char-before beg) ?\())
- (quoted (elisp--form-quoted-p beg)))
+ (quoted (elisp--form-quoted-p beg))
+ (fun-sym (condition-case nil
+ (save-excursion
+ (up-list -1)
+ (forward-char 1)
+ (and (memq (char-syntax (char-after)) '(?w ?_))
+ (read (current-buffer))))
+ (error nil))))
+ (message "sym: %s %s %s %s" fun-sym funpos beg end)
(when (and end (or (not (nth 8 (syntax-ppss)))
(memq (char-before beg) '(?` ?‘))))
(let ((table-etc
(if (or (not funpos) quoted)
- ;; FIXME: We could look at the first element of the list and
- ;; use it to provide a more specific completion table in some
- ;; cases. E.g. filter out keywords that are not understood by
- ;; the macro/function being called.
(cond
+ ;; FIXME: We could look at the first element of
+ ;; the current form and use it to provide a more
+ ;; specific completion table in more cases.
+ ((eq fun-sym 'ignore-error)
+ (list t obarray
+ :predicate (lambda (sym)
+ (get sym 'error-conditions))))
((elisp--expect-function-p beg)
(list nil obarray
:predicate #'fboundp
(< (point) beg)))))
(list t obarray
:predicate (lambda (sym) (get sym 'error-conditions))))
+ ;; `ignore-error' with a list CONDITION parameter.
+ ('ignore-error
+ (list t obarray
+ :predicate (lambda (sym)
+ (get sym 'error-conditions))))
((and (or ?\( 'let 'let*)
(guard (save-excursion
(goto-char (1- beg))
without silencing all errors."
(declare (debug t) (indent 0))
`(condition-case nil (progn ,@body) (error nil)))
+
+(defmacro ignore-error (condition &rest body)
+ "Execute BODY; if the error CONDITION occurs, return nil.
+Otherwise, return result of last form in BODY.
+
+CONDITION can also be a list of error conditions."
+ (declare (debug t) (indent 1))
+ `(condition-case nil (progn ,@body) (,condition nil)))
\f
;;;; Basic Lisp functions.
(should (equal subr-tests--hook '(f5 f10 f9 f6 f2 f1 f4 f3 f7 f8)))
)
+(ert-deftest ignore-error-tests ()
+ (should (equal (ignore-error (end-of-file)
+ (read ""))
+ nil))
+ (should (equal (ignore-error end-of-file
+ (read ""))
+ nil))
+ (should-error (ignore-error foo
+ (read ""))))
+
(provide 'subr-tests)
;;; subr-tests.el ends here