Add the new macro with-suppressed-warnings

* lisp/emacs-lisp/byte-run.el (with-suppressed-warnings): New macro.

* doc/lispref/compile.texi (Compiler Errors): Document
with-suppressed-warnings and deemphasise with-no-warnings
slightly.

* lisp/emacs-lisp/bytecomp.el (byte-compile--suppressed-warnings):
New internal variable.
(byte-compile-warning-enabled-p): Heed
byte-compile--suppressed-warnings, bound via with-suppressed-warnings.
(byte-compile-initial-macro-environment): Provide a macro
expansion of with-suppressed-warnings.
(byte-compile-file-form-with-suppressed-warnings): New byte hunk
handler for the suppressed symbol machinery.
(byte-compile-suppressed-warnings): Ditto for the byteop.
(byte-compile-file-form-defmumble): Ditto.
(byte-compile-form, byte-compile-normal-call)
(byte-compile-normal-call, byte-compile-variable-ref)
(byte-compile-set-default, byte-compile-variable-set)
(byte-compile-function-form, byte-compile-set-default)
(byte-compile-warn-obsolete, byte-compile--declare-var): Pass the
symbol being warned in to byte-compile-warning-enabled-p.

* test/lisp/emacs-lisp/bytecomp-tests.el (test-suppression): New
function.
(bytecomp-test--with-suppressed-warnings): Tests.
This commit is contained in:
Lars Ingebrigtsen 2019-06-12 15:59:19 +02:00
parent b8350e52ef
commit f2071b6de4
5 changed files with 203 additions and 27 deletions

View file

@ -494,6 +494,34 @@ is enabled."
;; The implementation for the interpreter is basically trivial.
(car (last body)))
(defmacro with-suppressed-warnings (_warnings &rest body)
"Like `progn', but prevents compiler WARNINGS in BODY.
WARNINGS is an associative list where the first element of each
item is a warning type, and the rest of the elements in each item
are symbols they apply to. For instance, if you want to suppress
byte compilation warnings about the two obsolete functions `foo'
and `bar', as well as the function `zot' being called with the
wrong number of parameters, say
\(with-suppressed-warnings ((obsolete foo bar)
(callargs zot))
(foo (bar))
(zot 1 2))
The warnings that can be suppressed are a subset of the warnings
in `byte-compile-warning-types'; see this variable for a fuller
explanation of the warning types. The types that can be
suppressed with this macro are `free-vars', `callargs',
`redefine', `obsolete', `interactive-only', `lexical', `mapcar',
`constants' and `suspicious'.
For the `mapcar' case, only the `mapcar' function can be used in
the symbol list. For `suspicious', only `set-buffer' can be used."
(declare (debug (sexp &optional body)) (indent 1))
;; The implementation for the interpreter is basically trivial.
`(progn ,@body))
(defun byte-run--unescaped-character-literals-warning ()
"Return a warning about unescaped character literals.