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: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, yikai <at> z1k.dev
Cc: rpluim <at> gmail.com, 74964 <at> debbugs.gnu.org
Subject: bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
Date: Sat, 04 Jan 2025 13:42:11 +0200
Ping!

> Cc: Yikai Zhao <yikai <at> z1k.dev>, 74964 <at> debbugs.gnu.org
> Date: Sat, 21 Dec 2024 22:36:07 -0500
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> >>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao <yikai <at> z1k.dev> said:
> >
> >     Yikai> How to reproduce:
> >     Yikai> With following content in /tmp/test/.dir-locals.el:
> >
> >     Yikai> ((nil . ((my/test . "test")))
> >     Yikai>  (c-mode . ((eval . (when (eq major-mode 'c-mode)
> >     Yikai>                       (c++-mode))))))
> >     Yikai> ;; I use this code because I want my projects' .h files always opened
> >     Yikai> in c++ mode
> 
> We need to offer our users a better solution than such a hack.
> E.g. a dir-local way to set `auto-mode-alist` and/or `major-mode-remap-alist`.
> 
> > Stefan, reverting f713258416f (Bug#74349) fixes this
> 
> How 'bout a patch like the one below?
> 
> 
>         Stefan
> 
> 
> diff --git a/lisp/files.el b/lisp/files.el
> index c92fc0608dd..594ee83efbe 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -4488,11 +4485,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.")
> +
>  (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)
>      ('mode
>       (let ((mode (intern (concat (downcase (symbol-name val))
>                                   "-mode"))))
> @@ -4500,7 +4501,8 @@ hack-one-local-variable
>      ('eval
>       (pcase val
>         (`(add-hook ',hook . ,_) (hack-one-local-variable--obsolete hook)))
> -     (let ((enable-local-variables nil)) ;FIXME: Should be buffer-local!
> +     (let ((hack-local-variables--inhibit ;; FIXME: Should be buffer-local!
> +            (cons 'eval hack-local-variables--inhibit)))
>         (save-excursion (eval val t))))
>      (_
>       (hack-one-local-variable--obsolete var)
> 
> 
> 
> 
> 




This bug report was last modified 122 days ago.

Previous Next


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