[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Towards a cleaner build
From: |
Lars Ingebrigtsen |
Subject: |
Re: Towards a cleaner build |
Date: |
Sat, 18 May 2019 08:45:08 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
>> So if we want to go this direction it looks like it can be done in a
>> pretty clean fashion.
>
> Pretty please?
I made a proof of concept thing by just cargo-culting the code for
with-no-warnings, and it works!
I used the ehelp.el warning to test with
(with-suppressed-warnings ((interactive-only execute-extended-command))
(setq electric-help-form-to-execute
(lambda () (execute-extended-command nil))))
and now it compiles cleanly and even seems to work!? Both interactively
and byte-compiled, although more testing is required.
There's some details in the interface that could be bike-shedded... for
instance, how often do we need several things suppressed at once? If we
limit it to one thing at a time, then we lose one set of parentheses:
(with-suppressed-warnings (interactive-only execute-extended-command)
...)
In the rare cases you need more, you can say
(with-suppressed-warnings (obsolete something-else)
(with-suppressed-warnings (interactive-only execute-extended-command)
...))
You can also either just allow one symbol to be suppressed per warning
type, or more, and the implementation supports the latter, so you can
say:
(with-suppressed-warnings ((obsolete something something-else))
...)
I think that makes sense, and it doesn't add more (or less) visual
clutter..
Eli, what do you think? Is `with-suppressed-warnings' something you can
see Emacs having? If so, I can finish it up and write some
documentation...
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 842d1d48b4..9a9d93367b 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -494,6 +494,18 @@ with-no-warnings
;; 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 e76baf5ed0..1285ef9037 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -331,18 +331,26 @@ byte-compile-warnings
,@(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)
@@ -2518,6 +2526,15 @@ byte-compile-file-form-with-no-warnings
(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)
@@ -3150,7 +3167,7 @@ byte-compile-form
(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
@@ -4765,6 +4782,14 @@ byte-compile-no-warnings
(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)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
- Re: Towards a cleaner build, (continued)
- Re: Towards a cleaner build, Stefan Monnier, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Eli Zaretskii, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Eli Zaretskii, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Noam Postavsky, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Stefan Monnier, 2019/05/17
- Re: Towards a cleaner build,
Lars Ingebrigtsen <=
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/17
- Re: Towards a cleaner build, Noam Postavsky, 2019/05/27
- Re: Towards a cleaner build, Lars Ingebrigtsen, 2019/05/28
- Re: Towards a cleaner build, Noam Postavsky, 2019/05/28