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