"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.\")")
"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)
((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"
((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"
(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