emacs-31 e78a0fc9f4d: Resurrect effect of 2nd arg t in 'format-mode-line'

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: emacs-31
commit e78a0fc9f4d38c524601dacfa5b01b060f46c764
Author: Eli Zaretskii <[email protected]>
Commit: Eli Zaretskii <[email protected]>

    Resurrect effect of 2nd arg t in 'format-mode-line'
    
    * src/xdisp.c (Fformat_mode_line): Resurrect support for FACE = t.
    Doc fix.  (Bug#81271)
    
    * doc/lispref/modes.texi (Emulating Mode Line): Fix documentation
    of 'format-mode-line' when 2nd argument is t.
    
    * test/src/xdisp-tests.el (xdisp-test-format-mode-line): New test.
---
 doc/lispref/modes.texi  |  2 +-
 src/xdisp.c             |  7 ++++++-
 test/src/xdisp-tests.el | 13 +++++++++++++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 5f0e9a0fade..a2cc2198108 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -2869,7 +2869,7 @@ The value string normally has text properties that correspond to the
 faces, keymaps, etc., that the mode line would have.  Any character for
 which no @code{face} property is specified by @var{format} gets a
 default value determined by @var{face}.  If @var{face} is @code{t}, that
-stands for either @code{mode-line} if @var{window} is selected,
+stands for either @code{mode-line-active} if @var{window} is selected,
 otherwise @code{mode-line-inactive}.  If @var{face} is @code{nil} or
 omitted, that stands for the default face.  If @var{face} is an integer,
 the value returned by this function will have no text properties.
diff --git a/src/xdisp.c b/src/xdisp.c
index f0c787bcb5c..5080c5253a4 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -28985,7 +28985,7 @@ By default, the format is evaluated for the currently selected window.
 Optional second arg FACE specifies the face property to put on all
 characters for which no face is specified.  The value nil means the
 default face.  The value t means whatever face the window's mode line
-currently uses (either `mode-line' or `mode-line-inactive',
+currently uses (either `mode-line-active' or `mode-line-inactive',
 depending on whether the window is the selected window or not).
 An integer value means the value string has no text
 properties.
@@ -29036,6 +29036,11 @@ are the selected window and the WINDOW's buffer).  */)
     : EQ (face, Qtool_bar) ? TOOL_BAR_FACE_ID
     : DEFAULT_FACE_ID;
 
+  if (EQ (face, Qt))
+    face = EQ (window, selected_window)
+      ? Qmode_line_active
+      : Qmode_line_inactive;
+
   old_buffer = current_buffer;
 
   /* Save things including mode_line_proptrans_alist,
diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el
index 3b5ab902cc2..4369c00ca34 100644
--- a/test/src/xdisp-tests.el
+++ b/test/src/xdisp-tests.el
@@ -179,4 +179,17 @@ int main () {
         (buffer-string)))
     "foo\n")))
 
+(ert-deftest xdisp-test-format-mode-line ()
+  ;; 'format-mode-line' returns an empty string with no properties in
+  ;; noninteractive sessions.
+  (skip-when noninteractive)
+  (with-temp-buffer
+    (insert (format-mode-line " " t))
+    (should (equal (buffer-string) #(" " 0 1 (face mode-line-active)))))
+  (with-temp-buffer
+    (insert (format-mode-line
+             (propertize "x" 'face 'bold-italic)
+             1200000000000000000000000000))
+    (should (null (get-text-property 1 'face)))))
+
 ;;; xdisp-tests.el ends here
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.