aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-08-14 15:50:36 -0700
committerPaul Eggert2015-08-14 15:55:58 -0700
commite26006404ad1e9b273aafffbbb24074fba5bab37 (patch)
treeb9b41547bfcb8d1645e351efba020408bf79d11f
parent6af5aad26411ffe21c3fe4bc5438347110910111 (diff)
downloademacs-e26006404ad1e9b273aafffbbb24074fba5bab37.tar.gz
emacs-e26006404ad1e9b273aafffbbb24074fba5bab37.zip
Low-level diagnostics now use ‘text-quoting-style’
* src/doprnt.c (doprnt): Format ` and ' as per ‘text-quoting-style’. * src/xdisp.c (vmessage, message): Mention that the format should not contain ` or '.
-rw-r--r--src/doprnt.c60
-rw-r--r--src/xdisp.c6
2 files changed, 42 insertions, 24 deletions
diff --git a/src/doprnt.c b/src/doprnt.c
index 68750f519e6..7c5a6afb94b 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -49,8 +49,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
49 support features beyond those in `Fformat', which is used by `error' on the 49 support features beyond those in `Fformat', which is used by `error' on the
50 Lisp level. */ 50 Lisp level. */
51 51
52/* This function supports the following %-sequences in the `format' 52/* In the FORMAT argument this function supports ` and ' as directives
53 argument: 53 that output left and right quotes as per ‘text-quoting style’. It
54 also supports the following %-sequences:
54 55
55 %s means print a string argument. 56 %s means print a string argument.
56 %S is silently treated as %s, for loose compatibility with `Fformat'. 57 %S is silently treated as %s, for loose compatibility with `Fformat'.
@@ -144,6 +145,7 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
144 /* Buffer we have got with malloc. */ 145 /* Buffer we have got with malloc. */
145 char *big_buffer = NULL; 146 char *big_buffer = NULL;
146 147
148 enum text_quoting_style quoting_style = text_quoting_style ();
147 ptrdiff_t tem = -1; 149 ptrdiff_t tem = -1;
148 char *string; 150 char *string;
149 char fixed_buffer[20]; /* Default buffer for small formatting. */ 151 char fixed_buffer[20]; /* Default buffer for small formatting. */
@@ -164,7 +166,9 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
164 /* Loop until end of format string or buffer full. */ 166 /* Loop until end of format string or buffer full. */
165 while (fmt < format_end && bufsize > 0) 167 while (fmt < format_end && bufsize > 0)
166 { 168 {
167 if (*fmt == '%') /* Check for a '%' character */ 169 char const *fmt0 = fmt;
170 char fmtchar = *fmt++;
171 if (fmtchar == '%')
168 { 172 {
169 ptrdiff_t size_bound = 0; 173 ptrdiff_t size_bound = 0;
170 ptrdiff_t width; /* Columns occupied by STRING on display. */ 174 ptrdiff_t width; /* Columns occupied by STRING on display. */
@@ -180,7 +184,6 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
180 int maxmlen = max (max (1, pDlen), max (pIlen, pMlen)); 184 int maxmlen = max (max (1, pDlen), max (pIlen, pMlen));
181 int mlen; 185 int mlen;
182 186
183 fmt++;
184 /* Copy this one %-spec into fmtcpy. */ 187 /* Copy this one %-spec into fmtcpy. */
185 string = fmtcpy; 188 string = fmtcpy;
186 *string++ = '%'; 189 *string++ = '%';
@@ -438,22 +441,36 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
438 } 441 }
439 } 442 }
440 443
441 { 444 char const *src;
442 /* Just some character; Copy it if the whole multi-byte form 445 ptrdiff_t srclen;
443 fit in the buffer. */ 446 if (quoting_style == CURVE_QUOTING_STYLE && fmtchar == '`')
444 char *save_bufptr = bufptr; 447 src = uLSQM, srclen = sizeof uLSQM - 1;
445 448 else if (quoting_style == CURVE_QUOTING_STYLE && fmtchar == '\'')
446 do { *bufptr++ = *fmt++; } 449 src = uRSQM, srclen = sizeof uRSQM - 1;
447 while (fmt < format_end && --bufsize > 0 && !CHAR_HEAD_P (*fmt)); 450 else if (quoting_style == STRAIGHT_QUOTING_STYLE && fmtchar == '`')
448 if (!CHAR_HEAD_P (*fmt)) 451 src = "'", srclen = 1;
449 { 452 else
450 /* Truncate, but return value that will signal to caller 453 {
451 that the buffer was too small. */ 454 while (fmt < format_end && !CHAR_HEAD_P (*fmt))
452 *save_bufptr = 0; 455 fmt++;
453 break; 456 src = fmt0, srclen = fmt - fmt0;
454 } 457 }
455 } 458
456 }; 459 if (bufsize < srclen)
460 {
461 /* Truncate, but return value that will signal to caller
462 that the buffer was too small. */
463 do
464 *bufptr++ = '\0';
465 while (--bufsize != 0);
466 }
467 else
468 {
469 do
470 *bufptr++ = *src++;
471 while (--srclen != 0);
472 }
473 }
457 474
458 /* If we had to malloc something, free it. */ 475 /* If we had to malloc something, free it. */
459 xfree (big_buffer); 476 xfree (big_buffer);
@@ -467,7 +484,8 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
467/* Format to an unbounded buffer BUF. This is like sprintf, except it 484/* Format to an unbounded buffer BUF. This is like sprintf, except it
468 is not limited to returning an 'int' so it doesn't have a silly 2 485 is not limited to returning an 'int' so it doesn't have a silly 2
469 GiB limit on typical 64-bit hosts. However, it is limited to the 486 GiB limit on typical 64-bit hosts. However, it is limited to the
470 Emacs-style formats that doprnt supports. 487 Emacs-style formats that doprnt supports, and it requotes ` and '
488 as per ‘text-quoting-style’.
471 489
472 Return the number of bytes put into BUF, excluding the terminating 490 Return the number of bytes put into BUF, excluding the terminating
473 '\0'. */ 491 '\0'. */
diff --git a/src/xdisp.c b/src/xdisp.c
index 52c77bd434d..6d747ebc5ce 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10275,9 +10275,9 @@ message_with_string (const char *m, Lisp_Object string, bool log)
10275/* Dump an informative message to the minibuf. If M is 0, clear out 10275/* Dump an informative message to the minibuf. If M is 0, clear out
10276 any existing message, and let the mini-buffer text show through. 10276 any existing message, and let the mini-buffer text show through.
10277 10277
10278 The message must be safe ASCII only. If strings may contain escape 10278 The message must be safe ASCII and the format must not contain ` or
10279 sequences or non-ASCII characters, convert them to Lisp strings and 10279 '. If your message and format do not fit into this category,
10280 use Fmessage. */ 10280 convert your arguments to Lisp objects and use Fmessage instead. */
10281 10281
10282static void ATTRIBUTE_FORMAT_PRINTF (1, 0) 10282static void ATTRIBUTE_FORMAT_PRINTF (1, 0)
10283vmessage (const char *m, va_list ap) 10283vmessage (const char *m, va_list ap)