[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master e6bfc67: Make REs in magic-(fallback-)mode-alist ca
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] master e6bfc67: Make REs in magic-(fallback-)mode-alist case-sensitive. |
Date: |
Sat, 20 Jul 2019 05:29:57 -0400 (EDT) |
branch: master
commit e6bfc6753cac7d8eaf67ff3adea0087eb19e7f6e
Author: Benjamin Riefenstahl <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Make REs in magic-(fallback-)mode-alist case-sensitive.
These variables are used for well-defined file formats where relaxed
case matching is not wanted usually.
* lisp/files.el (magic-mode-alist, magic-fallback-mode-alist): Update
the doc string.
(set-auto-mode): Make looking-at for elements of magic-mode-alist and
magic-fallback-mode-alist use case-fold-search == nil.
* lisp/files.el (files-test-magic-mode-alist-re-baseline)
(files-test-magic-mode-alist-re-no-match)
(files-test-magic-mode-alist-re-case-diff): Add.
---
lisp/files.el | 18 ++++++++++--------
test/lisp/files-tests.el | 27 +++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/lisp/files.el b/lisp/files.el
index e26b482..34fdc30 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2964,9 +2964,9 @@ associated with that interpreter in
`interpreter-mode-alist'.")
"Alist of buffer beginnings vs. corresponding major mode functions.
Each element looks like (REGEXP . FUNCTION) or (MATCH-FUNCTION . FUNCTION).
After visiting a file, if REGEXP matches the text at the beginning of the
-buffer, or calling MATCH-FUNCTION returns non-nil, `normal-mode' will
-call FUNCTION rather than allowing `auto-mode-alist' to decide the buffer's
-major mode.
+buffer (respecting case), or calling MATCH-FUNCTION returns non-nil,
+`normal-mode' will call FUNCTION rather than allowing `auto-mode-alist' to
+decide the buffer's major mode.
If FUNCTION is nil, then it is not called. (That is a way of saying
\"allow `auto-mode-alist' to decide for these files.\")")
@@ -2998,9 +2998,9 @@ If FUNCTION is nil, then it is not called. (That is a
way of saying
"Like `magic-mode-alist' but has lower priority than `auto-mode-alist'.
Each element looks like (REGEXP . FUNCTION) or (MATCH-FUNCTION . FUNCTION).
After visiting a file, if REGEXP matches the text at the beginning of the
-buffer, or calling MATCH-FUNCTION returns non-nil, `normal-mode' will
-call FUNCTION, provided that `magic-mode-alist' and `auto-mode-alist'
-have not specified a mode for this file.
+buffer (respecting case), or calling MATCH-FUNCTION returns non-nil,
+`normal-mode' will call FUNCTION, provided that `magic-mode-alist' and
+`auto-mode-alist' have not specified a mode for this file.
If FUNCTION is nil, then it is not called.")
(put 'magic-fallback-mode-alist 'risky-local-variable t)
@@ -3117,7 +3117,8 @@ we don't actually set it to the same mode the buffer
already has."
((functionp re)
(funcall re))
((stringp re)
- (looking-at re))
+ (let ((case-fold-search nil))
+ (looking-at re)))
(t
(error
"Problem in magic-mode-alist with element %s"
@@ -3178,7 +3179,8 @@ we don't actually set it to the same mode the buffer
already has."
((functionp re)
(funcall re))
((stringp re)
- (looking-at re))
+ (let ((case-fold-search nil))
+ (looking-at re)))
(t
(error
"Problem with
magic-fallback-mode-alist element: %s"
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index aa5dbe7..df2c3f4 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1282,5 +1282,32 @@ renaming only, rather than modified in-place."
(should (equal (file-size-human-readable 10000 'si " " "bit") "10 kbit"))
(should (equal (file-size-human-readable 10000 'iec " " "bit") "9.8 Kibit")))
+(ert-deftest files-test-magic-mode-alist-re-baseline ()
+ "Test magic-mode-alist with RE, expected behaviour for match."
+ (let ((magic-mode-alist '(("my-tag" . text-mode))))
+ (with-temp-buffer
+ (insert "my-tag")
+ (normal-mode)
+ (should (eq major-mode 'text-mode)))))
+
+(ert-deftest files-test-magic-mode-alist-re-no-match ()
+ "Test magic-mode-alist with RE, expected behaviour for no match."
+ (let ((magic-mode-alist '(("my-tag" . text-mode))))
+ (with-temp-buffer
+ (insert "not-my-tag")
+ (normal-mode)
+ (should (not (eq major-mode 'text-mode))))))
+
+(ert-deftest files-test-magic-mode-alist-re-case-diff ()
+ "Test that regexps in magic-mode-alist are case-sensitive.
+See <https://debbugs.gnu.org/36401>."
+ (let ((case-fold-search t)
+ (magic-mode-alist '(("my-tag" . text-mode))))
+ (with-temp-buffer
+ (goto-char (point-min))
+ (insert "My-Tag")
+ (normal-mode)
+ (should (not (eq major-mode 'text-mode))))))
+
(provide 'files-tests)
;;; files-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master e6bfc67: Make REs in magic-(fallback-)mode-alist case-sensitive.,
Eli Zaretskii <=