summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/editfns.c12
-rw-r--r--test/src/editfns-tests.el16
2 files changed, 25 insertions, 3 deletions
diff --git a/src/editfns.c b/src/editfns.c
index a8acff659cd..081ea0b3b7c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -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++;
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index ec411ff773b..c2ec99d8032 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -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)