Subject: Re: bug#55811: 29.0.50; No flymake diagnostics for no-byte-compile files

From: João Távora <[email-masked]>
Date: Tue, 07 Jun 2022 13:02:41 +0100

Stefan Monnier <[email-masked]> writes:

>> Of course you know this -- but just to clarify -- the byte-compilation
>> backend works by launching a Emacs -Q which is asked to byte-compile
>> only a file containing the current buffer's contents.  During that
>> byte-compilation nothing more is loaded apart from what is preloaded or
>> explicitly loaded by the file at compile-time (via require or
>> eval-when/and-compile stuff).
>
> This bug-report is about the fact that there is no benefit to
> obeying `no-byte-compile` in flymake.  Not about improving the way the
> sub-process reproduces a "good" initial state to compile the file
> (e.g. set up of `load-path` and whatnot).

Sure, I understood.  I was just commenting on the fact that the quality
of Flymake diagnostics might not be so good/helpful since those
diagnostics are likely affected by the same root causes that prevent
normal byte compilation anyway.

( Also, on the tangent note about load-path and Flymake, I completely
forgot that I added elisp-flymake-byte-compile-load-path some 4 years
ago.)

>> Anyway, maybe you could give small example of such a file containing
>> such a cookie where you think Flymake's "I refuse to lint this" behavior
>> could be improved.
>
> A good example are all the files in the
> [EEV](http://elpa.gnu.org/packages/eev.html) package.

OK.  Try this "100% untested patch" (TM) then:

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 70826b4c3a..b99007c938 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -2152,7 +2152,9 @@ elisp-flymake--batch-compile-for-flymake
                   collected)
             t)))
     (unwind-protect
-        (byte-compile-file file)
+        (progn
+          (setq-local no-byte-compile nil)
+          (byte-compile-file file))
       (ignore-errors
         (kill-buffer byte-compile-log-buffer)))
     (prin1 :elisp-flymake-output-start)