emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 71c92d8: Fix copying text properties by 'format'


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-26 71c92d8: Fix copying text properties by 'format'
Date: Thu, 9 Aug 2018 11:09:49 -0400 (EDT)

branch: emacs-26
commit 71c92d89137b7fdde6c2bd4bed9b8dfda5fa53dd
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    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.
---
 src/editfns.c             | 12 ++++++++++--
 test/src/editfns-tests.el | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/editfns.c b/src/editfns.c
index a8acff6..081ea0b 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 ec411ff..c2ec99d 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]