aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-04-22 10:58:13 -0700
committerPaul Eggert2015-04-22 11:00:16 -0700
commit7128b0de899111c97749e3b7cddfb2935a7f0a9a (patch)
tree19f5ce0fa1e88999f165123149acd58d1a35ef97 /src
parentdf61b078228d8ee62abc9b03ae357a867c1013b3 (diff)
downloademacs-7128b0de899111c97749e3b7cddfb2935a7f0a9a.tar.gz
emacs-7128b0de899111c97749e3b7cddfb2935a7f0a9a.zip
Omit needless "\ " after multibyte then newline
* src/print.c: Include <c-ctype.h>, for c_isxdigit. (print_object): When print-escape-multibyte is non-nil and a multibyte character is followed by a newline or formfeed, followed by a hex digit, don't output a needless "\ " before the hex digit. * test/automated/print-tests.el (print-hex-backslash): New test.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c2
-rw-r--r--src/print.c71
2 files changed, 30 insertions, 43 deletions
diff --git a/src/lread.c b/src/lread.c
index fa9a63e63a9..a84450a4364 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3024,7 +3024,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
3024 3024
3025 ch = read_escape (readcharfun, 1); 3025 ch = read_escape (readcharfun, 1);
3026 3026
3027 /* CH is -1 if \ newline has just been seen. */ 3027 /* CH is -1 if \ newline or \ space has just been seen. */
3028 if (ch == -1) 3028 if (ch == -1)
3029 { 3029 {
3030 if (p == read_buffer) 3030 if (p == read_buffer)
diff --git a/src/print.c b/src/print.c
index 916276bc961..bff5932c1d1 100644
--- a/src/print.c
+++ b/src/print.c
@@ -37,6 +37,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
37#include "termhooks.h" /* For struct terminal. */ 37#include "termhooks.h" /* For struct terminal. */
38#include "font.h" 38#include "font.h"
39 39
40#include <c-ctype.h>
40#include <float.h> 41#include <float.h>
41#include <ftoastr.h> 42#include <ftoastr.h>
42 43
@@ -1385,9 +1386,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1385 register ptrdiff_t i, i_byte; 1386 register ptrdiff_t i, i_byte;
1386 struct gcpro gcpro1; 1387 struct gcpro gcpro1;
1387 ptrdiff_t size_byte; 1388 ptrdiff_t size_byte;
1388 /* 1 means we must ensure that the next character we output 1389 /* True means we must ensure that the next character we output
1389 cannot be taken as part of a hex character escape. */ 1390 cannot be taken as part of a hex character escape. */
1390 bool need_nonhex = 0; 1391 bool need_nonhex = false;
1391 bool multibyte = STRING_MULTIBYTE (obj); 1392 bool multibyte = STRING_MULTIBYTE (obj);
1392 1393
1393 GCPRO1 (obj); 1394 GCPRO1 (obj);
@@ -1411,60 +1412,46 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1411 1412
1412 QUIT; 1413 QUIT;
1413 1414
1414 if (c == '\n' && print_escape_newlines) 1415 if (multibyte
1415 print_c_string ("\\n", printcharfun); 1416 ? (CHAR_BYTE8_P (c) && (c = CHAR_TO_BYTE8 (c), true))
1416 else if (c == '\f' && print_escape_newlines) 1417 : (SINGLE_BYTE_CHAR_P (c) && ! ASCII_CHAR_P (c)
1417 print_c_string ("\\f", printcharfun); 1418 && print_escape_nonascii))
1418 else if (multibyte
1419 && (CHAR_BYTE8_P (c)
1420 || (! ASCII_CHAR_P (c) && print_escape_multibyte)))
1421 {
1422 /* When multibyte is disabled,
1423 print multibyte string chars using hex escapes.
1424 For a char code that could be in a unibyte string,
1425 when found in a multibyte string, always use a hex escape
1426 so it reads back as multibyte. */
1427 char outbuf[50];
1428 int len;
1429
1430 if (CHAR_BYTE8_P (c))
1431 len = sprintf (outbuf, "\\%03o", CHAR_TO_BYTE8 (c));
1432 else
1433 {
1434 len = sprintf (outbuf, "\\x%04x", c);
1435 need_nonhex = 1;
1436 }
1437 strout (outbuf, len, len, printcharfun);
1438 }
1439 else if (! multibyte
1440 && SINGLE_BYTE_CHAR_P (c) && ! ASCII_CHAR_P (c)
1441 && print_escape_nonascii)
1442 { 1419 {
1443 /* When printing in a multibyte buffer 1420 /* When printing a raw 8-bit byte in a multibyte buffer, or
1444 or when explicitly requested, 1421 (when requested) a non-ASCII character in a unibyte buffer,
1445 print single-byte non-ASCII string chars 1422 print single-byte non-ASCII string chars
1446 using octal escapes. */ 1423 using octal escapes. */
1447 char outbuf[5]; 1424 char outbuf[5];
1448 int len = sprintf (outbuf, "\\%03o", c); 1425 int len = sprintf (outbuf, "\\%03o", c);
1449 strout (outbuf, len, len, printcharfun); 1426 strout (outbuf, len, len, printcharfun);
1427 need_nonhex = false;
1428 }
1429 else if (multibyte
1430 && ! ASCII_CHAR_P (c) && print_escape_multibyte)
1431 {
1432 /* When requested, print multibyte chars using hex escapes. */
1433 char outbuf[sizeof "\\x" + INT_STRLEN_BOUND (c)];
1434 int len = sprintf (outbuf, "\\x%04x", c);
1435 strout (outbuf, len, len, printcharfun);
1436 need_nonhex = true;
1450 } 1437 }
1451 else 1438 else
1452 { 1439 {
1453 /* If we just had a hex escape, and this character 1440 /* If we just had a hex escape, and this character
1454 could be taken as part of it, 1441 could be taken as part of it,
1455 output `\ ' to prevent that. */ 1442 output `\ ' to prevent that. */
1456 if (need_nonhex) 1443 if (need_nonhex && c_isxdigit (c))
1457 { 1444 print_c_string ("\\ ", printcharfun);
1458 need_nonhex = 0; 1445
1459 if ((c >= 'a' && c <= 'f') 1446 if (c == '\n' && print_escape_newlines
1460 || (c >= 'A' && c <= 'F') 1447 ? (c = 'n', true)
1461 || (c >= '0' && c <= '9')) 1448 : c == '\f' && print_escape_newlines
1462 print_c_string ("\\ ", printcharfun); 1449 ? (c = 'f', true)
1463 } 1450 : c == '\"' || c == '\\')
1464
1465 if (c == '\"' || c == '\\')
1466 printchar ('\\', printcharfun); 1451 printchar ('\\', printcharfun);
1452
1467 printchar (c, printcharfun); 1453 printchar (c, printcharfun);
1454 need_nonhex = false;
1468 } 1455 }
1469 } 1456 }
1470 printchar ('\"', printcharfun); 1457 printchar ('\"', printcharfun);