Commit 1c094238 authored by Eli Zaretskii's avatar Eli Zaretskii

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.
parent fabb5582
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment