Fix copying text properties by 'format'
* src/editfns.c (styled_format): Add the spec beginning index to the info recorded for each format spec, and use it to detect the case that a format spec and its text property end where the next spec with another property begins. (Bug#32404) * test/src/editfns-tests.el (format-properties): Add tests for bug#32404.
This commit is contained in:
parent
96be6b6eb9
commit
71c92d8913
2 changed files with 25 additions and 3 deletions
|
@ -4257,6 +4257,9 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
|
|||
/* The start and end bytepos in the output string. */
|
||||
ptrdiff_t start, end;
|
||||
|
||||
/* The start of the spec in the format string. */
|
||||
ptrdiff_t fbeg;
|
||||
|
||||
/* Whether the argument is a string with intervals. */
|
||||
bool_bf intervals : 1;
|
||||
} *info;
|
||||
|
@ -4408,6 +4411,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
|
|||
char conversion = *format++;
|
||||
memset (&discarded[format0 - format_start], 1,
|
||||
format - format0 - (conversion == '%'));
|
||||
info[ispec].fbeg = format0 - format_start;
|
||||
if (conversion == '%')
|
||||
{
|
||||
new_result = true;
|
||||
|
@ -4981,7 +4985,9 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
|
|||
else if (discarded[bytepos] == 1)
|
||||
{
|
||||
position++;
|
||||
if (fieldn < nspec && translated == info[fieldn].start)
|
||||
if (fieldn < nspec
|
||||
&& position > info[fieldn].fbeg
|
||||
&& translated == info[fieldn].start)
|
||||
{
|
||||
translated += info[fieldn].end - info[fieldn].start;
|
||||
fieldn++;
|
||||
|
@ -5001,7 +5007,9 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
|
|||
else if (discarded[bytepos] == 1)
|
||||
{
|
||||
position++;
|
||||
if (fieldn < nspec && translated == info[fieldn].start)
|
||||
if (fieldn < nspec
|
||||
&& position > info[fieldn].fbeg
|
||||
&& translated == info[fieldn].start)
|
||||
{
|
||||
translated += info[fieldn].end - info[fieldn].start;
|
||||
fieldn++;
|
||||
|
|
|
@ -88,7 +88,21 @@
|
|||
(format "%-10s" (concat (propertize "01" 'face 'bold)
|
||||
(propertize "23" 'face 'underline)
|
||||
(propertize "45" 'face 'italic)))
|
||||
#("012345 " 0 2 (face bold) 2 4 (face underline) 4 10 (face italic)))))
|
||||
#("012345 "
|
||||
0 2 (face bold) 2 4 (face underline) 4 10 (face italic))))
|
||||
;; Bug #32404
|
||||
(should (ert-equal-including-properties
|
||||
(format (concat (propertize "%s" 'face 'bold)
|
||||
""
|
||||
(propertize "%s" 'face 'error))
|
||||
"foo" "bar")
|
||||
#("foobar" 0 3 (face bold) 3 6 (face error))))
|
||||
(should (ert-equal-including-properties
|
||||
(format (concat "%s" (propertize "%s" 'face 'error)) "foo" "bar")
|
||||
#("foobar" 3 6 (face error))))
|
||||
(should (ert-equal-including-properties
|
||||
(format (concat "%s " (propertize "%s" 'face 'error)) "foo" "bar")
|
||||
#("foo bar" 4 7 (face error)))))
|
||||
|
||||
;; Tests for bug#5131.
|
||||
(defun transpose-test-reverse-word (start end)
|
||||
|
|
Loading…
Add table
Reference in a new issue