unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#64415: [PATCH] Use first match in dir-local `auto-mode-alist'
@ 2023-07-02 10:29 Shynur Xie
  2023-07-02 10:58 ` Eli Zaretskii
  2024-06-08 23:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 5+ messages in thread
From: Shynur Xie @ 2023-07-02 10:29 UTC (permalink / raw)
  To: 64415

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

lispref says var `auto-mode-alist' uses first match, so pseudo
var `auto-mode-alist' in _dir-locals.el should also do that, for
consistency.

Here is a problem caused by the original behavior when Emacs handles
_dir-locals file: <https://emacs.stackexchange.com/questions/77841>.

--
shynur

[-- Attachment #2: 0001-Use-first-match-in-dir-local-auto-mode-alist.patch --]
[-- Type: application/octet-stream, Size: 1227 bytes --]

From 6cb2063a807b7dc2c3da9378db1c134b2e82a0a3 Mon Sep 17 00:00:00 2001
From: Shynur <one.last.kiss@outlook.com>
Date: Sun, 2 Jul 2023 18:15:02 +0800
Subject: [PATCH] Use first match in dir-local `auto-mode-alist'

* lisp/files.el (set-auto-mode): Reverse the reversed alist.
---
 lisp/files.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 148f47cbc97..fc3b47082ea 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3396,8 +3396,9 @@ we don't actually set it to the same mode the buffer already has."
     (unless done
       (with-demoted-errors "Directory-local variables error: %s"
 	;; Note this is a no-op if enable-local-variables is nil.
-        (let* ((mode-alist (cdr (hack-dir-local--get-variables
-                                 (lambda (key) (eq key 'auto-mode-alist))))))
+        (let* ((mode-alist (reverse (cdr (hack-dir-local--get-variables
+                                          (lambda (key)
+                                            (eq key 'auto-mode-alist)))))))
           (setq done (set-auto-mode--apply-alist mode-alist
                                                  keep-mode-if-same t)))))
     (and (not done)
-- 
2.39.1


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

end of thread, other threads:[~2024-06-08 23:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-02 10:29 bug#64415: [PATCH] Use first match in dir-local `auto-mode-alist' Shynur Xie
2023-07-02 10:58 ` Eli Zaretskii
2023-07-02 11:16   ` Shynur Xie
2023-07-02 11:29   ` Shynur Xie
2024-06-08 23:38 ` 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).