GNU bug report logs - #74964
31.0.50 master; .dir-locals.el vars does not work with changing major mode

Previous Next

Package: emacs;

Reported by: Yikai Zhao <yikai <at> z1k.dev>

Date: Thu, 19 Dec 2024 07:55:02 UTC

Severity: normal

Found in version 31.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Yikai Zhao <yikai <at> z1k.dev>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 74964 <at> debbugs.gnu.org, rpluim <at> gmail.com, 74964-done <at> debbugs.gnu.org
Subject: bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
Date: Thu, 16 Jan 2025 23:34:34 -0500
[Message part 1 (text/plain, inline)]
> ((nil . ((my/test . "test")
>          (eval . (setq-local my/test2 "test2"))))
>  (c-mode . ((eval . (when (eq major-mode 'c-mode)
>                       (c++-mode))))))

[ Sigh!  This is starting to make me remember the ugly hacks I added to
  try and avoid inf-loops in my type checker.  ]

How 'bout the patch below?


        Stefan
[files.patch (text/x-diff, inline)]
diff --git a/lisp/files.el b/lisp/files.el
index e9f69fcd33c..9981e7083c3 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4490,15 +4490,15 @@ hack-one-local-variable--obsolete
                      (substitute-command-keys instead)
                    (format-message "use `%s' instead" instead)))))))
 
-(defvar hack-local-variables--inhibit nil
-  "List of file/dir local variables to ignore.")
+(defvar hack-local-variables--inhibit-eval nil
+  "List of `eval' forms to ignore in file/dir local variables.")
 
 (defun hack-one-local-variable (var val)
   "Set local variable VAR with value VAL.
 If VAR is `mode', call `VAL-mode' as a function unless it's
 already the major mode."
   (pcase var
-    ((guard (memq var hack-local-variables--inhibit)) nil)
+    ((and 'eval (guard (memq val hack-local-variables--inhibit-eval))) nil)
     ('mode
      (let ((mode (intern (concat (downcase (symbol-name val))
                                  "-mode"))))
@@ -4506,8 +4506,8 @@ hack-one-local-variable
     ('eval
      (pcase val
        (`(add-hook ',hook . ,_) (hack-one-local-variable--obsolete hook)))
-     (let ((hack-local-variables--inhibit ;; FIXME: Should be buffer-local!
-            (cons 'eval hack-local-variables--inhibit)))
+     (let ((hack-local-variables--inhibit-eval ;; FIXME: Should be buffer-local!
+            (cons val hack-local-variables--inhibit-eval)))
        (save-excursion (eval val t))))
     (_
      (hack-one-local-variable--obsolete var)

This bug report was last modified 123 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.