From 1c09423880e1c48d6ba02a196430e829d1d87d57 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 9 Jun 2016 16:52:08 +0300 Subject: [PATCH] Fix copying text properties by 'format' * src/editfns.c (styled_format): Fix copying text properties from the format specification to the produced string representation. (Bug#23730) (Fformat) Doc fix. * doc/lispref/strings.texi (Formatting Strings): Document that text properties from the format specifiers are also copied to the produced string. --- doc/lispref/strings.texi | 3 ++- src/editfns.c | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index cf0505f446..fc356af51b 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -833,7 +833,8 @@ arguments @var{objects} are the computed values to be formatted. The characters in @var{string}, other than the format specifications, are copied directly into the output, including their text properties, -if any. +if any. Any text properties of the format specifications are copied +to the produced string representations of the argument @var{objects}. @end defun @defun format-message string &rest objects diff --git a/src/editfns.c b/src/editfns.c index f29fc510a2..a6d1354571 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3883,6 +3883,9 @@ precision specifier says how many decimal places to show; if zero, the decimal point itself is omitted. For %s and %S, the precision specifier truncates the string to the given width. +Text properties, if any, are copied from the format-string to the +produced text. + usage: (format STRING &rest OBJECTS) */) (ptrdiff_t nargs, Lisp_Object *args) { @@ -4170,6 +4173,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) convbytes += padding; if (convbytes <= buf + bufsize - p) { + info[n].start = nchars; if (! minus_flag) { memset (p, ' ', padding); @@ -4188,9 +4192,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) nbytes, STRING_MULTIBYTE (args[n]), multibyte); - info[n].start = nchars; nchars += nchars_string; - info[n].end = nchars; if (minus_flag) { @@ -4198,6 +4200,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) p += padding; nchars += padding; } + info[n].end = nchars; /* If this argument has text properties, record where in the result string it appears. */ @@ -4415,6 +4418,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) exponent_bytes = src + sprintf_bytes - e; } + info[n].start = nchars; if (! minus_flag) { memset (p, ' ', padding); @@ -4437,9 +4441,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) memcpy (p, src, exponent_bytes); p += exponent_bytes; - info[n].start = nchars; nchars += leading_zeros + sprintf_bytes + trailing_zeros; - info[n].end = nchars; if (minus_flag) { @@ -4447,6 +4449,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) p += padding; nchars += padding; } + info[n].end = nchars; continue; } -- 2.39.2