summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/byte-run.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/byte-run.el')
-rw-r--r--lisp/emacs-lisp/byte-run.el79
1 files changed, 74 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 3e9e0808b57..1115c096679 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -45,7 +45,10 @@ So far, FUNCTION can only be a symbol, not a lambda expression."
;; `macro-declaration-function' are both obsolete (as marked at the end of this
;; file) but used in many .elc files.
-(defvar macro-declaration-function #'macro-declaration-function
+;; We don't use #' here, because it's an obsolete function, and we
+;; can't use `with-suppressed-warnings' here due to how this file is
+;; used in the bootstrapping process.
+(defvar macro-declaration-function 'macro-declaration-function
"Function to process declarations in a macro definition.
The function will be called with two args MACRO and DECL.
MACRO is the name of the macro being defined.
@@ -116,7 +119,10 @@ If `error-free', drop calls even if `byte-compile-delete-errors' is nil.")
(if (not (eq (car-safe compiler-function) 'lambda))
`(eval-and-compile
(function-put ',f 'compiler-macro #',compiler-function))
- (let ((cfname (intern (concat (symbol-name f) "--anon-cmacro"))))
+ (let ((cfname (intern (concat (symbol-name f) "--anon-cmacro")))
+ ;; Avoid cadr/cddr so we can use `compiler-macro' before
+ ;; defining cadr/cddr.
+ (data (cdr compiler-function)))
`(progn
(eval-and-compile
(function-put ',f 'compiler-macro #',cfname))
@@ -125,8 +131,8 @@ If `error-free', drop calls even if `byte-compile-delete-errors' is nil.")
;; if needed.
:autoload-end
(eval-and-compile
- (defun ,cfname (,@(cadr compiler-function) ,@args)
- ,@(cddr compiler-function))))))))
+ (defun ,cfname (,@(car data) ,@args)
+ ,@(cdr data))))))))
(list 'doc-string
#'(lambda (f _args pos)
(list 'function-put (list 'quote f)
@@ -420,7 +426,7 @@ variable (this is due to the way `defvaralias' works).
If provided, WHEN should be a string indicating when the variable
was first made obsolete, for example a date or a release number.
-For the benefit of `custom-set-variables', if OBSOLETE-NAME has
+For the benefit of Customize, if OBSOLETE-NAME has
any of the following properties, they are copied to
CURRENT-NAME, if it does not already have them:
`saved-value', `saved-variable-comment'."
@@ -491,6 +497,69 @@ 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."
+ ;; Note: during compilation, this definition is overridden by the one in
+ ;; byte-compile-initial-macro-environment.
+ (declare (debug (sexp &optional 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))))
+
+(defun byte-run--unescaped-character-literals-warning ()
+ "Return a warning about unescaped character literals.
+If there were any unescaped character literals in the last form
+read, return an appropriate warning message as a string.
+Otherwise, return nil. For internal use only."
+ ;; This is called from lread.c and therefore needs to be preloaded.
+ (if lread--unescaped-character-literals
+ (let ((sorted (sort lread--unescaped-character-literals #'<)))
+ (format-message "unescaped character literals %s detected, %s expected!"
+ (mapconcat (lambda (char) (format "`?%c'" char))
+ sorted ", ")
+ (mapconcat (lambda (char) (format "`?\\%c'" char))
+ sorted ", ")))))
+
+(defun byte-compile-info-string (&rest args)
+ "Format ARGS in a way that looks pleasing in the compilation output."
+ (format " %-9s%s" "INFO" (apply #'format args)))
+
+(defun byte-compile-info-message (&rest args)
+ "Message format ARGS in a way that looks pleasing in the compilation output."
+ (message "%s" (apply #'byte-compile-info-string args)))
+
;; I nuked this because it's not a good idea for users to think of using it.
;; These options are a matter of installation preference, and have nothing to