Fix 'format-mode-line' when faces are in format string

* src/xdisp.c (store_mode_line_string): Don't assume that PROPS
can only specify the face for LISP_STRING; if PROPS don't specify
a face, fall back on the 'face' property of LISP_STRING.
(Bug#81316)

* test/src/xdisp-tests.el (xdisp-test-format-mode-line): Add a
test for this issue.
This commit is contained in:
Eli Zaretskii 2026-06-28 14:59:16 +03:00
parent a34c29e459
commit 4d2701ecde
2 changed files with 21 additions and 5 deletions

View file

@ -28934,14 +28934,24 @@ store_mode_line_string (const char *string, Lisp_Object lisp_string,
if (!NILP (mode_line_string_face))
{
Lisp_Object face;
if (NILP (props))
props = Ftext_properties_at (make_fixnum (0), lisp_string);
face = plist_get (props, Qface);
Lisp_Object string_face =
plist_get (Ftext_properties_at (make_fixnum (0), lisp_string),
Qface);
/* Use the face in PROPS, if any, falling back to the face of
LISP_STRING. */
face = string_face;
if (!NILP (props))
{
Lisp_Object propface = plist_get (props, Qface);
if (!NILP (propface))
face = propface;
}
if (NILP (face))
face = mode_line_string_face;
else
face = list2 (face, mode_line_string_face);
props = list2 (Qface, face);
props = Fcopy_sequence (props);
props = plist_put (props, Qface, face);
if (copy_string)
lisp_string = Fcopy_sequence (lisp_string);
}

View file

@ -190,6 +190,12 @@ int main () {
(insert (format-mode-line
(propertize "x" 'face 'bold-italic)
1200000000000000000000000000))
(should (null (get-text-property 1 'face)))))
(should (null (get-text-property 1 'face))))
(should
(equal
(text-properties-at
0
(format-mode-line '((:propertize "Hello!" face bold)) 'mode-line))
(list 'face '(bold mode-line) 'mode-line-elt-no 3))))
;;; xdisp-tests.el ends here