GNU bug report logs -
#77656
[PATCH] Don't escape "." in `prin1' unless followed by "?" or nothing
Previous Next
Reported by: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Tue, 8 Apr 2025 21:43:02 UTC
Severity: normal
Tags: patch
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 77656 in the body.
You can then email your comments to 77656 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
larsi <at> gnus.org, bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Tue, 08 Apr 2025 21:43:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Spencer Baugh <sbaugh <at> janestreet.com>
:
New bug report received and forwarded. Copy sent to
larsi <at> gnus.org, bug-gnu-emacs <at> gnu.org
.
(Tue, 08 Apr 2025 21:43:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Tags: patch
This is a followup to 637dde4aba921435f78d0de769ad74c4f3230aa6, which
removed some unnecessary escaping of "." and "?" when printing symbols
in prin1.
This change removes more unnecessary escaping of "."; "." only
needs to be escaped when it's the entire symbol or if it's
followed by a "?".
(Actually, if we always escaped "?" (which was the case before
637dde4aba92) then "." only ever needs to be escaped when
string_to_number returns non-nil. So 637dde4aba92 could have
just dropped the escaping of "." with no other changes, if it
didn't also remove escaping of "?")
In GNU Emacs 30.1.50 (build 4, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.15.12, Xaw scroll bars) of 2025-04-08 built on
igm-qws-u22796a
Repository revision: 66de38ffb76fbd3ecb1cea52e655189b1b173fa1
Repository branch: emacs-30
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.10 (Green Obsidian)
Configured using:
'configure --config-cache --with-x-toolkit=lucid --without-gpm
--without-gconf --without-selinux --without-imagemagick --with-modules
--with-gif=no --with-cairo --with-rsvg --without-compress-install
--with-tree-sitter --with-native-compilation=aot'
[0001-Don-t-escape-.-in-prin1-unless-followed-by-or-nothin.patch (text/patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Sat, 12 Apr 2025 11:15:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 77656 <at> debbugs.gnu.org (full text, mbox):
> Cc: Lars Ingebrigtsen <larsi <at> gnus.org>
> Date: Tue, 08 Apr 2025 17:41:56 -0400
> From: Spencer Baugh via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> This is a followup to 637dde4aba921435f78d0de769ad74c4f3230aa6, which
> removed some unnecessary escaping of "." and "?" when printing symbols
> in prin1.
>
> This change removes more unnecessary escaping of "."; "." only
> needs to be escaped when it's the entire symbol or if it's
> followed by a "?".
>
> (Actually, if we always escaped "?" (which was the case before
> 637dde4aba92) then "." only ever needs to be escaped when
> string_to_number returns non-nil. So 637dde4aba92 could have
> just dropped the escaping of "." with no other changes, if it
> didn't also remove escaping of "?")
Any objections or comments, anyone?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Sat, 12 Apr 2025 13:35:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 77656 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> Cc: Lars Ingebrigtsen <larsi <at> gnus.org>
>> Date: Tue, 08 Apr 2025 17:41:56 -0400
>> From: Spencer Baugh via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>> This is a followup to 637dde4aba921435f78d0de769ad74c4f3230aa6, which
>> removed some unnecessary escaping of "." and "?" when printing symbols
>> in prin1.
>>
>> This change removes more unnecessary escaping of "."; "." only
>> needs to be escaped when it's the entire symbol or if it's
>> followed by a "?".
>>
>> (Actually, if we always escaped "?" (which was the case before
>> 637dde4aba92) then "." only ever needs to be escaped when
>> string_to_number returns non-nil. So 637dde4aba92 could have
>> just dropped the escaping of "." with no other changes, if it
>> didn't also remove escaping of "?")
>
> Any objections or comments, anyone?
I guess the difference is this chunk:
- (should (equal (prin1-to-string '.foo) "\\.foo"))
- (should (equal (prin1-to-string '.foo.) "\\.foo."))
+ (should (equal (prin1-to-string '.foo) ".foo"))
+ (should (equal (prin1-to-string '.foo.) ".foo."))
No objections from me.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Sat, 12 Apr 2025 15:35:05 GMT)
Full text and
rfc822 format available.
Message #14 received at 77656 <at> debbugs.gnu.org (full text, mbox):
>>> This is a followup to 637dde4aba921435f78d0de769ad74c4f3230aa6, which
>>> removed some unnecessary escaping of "." and "?" when printing symbols
>>> in prin1.
>>>
>>> This change removes more unnecessary escaping of "."; "." only
>>> needs to be escaped when it's the entire symbol or if it's
>>> followed by a "?".
>>>
>>> (Actually, if we always escaped "?" (which was the case before
>>> 637dde4aba92) then "." only ever needs to be escaped when
>>> string_to_number returns non-nil. So 637dde4aba92 could have
>>> just dropped the escaping of "." with no other changes, if it
>>> didn't also remove escaping of "?")
>>
>> Any objections or comments, anyone?
No real objection, but I'm a bit worried that it seems this is designed
based on the idea that `prin1` should be `read`able by the same Emacs
that printed it, whereas I think it should aim to generate output
that's `read`able also by past and future Emacsen and that it shouldn't
unduly restrict future changes to our lexical rules.
I *think* the proposed change is OK in this respect, but at the same
time I wonder if the gain is really worth the risk.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Tue, 15 Apr 2025 15:49:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 77656 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>>>> This is a followup to 637dde4aba921435f78d0de769ad74c4f3230aa6, which
>>>> removed some unnecessary escaping of "." and "?" when printing symbols
>>>> in prin1.
>>>>
>>>> This change removes more unnecessary escaping of "."; "." only
>>>> needs to be escaped when it's the entire symbol or if it's
>>>> followed by a "?".
>>>>
>>>> (Actually, if we always escaped "?" (which was the case before
>>>> 637dde4aba92) then "." only ever needs to be escaped when
>>>> string_to_number returns non-nil. So 637dde4aba92 could have
>>>> just dropped the escaping of "." with no other changes, if it
>>>> didn't also remove escaping of "?")
>>>
>>> Any objections or comments, anyone?
>
> No real objection, but I'm a bit worried that it seems this is designed
> based on the idea that `prin1` should be `read`able by the same Emacs
> that printed it, whereas I think it should aim to generate output
> that's `read`able also by past and future Emacsen and that it shouldn't
> unduly restrict future changes to our lexical rules.
>
> I *think* the proposed change is OK in this respect, but at the same
> time I wonder if the gain is really worth the risk.
Yes, to be clear I think (though I haven't tested on truly ancient
Emacsen) that this is readable by all past versions of Emacs so it's
good in that department.
As for future Emacsen, I contend that we won't want to change how this
lexes in the future - it would break let-alist, for one thing.
Incidentally, making it easier to work with let-alist was one of my main
motivations for this change, since it ubiquitously uses symbols which
start with ".".
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Tue, 15 Apr 2025 16:24:03 GMT)
Full text and
rfc822 format available.
Message #20 received at 77656 <at> debbugs.gnu.org (full text, mbox):
> As for future Emacsen, I contend that we won't want to change how this
> lexes in the future - it would break let-alist, for one thing.
>
> Incidentally, making it easier to work with let-alist was one of my main
> motivations for this change, since it ubiquitously uses symbols which
> start with ".".
Thanks, it's good to have a clear use-case. You might want to mention
it in the commit message (tho at least now it's in the associated bug thread).
How often/much do we care about the printed form of `let-alist` expressions?
Maybe limiting the effect to ". at the beginning of symbol doesn't need
to be a escaped if the second char is a letter" would be good enough?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77656
; Package
emacs
.
(Tue, 15 Apr 2025 19:53:03 GMT)
Full text and
rfc822 format available.
Message #23 received at 77656 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> As for future Emacsen, I contend that we won't want to change how this
>> lexes in the future - it would break let-alist, for one thing.
>>
>> Incidentally, making it easier to work with let-alist was one of my main
>> motivations for this change, since it ubiquitously uses symbols which
>> start with ".".
>
> Thanks, it's good to have a clear use-case. You might want to mention
> it in the commit message (tho at least now it's in the associated bug thread).
Sure, done in the attached revised patch.
> How often/much do we care about the printed form of `let-alist` expressions?
Not often, it's mostly just that it's more convenient when hacking on it
(as I was a while back to add numeric indexing), and I figured it was a
harmless change.
> Maybe limiting the effect to ". at the beginning of symbol doesn't need
> to be a escaped if the second char is a letter" would be good enough?
That sounds reasonable to me, done in the attached patch.
[0001-Don-t-escape-.-in-prin1-when-followed-by-a-letter.patch (text/x-patch, inline)]
From 6db264d4f8ab2a6f520591958263bf61e92f10cc Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Tue, 4 Jun 2024 10:35:10 -0400
Subject: [PATCH] Don't escape "." in `prin1' when followed by a letter
Among other users, let-alist widely uses symbols which start with a ".".
Make those symbols print more nicely by tweaking the escaping rules in
print_object to not escape a leading "." followed by a letter. This is
a conservative change to avoid constraining future lexer changes.
This is a followup to 637dde4aba921435f78d0de769ad74c4f3230aa6, which
removed some unnecessary escaping of "." and "?" when printing symbols
in prin1. (Actually, if we always escaped "?" (which was the case
before 637dde4aba92) then "." only ever needs to be escaped when
string_to_number returns non-nil. So 637dde4aba92 could have just
dropped the escaping of "." with no other changes, if it didn't also
remove escaping of "?")
* src/print.c (print_object): Don't escape "." as the first
character in a symbol if followed by a letter. (bug#77656).
* test/src/print-tests.el (test-dots): Update for new behavior.
---
src/print.c | 9 ++++++---
test/src/print-tests.el | 6 ++++--
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/print.c b/src/print.c
index c7cba5bface..b17ec337f70 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2442,10 +2442,13 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
((c_isdigit (p[signedp]) || p[signedp] == '.')
&& !NILP (string_to_number (p, 10, &len))
&& len == size_byte)
- /* We don't escape "." or "?" (unless they're the first
- character in the symbol name). */
+ /* We don't escape "?" unless it's the first character in the
+ symbol name. */
|| *p == '?'
- || *p == '.';
+ /* We don't escape "." unless it's the first character in the
+ symbol name; even then, we don't escape it if it's followed
+ by [a-zA-Z]. */
+ || (*p == '.' && !(size_byte > 1 && c_isalpha (*(p+1))));
if (! NILP (Vprint_gensym)
&& !SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (obj))
diff --git a/test/src/print-tests.el b/test/src/print-tests.el
index 1a04cf73f30..af57311135b 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -415,8 +415,10 @@ test-unreadable
(ert-deftest test-dots ()
(should (equal (prin1-to-string 'foo.bar) "foo.bar"))
- (should (equal (prin1-to-string '.foo) "\\.foo"))
- (should (equal (prin1-to-string '.foo.) "\\.foo."))
+ (should (equal (prin1-to-string '.foo) ".foo"))
+ (should (equal (prin1-to-string '.foo.) ".foo."))
+ (should (equal (prin1-to-string '.$) "\\.$"))
+ (should (equal (prin1-to-string '\.) "\\."))
(should (equal (prin1-to-string 'bar?bar) "bar?bar"))
(should (equal (prin1-to-string '\?bar) "\\?bar"))
(should (equal (prin1-to-string '\?bar?) "\\?bar?")))
--
2.39.3
Reply sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
You have taken responsibility.
(Mon, 28 Apr 2025 17:48:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Spencer Baugh <sbaugh <at> janestreet.com>
:
bug acknowledged by developer.
(Mon, 28 Apr 2025 17:48:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 77656-done <at> debbugs.gnu.org (full text, mbox):
> That sounds reasonable to me, done in the attached patch.
Thanks, pushed to `master`, closing,
Stefan
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 27 May 2025 11:24:15 GMT)
Full text and
rfc822 format available.
This bug report was last modified 6 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.