From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Robert Pluim <rpluim@gmail.com>
Cc: Yikai Zhao <yikai@z1k.dev>, 74964@debbugs.gnu.org
Subject: bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode
Date: Sat, 21 Dec 2024 22:36:07 -0500 [thread overview]
Message-ID: <jwvy108bdfm.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87zfkqtjgl.fsf@gmail.com> (Robert Pluim's message of "Fri, 20 Dec 2024 17:20:10 +0100")
>>>>>> 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)
prev parent reply other threads:[~2024-12-22 3:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvy108bdfm.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=74964@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=rpluim@gmail.com \
--cc=yikai@z1k.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).