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#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode Date: Tue, 05 Mar 2024 02:01:25 -0500 Message-ID: References: <87r0jrplx1.fsf@posteo.net> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19198"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 67795@debbugs.gnu.org To: Brian Leung Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 05 08:02:53 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 1rhOpA-0004dk-H4 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Mar 2024 08:02:52 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhOos-0003F5-D3; Tue, 05 Mar 2024 02:02:34 -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 1rhOoq-0003E9-I1 for bug-gnu-emacs@gnu.org; Tue, 05 Mar 2024 02:02:32 -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 1rhOoq-00088u-8V for bug-gnu-emacs@gnu.org; Tue, 05 Mar 2024 02:02:32 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rhOpJ-00022W-SR for bug-gnu-emacs@gnu.org; Tue, 05 Mar 2024 02:03: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: Tue, 05 Mar 2024 07:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67795 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 67795-submit@debbugs.gnu.org id=B67795.17096221327782 (code B ref 67795); Tue, 05 Mar 2024 07:03:01 +0000 Original-Received: (at 67795) by debbugs.gnu.org; 5 Mar 2024 07:02:12 +0000 Original-Received: from localhost ([127.0.0.1]:45880 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhOoV-00021S-Pp for submit@debbugs.gnu.org; Tue, 05 Mar 2024 02:02:12 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:62107) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhOoT-00021E-Bs for 67795@debbugs.gnu.org; Tue, 05 Mar 2024 02:02:10 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 679B0100196; Tue, 5 Mar 2024 02:01:32 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1709622087; bh=u3Davw2eQC+cvzay576GUZq81L08ANRxxPJOnIatL7o=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=XQCg0/Zn56Be2G2fzzOTUNfbi8lnYQr3ktk2dyOJCxN6669bMcZm92v1uYalm/N+R BbSbt41MzvwkoTz7/oTLKDrg2RDoSzYYUc/c7wnHcY5reUpfNOT6qDxohUiQY1CFt3 5UrjqZ9on3auUzumF9GPk/8nXCw2u3k6S25+gH+I8ajNPJ3EZEdSqc7D+//q481DFj p9J116Cw8Z440kDEcOnYmsKwAprAZDh3bUfcLDgzj5Qgzm3OYQpz7UTSGvjqLEIaxQ AwwbW+LOxG9QoiQzoaStP7NurR2peI1EBfl8o9wu1gKyFFS4HpSKcmZZHnOU4XgQ+X ZC6m99c65kg0Q== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 29EF01000D6; Tue, 5 Mar 2024 02:01:27 -0500 (EST) Original-Received: from pastel (unknown [104.247.233.29]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 07F531200A1; Tue, 5 Mar 2024 02:01:27 -0500 (EST) In-Reply-To: <87r0jrplx1.fsf@posteo.net> (Brian Leung's message of "Tue, 12 Dec 2023 13:52:53 +0000") 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:281033 Archived-At: --=-=-= Content-Type: text/plain I also had time to look at the first hunk, and the "good start" I proposed wasn't right. The patch below should be much more than just a "good start", because I think I got to understand the code this time around :-) The previous code worked OK but was inconsistent in its handling of modes that we don't have (i.e. is non-existent). When `set-auto-mode` does is go through a list of potential candidates and uses the first one that can be used. For each candidates, there are several possibilities: A. This is the major mode already activated and `keep-mode-if-same` is set, so we should do nothing *AND* we should stop right here. B. The candidate is nil (absent) or is a function we don't have. We should skip it and try further candidates. This was done for some candidates but not all. C. The candidate exists: activate it. So I changed `set-auto-mode-0` to handle B (and return nil in that case) so that B work consistently for all the candidates and so that the `functionp` test is applied after remapping rather than before. But nil was the value returned for A, so I changed that to `:keep`, so it can be distinguished from B and C. Then I massaged the `set-auto-mode` code so as to call `set-auto-mode-0` according to these new rules, which arguably makes the code a bit simpler (instead of using a `done` variable that we constantly set and then test, it's just one big `or` where each arm returns the equivalent of `done`). Stefan * lisp/files.el (set-auto-mode-0): Return `:keep` rather than nil if the mode is already set and we decided to keep it. Skip the mode (and return nil) if its function (after remapping) is missing. (set-auto-mode): Don't test `functionp` any more since `set-auto-mode-0` does it for us now. Restructure the code to account for the new behavior of `set-auto-mode-0`, mostly by replacing the `done` variable with a big `or`. (hack-local-variables--find-variables): Simplify the (eq handle-mode t) code so we don't bother building a list, and make it test the remapped function rather than the mode name instead. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=files.patch --=-=-=--