From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs 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 Message-ID: References: <87zfkqtjgl.fsf@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20183"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Yikai Zhao , 74964@debbugs.gnu.org To: Robert Pluim Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 22 04:37:19 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tPCmM-000584-GE for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 22 Dec 2024 04:37:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPCm9-0002ek-Ny; Sat, 21 Dec 2024 22:37:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tPCm7-0002eO-1f for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 22:37:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPCm6-0005GW-PC for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 22:37:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=FjTGOqPPipZoqmxCXa4VTFxEimEJ3EYr3qdZ+qC681g=; b=ZEQUUsVONtYc2QflkBUMpVPJURT+uZ66Ilvf9uKESuUzs4V33RBx/oX0UwX4xMhPL6msuqmVNyj06NtC0g/7zUc6fxRZ/9jckslKmbzV2jbQUgNlua7Kc12VwBLdAek8BeTAi2DYbdgYanHnMC6bPexz5OQnWNKsu2pOg+ISU0e04k2TCwUo+2SmEhi76Mam03ndLny8duTff2gfbSVQ1hZmUdldXGexEInI3zlAYCshkXNyMnTprJDCz19LUgx1C0sxR5jM0CldzzTymWJjWhSagnnJYHQ2ey00I1ABAShiaA6RWYqXwZr7nL/0UOjPjjjuJ6ecOmvvcZebd1MTJg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tPCm5-0001BK-Kk for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 22:37:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Dec 2024 03:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74964 X-GNU-PR-Package: emacs Original-Received: via spool by 74964-submit@debbugs.gnu.org id=B74964.17348385804473 (code B ref 74964); Sun, 22 Dec 2024 03:37:01 +0000 Original-Received: (at 74964) by debbugs.gnu.org; 22 Dec 2024 03:36:20 +0000 Original-Received: from localhost ([127.0.0.1]:48608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPClP-0001A4-NN for submit@debbugs.gnu.org; Sat, 21 Dec 2024 22:36:20 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:20631) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPClN-00019j-8e for 74964@debbugs.gnu.org; Sat, 21 Dec 2024 22:36:18 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 7366C80834; Sat, 21 Dec 2024 22:36:10 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1734838569; bh=o1CzJtbdRHa/4tlUHKOyqO21gtu5HazFa1RigVeFBK8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=JXyXyFELohkhiN2+aiq14NndIqirOOplwuhNV5zs5llLyyXUN4kFy4z1VqqcUi8XH 86v5ny/qBEdoX1CRYOQij0428E4aJSsXsFjCmNMBs+v8BfQyPD9XsVwoONlpQ7AYH1 qNjeNggLBk6B/OBnGIO2Jr6l19YyvTZglW7NfB69VJGYWB2jtC/iP0mPKAAQZ13LCe tmg72f2rlQFXpG72v/vAdAS5c3g1XXDgILgrQgO37wJkMeroEIH9RQdpX9UB5Zhn5Z Ng2klMjvo+oV53i4wzIstIV8xL+h+Ui/BrF4clgd3alt0o0edX3KUJ0d8yF8zlosBe kJKUNAVqELDaA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 7E38A80039; Sat, 21 Dec 2024 22:36:09 -0500 (EST) Original-Received: from asado (unknown [199.119.74.1]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 3AFF71204C9; Sat, 21 Dec 2024 22:36:09 -0500 (EST) In-Reply-To: <87zfkqtjgl.fsf@gmail.com> (Robert Pluim's message of "Fri, 20 Dec 2024 17:20:10 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297569 Archived-At: >>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao 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)