Subject: bug#67920: 30.0.50; "*Compile-Log" is not `compilation-mode' if `byte-compile-file' found "no lexical-binding"

From: Eli Zaretskii <[email-masked]>
Date: Thu, 21 Dec 2023 15:07:15 +0200

> From: OGAWA Hirofumi <[email-masked]>
> Date: Wed, 20 Dec 2023 15:43:25 +0900
> 
> 
> `byte-compile-file' in current master branch behaves strange if the file
> is not including "-*- lexical-binding: t; -*-" mark.
> 
> (progn
>   (with-temp-file "foo.el" ())
>   (byte-compile-file "foo.el"))
> 
> The above code outputs to "*Compile-Log" with `special-mode' like following
> 
> 	In toplevel form:
> 	foo.el:1:1: Warning: file has no ‘lexical-binding’ directive on its first
> 	    line
> 
> If there is "-*- lexical-binding: t; -*-" mark in the file,
> "*Compile-Log*" is with `compilation-mode' as expected.

Mattias, this seems to be due to your change in commit a3db503351e:
the call to byte-compile-warn-x you added there logs a warning too
early, which has two adverse effects: (a) the compilation directory is
not logged as the directory of the file being compiled (Emacs thinks
it's the original directory where Emacs was started), and (b) the
value of byte-compile-last-logged-file is set to the name of the file
being compiled, which then defeats the logic in byte-compile-log-file
of turning on emacs-lisp-compilation-mode in the log buffer.

Could you please look into this?