Function: with-suppressed-warnings

with-suppressed-warnings is a macro defined in byte-run.el.gz.

Signature

(with-suppressed-warnings WARNINGS &rest BODY)

Documentation

Like progn, but prevents compiler WARNINGS in BODY.

WARNINGS is an association 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 the variable byte-compile-warnings 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, ignored-return-value, constants, suspicious, empty-body and mutate-constant.

View in manual

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/byte-run.el.gz
(defmacro with-suppressed-warnings (warnings &rest body)
  "Like `progn', but prevents compiler WARNINGS in BODY.

WARNINGS is an association 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 the variable
`byte-compile-warnings' 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', `ignored-return-value', `constants',
`suspicious', `empty-body' and `mutate-constant'."
  ;; Note: during compilation, this definition is overridden by the one in
  ;; byte-compile-initial-macro-environment.
  (declare (debug (sexp body)) (indent 1))
  (if (not (and (featurep 'macroexp)
                (boundp 'byte-compile--suppressed-warnings)))
      ;; If `macroexp' is not yet loaded, we're in the middle of
      ;; bootstrapping, so better risk emitting too many warnings
      ;; than risk breaking the bootstrap.
      `(progn ,@body)
    ;; We need to let-bind byte-compile--suppressed-warnings here, so as to
    ;; silence warnings emitted during macro-expansion performed outside of
    ;; byte-compilation.
    (let ((byte-compile--suppressed-warnings
           (append warnings byte-compile--suppressed-warnings)))
      (macroexpand-all (macroexp-progn body)
                       macroexpand-all-environment))))