From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yikai Zhao Newsgroups: gmane.emacs.bugs Subject: bug#74964: 31.0.50 master; .dir-locals.el vars does not work with changing major mode Date: Sun, 5 Jan 2025 16:02:06 +0800 Message-ID: References: <87zfkqtjgl.fsf@gmail.com> <86jzbaerfw.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39514"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rpluim@gmail.com, 74964@debbugs.gnu.org, Stefan Monnier To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 05 09:03:21 2025 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 1tULbV-000A9Q-2j for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Jan 2025 09:03:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tULbE-0001Qo-Qh; Sun, 05 Jan 2025 03:03:04 -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 1tULbC-0001QX-Mj for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 03:03:02 -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 1tULbC-0003KK-EF for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 03:03:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=PiVpZaQR7Id/BZAUr/yEmBGvqkM10CyhT3grjOmX8o0=; b=g0JR38ebxBqIqInDds5KLhs9qkTGYShNFinhHgPFj9yIohUbudZHoUhoXs1GkrWrgo5NhPMegeDbnaANDmWzcuf+eTYDqb0kH6Zx1bCxkWxtMiuJlRg6J0o1pvbNXQO4AYMJdoZCjW9IoVyZcbNsub+aZWABhzvTufBCCnZxKe6IyodtdjaeRkpm9Hc7a9dvVUA9xtRQDWj2sRa2SDywSB4mZN3AAXCkiKlMDhzT73n0Eq9940e02coxF0XWlHXD4M0eiUHf9oZ8riVN7YEjkwNLwmJbM2UGjUKue58V9ZFBBGyGvcIPw0D7UME+VLIsV1EAmROia8xaahN6KQB+vw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tULbC-0002q1-9j for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 03:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yikai Zhao Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Jan 2025 08:03:02 +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.173606414710842 (code B ref 74964); Sun, 05 Jan 2025 08:03:02 +0000 Original-Received: (at 74964) by debbugs.gnu.org; 5 Jan 2025 08:02:27 +0000 Original-Received: from localhost ([127.0.0.1]:59670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tULad-0002oo-0X for submit@debbugs.gnu.org; Sun, 05 Jan 2025 03:02:27 -0500 Original-Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:54349) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1tULaa-0002oF-0w for 74964@debbugs.gnu.org; Sun, 05 Jan 2025 03:02:25 -0500 Original-Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-436326dcb1cso88842555e9.0 for <74964@debbugs.gnu.org>; Sun, 05 Jan 2025 00:02:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=z1k.dev; s=google; t=1736064138; x=1736668938; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PiVpZaQR7Id/BZAUr/yEmBGvqkM10CyhT3grjOmX8o0=; b=cHAujG+xFtOOGPlDjMcRQLQFWtiWHhuWyGl6MYjy0Ap/mKmKqKo+ce05DZDHkb5+jH lmAf5oYuIoKrOIvAHeMFFQ/R9ZdbZumekV1iEyUSR0rw786+QFgpOlsjTo7xL0ZI3SwW YeQHaEwFDNV2KrbmfBnQaADWpqFPg479rYQwLdHc5UlbX8ygQgaH6g6jGf36FH8lksqk mWU5JkcH2k97jQdKFyb0oB8vkGe6GH0/lZmgflcwpmpK9/A8cOLFMoqssJQXfMFQSiPx oQA2k41elvIJmhUfmEOiRGm6hjmpTn5AlZ8fcSGk9lCw2X27p0utGGtv0HEUrLWjHyPa JoiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736064138; x=1736668938; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PiVpZaQR7Id/BZAUr/yEmBGvqkM10CyhT3grjOmX8o0=; b=u5C/PPTuax84t7t5EGErrFKKZ29ZAIcD+MrrJ/sFu2hR8SiHUw7uL82PCERAzVPc+D 4AvChmyVpGKjY3iIt8fuAD4FMXxhJOQ5SEOlSp+cjNacjSNBWInRbh8JVjGGCw3Z0LRE mFGwpc4E6NVLCi1JgV621bP/SJXbqx9aIP0XmZ+C0F2EqL5tdYHiwKul/nc3TsVAxaKN MDEyKd41OQcdET6jm2Lkr7UFPA8LpapBhuHk007kzTkmPDdQ+ogahxrlzJmnwisXpEct rrkbtZ4itkByRB1dKd16RMPKT1r/B/LSA+C06x2EbVRy7wI/tFotjvSUDns6Hn0yW1+s NYUA== X-Forwarded-Encrypted: i=1; AJvYcCXmOzI9YiD7T/Fe/tLVA46AxU4/nyscfIiXSGhWszwPNDr8JARHlXgqczv9obeNariXWXS5tg==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwXVsp7noB8yGYEaERYBV+NCRVu50pEtOWnzRJTLCD9pnXJmxT2 eYzLez5UBtUwlOmnlstWNNK+rbb9KjyyGx03zxggFS1b1dnQ0eGG4YIoBJWco9ct18M8ZKwyvr+ TbwXXGWR5El/KM15zxUOzhP7tjJlhnflJ6mDYSg== X-Gm-Gg: ASbGncsBimjUbXNwB2e/4LzF/ukjsN/n0re6IctY6L+EAk8oZlZDkMAqpgxmX/z6m5J TwxxQd2Rja9ovfF4Hb76l/xjCyEZhqEN34eOtrEgLxvtrH7qxhFLsr8e5lVLUPGKhNUZGStxM X-Google-Smtp-Source: AGHT+IHpn1OfT1yl7hLnWm479igeTLB2715SW1n3yhFRGvt8TedFyNKAsfPYKEhA0GB75W5Anj3m5nEdKHtUD67pXy8= X-Received: by 2002:a05:600c:3b9d:b0:436:6160:5b81 with SMTP id 5b1f17b1804b1-43668643bd7mr456601125e9.14.1736064137799; Sun, 05 Jan 2025 00:02:17 -0800 (PST) In-Reply-To: <86jzbaerfw.fsf@gnu.org> 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:298510 Archived-At: This patch does fix the issue for me. Thanks. On Sat, Jan 4, 2025 at 7:42=E2=80=AFPM Eli Zaretskii wrote: > > Ping! > > > Cc: Yikai Zhao , 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" > > > > >>>>>> On Thu, 19 Dec 2024 15:53:58 +0800, Yikai Zhao s= aid: > > > > > > 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 al= ways 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 hoo= k))) > > - (let ((enable-local-variables nil)) ;FIXME: Should be buffer-loca= l! > > + (let ((hack-local-variables--inhibit ;; FIXME: Should be buffer-l= ocal! > > + (cons 'eval hack-local-variables--inhibit))) > > (save-excursion (eval val t)))) > > (_ > > (hack-one-local-variable--obsolete var) > > > > > > > > > >