* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
@ 2024-12-18 14:19 Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-19 1:00 ` Stefan Kangas
0 siblings, 1 reply; 10+ messages in thread
From: Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-18 14:19 UTC (permalink / raw)
To: 74946
[-- Attachment #1: Type: text/plain, Size: 3027 bytes --]
Tags: patch
Include gdbinit inside auto-mode-alist.
Since gdb 11.1 it's the preferred name of gdbinit.
Please also include into Emacs 30 if possible.
In GNU Emacs 31.0.50 (build 1, x86_64-suse-linux-gnu, GTK+ Version
3.24.43, cairo version 1.18.2)
Repository revision: eaf5bf736e1dd5eb977a16a3f1b3dfd3da3c4612
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101014
System Description: openSUSE Tumbleweed
Configured using:
'configure --disable-build-details --without-pop --with-mailutils
--without-hesiod --with-gameuser=:games --with-kerberos
--with-kerberos5 --with-file-notification=inotify --with-modules
--enable-autodepend --enable-link-time-optimization --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share
--localstatedir=/var --sharedstatedir=/var/lib
--libexecdir=/usr/libexec --with-file-notification=yes
--libdir=/usr/lib64 --with-native-compilation=aot
--enable-locallisppath=/usr/share/emacs/31.0.50/site-lisp:/usr/share/emacs/site-lisp
--with-x --with-xim --with-sound --with-xpm --with-jpeg --with-tiff
--with-gif --with-png --with-rsvg --with-dbus --with-xft --without-gpm
--with-tree-sitter --with-x-toolkit=gtk --without-pgtk
--with-toolkit-scroll-bars --x-includes=/usr/include
--x-libraries=/usr/lib64 --with-libotf --with-m17n-flt --with-cairo
--build=x86_64-suse-linux --with-dumping=pdumper
build_alias=x86_64-suse-linux 'CC=sccache cc' 'CFLAGS=-O2 -Wall
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
-funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection
-Werror=return-type -flto=auto -march=znver3 -mmmx -mpopcnt -msse
-msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -msse4a -mno-fma4
-mno-xop -mfma -mbmi -mbmi2 -maes -mpclmul -mno-gfni -mvpclmulqdq
-mno-3dnow -madx -mabm -mno-cldemote -mclflushopt -mclwb -mclzero
-mcx16 -mno-enqcmd -mf16c -mfsgsbase -mfxsr -mno-hle -msahf -mno-lwp
-mlzcnt -mmovbe -mno-movdir64b -mno-movdiri -mmwaitx -mno-pconfig -mpku
-mprfchw -mno-ptwrite -mrdpid -mrdrnd -mrdseed -mno-rtm -mno-serialize
-mno-sgx -msha -mshstk -mno-tbm -mno-tsxldtrk -mvaes -mno-waitpkg
-mwbnoinvd -mxsave -mxsavec -mxsaveopt -mxsaves -mno-amx-tile
-mno-amx-int8 -mno-amx-bf16 -mno-uintr -mno-hreset -mno-kl -mno-widekl
-mno-avxvnni -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert
-mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint
-mno-amx-complex --param l1-cache-size=32 --param l1-cache-line-size=64
--param l2-cache-size=512 -mtune=znver3 -fno-optimize-sibling-calls -O2
-Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
-funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection
-Werror=return-type -flto=auto -g -D_GNU_SOURCE
-DGDK_DISABLE_DEPRECATION_WARNINGS -DGLIB_DISABLE_DEPRECATION_WARNINGS
-pipe -Wno-pointer-sign -Wno-unused-variable -Wno-unused-label
-DPDMP_BASE='\''"emacs-gtk"'\''' LDFLAGS=-Wl,-O2 'CXX=sccache c++'
PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-files.el-auto-mode-alist-Include-gdbinit-too.patch --]
[-- Type: text/patch, Size: 1491 bytes --]
From 1ba2ce9320513efa0fb4b2d6a5022bb9d635af68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bidar@thaodan.de>
Date: Wed, 18 Dec 2024 16:07:34 +0200
Subject: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
Since gdb 11.1 .gdbinit can be also called gdbinit saved inside
$XDG_CONFIG_HOME or $HOME/Library/Preferences/gdb on Apple Hosts.
https://lists.gnu.org/archive/html/info-gnu/2021-09/msg00007.html
---
lisp/files.el | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lisp/files.el b/lisp/files.el
index 9f13804540b..6fe037f30e7 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3001,11 +3001,12 @@ auto-mode-alist
("\\.css\\'" . css-mode)
("\\.mixal\\'" . mixal-mode)
("\\.gcov\\'" . compilation-mode)
- ;; Besides .gdbinit, gdb documents other names to be usable for init
+ ;; gdbinit can be gdbinit or .gdbinit the exact prefix does not matter.
+ ;; Besides gdbinit, gdb documents other names to be usable for init
;; 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-z0-9-]*gdbinit" . gdb-script-mode)
;; 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'.
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-18 14:19 bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-12-19 1:00 ` Stefan Kangas
2024-12-19 8:14 ` Eli Zaretskii
0 siblings, 1 reply; 10+ messages in thread
From: Stefan Kangas @ 2024-12-19 1:00 UTC (permalink / raw)
To: Björn Bidar, 74946; +Cc: Eli Zaretskii, Andrea Corallo
Björn Bidar via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs@gnu.org> writes:
> From 1ba2ce9320513efa0fb4b2d6a5022bb9d635af68 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bidar@thaodan.de>
> Date: Wed, 18 Dec 2024 16:07:34 +0200
> Subject: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
>
> Since gdb 11.1 .gdbinit can be also called gdbinit saved inside
> $XDG_CONFIG_HOME or $HOME/Library/Preferences/gdb on Apple Hosts.
>
> https://lists.gnu.org/archive/html/info-gnu/2021-09/msg00007.html
> ---
> lisp/files.el | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/files.el b/lisp/files.el
> index 9f13804540b..6fe037f30e7 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -3001,11 +3001,12 @@ auto-mode-alist
> ("\\.css\\'" . css-mode)
> ("\\.mixal\\'" . mixal-mode)
> ("\\.gcov\\'" . compilation-mode)
> - ;; Besides .gdbinit, gdb documents other names to be usable for init
> + ;; gdbinit can be gdbinit or .gdbinit the exact prefix does not matter.
> + ;; Besides gdbinit, gdb documents other names to be usable for init
I'd leave the comment as is.
> ;; 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-z0-9-]*gdbinit" . gdb-script-mode)
Thanks, but shouldn't that be
- ("/\\.[a-z0-9-]*gdbinit" . gdb-script-mode)
+ ("/\\.?[a-z0-9-]*gdbinit" . gdb-script-mode)
?
> Please also include into Emacs 30 if possible.
If Eli and Andrea agrees, I think we could do it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-19 1:00 ` Stefan Kangas
@ 2024-12-19 8:14 ` Eli Zaretskii
2024-12-19 21:29 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Eli Zaretskii @ 2024-12-19 8:14 UTC (permalink / raw)
To: Stefan Kangas; +Cc: bjorn.bidar, acorallo, 74946
> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Wed, 18 Dec 2024 20:00:37 -0500
> Cc: Eli Zaretskii <eliz@gnu.org>, Andrea Corallo <acorallo@gnu.org>
>
> > Please also include into Emacs 30 if possible.
>
> If Eli and Andrea agrees, I think we could do it.
It looks innocent enough, but at this point I'd like to limit changes
on the release branch to only really urgent and important ones (or
documentation). We have lived with this outdated code for several
years (GDB 11.1 was released in 2022), so this change doesn't look
urgent to me.
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?
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-19 8:14 ` Eli Zaretskii
@ 2024-12-19 21:29 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-19 22:55 ` Stefan Kangas
[not found] ` <87frmjtl9f.fsf@>
2 siblings, 0 replies; 10+ messages in thread
From: Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-19 21:29 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: acorallo, Stefan Kangas, 74946
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Stefan Kangas <stefankangas@gmail.com>
>> Date: Wed, 18 Dec 2024 20:00:37 -0500
>> Cc: Eli Zaretskii <eliz@gnu.org>, Andrea Corallo <acorallo@gnu.org>
>>
>> > Please also include into Emacs 30 if possible.
>>
>> If Eli and Andrea agrees, I think we could do it.
>
> It looks innocent enough, but at this point I'd like to limit changes
> on the release branch to only really urgent and important ones (or
> documentation). We have lived with this outdated code for several
> years (GDB 11.1 was released in 2022), so this change doesn't look
> urgent to me.
Not really that urgent but to new users of Emacs it would be
beneficial if things would work out of the box. I thought at first Emacs
just didn't support the file.
> 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)
Is this a gdbinit file? The extension looks off.
> 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?
With Stefan correction all these without extension match. What are the
official extensions? gdbinit.in sounds like a normal extension for
gdbinit template in the source but the others such as gdb.ini look off.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-19 8:14 ` Eli Zaretskii
2024-12-19 21:29 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-12-19 22:55 ` Stefan Kangas
2024-12-20 1:33 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-20 7:05 ` Eli Zaretskii
[not found] ` <87frmjtl9f.fsf@>
2 siblings, 2 replies; 10+ messages in thread
From: Stefan Kangas @ 2024-12-19 22:55 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: bjorn.bidar, acorallo, 74946
[-- Attachment #1: Type: text/plain, Size: 696 bytes --]
Eli Zaretskii <eliz@gnu.org> 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?
[-- Attachment #2: 0001-Match-more-gdbinit-files.patch --]
[-- Type: text/x-patch, Size: 5858 bytes --]
From a5a5dcd0452cadfee988a0256c10877835eefcef Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
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)
;; 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))
+
(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.
--
2.47.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-19 22:55 ` Stefan Kangas
@ 2024-12-20 1:33 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-20 7:05 ` Eli Zaretskii
1 sibling, 0 replies; 10+ messages in thread
From: Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-20 1:33 UTC (permalink / raw)
To: Stefan Kangas; +Cc: Eli Zaretskii, acorallo, 74946
Stefan Kangas <stefankangas@gmail.com> writes:
> Eli Zaretskii <eliz@gnu.org> 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 <stefankangas@gmail.com>
> 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-19 22:55 ` Stefan Kangas
2024-12-20 1:33 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-12-20 7:05 ` Eli Zaretskii
2024-12-22 2:08 ` Stefan Kangas
1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2024-12-20 7:05 UTC (permalink / raw)
To: Stefan Kangas; +Cc: bjorn.bidar, acorallo, 74946
> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Thu, 19 Dec 2024 17:55:22 -0500
> Cc: bjorn.bidar@thaodan.de, 74946@debbugs.gnu.org, acorallo@gnu.org
>
> > .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?
Maybe. Try it against any similar name you have on your system. I
used "locate -b gdbinit" to find matching files on mine.
> BTW, should the .gdbinit.py.in file be in python-mode perhaps?
Yes, it should be.
> And what about gdbinit.5?
It's a roff file (source of a man page).
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-20 7:05 ` Eli Zaretskii
@ 2024-12-22 2:08 ` Stefan Kangas
0 siblings, 0 replies; 10+ messages in thread
From: Stefan Kangas @ 2024-12-22 2:08 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: bjorn.bidar, acorallo, 74946-done
Version: 31.1
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Stefan Kangas <stefankangas@gmail.com>
>> Date: Thu, 19 Dec 2024 17:55:22 -0500
>> Cc: bjorn.bidar@thaodan.de, 74946@debbugs.gnu.org, acorallo@gnu.org
>>
>> > .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?
>
> Maybe. Try it against any similar name you have on your system. I
> used "locate -b gdbinit" to find matching files on mine.
Everything makes sense to me, so I pushed the change to master.
I'm closing this bug report with this message.
Please report back if you notice any problems.
Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <87frmjtl9f.fsf@>]
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
[not found] ` <87frmjtl9f.fsf@>
@ 2024-12-20 6:46 ` Eli Zaretskii
2024-12-20 8:07 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2024-12-20 6:46 UTC (permalink / raw)
To: Björn Bidar; +Cc: acorallo, stefankangas, 74946
> From: Björn Bidar <bjorn.bidar@thaodan.de>
> Cc: Stefan Kangas <stefankangas@gmail.com>, 74946@debbugs.gnu.org,
> acorallo@gnu.org
> Date: Thu, 19 Dec 2024 23:29:00 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > It looks innocent enough, but at this point I'd like to limit changes
> > on the release branch to only really urgent and important ones (or
> > documentation). We have lived with this outdated code for several
> > years (GDB 11.1 was released in 2022), so this change doesn't look
> > urgent to me.
>
> Not really that urgent but to new users of Emacs it would be
> beneficial if things would work out of the box. I thought at first Emacs
> just didn't support the file.
I understand, but my main worry is the potential unintended
consequences. Regexps are tricky, as we all know.
> > 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)
>
> Is this a gdbinit file? The extension looks off.
Yes, gdb.ini is a gdbinit file. But if supporting it is problematic
or causes too many complications, I'm okay with not supporting that
particular file name.
> > 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?
>
> With Stefan correction all these without extension match. What are the
> official extensions? gdbinit.in sounds like a normal extension for
> gdbinit template in the source but the others such as gdb.ini look off.
So we should at least allow the ".in" extension? Also, note that the
current regexp doesn't end with a \\' so it could be a partial match
with, say, /foo/bar/gdbinit-but-not-really.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too
2024-12-20 6:46 ` Eli Zaretskii
@ 2024-12-20 8:07 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 10+ messages in thread
From: Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-20 8:07 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: acorallo, stefankangas, 74946
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Björn Bidar <bjorn.bidar@thaodan.de>
>> Cc: Stefan Kangas <stefankangas@gmail.com>, 74946@debbugs.gnu.org,
>> acorallo@gnu.org
>> Date: Thu, 19 Dec 2024 23:29:00 +0200
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> > It looks innocent enough, but at this point I'd like to limit changes
>> > on the release branch to only really urgent and important ones (or
>> > documentation). We have lived with this outdated code for several
>> > years (GDB 11.1 was released in 2022), so this change doesn't look
>> > urgent to me.
>>
>> Not really that urgent but to new users of Emacs it would be
>> beneficial if things would work out of the box. I thought at first Emacs
>> just didn't support the file.
>
> I understand, but my main worry is the potential unintended
> consequences. Regexps are tricky, as we all know.
Yeah I get it np. Your call. The risks are low I'd say.
>> > 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)
>>
>> Is this a gdbinit file? The extension looks off.
>
> Yes, gdb.ini is a gdbinit file. But if supporting it is problematic
> or causes too many complications, I'm okay with not supporting that
> particular file name.
I later got that too. The gdb manual states that gdb.ini is the official
name of gdb on DOS systems. I think it should be fine as the chance for
false-positives in low on this one.
>> > 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?
>>
>> With Stefan correction all these without extension match. What are the
>> official extensions? gdbinit.in sounds like a normal extension for
>> gdbinit template in the source but the others such as gdb.ini look off.
>
> So we should at least allow the ".in" extension? Also, note that the
> current regexp doesn't end with a \\' so it could be a partial match
> with, say, /foo/bar/gdbinit-but-not-really.
I think so yes. In most instances the .in extension should also match
the preceding match it I think.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-12-22 2:08 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-18 14:19 bug#74946: [PATCH] * lisp/files.el (auto-mode-alist): Include gdbinit too Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-19 1:00 ` Stefan Kangas
2024-12-19 8:14 ` Eli Zaretskii
2024-12-19 21:29 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-19 22:55 ` Stefan Kangas
2024-12-20 1:33 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-20 7:05 ` Eli Zaretskii
2024-12-22 2:08 ` Stefan Kangas
[not found] ` <87frmjtl9f.fsf@>
2024-12-20 6:46 ` Eli Zaretskii
2024-12-20 8:07 ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.