all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Brian Leung <leungbk@posteo.net>
To: 67795@debbugs.gnu.org
Subject: bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode
Date: Tue, 12 Dec 2023 13:52:53 +0000	[thread overview]
Message-ID: <87r0jrplx1.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

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'

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-local-variable-major-mode-remaps-specifying-n.patch --]
[-- Type: text/patch, Size: 1765 bytes --]

From 46435cac589506ecb131f480171a2ec1f0f03c55 Mon Sep 17 00:00:00 2001
From: Brian Leung <leungbk@posteo.net>
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


             reply	other threads:[~2023-12-12 13:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12 13:52 Brian Leung [this message]
2023-12-12 14:04 ` bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode Eli Zaretskii
2023-12-12 16:02   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-12 17:17     ` Eli Zaretskii
2024-03-05  6:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-05  7:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-15  2:17   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r0jrplx1.fsf@posteo.net \
    --to=leungbk@posteo.net \
    --cc=67795@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.