aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2016-07-08 22:34:34 +0300
committerEli Zaretskii2016-07-08 22:34:34 +0300
commitd8a9c450cf4c575d21297885d6823920aec0482f (patch)
tree35d2299a4dd5779e6c5afe2ed849c4942480c902
parentd0c0b71d889ff223d2e5073b733f4047d541343b (diff)
downloademacs-d8a9c450cf4c575d21297885d6823920aec0482f.tar.gz
emacs-d8a9c450cf4c575d21297885d6823920aec0482f.zip
Yet another fix for copying properties by 'format'
* src/textprop.c (extend_property_ranges): Accept an additional argument OLD_END, and only extend the end of a property range if its original end is at OLD_END; all the other ranges are left intact. (Bug#23897) * src/editfns.c (styled_format): Pass the original length of the string to 'extend_property_ranges'. * src/intervals.h (extend_property_ranges): Adjust prototype. * test/src/editfns-tests.el (format-properties): Add tests for bug#23897.
-rw-r--r--src/editfns.c2
-rw-r--r--src/intervals.h2
-rw-r--r--src/textprop.c13
-rw-r--r--test/src/editfns-tests.el12
4 files changed, 21 insertions, 8 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 0c01c748d22..73f024409b1 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4631,7 +4631,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
4631 len = make_number (SCHARS (args[i])); 4631 len = make_number (SCHARS (args[i]));
4632 Lisp_Object new_len = make_number (info[i].end - info[i].start); 4632 Lisp_Object new_len = make_number (info[i].end - info[i].start);
4633 props = text_property_list (args[i], make_number (0), len, Qnil); 4633 props = text_property_list (args[i], make_number (0), len, Qnil);
4634 props = extend_property_ranges (props, new_len); 4634 props = extend_property_ranges (props, len, new_len);
4635 /* If successive arguments have properties, be sure that 4635 /* If successive arguments have properties, be sure that
4636 the value of `composition' property be the copy. */ 4636 the value of `composition' property be the copy. */
4637 if (1 < i && info[i - 1].end) 4637 if (1 < i && info[i - 1].end)
diff --git a/src/intervals.h b/src/intervals.h
index 6a5a4129abc..9a38d849b88 100644
--- a/src/intervals.h
+++ b/src/intervals.h
@@ -285,7 +285,7 @@ extern void set_text_properties_1 (Lisp_Object, Lisp_Object,
285Lisp_Object text_property_list (Lisp_Object, Lisp_Object, Lisp_Object, 285Lisp_Object text_property_list (Lisp_Object, Lisp_Object, Lisp_Object,
286 Lisp_Object); 286 Lisp_Object);
287void add_text_properties_from_list (Lisp_Object, Lisp_Object, Lisp_Object); 287void add_text_properties_from_list (Lisp_Object, Lisp_Object, Lisp_Object);
288Lisp_Object extend_property_ranges (Lisp_Object, Lisp_Object); 288Lisp_Object extend_property_ranges (Lisp_Object, Lisp_Object, Lisp_Object);
289Lisp_Object get_char_property_and_overlay (Lisp_Object, Lisp_Object, 289Lisp_Object get_char_property_and_overlay (Lisp_Object, Lisp_Object,
290 Lisp_Object, Lisp_Object*); 290 Lisp_Object, Lisp_Object*);
291extern int text_property_stickiness (Lisp_Object prop, Lisp_Object pos, 291extern int text_property_stickiness (Lisp_Object prop, Lisp_Object pos,
diff --git a/src/textprop.c b/src/textprop.c
index aabd5671e76..7af8c698736 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -2043,18 +2043,19 @@ add_text_properties_from_list (Lisp_Object object, Lisp_Object list, Lisp_Object
2043 end-points to NEW_END. */ 2043 end-points to NEW_END. */
2044 2044
2045Lisp_Object 2045Lisp_Object
2046extend_property_ranges (Lisp_Object list, Lisp_Object new_end) 2046extend_property_ranges (Lisp_Object list, Lisp_Object old_end, Lisp_Object new_end)
2047{ 2047{
2048 Lisp_Object prev = Qnil, head = list; 2048 Lisp_Object prev = Qnil, head = list;
2049 ptrdiff_t max = XINT (new_end); 2049 ptrdiff_t max = XINT (new_end);
2050 2050
2051 for (; CONSP (list); prev = list, list = XCDR (list)) 2051 for (; CONSP (list); prev = list, list = XCDR (list))
2052 { 2052 {
2053 Lisp_Object item, beg, end; 2053 Lisp_Object item, beg;
2054 ptrdiff_t end;
2054 2055
2055 item = XCAR (list); 2056 item = XCAR (list);
2056 beg = XCAR (item); 2057 beg = XCAR (item);
2057 end = XCAR (XCDR (item)); 2058 end = XINT (XCAR (XCDR (item)));
2058 2059
2059 if (XINT (beg) >= max) 2060 if (XINT (beg) >= max)
2060 { 2061 {
@@ -2065,12 +2066,14 @@ extend_property_ranges (Lisp_Object list, Lisp_Object new_end)
2065 else 2066 else
2066 XSETCDR (prev, XCDR (list)); 2067 XSETCDR (prev, XCDR (list));
2067 } 2068 }
2068 else if (XINT (end) != max) 2069 else if ((end == XINT (old_end) && end != max)
2070 || end > max)
2069 { 2071 {
2070 /* Either the end-point is past the end of the new string, 2072 /* Either the end-point is past the end of the new string,
2071 and we need to discard the properties past the new end, 2073 and we need to discard the properties past the new end,
2072 or the caller is extending the property range, and we 2074 or the caller is extending the property range, and we
2073 should update the end-point to reflect that. */ 2075 should update all end-points that are on the old end of
2076 the range to reflect that. */
2074 XSETCAR (XCDR (item), new_end); 2077 XSETCAR (XCDR (item), new_end);
2075 } 2078 }
2076 } 2079 }
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index c515927cff1..62d7bc4f5be 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -54,4 +54,14 @@
54 ;; Bug #23859 54 ;; Bug #23859
55 (should (ert-equal-including-properties 55 (should (ert-equal-including-properties
56 (format "%4s" (propertize "hi" 'face 'bold)) 56 (format "%4s" (propertize "hi" 'face 'bold))
57 #(" hi" 0 4 (face bold))))) 57 #(" hi" 0 4 (face bold))))
58
59 ;; Bug #23897
60 (should (ert-equal-including-properties
61 (format "%s" (concat (propertize "01234" 'face 'bold) "56789"))
62 #("0123456789" 0 5 (face bold))))
63 (should (ert-equal-including-properties
64 (format "%s" (concat (propertize "01" 'face 'bold)
65 (propertize "23" 'face 'underline)
66 "45"))
67 #("012345" 0 2 (face bold) 2 4 (face underline)))))