>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