* doc/lispref/modes.texi (Mode Line Basics): Mention it (bug#53629).
* lisp/bindings.el (mode-line-window-selected-p): New function
from martin rudalics <rudalics@gmx.at>.
@end defun
The selected window's mode line is usually displayed in a different
-color using the face @code{mode-line}. Other windows' mode lines appear
-in the face @code{mode-line-inactive} instead. @xref{Faces}.
+color using the face @code{mode-line-active}. Other windows' mode
+lines appear in the face @code{mode-line-inactive} instead.
+@xref{Faces}.
+
+@defun mode-line-window-selected-p
+If you want to have more extensive differences between the mode lines
+in selected and non-selected windows, you can use this predicate in an
+@code{:eval} construct. For instance, if you want to display the
+buffer name in bold in selected windows, but in italics in the other
+windows, you can say something like:
+
+@lisp
+(setq-default
+ mode-line-buffer-identification
+ '(:eval (propertize "%12b"
+ 'face (if (mode-line-window-selected-p)
+ 'bold
+ 'italic))))
+@end lisp
+@end defun
@vindex mode-line-compact
Some modes put a lot of data in the mode line, pushing elements at
\f
* Lisp Changes in Emacs 29.1
++++
+** New utility predicate 'mode-line-window-selected-p'.
+This is meant to be used from ':eval' mode line constructs to create
+different mode line looks for selected and unselected windows.
+
++++
** New variable 'messages-buffer-name'.
This variable (defaulting to "*Messages*") allows packages to override
where messages are logged.
(with-selected-window (posn-window (event-start event))
(previous-buffer)))
+(defun mode-line-window-selected-p ()
+ "Return non-nil if we're updating the mode line for the selected window.
+This function is meant to be called in `:eval' mode line
+constructs to allow altering the look of the mode line depending
+on whether the mode line belongs to the currently selected window
+or not."
+ (let ((window (selected-window)))
+ (or (eq window (old-selected-window))
+ (and (minibuffer-window-active-p (minibuffer-window))
+ (with-selected-window (minibuffer-window)
+ (eq window (minibuffer-selected-window)))))))
+
(defmacro bound-and-true-p (var)
"Return the value of symbol VAR if it is bound, else nil.
Note that if `lexical-binding' is in effect, this function isn't