Subject: bug#77656: closed (Re: bug#77656: [PATCH] Don't escape "." in `prin1' unless followed by "?" or nothing)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 28 Apr 2025 17:48:02 +0000

Your bug report

#77656: [PATCH] Don't escape "." in `prin1' unless followed by "?" or nothing

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
77656: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77656
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#77656: [PATCH] Don't escape "." in `prin1' unless followed by "?" or nothing
From: Stefan Monnier <[email-masked]>
To: Spencer Baugh <[email-masked]>
Cc: [email-masked], Andrea Corallo <[email-masked]>, Eli Zaretskii <[email-masked]>, [email-masked], Stefan Kangas <[email-masked]>
Date: Mon, 28 Apr 2025 13:47:32 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> That sounds reasonable to me, done in the attached patch.

Thanks, pushed to `master`, closing,

        Stefan

Subject: [PATCH] Don't escape "." in `prin1' unless followed by "?" or nothing
From: Spencer Baugh <[email-masked]>
To: [email-masked]
Date: Tue, 08 Apr 2025 17:41:56 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

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'

>From debb205a42505eac022c51886732304d026db8a8 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Tue, 4 Jun 2024 10:35:10 -0400
Subject: [PATCH] Don't escape "." in `prin1' unless followed by "?" or nothing

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 "?")

* src/print.c (print_object): Only escape "." as the first
character in a symbol if followed by "?" or nothing.
* test/src/print-tests.el (test-dots): Update for new behavior.
---
 src/print.c             | 8 +++++---
 test/src/print-tests.el | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/print.c b/src/print.c
index c7cba5bface..c8ab73f6275 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2442,10 +2442,12 @@ 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 entire symbol name, or
+	     followed by a "?". */
+	  || (*p == '.' && (size_byte == 1 || *(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..34254963e6d 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -415,8 +415,8 @@ 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 'bar?bar) "bar?bar"))
   (should (equal (prin1-to-string '\?bar) "\\?bar"))
   (should (equal (prin1-to-string '\?bar?) "\\?bar?")))
-- 
2.39.3