From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Bj=C3=B6rn?= Bidar via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too Date: Fri, 20 Dec 2024 03:33:18 +0200 Message-ID: <46947.5245032058$1734658468@news.gmane.org> References: <87frml6pkg.fsf@thaodan.de> <86o718ks3b.fsf@gnu.org> Reply-To: =?UTF-8?Q?Bj=C3=B6rn?= Bidar Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27743"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , acorallo@gnu.org, 74946@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 20 02:34:20 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tORuE-00073l-Rz for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Dec 2024 02:34:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tORu2-0001qC-1Q; Thu, 19 Dec 2024 20:34:06 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tORtz-0001pd-Gd for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2024 20:34:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tORtz-00084H-0i for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2024 20:34:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=gVwwxTnXMcFtI8eFo4Hg2ZNKbSeAcExBYOeU8czPEak=; b=DX2IoMrUKtgnobthTdC6CZEDy3pPECtxSysUuw6j9uRX9xEW2StXYXsEkrDZ9U2wG9jC/VIWqydn3SCIeaZ3csWxuOGCO3Z4j9NXYhrM+DRG7+GLnQp5VOR2424eESpnwXVIbM7mbJwNeZ+ck7C0VhTJOl7gauLKHAPGym5Bas0i7xQnXnDFtuxl401+Bb1ger8/Ss0bYZshIlBL5HWa+Yriga2IlErevsxeM8TStkUSQrHDPNdqiFt3woSyvY3I4EFkFhdJScYQuGNr9+ID9AOnT3sKHE1JS2fSIhifsMt4nfZcFRGbyC8EiAe+bYNubKqMjzf6lWQFrIOlsgIDFw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tORty-0000BX-Fv for bug-gnu-emacs@gnu.org; Thu, 19 Dec 2024 20:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Bj=C3=B6rn?= Bidar Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Dec 2024 01:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74946 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74946-submit@debbugs.gnu.org id=B74946.1734658410662 (code B ref 74946); Fri, 20 Dec 2024 01:34:02 +0000 Original-Received: (at 74946) by debbugs.gnu.org; 20 Dec 2024 01:33:30 +0000 Original-Received: from localhost ([127.0.0.1]:40778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tORtR-0000Ab-Vn for submit@debbugs.gnu.org; Thu, 19 Dec 2024 20:33:30 -0500 Original-Received: from thaodan.de ([185.216.177.71]:37812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tORtP-0000AL-CC for 74946@debbugs.gnu.org; Thu, 19 Dec 2024 20:33:28 -0500 Original-Received: from odin (dsl-trebng12-50dc7b-49.dhcp.inet.fi [80.220.123.49]) by thaodan.de (Postfix) with ESMTPSA id B316CD00038; Fri, 20 Dec 2024 03:33:19 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=thaodan.de; s=mail; t=1734658399; bh=MqfsXOA3rOhzlz0b3KFh6WLECSk9oZ4bxVin0RKJ0sI=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=eGGw2GsVcIvEZbatnfNsEQ3tTHPiShdsbJmmBBlVAKhN0L11uO53Vpu2o5kYwLhxT 2lM4Tmkq7Xcw0VlySdvhydAt2PwIo/f/BCKWs4ah300J8Eb6FYytUELFgJIS34zaT0 5HmsJ9MyzWJKpuqI/p+sIPg7irG6STr7IuNnnq9hewVJf/kZUx/PJ/q4xD9tJD9rIx 3bWRmBDgH/Iu2Is3zskwKXlGPwWEbpWQzQzaS+11k4PllT2gZuYxklJEMMEug0EDv6 or+FUQMqU+0j9iPLyzapNlqvLtYrZCi4Nch8VIOweMr+BZyrrxw9zFwNR5emk+RuKw /7wHIbBwjq6mYwM1aUVqhw0cqF7mCFVkjSjmPJNmxYyJQj1Jw1sLSlEN/m/513QCo6 yPlze49PeyjiXoTsjEQw0Zna+OnM1WmoKQLnTzYyPoQwIeh61+K6KVmADW1QIQBFpM lhwiqf4mG640jgsrSOdsgjjBVP/K2biSxqlbMlXsws89qErxoY42eqaA8RxGzUvUDT Rr+OFUN8fTOSoXI4PUvqs4/oRskjxZxzrAh6DYvimo5gFq5jrxs0TwMU9V6/n0NmHo aQ+Vl24qJN1/dDKUpqznr8TC/LcTnGwirPvhgtIeOmgr66G0j9PJZYbBIKO/Ht1+8+ 3bE8bQrLg+i7J3QkzZLdtvZg= In-Reply-To: (Stefan Kangas's message of "Thu, 19 Dec 2024 17:55:22 -0500") Autocrypt: addr=bjorn.bidar@thaodan.de; prefer-encrypt=nopreference; keydata= mDMEZNfpPhYJKwYBBAHaRw8BAQdACBEmr+0xwIIHZfIDlZmm7sa+lHHSb0g9FZrN6qE6ru60JUJq w7ZybiBCaWRhciA8Ympvcm4uYmlkYXJAdGhhb2Rhbi5kZT6IlgQTFgoAPgIbAwULCQgHAgIiAgYV CgkICwIEFgIDAQIeBwIXgBYhBFHxdut1RzAepymoq1wbdKFlHF9oBQJk1/YmAhkBAAoJEFwbdKFl HF9oB9cBAJoIIGQKXm4cpap+Flxc/EGnYl0123lcEyzuduqvlDT0AQC3OlFKm/OiqJ8IMTrzJRZ8 phFssTkSrrFXnM2jm5PYDoiTBBMWCgA7FiEEUfF263VHMB6nKairXBt0oWUcX2gFAmTX6T4CGwMF CwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQXBt0oWUcX2hbCQEAtru7kvM8hi8zo6z9ux2h K+B5xViKuo7Z8K3IXuK5ugwA+wUfKzomzdBPhfxDsqLcEziGRxoyx0Q3ld9aermBUccHtBxCasO2 cm4gQmlkYXIgPG1lQHRoYW9kYW4uZGU+iJMEExYKADsCGwMFCwkIBwICIgIGFQoJCAsCBBYCAwEC HgcCF4AWIQRR8XbrdUcwHqcpqKtcG3ShZRxfaAUCZNf2FQAKCRBcG3ShZRxfaCzSAP4hZ7cSp0YN XYpcjHdsySh2MuBhhoPeLGXs+2kSiqBiOwD/TP8AgPEg/R+SI9GI9on7fBJJ0mp2IT8kZ2rhDOjg gA6IkwQTFgoAOxYhBFHxdut1RzAepymoq1wbdKFlH X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297418 Archived-At: Stefan Kangas writes: > Eli Zaretskii writes: > >> Btw, if we want to fix this entry, we should perhaps do a more >> thorough job. For example, on my system I have files with the >> following base names: >> >> .gdbinit.in >> .gdbinit >> _gdbinit (for MS-DOS) >> gdb.ini (likewise) >> gdbinit >> gdbinit.in >> SOMETHING-gdbinit >> .gdbinit.loader >> gdbinit-history.exp (not a GDB init file) >> gdbinit.5 (likewise) >> gdbinit.c (likewise) >> .gdbinit.py.in (likewise) >> >> Should we improve the regexp to DTRT for those additional files, but >> without false positives? > > Maybe something like the below patch? > > BTW, should the .gdbinit.py.in file be in python-mode perhaps? > And what about gdbinit.5? That's a man page file. > From a5a5dcd0452cadfee988a0256c10877835eefcef Mon Sep 17 00:00:00 2001 > From: Stefan Kangas > Date: Thu, 19 Dec 2024 23:51:38 +0100 > Subject: [PATCH] Match more gdbinit files > > * lisp/files.el (auto-mode-alist): Match more gdbinit files, > including XDG, and MS-Windows. Avoid false positives. > (Bug#74946) > (set-auto-mode--find-matching-alist-entry): Break out function... > (set-auto-mode--apply-alist): ...from here. > * test/lisp/files-tests.el (files-tests-auto-mode-alist): New > test. > --- > lisp/files.el | 56 +++++++++++++++++++++++----------------- > test/lisp/files-tests.el | 17 ++++++++++++ > 2 files changed, 49 insertions(+), 24 deletions(-) > > diff --git a/lisp/files.el b/lisp/files.el > index 9f13804540b..68ce2e0c273 100644 > --- a/lisp/files.el > +++ b/lisp/files.el > @@ -3005,7 +3005,7 @@ auto-mode-alist > ;; files, cross-debuggers can use something like > ;; .PROCESSORNAME-gdbinit so that the host and target gdbinit files > ;; don't interfere with each other. > - ("/\\.[a-z0-9-]*gdbinit" . gdb-script-mode) > + ("/[._]?[A-Za-z0-9-]*\\(?:gdbinit\\(?:\\.\\(?:ini?\\|loader\\)\\)?\\|gdb\\.ini\\)\\'" . gdb-script-mode) .gdbinit.loader seems to be Mozilla thing. It might be better to either let users manually set the mode for these files or allow for text to be after .gdbinit. > ;; GDB 7.5 introduced OBJFILE-gdb.gdb script files; e.g. a file > ;; named 'emacs-gdb.gdb', if it exists, will be automatically > ;; loaded when GDB reads an objfile called 'emacs'. > @@ -3404,6 +3404,35 @@ magic-mode-regexp-match-limit > "Upper limit on `magic-mode-alist' regexp matches. > Also applies to `magic-fallback-mode-alist'.") > > +(defun set-auto-mode--find-matching-alist-entry (alist name case-insensitive) > + "Find first matching entry in ALIST for file NAME. > + > +If CASE-INSENSITIVE, the file system of file NAME is case-insensitive." > + (let (mode) > + (while name > + (setq mode > + (if case-insensitive > + ;; Filesystem is case-insensitive. > + (let ((case-fold-search t)) > + (assoc-default name alist 'string-match)) > + ;; Filesystem is case-sensitive. > + (or > + ;; First match case-sensitively. > + (let ((case-fold-search nil)) > + (assoc-default name alist 'string-match)) > + ;; Fallback to case-insensitive match. > + (and auto-mode-case-fold > + (let ((case-fold-search t)) > + (assoc-default name alist 'string-match)))))) > + (if (and mode > + (not (functionp mode)) > + (consp mode) > + (cadr mode)) > + (setq mode (car mode) > + name (substring name 0 (match-beginning 0))) > + (setq name nil))) > + mode)) > + This function looks very useful for applications with preferential orders of files as in e.g. a .dotfile and .dotconfig/file. It could also be a generic function. > (defun set-auto-mode--apply-alist (alist keep-mode-if-same dir-local) > "Helper function for `set-auto-mode'. > This function takes an alist of the same form as > @@ -3425,29 +3454,8 @@ set-auto-mode--apply-alist > (when (and (stringp remote-id) > (string-match (regexp-quote remote-id) name)) > (setq name (substring name (match-end 0)))) > - (while name > - ;; Find first matching alist entry. > - (setq mode > - (if case-insensitive-p > - ;; Filesystem is case-insensitive. > - (let ((case-fold-search t)) > - (assoc-default name alist 'string-match)) > - ;; Filesystem is case-sensitive. > - (or > - ;; First match case-sensitively. > - (let ((case-fold-search nil)) > - (assoc-default name alist 'string-match)) > - ;; Fallback to case-insensitive match. > - (and auto-mode-case-fold > - (let ((case-fold-search t)) > - (assoc-default name alist 'string-match)))))) > - (if (and mode > - (not (functionp mode)) > - (consp mode) > - (cadr mode)) > - (setq mode (car mode) > - name (substring name 0 (match-beginning 0))) > - (setq name nil))) > + (setq mode (set-auto-mode--find-matching-alist-entry > + alist name case-insensitive-p)) > (when (and dir-local mode > (not (set-auto-mode--dir-local-valid-p mode))) > (message "Ignoring invalid mode `%s'" mode) > diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el > index ad54addf06b..0edc78d01e5 100644 > --- a/test/lisp/files-tests.el > +++ b/test/lisp/files-tests.el > @@ -1680,6 +1680,23 @@ files-tests--check-shebang > (when (eq expected-mode 'sh-base-mode) > (should (eq sh-shell expected-dialect)))))) > > +(ert-deftest files-tests-auto-mode-alist () > + (cl-flet ((find (file mode &optional case-insensitive) > + (eq mode (set-auto-mode--find-matching-alist-entry > + auto-mode-alist (concat "/home/stefank/" file) case-insensitive)))) > + (should (find ".gdbinit.in" #'gdb-script-mode)) > + (should (find ".gdbinit" #'gdb-script-mode)) > + (should (find "_gdbinit" #'gdb-script-mode)) ; for MS-DOS > + (should (find "gdb.ini" #'gdb-script-mode)) ; likewise > + (should (find "gdbinit" #'gdb-script-mode)) > + (should (find "gdbinit.in" #'gdb-script-mode)) > + (should (find "SOMETHING-gdbinit" #'gdb-script-mode)) > + (should (find ".gdbinit.loader" #'gdb-script-mode)) > + (should-not (find "gdbinit-history.exp" #'gdb-script-mode)) ; not a GDB init file > + (should-not (find "gdbinit.5" #'gdb-script-mode)) ; likewise > + (should-not (find "gdbinit.c" #'gdb-script-mode)) ; likewise > + (should-not (find ".gdbinit.py.in" #'gdb-script-mode)))) ; likewise > + > (ert-deftest files-tests-auto-mode-interpreter () > "Test that `set-auto-mode' deduces correct modes from shebangs." > ;; Straightforward interpreter invocation.