From unknown Sat Jun 14 18:52:45 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#67795 <67795@debbugs.gnu.org> To: bug#67795 <67795@debbugs.gnu.org> Subject: Status: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode Reply-To: bug#67795 <67795@debbugs.gnu.org> Date: Sun, 15 Jun 2025 01:52:45 +0000 retitle 67795 [PATCH] Handle local-variable major-mode remaps specifying no= n-existent mode reassign 67795 emacs submitter 67795 Brian Leung severity 67795 normal tag 67795 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 12 08:53:48 2023 Received: (at submit) by debbugs.gnu.org; 12 Dec 2023 13:53:48 +0000 Received: from localhost ([127.0.0.1]:55580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD3Cl-0005SP-L8 for submit@debbugs.gnu.org; Tue, 12 Dec 2023 08:53:48 -0500 Received: from lists.gnu.org ([2001:470:142::17]:37118) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD3Ck-0005SB-Aq for submit@debbugs.gnu.org; Tue, 12 Dec 2023 08:53:46 -0500 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 1rD3CP-0006TQ-LE for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 08:53:25 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rD3CN-0007x7-Ld for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2023 08:53:25 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 6943D240101 for ; Tue, 12 Dec 2023 14:53:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1702389198; bh=AvfXDnYl0YAaFnvFAmRvC8VqpCMFjQEg2xtNp3w1qHU=; h=From:To:Subject:Date:Message-ID:MIME-Version:From; b=Kn5VsYgehWrX7rDcCf4bSh4wUYsDVBsxXJfcssyKbGLhBpJfklem3CgiH28iSE0RU 0oSIsvu1Tf6LHhdLP2vZyqj8whIdstbowSHljEkPNJJ146S0iGEek5djEH5fMbzu73 Hf5maFkrMiOYijFT2/topWr5gKoNWKuHniPQ3keThH6M4Rul/7fIYJJKZsJVaGX3uo DT1l8RS0QxyKhHAPBgRJ+RqP9hPjZXLnpgMXK8r8ncnQAs2mJrhXfZXABbAhvJG8yB Enp4qzgmIYkHYUEULKMA4yJ/FMJ5DZBFpf7VCg7++1T+FnMvbt4w/QyMZsK5P61gom t2izfUZ8yDJNA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SqKnn49XYz6twM for ; Tue, 12 Dec 2023 14:53:17 +0100 (CET) From: Brian Leung To: bug-gnu-emacs@gnu.org Subject: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode Date: Tue, 12 Dec 2023 13:52:53 +0000 Message-ID: <87r0jrplx1.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=leungbk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain; format=flowed Tags: patch In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.0, Xaw3d scroll bars) Repository revision: 9434ad25ce2747864e0bcf5665f65eb65a079178 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101009 System Description: NixOS 24.05 (Uakari) Configured using: 'configure --prefix=/nix/store/q131p42vldq964fr9rpdz1qmsqrywa00-emacs-git-20231211.0 --disable-build-details --with-modules --with-x-toolkit=lucid --with-xft --with-cairo --with-compress-install --with-toolkit-scroll-bars --with-native-compilation --without-imagemagick --without-small-ja-dic --with-tree-sitter --without-xinput2 --without-xwidgets' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Handle-local-variable-major-mode-remaps-specifying-n.patch >From 46435cac589506ecb131f480171a2ec1f0f03c55 Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Tue, 12 Dec 2023 05:42:56 -0800 Subject: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode In the .clang-format file of current Emacs HEAD, the major mode is specified as yaml-mode via a local variable. However, a user who has loaded yaml-ts-mode and executed (add-to-list 'major-mode-remap-alist '(yaml-mode . yaml-ts-mode) but does not have yaml-mode defined will find that opening the .clang-format file does not use yaml-ts-mode. This patch fixes that. * lisp/files.el (set-auto-mode): Check for any remapping specified in major-mode-remap-alist. (hack-local-variables--find-variables): Same. --- lisp/files.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index f87e7807301..8e92da6d49d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3445,7 +3445,7 @@ set-auto-mode (and (not done) (setq mode (hack-local-variables t (not try-locals))) (not (memq mode modes)) ; already tried and failed - (if (not (functionp mode)) + (if (not (functionp (alist-get mode major-mode-remap-alist mode))) (message "Ignoring unknown mode `%s'" mode) (setq done t) (set-auto-mode-0 mode keep-mode-if-same))) @@ -4182,7 +4182,9 @@ 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)) + (seq-find (lambda (mode) + (fboundp (alist-get mode major-mode-remap-alist mode))) + result) result))) (defun hack-local-variables-apply () -- 2.42.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 12 09:06:00 2023 Received: (at 67795) by debbugs.gnu.org; 12 Dec 2023 14:06:00 +0000 Received: from localhost ([127.0.0.1]:55587 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD3Oa-0005lg-2L for submit@debbugs.gnu.org; Tue, 12 Dec 2023 09:06:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34746) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD3OU-0005lM-Va for 67795@debbugs.gnu.org; Tue, 12 Dec 2023 09:05:58 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rD3O8-0004AE-Dt; Tue, 12 Dec 2023 09:05:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=J3ZjhxCXvmSdWYtJ7cigzv8Kn8tJ2Hrcv4CE9tsBYxQ=; b=AcZgej+S98Pg Jxcbvuv52Mni1EzEQZE9Q1mcG4fQvBJEEAtp3364gTili78qfrikXRyFWCHM4BW3fUZ8+DExIATE1 d+4ENmPQxce3rIyDAzltJTgKyQSDR556NIM2Vajwwt9XQ3eQgP6q4a1Blp6arVWIAO2v8CBKqEAut x5lDaoxeETGypJ+IBSS7/2aTSbvBxchM1Uch3IsX5flaPqwGJ49PIqAnv5r3GqRiSb+TI6V0k8bZr /bYnq4PACUMrqNWmu975l8MBrAlXKCUi5BZOv1pFJ8hoqojPyNzlCuc0M6Ivt24cywpzxu+iX0yV0 xSsBotn3IpZVYwzDVsZmoA==; Date: Tue, 12 Dec 2023 16:04:55 +0200 Message-Id: <83plzbtt2w.fsf@gnu.org> From: Eli Zaretskii To: Brian Leung , Stefan Monnier In-Reply-To: <87r0jrplx1.fsf@posteo.net> (message from Brian Leung on Tue, 12 Dec 2023 13:52:53 +0000) Subject: Re: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode References: <87r0jrplx1.fsf@posteo.net> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67795 Cc: 67795@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Brian Leung > Date: Tue, 12 Dec 2023 13:52:53 +0000 > > >From 46435cac589506ecb131f480171a2ec1f0f03c55 Mon Sep 17 00:00:00 2001 > From: Brian Leung > Date: Tue, 12 Dec 2023 05:42:56 -0800 > Subject: [PATCH] Handle local-variable major-mode remaps specifying > non-existent mode > > In the .clang-format file of current Emacs HEAD, the major mode is > specified as yaml-mode via a local variable. However, a user who has > loaded yaml-ts-mode and executed > > (add-to-list 'major-mode-remap-alist '(yaml-mode . yaml-ts-mode) > > but does not have yaml-mode defined will find that opening the > .clang-format file does not use yaml-ts-mode. > > This patch fixes that. Thanks, but if we want to integrate major-mode-remap-alist better, I'd rather we did that in some lower-level place, so that we wouldn't need to sprinkle these alist-get calls all over Emacs. Also, if we do this, there will be no way for specifying a particular mode in file-local variables. Do we really want that? Stefan, WDYT? From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 12 11:03:09 2023 Received: (at 67795) by debbugs.gnu.org; 12 Dec 2023 16:03:09 +0000 Received: from localhost ([127.0.0.1]:57295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD5Dw-00011a-O6 for submit@debbugs.gnu.org; Tue, 12 Dec 2023 11:03:09 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:32376) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD5Dv-000112-Aq for 67795@debbugs.gnu.org; Tue, 12 Dec 2023 11:03:07 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 7AB8544473B; Tue, 12 Dec 2023 11:02:46 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1702396964; bh=SQzfsTHyCsb/+4+DdqP8IQGDEy0c/EH05tePNGPXZBA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=SuhctnhXc3velL8DdVaxWlRR8b38d2e92iHuJitFa3xqO/YthOBMCdAwvuaR0yYvI ie40taZ5C0sbfONBoy1ZHghrcnT6f5g+bi+qaEyqU8J0NrtcWBRYSvS8wpRXnJ4eKj Io/k/XCvTyQFbM7hZm97DV4RCBDnCB5JMovX1F2HYwbWxXeYc5VN4U9Raj8yl/tT8Z kdx1hEhotnbzXO5u/d+e2MzGdpofL7kJ1P5dsK+J4A67uhkNwOmN+1WQt6DEVyP4eT kF2RiAIeJ75cGw0bXV0cH+zKRMt1FRpj7Gob9eylT3xhNkRRwSEeTTnP/gEKLcIrxc sHQs5Qa7rK9Hw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C640D444738; Tue, 12 Dec 2023 11:02:44 -0500 (EST) Received: from pastel (unknown [45.72.203.88]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 9E826120370; Tue, 12 Dec 2023 11:02:44 -0500 (EST) From: Stefan Monnier To: Eli Zaretskii Subject: Re: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode In-Reply-To: <83plzbtt2w.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 12 Dec 2023 16:04:55 +0200") Message-ID: References: <87r0jrplx1.fsf@posteo.net> <83plzbtt2w.fsf@gnu.org> Date: Tue, 12 Dec 2023 11:02:43 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.026 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67795 Cc: Brian Leung , 67795@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain > Thanks, but if we want to integrate major-mode-remap-alist better, I'd > rather we did that in some lower-level place, so that we wouldn't need > to sprinkle these alist-get calls all over Emacs. > > Also, if we do this, there will be no way for specifying a particular > mode in file-local variables. Do we really want that? > > Stefan, WDYT? I agree that we should try to keep it in "one place", but I don't think it can be done right now without some code reorganization :-( I can't wrap my head around what `hack-local-variables--find-variables` is supposed to do, but for the other part of the change, maybe the patch below is a good start? Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=mode-remap.patch diff --git a/lisp/files.el b/lisp/files.el index f87e7807301..1935e4dbb4b 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3428,12 +3451,9 @@ set-auto-mode (if modes (catch 'nop (dolist (mode (nreverse modes)) - (if (not (functionp mode)) - (message "Ignoring unknown mode `%s'" mode) - (setq done t) - (or (set-auto-mode-0 mode keep-mode-if-same) - ;; continuing would call minor modes again, toggling them off - (throw 'nop nil)))))) + (or (setq done (set-auto-mode-0 mode keep-mode-if-same)) + ;; continuing would call minor modes again, toggling them off + (throw 'nop nil))))) ;; Check for auto-mode-alist entry in dir-locals. (unless done (with-demoted-errors "Directory-local variables error: %s" @@ -3445,10 +3465,7 @@ set-auto-mode (and (not done) (setq mode (hack-local-variables t (not try-locals))) (not (memq mode modes)) ; already tried and failed - (if (not (functionp mode)) - (message "Ignoring unknown mode `%s'" mode) - (setq done t) - (set-auto-mode-0 mode keep-mode-if-same))) + (setq done (set-auto-mode-0 mode keep-mode-if-same))) ;; If we didn't, look for an interpreter specified in the first line. ;; As a special case, allow for things like "#!/bin/env perl", which ;; finds the interpreter anywhere in $PATH. @@ -3490,7 +3507,7 @@ set-auto-mode (error "Problem in magic-mode-alist with element %s" re)))))))) - (set-auto-mode-0 done keep-mode-if-same))) + (setq done (set-auto-mode-0 done keep-mode-if-same)))) ;; Next compare the filename against the entries in auto-mode-alist. (unless done (setq done (set-auto-mode--apply-alist auto-mode-alist @@ -3515,7 +3532,7 @@ set-auto-mode (error "Problem with magic-fallback-mode-alist element: %s" re)))))))) - (set-auto-mode-0 done keep-mode-if-same))) + (setq done (set-auto-mode-0 done keep-mode-if-same)))) (unless done (set-buffer-major-mode (current-buffer))))) @@ -3539,17 +3556,22 @@ set-auto-mode-0 If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of any aliases and compared to current major mode. If they are the same, do nothing and return nil." - (unless (and keep-mode-if-same - (or (eq (indirect-function mode) + (let ((modefun (alist-get mode major-mode-remap-alist mode))) + (unless (and keep-mode-if-same + (or (eq (indirect-function mode) (indirect-function major-mode)) (and set-auto-mode--last (eq mode (car set-auto-mode--last)) (eq major-mode (cdr set-auto-mode--last))))) - (when mode - (funcall (alist-get mode major-mode-remap-alist mode)) - (unless (eq mode major-mode) - (setq set-auto-mode--last (cons mode major-mode))) - mode))) + (when mode + (if (not (functionp modefun)) + (progn + (message "Ignoring unknown mode `%s'" mode) + nil) + (funcall modefun) + (unless (eq mode major-mode) + (setq set-auto-mode--last (cons mode major-mode))) + mode))))) (defvar file-auto-mode-skip "^\\(#!\\|'\\\\\"\\)" "Regexp of lines to skip when looking for file-local settings. --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 12 12:18:12 2023 Received: (at 67795) by debbugs.gnu.org; 12 Dec 2023 17:18:12 +0000 Received: from localhost ([127.0.0.1]:57415 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD6OZ-0008Gf-Nd for submit@debbugs.gnu.org; Tue, 12 Dec 2023 12:18:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rD6ON-0008Fw-47 for 67795@debbugs.gnu.org; Tue, 12 Dec 2023 12:18:10 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rD6Nz-0003A4-3z; Tue, 12 Dec 2023 12:17:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=EXWu5wlMer8u+qHniDj5mbuitYNWH9utB9LbtKxgVs8=; b=Pf4pFWJvpOS3 4xnIAur+l3fA9w+hK3zSGqHTquHR92jDQzFQQNu/fF1Ur/WQnmeqe/ucbm7AodX/l5T3ts0CnxSuG /D8BB8WwiQx0JT4n5GYjdgkq2DagptVCwPy4Jxh8fNkI3mOFHTbVelsSMXkXkDVOkS1qwDONik9w1 ngNevq7Svm8KV0FM2GOd/IeSjawdWvuhiTx+qqAE3XOd5lIMV83AsqcUC44K609XGqk4or7+6RlqU s7qXY3k2aUS1aN8fBXJXXyLnN8+TLJs0P4HuaM0GAASTzFBuPcNHDtlWxpWQaQHZrtsrnWxUR1b7d AQFRebyw7WAviGO1xTFIwg==; Date: Tue, 12 Dec 2023 19:17:25 +0200 Message-Id: <83h6kntk62.fsf@gnu.org> From: Eli Zaretskii To: Stefan Monnier In-Reply-To: (message from Stefan Monnier on Tue, 12 Dec 2023 11:02:43 -0500) Subject: Re: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode References: <87r0jrplx1.fsf@posteo.net> <83plzbtt2w.fsf@gnu.org> X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 67795 Cc: leungbk@posteo.net, 67795@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: Brian Leung , 67795@debbugs.gnu.org > Date: Tue, 12 Dec 2023 11:02:43 -0500 > > I can't wrap my head around what `hack-local-variables--find-variables` > is supposed to do, but for the other part of the change, maybe the patch > below is a good start? Maybe. Someone should try running with this for a while and come back with feedback. In particular, what happens if MODEFUN is from some unbundled mode, and we expect Emacs to fall back on something sensible, instead of signaling an error. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 01:29:12 2024 Received: (at 67795) by debbugs.gnu.org; 5 Mar 2024 06:29:12 +0000 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 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 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== 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) 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) From: Stefan Monnier To: Brian Leung Subject: Re: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode In-Reply-To: <87r0jrplx1.fsf@posteo.net> (Brian Leung's message of "Tue, 12 Dec 2023 13:52:53 +0000") Message-ID: References: <87r0jrplx1.fsf@posteo.net> Date: Tue, 05 Mar 2024 01:28:31 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.490 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67795 Cc: 67795@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) 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 From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 02:02:12 2024 Received: (at 67795) by debbugs.gnu.org; 5 Mar 2024 07:02:12 +0000 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 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 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== 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) 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) From: Stefan Monnier To: Brian Leung Subject: Re: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode In-Reply-To: <87r0jrplx1.fsf@posteo.net> (Brian Leung's message of "Tue, 12 Dec 2023 13:52:53 +0000") Message-ID: References: <87r0jrplx1.fsf@posteo.net> Date: Tue, 05 Mar 2024 02:01:25 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.441 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67795 Cc: 67795@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 14 22:18:23 2024 Received: (at 67795-done) by debbugs.gnu.org; 15 Mar 2024 02:18:23 +0000 Received: from localhost ([127.0.0.1]:51014 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rkx9L-0004vr-7F for submit@debbugs.gnu.org; Thu, 14 Mar 2024 22:18:23 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:24967) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rkx9J-0004vf-9a for 67795-done@debbugs.gnu.org; Thu, 14 Mar 2024 22:18:22 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A2A3910004C; Thu, 14 Mar 2024 22:17:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1710469058; bh=2HyQCyNkh/qq20cf2COICuB/wb4vWZ5bgQLem7DoPNk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=XoZIX38pWh22F4qeFOWh7hdtL9d3/7sbK/EgS/MqtJJYozxek5Kw0b/T+6lcSwwqL xNxACO8KL8+V+p1AaDl/1aUMI4AvYRtxElJZJXjfJ4QAHGlwrkyXoO+nTQJpI76inJ b7EySurwF/Je8OKEZbPC0W5ykQsUBILoluOP6QzUMR2ukvp4tOpqJca9wuWPestbgS sBfsPDSGwyJS0w3HPPTELaaQCn8IF0FKHJ5bkdu4CJ1t7yqo775EGvLmbqqz5bi7Z4 VFZyj7j1Cr76pIIIEZ9I/0iyonK39KI0Lkacmvkq9f/b/3SjJ/U0+9hpodZQRo10b8 Hi6F1JXtpw1hw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id BACBB100046; Thu, 14 Mar 2024 22:17:38 -0400 (EDT) Received: from pastel (unknown [216.154.27.181]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 942C712039E; Thu, 14 Mar 2024 22:17:38 -0400 (EDT) From: Stefan Monnier To: Brian Leung Subject: Re: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode In-Reply-To: (Stefan Monnier's message of "Tue, 05 Mar 2024 02:01:25 -0500") Message-ID: References: <87r0jrplx1.fsf@posteo.net> Date: Thu, 14 Mar 2024 22:17:37 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.053 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 67795-done Cc: 67795-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > 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). Pushed to `master`. I think we can close this. Thanks Brian for the initial patch. It was very helpful. Stefan From unknown Sat Jun 14 18:52:45 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 12 Apr 2024 11:24:31 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator