Subject: 31.0.50; Directory local variables not effective when loading Elisp file

From: Óscar Fuentes <[email-masked]>
Date: Fri, 13 Jun 2025 13:53:34 +0200

In ~/elisp/singles I created this .dir-locals.el file:

((nil
  . ((warning-suppress-log-types
      . '(missing-lexbind-cookie)))))

Then emacs -Q and eval this:

(load "~/elisp/singles/buffer-flip.el")

That file does not contain the lexical-binding cookie. The *Warnings*
file pops out:

  Warning (files): Missing ‘lexical-binding’ cookie in
  "~/elisp/singles/buffer-flip.el".

If I visit the file Emacs asks about applying .dir-locals ("The local
variables list in /home/oscar/elisp/singles or .dir-locals.el contains
values..."), press "y" and then C-h v warning-suppress-log-types

warning-suppress-log-types is a variable defined in ‘warnings.el’.

Its value is '((missing-lexbind-cookie))
Original value was nil
Local in buffer buffer-flip.el; global value is nil

It seems that .dir-locals.el is ignored when Emacs load files on the
directory.

I'm not sure it should, as asking for the user's permission when the
file is loaded (usually at start time) is quite inconvenient, and on
some scenarios there is no user present (--daemon)

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.18.4) of 2025-06-08 built on sky
Repository revision: f90cee6f761b0c2bffcfa64556284884c0f7348f
Repository branch: igc
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Debian GNU/Linux 13 (trixie)

Configured using:
 'configure 'CPPFLAGS=-O2 -fno-omit-frame-pointer -g3'
 CPPFLAGS=-I/home/oscar/dev/include/mps
 LDFLAGS=-L/home/oscar/dev/other/mps/code --with-native-compilation
 --with-tree-sitter --without-toolkit-scroll-bars --with-x-toolkit=lucid
 --with-modules --without-imagemagick --with-mps=yes'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBOTF
LIBSELINUX LIBSYSTEMD LIBXML2 MODULES MPS NATIVE_COMP NOTIFY INOTIFY
PDUMPER PNG SECCOMP SOUND SQLITE3 THREADS TIFF TREE_SITTER WEBP X11
XAW3D XDBE XIM XINERAMA XINPUT2 XPM XRANDR LUCID ZLIB