all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
@ 2024-12-19  7:53 Yikai Zhao
  2024-12-20 16:20 ` Robert Pluim
  0 siblings, 1 reply; 7+ messages in thread
From: Yikai Zhao @ 2024-12-19  7:53 UTC (permalink / raw)
  To: 74964

How to reproduce:

With following content in /tmp/test/.dir-locals.el:

((nil . ((my/test . "test")))
 (c-mode . ((eval . (when (eq major-mode 'c-mode)
                      (c++-mode))))))
;; I use this code because I want my projects' .h files always opened
in c++ mode

Then open a new file test.c in the folder.

Expected behavior: my/test variable is set.
Actual behavior: my/test variable is not set.

Emacs 29 and 30 does give me the expected result.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
  2024-12-19  7:53 bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode Yikai Zhao
@ 2024-12-20 16:20 ` Robert Pluim
  2024-12-22  3:36   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Pluim @ 2024-12-20 16:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Yikai Zhao, 74964

>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao <yikai@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

    Yikai> Then open a new file test.c in the folder.

    Yikai> Expected behavior: my/test variable is set.
    Yikai> Actual behavior: my/test variable is not set.

    Yikai> Emacs 29 and 30 does give me the expected result.

Stefan, reverting f713258416f (Bug#74349) fixes this

Robert
-- 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
  2024-12-20 16:20 ` Robert Pluim
@ 2024-12-22  3:36   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2025-01-04 11:42     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-22  3:36 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Yikai Zhao, 74964

>>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao <yikai@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)






^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
  2024-12-22  3:36   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-01-04 11:42     ` Eli Zaretskii
  2025-01-05  8:02       ` Yikai Zhao
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2025-01-04 11:42 UTC (permalink / raw)
  To: Stefan Monnier, yikai; +Cc: rpluim, 74964

Ping!

> Cc: Yikai Zhao <yikai@z1k.dev>, 74964@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@gnu.org>
> 
> >>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao <yikai@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)
> 
> 
> 
> 
> 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
  2025-01-04 11:42     ` Eli Zaretskii
@ 2025-01-05  8:02       ` Yikai Zhao
  2025-01-05  9:11         ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Yikai Zhao @ 2025-01-05  8:02 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rpluim, 74964, Stefan Monnier

This patch does fix the issue for me. Thanks.

On Sat, Jan 4, 2025 at 7:42 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> Ping!
>
> > Cc: Yikai Zhao <yikai@z1k.dev>, 74964@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@gnu.org>
> >
> > >>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao <yikai@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)
> >
> >
> >
> >
> >





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
  2025-01-05  8:02       ` Yikai Zhao
@ 2025-01-05  9:11         ` Eli Zaretskii
  2025-01-05 15:05           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2025-01-05  9:11 UTC (permalink / raw)
  To: Yikai Zhao; +Cc: rpluim, 74964, monnier

> From: Yikai Zhao <yikai@z1k.dev>
> Date: Sun, 5 Jan 2025 16:02:06 +0800
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, rpluim@gmail.com, 74964@debbugs.gnu.org
> 
> This patch does fix the issue for me. Thanks.

Thanks for testing.  Stefan, please install, and thanks.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
  2025-01-05  9:11         ` Eli Zaretskii
@ 2025-01-05 15:05           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-01-05 15:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rpluim, Yikai Zhao, 74964-done

>> This patch does fix the issue for me. Thanks.

Thank you for confirming!

> Thanks for testing.  Stefan, please install, and thanks.

Closing,


        Stefan






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-05 15:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-19  7:53 bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode Yikai Zhao
2024-12-20 16:20 ` Robert Pluim
2024-12-22  3:36   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-01-04 11:42     ` Eli Zaretskii
2025-01-05  8:02       ` Yikai Zhao
2025-01-05  9:11         ` Eli Zaretskii
2025-01-05 15:05           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.