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 01:28:31 -0500 Message-ID: References: <87r0jrplx1.fsf@posteo.net> 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="2747"; 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 07:30:04 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 1rhOJP-0000Sq-L9 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Mar 2024 07:30:03 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhOIy-0004pE-9a; Tue, 05 Mar 2024 01:29:36 -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 1rhOIu-0004oS-Nc for bug-gnu-emacs@gnu.org; Tue, 05 Mar 2024 01:29: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 1rhOIu-0002Oe-C8 for bug-gnu-emacs@gnu.org; Tue, 05 Mar 2024 01:29:32 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rhOJO-00013L-19 for bug-gnu-emacs@gnu.org; Tue, 05 Mar 2024 01:30:02 -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 06:30: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.17096201523960 (code B ref 67795); Tue, 05 Mar 2024 06:30:01 +0000 Original-Received: (at 67795) by debbugs.gnu.org; 5 Mar 2024 06:29:12 +0000 Original-Received: from localhost ([127.0.0.1]:45844 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhOIa-00011l-5b for submit@debbugs.gnu.org; Tue, 05 Mar 2024 01:29:12 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:16944) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhOIX-00011W-Gf for 67795@debbugs.gnu.org; Tue, 05 Mar 2024 01:29:10 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 803F2100196; Tue, 5 Mar 2024 01:28:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1709620112; bh=qw8LNuSNX+TzpOD0EMOfYwn6WjL642uFybvkGdwOyhY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=R1kgF3Uef8yemRjj8qchNPvGnftZJwfc7vLs04gXXyJcr4siGM/ZLZVGcupwW6aRn R6dPO/sxpsogfnjM9HZwF41zoWiRq6ZGNtJrqbXC63oURMmIN8g7NxxSSzm/vuEVK0 aK1dcb8C21Nxe+dD3CZXjw2AJRND7HGwSApKpr1IOxkf9erXA6iPkmrJVs6FC2BZ0V f7sxh60LYPrzG5CC3QeJ/fZ+MPpzyWeiq9EtheI5qVXwkQoAFG8dP5Jk7GDWWu7C/0 j95WeoOL0Myg9vQMOOY4QIneJnyK2vFT7Eqrqi27CL91QBNd+nLYDaSlh7wLNwk3v/ 3qoRFfc2v5P+A== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7757010005D; Tue, 5 Mar 2024 01:28:32 -0500 (EST) Original-Received: from pastel (unknown [104.247.233.29]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5190F1201BF; Tue, 5 Mar 2024 01:28:32 -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:281031 Archived-At: OK, I had another look at the problem. For `hack-local-variables--find-variables` I still don't really understand why we need this (eq handle-mode t) functionality of the function, so maybe I missed a better way to fix the problem, but the proposed hunk looks OK, tho it need to be updated to account for recent changes in `master`. The new hunk would look like: @@ -4235,7 +4241,7 @@ hack-local-variables--find-variables (forward-line 1))))))) (if (eq handle-mode t) ;; Return the final mode: setting that's defined. - (car (seq-filter #'fboundp result)) + (car (seq-filter (lambda (mode) (fboundp (major-mode-remap mode))) result)) result))) (defun hack-local-variables-apply () Tho the code can be streamlined a bit so as not to create a list only to select its first element: @@ -4201,8 +4207,9 @@ hack-local-variables--find-variables (not (string-match "-minor\\'" (setq val2 (downcase (symbol-name val))))) - ;; Allow several mode: elements. - (push (intern (concat val2 "-mode")) result)) + (let ((mode (intern (concat val2 "-mode")))) + (when (fboundp (major-mode-remap mode)) + (setq result mode)))) (cond ((eq var 'coding)) ((eq var 'lexical-binding) (unless hack-local-variables--warned-lexical @@ -4233,10 +4240,7 @@ hack-local-variables--find-variables val) result)))))) (forward-line 1))))))) - (if (eq handle-mode t) - ;; Return the final mode: setting that's defined. - (car (seq-filter #'fboundp result)) - result))) + result)) (defun hack-local-variables-apply () "Apply the elements of `file-local-variables-alist'. Any comment/objection on this part? Stefan