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

* bug#64415: [PATCH] Use first match in dir-local `auto-mode-alist'
  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
  1 sibling, 2 replies; 5+ messages in thread
From: Eli Zaretskii @ 2023-07-02 10:58 UTC (permalink / raw)
  To: Shynur Xie; +Cc: 64415

> From: Shynur Xie <one.last.kiss@outlook.com>
> Date: Sun, 2 Jul 2023 10:29:13 +0000
> msip_labels: 
> 
> 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.

Isn't that an incompatible change in long-time behavior?  Your
stack-exchange correspondent might be pleased, but someone else, who
relies on the current behavior, will not be.





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

* bug#64415: [PATCH] Use first match in dir-local `auto-mode-alist'
  2023-07-02 10:58 ` Eli Zaretskii
@ 2023-07-02 11:16   ` Shynur Xie
  2023-07-02 11:29   ` Shynur Xie
  1 sibling, 0 replies; 5+ messages in thread
From: Shynur Xie @ 2023-07-02 11:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64415@debbugs.gnu.org

GNU Emacs Manual, 49.2.5 Per-Directory Local Variables:

> The special key auto-mode-alist in a .dir-locals.el ... works much
> like the variable auto-mode-alist (see Choosing File Modes).

GNU Emacs Lisp Reference Manual, 24.2.2 How Emacs Chooses a Major
Mode:

> If auto-mode-alist has more than one element whose regexp matches
> the file name, Emacs will use the first match.

___

> Eli> Isn't that an incompatible change in long-time behavior?

That is a bug fix.  What do you mean by ‘long-time behavior’?  To be
honest, it is a long-time bug IMO.

> Eli> someone else, who relies on the current behavior, will not be.

Yes, so just let them know that this behavior has changed in NEWS.
They just need to reverse their original alist, is that very
difficult?  Not to mention that the original behavior was not
guaranteed at all.

You can of course refuse that patch, and the inconsistency between
‘auto-mode-alist’ and dir-local ‘auto-mode-alist’ will last forever.




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

* bug#64415: [PATCH] Use first match in dir-local `auto-mode-alist'
  2023-07-02 10:58 ` Eli Zaretskii
  2023-07-02 11:16   ` Shynur Xie
@ 2023-07-02 11:29   ` Shynur Xie
  1 sibling, 0 replies; 5+ messages in thread
From: Shynur Xie @ 2023-07-02 11:29 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 64415@debbugs.gnu.org

I agree that compatibility should be considered, but this dir-local
var was introduced since 28, it’s not too late to change it.

The reverse order is so contrary to perception.




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

* bug#64415: [PATCH] Use first match in dir-local `auto-mode-alist'
  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
@ 2024-06-08 23:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-06-08 23:38 UTC (permalink / raw)
  To: Shynur Xie; +Cc: 64415

> * 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)

AFAICT the reversal happens within `dir-locals-collect-mode-variables`.
I think this is a bug in `hack-dir-local--get-variables`: it should return the
vars in the same order as found in the file.


        Stefan






^ permalink raw reply	[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).