unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode
@ 2023-12-12 13:52 Brian Leung
  2023-12-12 14:04 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Brian Leung @ 2023-12-12 13:52 UTC (permalink / raw)
  To: 67795

[-- 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-15  2:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 13:52 bug#67795: [PATCH] Handle local-variable major-mode remaps specifying non-existent mode Brian Leung
2023-12-12 14:04 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).