From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Benjamin Riefenstahl Newsgroups: gmane.emacs.bugs Subject: bug#36401: 26.0.90; set-auto-mode uses case-insensitive match for magic-mode-alist Date: Sun, 14 Jul 2019 17:23:57 +0200 Message-ID: <87muhgwsfm.fsf@turtle-trading.net> References: <87o92jtlx4.fsf@riefenstahl-linux.mecom.de> <83y31b8sqi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="212432"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.92 (gnu/linux) Cc: Benjamin Riefenstahl , 36401@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 14 17:25:08 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hmgNA-000t7H-OT for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Jul 2019 17:25:08 +0200 Original-Received: from localhost ([::1]:32858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmgN9-0003Gv-L3 for geb-bug-gnu-emacs@m.gmane.org; Sun, 14 Jul 2019 11:25:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34668) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmgN5-0003Fk-Mw for bug-gnu-emacs@gnu.org; Sun, 14 Jul 2019 11:25:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmgN4-0006kP-6p for bug-gnu-emacs@gnu.org; Sun, 14 Jul 2019 11:25:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36844) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hmgN4-0006k5-2t for bug-gnu-emacs@gnu.org; Sun, 14 Jul 2019 11:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hmgN3-0008LO-SA for bug-gnu-emacs@gnu.org; Sun, 14 Jul 2019 11:25:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Benjamin Riefenstahl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Jul 2019 15:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36401 X-GNU-PR-Package: emacs Original-Received: via spool by 36401-submit@debbugs.gnu.org id=B36401.156311784932002 (code B ref 36401); Sun, 14 Jul 2019 15:25:01 +0000 Original-Received: (at 36401) by debbugs.gnu.org; 14 Jul 2019 15:24:09 +0000 Original-Received: from localhost ([127.0.0.1]:45665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hmgMC-0008K5-PY for submit@debbugs.gnu.org; Sun, 14 Jul 2019 11:24:09 -0400 Original-Received: from odoacer.turtle-trading.net ([93.241.193.16]:48869) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hmgMB-0008Jg-6i for 36401@debbugs.gnu.org; Sun, 14 Jul 2019 11:24:07 -0400 Original-Received: from justinian.turtle-trading.net ([192.168.2.118]) by odoacer.turtle-trading.net with esmtp (Exim 4.80) (envelope-from ) id 1hmgM1-0003sS-Pn; Sun, 14 Jul 2019 17:23:57 +0200 Original-Received: from benny by justinian.turtle-trading.net with local (Exim 4.89) (envelope-from ) id 1hmgM1-00029S-FJ; Sun, 14 Jul 2019 17:23:57 +0200 In-Reply-To: <83y31b8sqi.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 06 Jul 2019 11:36:21 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:162998 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > I think this is an omission. Please do propose a patch to fix it. See attached. This applies against master, but the conflict against emacs-26 is also just minor. Please advise if you want this differently. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Make-REs-in-magic-fallback-mode-alist-case-sensitive.patch >From ea6ea194e8858789dce220e28ff33dcb5e313d30 Mon Sep 17 00:00:00 2001 From: Benjamin Riefenstahl Date: Sun, 14 Jul 2019 17:09:39 +0200 Subject: [PATCH] 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 b2249bfcb4..d97f11c32e 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2945,9 +2945,9 @@ magic-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.\")") @@ -2979,9 +2979,9 @@ magic-fallback-mode-alist "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) @@ -3098,7 +3098,8 @@ set-auto-mode ((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" @@ -3159,7 +3160,8 @@ set-auto-mode ((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 aa5dbe7acf..df2c3f47ae 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1282,5 +1282,32 @@ files-tests-file-attributes-equal (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 ." + (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 -- 2.11.0 --=-=-=--