From 2add3a1595f709bb071e2b775970038470b2fab2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 3 Feb 2018 20:30:48 -0800 Subject: [PATCH 3/4] prin1 etc. now escape more chars in symbols Inspired by email from Aaron Ecay in: https://lists.gnu.org/r/emacs-devel/2018-02/msg00125.html * etc/NEWS: Mention this. * src/print.c (print_object): Escape any character that is not documented to not require escaping. --- etc/NEWS | 7 +++++++ src/print.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index afd0fba..2a46002 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -87,6 +87,13 @@ regular expression was previously invalid, but is now accepted: x\{32768\} +** 'print' and related functions now escape more chars in symbols. +They now escape any symbol character that is outside the documented +set of characters that do not need escaping. For example, (print +(intern "n\u0456l")) now outputs "n\іl" instead of "nіl", as a hint to +the reader that the "і" is not the usual U+0069 LATIN SMALL LETTER I, +but is instead U+0456 CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I. + * Editing Changes in Emacs 27.1 diff --git a/src/print.c b/src/print.c index d3eb49d..7eca36a 100644 --- a/src/print.c +++ b/src/print.c @@ -1959,12 +1959,37 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) if (escapeflag) { - if (c == '\"' || c == '\\' || c == '\'' - || c == ';' || c == '#' || c == '(' || c == ')' - || c == ',' || c == '.' || c == '`' - || c == '[' || c == ']' || c == '?' || c <= 040 - || confusing - || (i == 1 && confusable_symbol_character_p (c))) + switch (c) + { + /* The Emacs Lisp manual lists these characters as + not requiring escaping in symbols. Although some + other characters might also work, play it safe + and escape all but these characters. */ + case '!': case '$': case '%': case '&': + case '*': case '-': case '+': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case '<': case '=': case '>': case '@': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case '{': case '}': case '~': + break; + + default: + confusing = true; + break; + } + + if (confusing) { printchar ('\\', printcharfun); confusing = false; -- 2.7.4