aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-07-26 09:58:23 +0200
committerLars Ingebrigtsen2019-07-26 09:58:53 +0200
commiteb45cc9521e25dc685bdfb4a6b7926c244fbf259 (patch)
tree293d9e053560d62f055e3348fb7378a75d5c7000
parent66db7b2c36c9189baf6f6b3d3fd7d04b3903cab4 (diff)
downloademacs-eb45cc9521e25dc685bdfb4a6b7926c244fbf259.tar.gz
emacs-eb45cc9521e25dc685bdfb4a6b7926c244fbf259.zip
Add new macro `ignore-error'
* doc/lispref/control.texi (Handling Errors): Document `ignore-error'. * lisp/subr.el (ignore-error): New macro. * lisp/progmodes/elisp-mode.el (elisp-completion-at-point): Provide completion for `ignore-error'.
-rw-r--r--doc/lispref/control.texi12
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/progmodes/elisp-mode.el26
-rw-r--r--lisp/subr.el8
-rw-r--r--test/lisp/subr-tests.el10
5 files changed, 56 insertions, 5 deletions
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index de6cd9301ff..e98daf66e98 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -2154,6 +2154,18 @@ Here's the example at the beginning of this subsection rewritten using
2154@end example 2154@end example
2155@end defmac 2155@end defmac
2156 2156
2157@defmac ignore-error condition body@dots{}
2158This macro is like @code{ignore-errors}, but will only ignore the
2159specific error condition specified.
2160
2161@example
2162 (ignore-error end-of-file
2163 (read ""))
2164@end example
2165
2166@var{condition} can also be a list of error conditions.
2167@end defmac
2168
2157@defmac with-demoted-errors format body@dots{} 2169@defmac with-demoted-errors format body@dots{}
2158This macro is like a milder version of @code{ignore-errors}. Rather 2170This macro is like a milder version of @code{ignore-errors}. Rather
2159than suppressing errors altogether, it converts them into messages. 2171than suppressing errors altogether, it converts them into messages.
diff --git a/etc/NEWS b/etc/NEWS
index 44a69213899..5673fc1b42d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1937,6 +1937,11 @@ buffer-local. `permanent' also sets the variable's
1937** The new macro `with-suppressed-warnings' can be used to suppress 1937** The new macro `with-suppressed-warnings' can be used to suppress
1938specific byte-compile warnings. 1938specific byte-compile warnings.
1939 1939
1940+++
1941** The new macro `ignore-error' is like `ignore-errors', but takes a
1942specific error condition, and will only ignore that condition. (This
1943can also be a list of conditions.)
1944
1940--- 1945---
1941** The new function `byte-compile-info-message' can be used to output 1946** The new function `byte-compile-info-message' can be used to output
1942informational messages that look pleasing during the Emacs build. 1947informational messages that look pleasing during the Emacs build.
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index da7a731ec22..1babb2f9094 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -500,16 +500,27 @@ functions are annotated with \"<f>\" via the
500 (scan-error pos)))) 500 (scan-error pos))))
501 ;; t if in function position. 501 ;; t if in function position.
502 (funpos (eq (char-before beg) ?\()) 502 (funpos (eq (char-before beg) ?\())
503 (quoted (elisp--form-quoted-p beg))) 503 (quoted (elisp--form-quoted-p beg))
504 (fun-sym (condition-case nil
505 (save-excursion
506 (up-list -1)
507 (forward-char 1)
508 (and (memq (char-syntax (char-after)) '(?w ?_))
509 (read (current-buffer))))
510 (error nil))))
511 (message "sym: %s %s %s %s" fun-sym funpos beg end)
504 (when (and end (or (not (nth 8 (syntax-ppss))) 512 (when (and end (or (not (nth 8 (syntax-ppss)))
505 (memq (char-before beg) '(?` ?‘)))) 513 (memq (char-before beg) '(?` ?‘))))
506 (let ((table-etc 514 (let ((table-etc
507 (if (or (not funpos) quoted) 515 (if (or (not funpos) quoted)
508 ;; FIXME: We could look at the first element of the list and
509 ;; use it to provide a more specific completion table in some
510 ;; cases. E.g. filter out keywords that are not understood by
511 ;; the macro/function being called.
512 (cond 516 (cond
517 ;; FIXME: We could look at the first element of
518 ;; the current form and use it to provide a more
519 ;; specific completion table in more cases.
520 ((eq fun-sym 'ignore-error)
521 (list t obarray
522 :predicate (lambda (sym)
523 (get sym 'error-conditions))))
513 ((elisp--expect-function-p beg) 524 ((elisp--expect-function-p beg)
514 (list nil obarray 525 (list nil obarray
515 :predicate #'fboundp 526 :predicate #'fboundp
@@ -568,6 +579,11 @@ functions are annotated with \"<f>\" via the
568 (< (point) beg))))) 579 (< (point) beg)))))
569 (list t obarray 580 (list t obarray
570 :predicate (lambda (sym) (get sym 'error-conditions)))) 581 :predicate (lambda (sym) (get sym 'error-conditions))))
582 ;; `ignore-error' with a list CONDITION parameter.
583 ('ignore-error
584 (list t obarray
585 :predicate (lambda (sym)
586 (get sym 'error-conditions))))
571 ((and (or ?\( 'let 'let*) 587 ((and (or ?\( 'let 'let*)
572 (guard (save-excursion 588 (guard (save-excursion
573 (goto-char (1- beg)) 589 (goto-char (1- beg))
diff --git a/lisp/subr.el b/lisp/subr.el
index f1a4e8bb292..eea4e045dde 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -302,6 +302,14 @@ See also `with-demoted-errors' that does something similar
302without silencing all errors." 302without silencing all errors."
303 (declare (debug t) (indent 0)) 303 (declare (debug t) (indent 0))
304 `(condition-case nil (progn ,@body) (error nil))) 304 `(condition-case nil (progn ,@body) (error nil)))
305
306(defmacro ignore-error (condition &rest body)
307 "Execute BODY; if the error CONDITION occurs, return nil.
308Otherwise, return result of last form in BODY.
309
310CONDITION can also be a list of error conditions."
311 (declare (debug t) (indent 1))
312 `(condition-case nil (progn ,@body) (,condition nil)))
305 313
306;;;; Basic Lisp functions. 314;;;; Basic Lisp functions.
307 315
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 06db8f5c902..0023680738d 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -400,5 +400,15 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
400 (should (equal subr-tests--hook '(f5 f10 f9 f6 f2 f1 f4 f3 f7 f8))) 400 (should (equal subr-tests--hook '(f5 f10 f9 f6 f2 f1 f4 f3 f7 f8)))
401 ) 401 )
402 402
403(ert-deftest ignore-error-tests ()
404 (should (equal (ignore-error (end-of-file)
405 (read ""))
406 nil))
407 (should (equal (ignore-error end-of-file
408 (read ""))
409 nil))
410 (should-error (ignore-error foo
411 (read ""))))
412
403(provide 'subr-tests) 413(provide 'subr-tests)
404;;; subr-tests.el ends here 414;;; subr-tests.el ends here