From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Drew Adams <drew.adams@oracle.com>
Cc: Alan Mackenzie <acm@muc.de>, 30217@debbugs.gnu.org
Subject: bug#30217: Ambiguity in NEWS in emacs-26.0.91
Date: Tue, 23 Jan 2018 19:02:13 -0500 [thread overview]
Message-ID: <87vafsm8e2.fsf@users.sourceforge.net> (raw)
In-Reply-To: <e64e0385-7138-4495-a653-30dff788bbf9@default> (Drew Adams's message of "Tue, 23 Jan 2018 15:19:07 -0800 (PST)")
[-- Attachment #1: Type: text/plain, Size: 624 bytes --]
Drew Adams <drew.adams@oracle.com> writes:
> Of course something about escaping has changed.
> \’bar is now read differently from ’bar.
Oh, I see. I was considering that since the meaning of \’bar hasn't
changed, then escaping hasn't changed (though non-escaped syntax has).
Anyway, thinking about this made realize I broke read->print
round-tripping for these symbols, because I didn't change print to add
the backslash. Attached is a patch which does this, but I'm not sure if
it can go into emacs-26. If not, then I think we should at least delay
introduction of the reader change to Emacs 27.
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 6255 bytes --]
From c661d622d7109dcddd957524c4dd4457b41c1561 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Tue, 23 Jan 2018 18:50:23 -0500
Subject: [PATCH] Fix round tripping of read->print for symbols with strange
quotes
Since 2017-07-22 "Signal error for symbol names with strange
quotes (Bug#2967)", symbol names beginning with certain quote
characters require an escaping backslash. However, the corresponding
change for printing missed, so that (eq (read (prin1-to-string SYM))
SYM) does not give `t' for such symbols.
* src/character.c (confusable_symbol_character_p): New function,
extracted from test `read1'.
* src/lread.c (read1): Use it.
* src/print.c (print_object): Use it to print a backslash for symbols
starting with characters that `read1' requires to be escaped.
* test/src/print-tests.el (print-read-roundtrip): New test.
* etc/NEWS: Clarify the announcement for the earlier reader
change (Bug#30217).
---
etc/NEWS | 12 +++++++++---
src/character.c | 26 ++++++++++++++++++++++++++
src/character.h | 2 ++
src/lread.c | 17 +++--------------
src/print.c | 3 ++-
test/src/print-tests.el | 4 ++++
6 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index f5859d7a60..c760738105 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1385,9 +1385,15 @@ renamed to 'lread--old-style-backquotes'. No user code should use
this variable.
---
-** To avoid confusion caused by "smart quotes", the reader no longer
-accepts Lisp symbols which begin with the following quotation
-characters: ‘’‛“”‟〞"', unless they are escaped with backslash.
+** To avoid confusion caused by "smart quotes", the reader signals an
+error when reading Lisp symbols which begin with one of the following
+quotation characters: ‘’‛“”‟〞"'. A symbol beginning with such a
+character can be written by escaping the quotation character with a
+backslash. For example:
+
+ (read "‘smart") => (invalid-read-syntax "strange quote" "‘")
+ (read "\\‘smart") == (intern "‘smart")
+
+++
** 'default-file-name-coding-system' now defaults to a coding system
diff --git a/src/character.c b/src/character.c
index fa817a5031..4a934c7801 100644
--- a/src/character.c
+++ b/src/character.c
@@ -1050,6 +1050,32 @@ blankp (int c)
return XINT (category) == UNICODE_CATEGORY_Zs; /* separator, space */
}
+
+/* Return true for characters that would read as symbol characters,
+ but graphically may be confused with some kind of punctuation. We
+ require an escaping backslash, when such characters begin a
+ symbol. */
+bool
+confusable_symbol_character_p (int ch)
+{
+ switch (ch)
+ {
+ case 0x2018: /* LEFT SINGLE QUOTATION MARK */
+ case 0x2019: /* RIGHT SINGLE QUOTATION MARK */
+ case 0x201B: /* SINGLE HIGH-REVERSED-9 QUOTATION MARK */
+ case 0x201C: /* LEFT DOUBLE QUOTATION MARK */
+ case 0x201D: /* RIGHT DOUBLE QUOTATION MARK */
+ case 0x201F: /* DOUBLE HIGH-REVERSED-9 QUOTATION MARK */
+ case 0x301E: /* DOUBLE PRIME QUOTATION MARK */
+ case 0xFF02: /* FULLWIDTH QUOTATION MARK */
+ case 0xFF07: /* FULLWIDTH APOSTROPHE */
+ return true;
+
+ default:
+ return false;
+ }
+}
+
signed char HEXDIGIT_CONST hexdigit[UCHAR_MAX + 1] =
{
#if HEXDIGIT_IS_CONST
diff --git a/src/character.h b/src/character.h
index c716885d46..d9e2d7bfc6 100644
--- a/src/character.h
+++ b/src/character.h
@@ -682,6 +682,8 @@ char_surrogate_p (int c)
extern bool printablep (int);
extern bool blankp (int);
+extern bool confusable_symbol_character_p (int ch);
+
/* Return a translation table of id number ID. */
#define GET_TRANSLATION_TABLE(id) \
(XCDR (XVECTOR (Vtranslation_table_vector)->contents[(id)]))
diff --git a/src/lread.c b/src/lread.c
index 45d60647be..82731781f0 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3482,20 +3482,9 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
if (!quoted && multibyte)
{
int ch = STRING_CHAR ((unsigned char *) read_buffer);
- switch (ch)
- {
- case 0x2018: /* LEFT SINGLE QUOTATION MARK */
- case 0x2019: /* RIGHT SINGLE QUOTATION MARK */
- case 0x201B: /* SINGLE HIGH-REVERSED-9 QUOTATION MARK */
- case 0x201C: /* LEFT DOUBLE QUOTATION MARK */
- case 0x201D: /* RIGHT DOUBLE QUOTATION MARK */
- case 0x201F: /* DOUBLE HIGH-REVERSED-9 QUOTATION MARK */
- case 0x301E: /* DOUBLE PRIME QUOTATION MARK */
- case 0xFF02: /* FULLWIDTH QUOTATION MARK */
- case 0xFF07: /* FULLWIDTH APOSTROPHE */
- xsignal2 (Qinvalid_read_syntax, build_string ("strange quote"),
- CALLN (Fstring, make_number (ch)));
- }
+ if (confusable_symbol_character_p (ch))
+ xsignal2 (Qinvalid_read_syntax, build_string ("strange quote"),
+ CALLN (Fstring, make_number (ch)));
}
{
Lisp_Object result;
diff --git a/src/print.c b/src/print.c
index 47cb33deeb..b0741531f7 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1971,7 +1971,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
|| c == ';' || c == '#' || c == '(' || c == ')'
|| c == ',' || c == '.' || c == '`'
|| c == '[' || c == ']' || c == '?' || c <= 040
- || confusing)
+ || confusing
+ || (i == 1 && confusable_symbol_character_p (c)))
{
printchar ('\\', printcharfun);
confusing = false;
diff --git a/test/src/print-tests.el b/test/src/print-tests.el
index 46368c69ad..01e65028bc 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -58,5 +58,9 @@
(buffer-string))
"--------\n"))))
+(ert-deftest print-read-roundtrip ()
+ (let ((sym '\’bar))
+ (should (eq (read (prin1-to-string sym)) sym))))
+
(provide 'print-tests)
;;; print-tests.el ends here
--
2.11.0
next prev parent reply other threads:[~2018-01-24 0:02 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 22:17 bug#30217: Ambiguity in NEWS in emacs-26.0.91 Alan Mackenzie
2018-01-22 22:42 ` Drew Adams
2018-01-23 0:42 ` Noam Postavsky
2018-01-23 0:56 ` Drew Adams
2018-01-23 1:40 ` Noam Postavsky
2018-01-23 6:07 ` Drew Adams
2018-01-23 6:21 ` Drew Adams
2018-01-23 12:54 ` Noam Postavsky
2018-01-23 15:53 ` Drew Adams
2018-01-23 23:00 ` Noam Postavsky
2018-01-23 23:19 ` Drew Adams
2018-01-24 0:02 ` Noam Postavsky [this message]
2018-01-28 15:52 ` Noam Postavsky
2018-02-02 18:52 ` Drew Adams
2018-02-02 19:08 ` Noam Postavsky
2018-02-02 21:37 ` Drew Adams
2018-02-02 22:14 ` Ista Zahn
2018-02-02 22:35 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vafsm8e2.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=30217@debbugs.gnu.org \
--cc=acm@muc.de \
--cc=drew.adams@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.