From: Spencer Baugh Date: Tue, 4 Jun 2024 14:35:10 +0000 (-0400) Subject: Don't escape "." in `prin1' when followed by a letter X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e0dce7dc5b0429c9ab28f8d3c6885cf27ccd0e70;p=emacs.git 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. (cherry picked from commit 21e340494a5a832453999d3853839db5d8a4d865) --- 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 @@ 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?")))