emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/with-suppressed-warnings b68f207 1/2: Initial impl


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] scratch/with-suppressed-warnings b68f207 1/2: Initial implementation
Date: Sun, 9 Jun 2019 09:52:39 -0400 (EDT)

branch: scratch/with-suppressed-warnings
commit b68f207b8d13cfef7ceaafbc1ec5dd9d0a5bd2cf
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Initial implementation
---
 lisp/emacs-lisp/byte-run.el | 12 ++++++++++++
 lisp/emacs-lisp/bytecomp.el | 37 +++++++++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 842d1d4..9a9d933 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -494,6 +494,18 @@ 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 the body."
+  (declare (indent 1))
+  ;; The implementation for the interpreter is basically trivial.
+  `(with-suppressed-warnings-1 ',warnings (progn ,@body)))
+
+(defun with-suppressed-warnings-1 (_ &rest body)
+  "Like `progn', but prevents compiler warnings in the body."
+  (declare (indent 1))
+  ;; The implementation for the interpreter is basically trivial.
+  (car (last body)))
+
 
 (defun byte-run--unescaped-character-literals-warning ()
   "Return a warning about unescaped character literals.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 38cce14..4d14327 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -331,18 +331,26 @@ suppress.  For example, (not mapcar) will suppress 
warnings about mapcar."
                       ,@(mapcar (lambda (x) `(const ,x))
                                 byte-compile-warning-types))))
 
+(defvar byte-compile-suppressed-warnings nil)
+
 ;;;###autoload
 (put 'byte-compile-warnings 'safe-local-variable
      (lambda (v)
        (or (symbolp v)
            (null (delq nil (mapcar (lambda (x) (not (symbolp x))) v))))))
 
-(defun byte-compile-warning-enabled-p (warning)
+(defun byte-compile-warning-enabled-p (warning &optional symbol)
   "Return non-nil if WARNING is enabled, according to `byte-compile-warnings'."
-  (or (eq byte-compile-warnings t)
-      (if (eq (car byte-compile-warnings) 'not)
-          (not (memq warning byte-compile-warnings))
-        (memq warning byte-compile-warnings))))
+  (let ((suppress nil))
+    (dolist (elem byte-compile-suppressed-warnings)
+      (when (and (eq (car elem) warning)
+                 (memq symbol (cdr elem)))
+        (setq suppress t)))
+    (and (not suppress)
+         (or (eq byte-compile-warnings t)
+             (if (eq (car byte-compile-warnings) 'not)
+                 (not (memq warning byte-compile-warnings))
+               (memq warning byte-compile-warnings))))))
 
 ;;;###autoload
 (defun byte-compile-disable-warning (warning)
@@ -2520,6 +2528,15 @@ list that represents a doc string reference.
     (mapc 'byte-compile-file-form (cdr form))
     nil))
 
+(put 'with-suppressed-warnings-1 'byte-hunk-handler
+     'byte-compile-file-form-with-suppressed-warnings)
+(defun byte-compile-file-form-with-suppressed-warnings (form)
+  ;; cf byte-compile-file-form-progn.
+  (let ((byte-compile-suppressed-warnings
+         (append (cadadr form) byte-compile-suppressed-warnings)))
+    (mapc 'byte-compile-file-form (cddr form))
+    nil))
+
 ;; Automatically evaluate define-obsolete-function-alias etc at top-level.
 (put 'make-obsolete 'byte-hunk-handler 'byte-compile-file-form-make-obsolete)
 (defun byte-compile-file-form-make-obsolete (form)
@@ -3152,7 +3169,7 @@ for symbols generated by the byte compiler itself."
         (when (and (byte-compile-warning-enabled-p 'suspicious)
                    (macroexp--const-symbol-p fn))
           (byte-compile-warn "`%s' called as a function" fn))
-       (when (and (byte-compile-warning-enabled-p 'interactive-only)
+       (when (and (byte-compile-warning-enabled-p 'interactive-only fn)
                   interactive-only)
          (byte-compile-warn "`%s' is for interactive use only%s"
                             fn
@@ -4766,6 +4783,14 @@ binding slots have been popped."
   (let (byte-compile-warnings)
     (byte-compile-form (cons 'progn (cdr form)))))
 
+(byte-defop-compiler-1 with-suppressed-warnings-1
+                       byte-compile-suppressed-warnings)
+(defun byte-compile-suppressed-warnings (form)
+  (let ((byte-compile-suppressed-warnings
+         (append (cadadr form) byte-compile-suppressed-warnings)))
+    (mapc 'byte-compile-file-form (cddr form))
+    nil))
+
 ;; Warn about misuses of make-variable-buffer-local.
 (byte-defop-compiler-1 make-variable-buffer-local
                        byte-compile-make-variable-buffer-local)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]