]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't escape "." in `prin1' when followed by a letter
authorSpencer Baugh <sbaugh@janestreet.com>
Tue, 4 Jun 2024 14:35:10 +0000 (10:35 -0400)
committerEshel Yaron <me@eshelyaron.com>
Tue, 29 Apr 2025 07:33:16 +0000 (09:33 +0200)
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.

(cherry picked from commit 21e340494a5a832453999d3853839db5d8a4d865)

src/print.c
test/src/print-tests.el

index c7cba5bface1cc5fda464df01231509ac66531d7..b17ec337f70af48fea740e689f5266abbb18e98e 100644 (file)
@@ -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))
index 1a04cf73f30a415238c647119cbcac1f206fef4d..af57311135bfea82eeb51daccb8e66f719d75fcd 100644 (file)
@@ -415,8 +415,10 @@ otherwise, use a different charset."
 
 (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?")))